blob: 6e11574ac6f2dbf266bfee0705a61118759bff63 [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>
dea31012005-04-17 16:05:31 -050037
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040038#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050039#include <scsi/scsi_device.h>
40#include <scsi/scsi_host.h>
41#include <scsi/scsi_transport_fc.h>
42
James Smartda0436e2009-05-22 14:51:39 -040043#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050044#include "lpfc_hw.h"
45#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040046#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040047#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050048#include "lpfc_disc.h"
49#include "lpfc_scsi.h"
50#include "lpfc.h"
51#include "lpfc_logmsg.h"
52#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050053#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050054#include "lpfc_version.h"
James Smart12f44452016-07-06 12:36:03 -070055#include "lpfc_ids.h"
dea31012005-04-17 16:05:31 -050056
James Smart81301a92008-12-04 22:39:46 -050057char *_dump_buf_data;
58unsigned long _dump_buf_data_order;
59char *_dump_buf_dif;
60unsigned long _dump_buf_dif_order;
61spinlock_t _dump_buf_lock;
62
James Smart7bb03bb2013-04-17 20:19:16 -040063/* Used when mapping IRQ vectors in a driver centric manner */
James Smartb246de12013-05-31 17:03:07 -040064uint16_t *lpfc_used_cpu;
65uint32_t lpfc_present_cpu;
James Smart7bb03bb2013-04-17 20:19:16 -040066
dea31012005-04-17 16:05:31 -050067static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
68static int lpfc_post_rcv_buf(struct lpfc_hba *);
James Smart5350d872011-10-10 21:33:49 -040069static int lpfc_sli4_queue_verify(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040070static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
71static int lpfc_setup_endian_order(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040072static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040073static void lpfc_free_els_sgl_list(struct lpfc_hba *);
74static void lpfc_init_sgl_list(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040075static int lpfc_init_active_sgl_array(struct lpfc_hba *);
76static void lpfc_free_active_sgl(struct lpfc_hba *);
77static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
78static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
79static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
80static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
81static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
James Smart618a5232012-06-12 13:54:36 -040082static void lpfc_sli4_disable_intr(struct lpfc_hba *);
83static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
James Smart1ba981f2014-02-20 09:56:45 -050084static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
dea31012005-04-17 16:05:31 -050085
86static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050087static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -050088static DEFINE_IDR(lpfc_hba_index);
89
James Smarte59058c2008-08-24 21:49:00 -040090/**
James Smart3621a712009-04-06 18:47:14 -040091 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
James Smarte59058c2008-08-24 21:49:00 -040092 * @phba: pointer to lpfc hba data structure.
93 *
94 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
95 * mailbox command. It retrieves the revision information from the HBA and
96 * collects the Vital Product Data (VPD) about the HBA for preparing the
97 * configuration of the HBA.
98 *
99 * Return codes:
100 * 0 - success.
101 * -ERESTART - requests the SLI layer to reset the HBA and try again.
102 * Any other value - indicates an error.
103 **/
dea31012005-04-17 16:05:31 -0500104int
James Smart2e0fef82007-06-17 19:56:36 -0500105lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500106{
107 lpfc_vpd_t *vp = &phba->vpd;
108 int i = 0, rc;
109 LPFC_MBOXQ_t *pmb;
110 MAILBOX_t *mb;
111 char *lpfc_vpd_data = NULL;
112 uint16_t offset = 0;
113 static char licensed[56] =
114 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -0400115 static int init_key = 1;
dea31012005-04-17 16:05:31 -0500116
117 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
118 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500119 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500120 return -ENOMEM;
121 }
122
James Smart04c68492009-05-22 14:52:52 -0400123 mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -0500124 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -0500125
126 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -0400127 if (init_key) {
128 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -0500129
James Smart65a29c12006-07-06 15:50:50 -0400130 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
131 *ptext = cpu_to_be32(*ptext);
132 init_key = 0;
133 }
dea31012005-04-17 16:05:31 -0500134
135 lpfc_read_nv(phba, pmb);
136 memset((char*)mb->un.varRDnvp.rsvd3, 0,
137 sizeof (mb->un.varRDnvp.rsvd3));
138 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
139 sizeof (licensed));
140
141 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
142
143 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500144 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400145 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500146 "error, mbxCmd x%x READ_NVPARM, "
147 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500148 mb->mbxCommand, mb->mbxStatus);
149 mempool_free(pmb, phba->mbox_mem_pool);
150 return -ERESTART;
151 }
152 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500153 sizeof(phba->wwnn));
154 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
155 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500156 }
157
James Smart92d7f7b2007-06-17 19:56:38 -0500158 phba->sli3_options = 0x0;
159
dea31012005-04-17 16:05:31 -0500160 /* Setup and issue mailbox READ REV command */
161 lpfc_read_rev(phba, pmb);
162 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
163 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500164 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400165 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500166 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500167 mb->mbxCommand, mb->mbxStatus);
168 mempool_free( pmb, phba->mbox_mem_pool);
169 return -ERESTART;
170 }
171
James Smart92d7f7b2007-06-17 19:56:38 -0500172
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500173 /*
174 * The value of rr must be 1 since the driver set the cv field to 1.
175 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500176 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500177 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500178 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500179 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400180 "0440 Adapter failed to init, READ_REV has "
181 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500182 mempool_free(pmb, phba->mbox_mem_pool);
183 return -ERESTART;
dea31012005-04-17 16:05:31 -0500184 }
185
James Smart495a7142008-06-14 22:52:59 -0400186 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
187 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500188 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400189 }
James Smarted957682007-06-17 19:56:37 -0500190
dea31012005-04-17 16:05:31 -0500191 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500192 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500193 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500194 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
195 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
196 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
197 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500198 vp->rev.biuRev = mb->un.varRdRev.biuRev;
199 vp->rev.smRev = mb->un.varRdRev.smRev;
200 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
201 vp->rev.endecRev = mb->un.varRdRev.endecRev;
202 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
203 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
204 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
205 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
206 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
207 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
208
James Smart92d7f7b2007-06-17 19:56:38 -0500209 /* If the sli feature level is less then 9, we must
210 * tear down all RPIs and VPIs on link down if NPIV
211 * is enabled.
212 */
213 if (vp->rev.feaLevelHigh < 9)
214 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
215
dea31012005-04-17 16:05:31 -0500216 if (lpfc_is_LC_HBA(phba->pcidev->device))
217 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
218 sizeof (phba->RandomData));
219
dea31012005-04-17 16:05:31 -0500220 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500221 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
222 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400223 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500224 do {
James Smarta0c87cb2009-07-19 10:01:10 -0400225 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
dea31012005-04-17 16:05:31 -0500226 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
227
228 if (rc != MBX_SUCCESS) {
229 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400230 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500231 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500232 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500233 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500234 }
James Smart04c68492009-05-22 14:52:52 -0400235 /* dump mem may return a zero when finished or we got a
236 * mailbox error, either way we are done.
237 */
238 if (mb->un.varDmp.word_cnt == 0)
239 break;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500240 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
241 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400242 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
243 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500244 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500245 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500246 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
247 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500248
249 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500250out_free_mbox:
251 mempool_free(pmb, phba->mbox_mem_pool);
252 return 0;
253}
254
James Smarte59058c2008-08-24 21:49:00 -0400255/**
James Smart3621a712009-04-06 18:47:14 -0400256 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
James Smarte59058c2008-08-24 21:49:00 -0400257 * @phba: pointer to lpfc hba data structure.
258 * @pmboxq: pointer to the driver internal queue element for mailbox command.
259 *
260 * This is the completion handler for driver's configuring asynchronous event
261 * mailbox command to the device. If the mailbox command returns successfully,
262 * it will set internal async event support flag to 1; otherwise, it will
263 * set internal async event support flag to 0.
264 **/
James Smart57127f12007-10-27 13:37:05 -0400265static void
266lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
267{
James Smart04c68492009-05-22 14:52:52 -0400268 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
James Smart57127f12007-10-27 13:37:05 -0400269 phba->temp_sensor_support = 1;
270 else
271 phba->temp_sensor_support = 0;
272 mempool_free(pmboxq, phba->mbox_mem_pool);
273 return;
274}
275
James Smarte59058c2008-08-24 21:49:00 -0400276/**
James Smart3621a712009-04-06 18:47:14 -0400277 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
James Smart97207482008-12-04 22:39:19 -0500278 * @phba: pointer to lpfc hba data structure.
279 * @pmboxq: pointer to the driver internal queue element for mailbox command.
280 *
281 * This is the completion handler for dump mailbox command for getting
282 * wake up parameters. When this command complete, the response contain
283 * Option rom version of the HBA. This function translate the version number
284 * into a human readable string and store it in OptionROMVersion.
285 **/
286static void
287lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
288{
289 struct prog_id *prg;
290 uint32_t prog_id_word;
291 char dist = ' ';
292 /* character array used for decoding dist type. */
293 char dist_char[] = "nabx";
294
James Smart04c68492009-05-22 14:52:52 -0400295 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
James Smart9f1e1b52008-12-04 22:39:40 -0500296 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500297 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500298 }
James Smart97207482008-12-04 22:39:19 -0500299
300 prg = (struct prog_id *) &prog_id_word;
301
302 /* word 7 contain option rom version */
James Smart04c68492009-05-22 14:52:52 -0400303 prog_id_word = pmboxq->u.mb.un.varWords[7];
James Smart97207482008-12-04 22:39:19 -0500304
305 /* Decode the Option rom version word to a readable string */
306 if (prg->dist < 4)
307 dist = dist_char[prg->dist];
308
309 if ((prg->dist == 3) && (prg->num == 0))
James Smarta2fc4aef2014-09-03 12:57:55 -0400310 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
James Smart97207482008-12-04 22:39:19 -0500311 prg->ver, prg->rev, prg->lev);
312 else
James Smarta2fc4aef2014-09-03 12:57:55 -0400313 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
James Smart97207482008-12-04 22:39:19 -0500314 prg->ver, prg->rev, prg->lev,
315 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500316 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500317 return;
318}
319
320/**
James Smart05580562011-05-24 11:40:48 -0400321 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
322 * cfg_soft_wwnn, cfg_soft_wwpn
323 * @vport: pointer to lpfc vport data structure.
324 *
325 *
326 * Return codes
327 * None.
328 **/
329void
330lpfc_update_vport_wwn(struct lpfc_vport *vport)
331{
332 /* If the soft name exists then update it using the service params */
333 if (vport->phba->cfg_soft_wwnn)
334 u64_to_wwn(vport->phba->cfg_soft_wwnn,
335 vport->fc_sparam.nodeName.u.wwn);
336 if (vport->phba->cfg_soft_wwpn)
337 u64_to_wwn(vport->phba->cfg_soft_wwpn,
338 vport->fc_sparam.portName.u.wwn);
339
340 /*
341 * If the name is empty or there exists a soft name
342 * then copy the service params name, otherwise use the fc name
343 */
344 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
345 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
346 sizeof(struct lpfc_name));
347 else
348 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
349 sizeof(struct lpfc_name));
350
351 if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn)
352 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
353 sizeof(struct lpfc_name));
354 else
355 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
356 sizeof(struct lpfc_name));
357}
358
359/**
James Smart3621a712009-04-06 18:47:14 -0400360 * lpfc_config_port_post - Perform lpfc initialization after config port
James Smarte59058c2008-08-24 21:49:00 -0400361 * @phba: pointer to lpfc hba data structure.
362 *
363 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
364 * command call. It performs all internal resource and state setups on the
365 * port: post IOCB buffers, enable appropriate host interrupt attentions,
366 * ELS ring timers, etc.
367 *
368 * Return codes
369 * 0 - success.
370 * Any other value - error.
371 **/
dea31012005-04-17 16:05:31 -0500372int
James Smart2e0fef82007-06-17 19:56:36 -0500373lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500374{
James Smart2e0fef82007-06-17 19:56:36 -0500375 struct lpfc_vport *vport = phba->pport;
James Smarta257bf92009-04-06 18:48:10 -0400376 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500377 LPFC_MBOXQ_t *pmb;
378 MAILBOX_t *mb;
379 struct lpfc_dmabuf *mp;
380 struct lpfc_sli *psli = &phba->sli;
381 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500382 int i, j;
383 int rc;
dea31012005-04-17 16:05:31 -0500384
James Smart7af67052007-10-27 13:38:11 -0400385 spin_lock_irq(&phba->hbalock);
386 /*
387 * If the Config port completed correctly the HBA is not
388 * over heated any more.
389 */
390 if (phba->over_temp_state == HBA_OVER_TEMP)
391 phba->over_temp_state = HBA_NORMAL_TEMP;
392 spin_unlock_irq(&phba->hbalock);
393
dea31012005-04-17 16:05:31 -0500394 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
395 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500396 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500397 return -ENOMEM;
398 }
James Smart04c68492009-05-22 14:52:52 -0400399 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500400
dea31012005-04-17 16:05:31 -0500401 /* Get login parameters for NID. */
James Smart9f1177a2010-02-26 14:12:57 -0500402 rc = lpfc_read_sparam(phba, pmb, 0);
403 if (rc) {
404 mempool_free(pmb, phba->mbox_mem_pool);
405 return -ENOMEM;
406 }
407
James Smarted957682007-06-17 19:56:37 -0500408 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500409 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500410 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400411 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500412 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500413 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500414 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500415 mp = (struct lpfc_dmabuf *) pmb->context1;
James Smart9f1177a2010-02-26 14:12:57 -0500416 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500417 lpfc_mbuf_free(phba, mp->virt, mp->phys);
418 kfree(mp);
419 return -EIO;
420 }
421
422 mp = (struct lpfc_dmabuf *) pmb->context1;
423
James Smart2e0fef82007-06-17 19:56:36 -0500424 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500425 lpfc_mbuf_free(phba, mp->virt, mp->phys);
426 kfree(mp);
427 pmb->context1 = NULL;
James Smart05580562011-05-24 11:40:48 -0400428 lpfc_update_vport_wwn(vport);
James Smarta257bf92009-04-06 18:48:10 -0400429
430 /* Update the fc_host data structures with new wwn. */
431 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
432 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart21e9a0a2009-05-22 14:53:21 -0400433 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smarta257bf92009-04-06 18:48:10 -0400434
dea31012005-04-17 16:05:31 -0500435 /* If no serial number in VPD data, use low 6 bytes of WWNN */
436 /* This should be consolidated into parse_vpd ? - mr */
437 if (phba->SerialNumber[0] == 0) {
438 uint8_t *outptr;
439
James Smart2e0fef82007-06-17 19:56:36 -0500440 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500441 for (i = 0; i < 12; i++) {
442 status = *outptr++;
443 j = ((status & 0xf0) >> 4);
444 if (j <= 9)
445 phba->SerialNumber[i] =
446 (char)((uint8_t) 0x30 + (uint8_t) j);
447 else
448 phba->SerialNumber[i] =
449 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
450 i++;
451 j = (status & 0xf);
452 if (j <= 9)
453 phba->SerialNumber[i] =
454 (char)((uint8_t) 0x30 + (uint8_t) j);
455 else
456 phba->SerialNumber[i] =
457 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
458 }
459 }
460
dea31012005-04-17 16:05:31 -0500461 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500462 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500463 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500464 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400465 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500466 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500467 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500468 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500469 mempool_free( pmb, phba->mbox_mem_pool);
470 return -EIO;
471 }
472
James Smarta0c87cb2009-07-19 10:01:10 -0400473 /* Check if the port is disabled */
474 lpfc_sli_read_link_ste(phba);
475
dea31012005-04-17 16:05:31 -0500476 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -0400477 i = (mb->un.varRdConfig.max_xri + 1);
478 if (phba->cfg_hba_queue_depth > i) {
479 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
480 "3359 HBA queue depth changed from %d to %d\n",
481 phba->cfg_hba_queue_depth, i);
482 phba->cfg_hba_queue_depth = i;
483 }
484
485 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
486 i = (mb->un.varRdConfig.max_xri >> 3);
487 if (phba->pport->cfg_lun_queue_depth > i) {
488 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
489 "3360 LUN queue depth changed from %d to %d\n",
490 phba->pport->cfg_lun_queue_depth, i);
491 phba->pport->cfg_lun_queue_depth = i;
492 }
dea31012005-04-17 16:05:31 -0500493
494 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500495
496 /* Get the default values for Model Name and Description */
497 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
498
James Smart2e0fef82007-06-17 19:56:36 -0500499 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500500
James Smart0b727fe2007-10-27 13:37:25 -0400501 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smart7e56aa22012-08-03 12:35:34 -0400502 if (psli->ring[psli->extra_ring].sli.sli3.cmdringaddr)
James Smarta4bc3372006-12-02 13:34:16 -0500503 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
James Smart7e56aa22012-08-03 12:35:34 -0400504 if (psli->ring[psli->fcp_ring].sli.sli3.cmdringaddr)
dea31012005-04-17 16:05:31 -0500505 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
James Smart7e56aa22012-08-03 12:35:34 -0400506 if (psli->ring[psli->next_ring].sli.sli3.cmdringaddr)
dea31012005-04-17 16:05:31 -0500507 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
508
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 Smartbcece5f2014-04-04 13:51:34 -0400895 pring = &psli->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;
928 struct lpfc_sli_ring *pring;
929 LIST_HEAD(completions);
930 int i;
931
James Smartbcece5f2014-04-04 13:51:34 -0400932 for (i = 0; i < psli->num_rings; i++) {
933 pring = &psli->ring[i];
934 if (phba->sli_rev >= LPFC_SLI_REV4)
935 spin_lock_irq(&pring->ring_lock);
936 else
937 spin_lock_irq(&phba->hbalock);
938 /* At this point in time the HBA is either reset or DOA. Either
939 * way, nothing should be on txcmplq as it will NEVER complete.
940 */
941 list_splice_init(&pring->txcmplq, &completions);
James Smartdb55fba2014-04-04 13:52:02 -0400942 pring->txcmplq_cnt = 0;
James Smartbcece5f2014-04-04 13:51:34 -0400943
944 if (phba->sli_rev >= LPFC_SLI_REV4)
945 spin_unlock_irq(&pring->ring_lock);
946 else
947 spin_unlock_irq(&phba->hbalock);
948
949 /* Cancel all the IOCBs from the completions list */
950 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
951 IOERR_SLI_ABORTED);
952 lpfc_sli_abort_iocb_ring(phba, pring);
953 }
954}
955
956/**
James Smart3772a992009-05-22 14:50:54 -0400957 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smartbcece5f2014-04-04 13:51:34 -0400958 int i;
James Smarte59058c2008-08-24 21:49:00 -0400959 * @phba: pointer to lpfc HBA data structure.
960 *
961 * This routine will do uninitialization after the HBA is reset when bring
962 * down the SLI Layer.
963 *
964 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200965 * 0 - success.
James Smarte59058c2008-08-24 21:49:00 -0400966 * Any other value - error.
967 **/
James Smart3772a992009-05-22 14:50:54 -0400968static int
969lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500970{
James Smartbcece5f2014-04-04 13:51:34 -0400971 lpfc_hba_free_post_buf(phba);
972 lpfc_hba_clean_txcmplq(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500973 return 0;
974}
James Smart5af5eee2010-10-22 11:06:38 -0400975
James Smartda0436e2009-05-22 14:51:39 -0400976/**
977 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
978 * @phba: pointer to lpfc HBA data structure.
979 *
980 * This routine will do uninitialization after the HBA is reset when bring
981 * down the SLI Layer.
982 *
983 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200984 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -0400985 * Any other value - error.
986 **/
987static int
988lpfc_hba_down_post_s4(struct lpfc_hba *phba)
989{
990 struct lpfc_scsi_buf *psb, *psb_next;
991 LIST_HEAD(aborts);
James Smartda0436e2009-05-22 14:51:39 -0400992 unsigned long iflag = 0;
James Smart0f65ff62010-02-26 14:14:23 -0500993 struct lpfc_sglq *sglq_entry = NULL;
James Smartdafe8ce2014-09-03 12:56:40 -0400994 struct lpfc_sli *psli = &phba->sli;
995 struct lpfc_sli_ring *pring;
James Smart0f65ff62010-02-26 14:14:23 -0500996
James Smartbcece5f2014-04-04 13:51:34 -0400997 lpfc_hba_free_post_buf(phba);
998 lpfc_hba_clean_txcmplq(phba);
James Smartdafe8ce2014-09-03 12:56:40 -0400999 pring = &psli->ring[LPFC_ELS_RING];
James Smartbcece5f2014-04-04 13:51:34 -04001000
James Smartda0436e2009-05-22 14:51:39 -04001001 /* At this point in time the HBA is either reset or DOA. Either
1002 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
1003 * on the lpfc_sgl_list so that it can either be freed if the
1004 * driver is unloading or reposted if the driver is restarting
1005 * the port.
1006 */
1007 spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */
1008 /* scsl_buf_list */
1009 /* abts_sgl_list_lock required because worker thread uses this
1010 * list.
1011 */
1012 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05001013 list_for_each_entry(sglq_entry,
1014 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1015 sglq_entry->state = SGL_FREED;
1016
James Smartdafe8ce2014-09-03 12:56:40 -04001017 spin_lock(&pring->ring_lock);
James Smartda0436e2009-05-22 14:51:39 -04001018 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
1019 &phba->sli4_hba.lpfc_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04001020 spin_unlock(&pring->ring_lock);
James Smartda0436e2009-05-22 14:51:39 -04001021 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
1022 /* abts_scsi_buf_list_lock required because worker thread uses this
1023 * list.
1024 */
1025 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1026 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
1027 &aborts);
1028 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1029 spin_unlock_irq(&phba->hbalock);
1030
1031 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1032 psb->pCmd = NULL;
1033 psb->status = IOSTAT_SUCCESS;
1034 }
James Smarta40fc5f2013-04-17 20:17:40 -04001035 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1036 list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
1037 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
James Smart68e814f2014-05-21 08:04:59 -04001038
1039 lpfc_sli4_free_sp_events(phba);
James Smartda0436e2009-05-22 14:51:39 -04001040 return 0;
1041}
1042
1043/**
1044 * lpfc_hba_down_post - Wrapper func for hba down post routine
1045 * @phba: pointer to lpfc HBA data structure.
1046 *
1047 * This routine wraps the actual SLI3 or SLI4 routine for performing
1048 * uninitialization after the HBA is reset when bring down the SLI Layer.
1049 *
1050 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001051 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001052 * Any other value - error.
1053 **/
1054int
1055lpfc_hba_down_post(struct lpfc_hba *phba)
1056{
1057 return (*phba->lpfc_hba_down_post)(phba);
1058}
Jamie Wellnitz41415862006-02-28 19:25:27 -05001059
James Smarte59058c2008-08-24 21:49:00 -04001060/**
James Smart3621a712009-04-06 18:47:14 -04001061 * lpfc_hb_timeout - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001062 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1063 *
1064 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1065 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1066 * work-port-events bitmap and the worker thread is notified. This timeout
1067 * event will be used by the worker thread to invoke the actual timeout
1068 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1069 * be performed in the timeout handler and the HBA timeout event bit shall
1070 * be cleared by the worker thread after it has taken the event bitmap out.
1071 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001072static void
James Smart858c9f62007-06-17 19:56:39 -05001073lpfc_hb_timeout(unsigned long ptr)
1074{
1075 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001076 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -05001077 unsigned long iflag;
1078
1079 phba = (struct lpfc_hba *)ptr;
James Smart93996272008-08-24 21:50:30 -04001080
1081 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -05001082 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001083 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1084 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -05001085 phba->pport->work_port_events |= WORKER_HB_TMO;
1086 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1087
James Smart93996272008-08-24 21:50:30 -04001088 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -04001089 if (!tmo_posted)
1090 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -05001091 return;
1092}
1093
James Smarte59058c2008-08-24 21:49:00 -04001094/**
James Smart19ca7602010-11-20 23:11:55 -05001095 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1096 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1097 *
1098 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1099 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1100 * work-port-events bitmap and the worker thread is notified. This timeout
1101 * event will be used by the worker thread to invoke the actual timeout
1102 * handler routine, lpfc_rrq_handler. Any periodical operations will
1103 * be performed in the timeout handler and the RRQ timeout event bit shall
1104 * be cleared by the worker thread after it has taken the event bitmap out.
1105 **/
1106static void
1107lpfc_rrq_timeout(unsigned long ptr)
1108{
1109 struct lpfc_hba *phba;
James Smart19ca7602010-11-20 23:11:55 -05001110 unsigned long iflag;
1111
1112 phba = (struct lpfc_hba *)ptr;
1113 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001114 if (!(phba->pport->load_flag & FC_UNLOADING))
1115 phba->hba_flag |= HBA_RRQ_ACTIVE;
1116 else
1117 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
James Smart19ca7602010-11-20 23:11:55 -05001118 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001119
1120 if (!(phba->pport->load_flag & FC_UNLOADING))
1121 lpfc_worker_wake_up(phba);
James Smart19ca7602010-11-20 23:11:55 -05001122}
1123
1124/**
James Smart3621a712009-04-06 18:47:14 -04001125 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -04001126 * @phba: pointer to lpfc hba data structure.
1127 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1128 *
1129 * This is the callback function to the lpfc heart-beat mailbox command.
1130 * If configured, the lpfc driver issues the heart-beat mailbox command to
1131 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1132 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1133 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1134 * heart-beat outstanding state. Once the mailbox command comes back and
1135 * no error conditions detected, the heart-beat mailbox command timer is
1136 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1137 * state is cleared for the next heart-beat. If the timer expired with the
1138 * heart-beat outstanding state set, the driver will put the HBA offline.
1139 **/
James Smart858c9f62007-06-17 19:56:39 -05001140static void
1141lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1142{
1143 unsigned long drvr_flag;
1144
1145 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1146 phba->hb_outstanding = 0;
1147 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1148
James Smart93996272008-08-24 21:50:30 -04001149 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -05001150 mempool_free(pmboxq, phba->mbox_mem_pool);
1151 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1152 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -04001153 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -05001154 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001155 jiffies +
1156 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001157 return;
1158}
1159
James Smarte59058c2008-08-24 21:49:00 -04001160/**
James Smart3621a712009-04-06 18:47:14 -04001161 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001162 * @phba: pointer to lpfc hba data structure.
1163 *
1164 * This is the actual HBA-timer timeout handler to be invoked by the worker
1165 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1166 * handler performs any periodic operations needed for the device. If such
1167 * periodic event has already been attended to either in the interrupt handler
1168 * or by processing slow-ring or fast-ring events within the HBA-timer
1169 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1170 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1171 * is configured and there is no heart-beat mailbox command outstanding, a
1172 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1173 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1174 * to offline.
1175 **/
James Smart858c9f62007-06-17 19:56:39 -05001176void
1177lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1178{
James Smart45ed1192009-10-02 15:17:02 -04001179 struct lpfc_vport **vports;
James Smart858c9f62007-06-17 19:56:39 -05001180 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -05001181 struct lpfc_dmabuf *buf_ptr;
James Smart45ed1192009-10-02 15:17:02 -04001182 int retval, i;
James Smart858c9f62007-06-17 19:56:39 -05001183 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -05001184 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -05001185
James Smart45ed1192009-10-02 15:17:02 -04001186 vports = lpfc_create_vport_work_array(phba);
1187 if (vports != NULL)
James Smart4258e982015-12-16 18:11:58 -05001188 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart45ed1192009-10-02 15:17:02 -04001189 lpfc_rcv_seq_check_edtov(vports[i]);
James Smart4258e982015-12-16 18:11:58 -05001190 lpfc_fdmi_num_disc_check(vports[i]);
1191 }
James Smart45ed1192009-10-02 15:17:02 -04001192 lpfc_destroy_vport_work_array(phba, vports);
1193
James Smart858c9f62007-06-17 19:56:39 -05001194 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -04001195 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -05001196 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1197 return;
1198
1199 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -05001200
James Smart256ec0d2013-04-17 20:14:58 -04001201 if (time_after(phba->last_completion_time +
1202 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1203 jiffies)) {
James Smart858c9f62007-06-17 19:56:39 -05001204 spin_unlock_irq(&phba->pport->work_port_lock);
1205 if (!phba->hb_outstanding)
1206 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001207 jiffies +
1208 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001209 else
1210 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001211 jiffies +
1212 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001213 return;
1214 }
1215 spin_unlock_irq(&phba->pport->work_port_lock);
1216
James Smart0ff10d42008-01-11 01:52:36 -05001217 if (phba->elsbuf_cnt &&
1218 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1219 spin_lock_irq(&phba->hbalock);
1220 list_splice_init(&phba->elsbuf, &completions);
1221 phba->elsbuf_cnt = 0;
1222 phba->elsbuf_prev_cnt = 0;
1223 spin_unlock_irq(&phba->hbalock);
1224
1225 while (!list_empty(&completions)) {
1226 list_remove_head(&completions, buf_ptr,
1227 struct lpfc_dmabuf, list);
1228 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1229 kfree(buf_ptr);
1230 }
1231 }
1232 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1233
James Smart858c9f62007-06-17 19:56:39 -05001234 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -05001235 if (phba->cfg_enable_hba_heartbeat) {
1236 if (!phba->hb_outstanding) {
James Smartbc739052010-08-04 16:11:18 -04001237 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1238 (list_empty(&psli->mboxq))) {
1239 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1240 GFP_KERNEL);
1241 if (!pmboxq) {
1242 mod_timer(&phba->hb_tmofunc,
1243 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001244 msecs_to_jiffies(1000 *
1245 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001246 return;
1247 }
James Smart13815c82008-01-11 01:52:48 -05001248
James Smartbc739052010-08-04 16:11:18 -04001249 lpfc_heart_beat(phba, pmboxq);
1250 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1251 pmboxq->vport = phba->pport;
1252 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1253 MBX_NOWAIT);
James Smart13815c82008-01-11 01:52:48 -05001254
James Smartbc739052010-08-04 16:11:18 -04001255 if (retval != MBX_BUSY &&
1256 retval != MBX_SUCCESS) {
1257 mempool_free(pmboxq,
1258 phba->mbox_mem_pool);
1259 mod_timer(&phba->hb_tmofunc,
1260 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001261 msecs_to_jiffies(1000 *
1262 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001263 return;
1264 }
1265 phba->skipped_hb = 0;
1266 phba->hb_outstanding = 1;
1267 } else if (time_before_eq(phba->last_completion_time,
1268 phba->skipped_hb)) {
1269 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1270 "2857 Last completion time not "
1271 " updated in %d ms\n",
1272 jiffies_to_msecs(jiffies
1273 - phba->last_completion_time));
1274 } else
1275 phba->skipped_hb = jiffies;
1276
James Smart858c9f62007-06-17 19:56:39 -05001277 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001278 jiffies +
1279 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001280 return;
James Smart13815c82008-01-11 01:52:48 -05001281 } else {
1282 /*
1283 * If heart beat timeout called with hb_outstanding set
James Smartdcf2a4e2010-09-29 11:18:53 -04001284 * we need to give the hb mailbox cmd a chance to
1285 * complete or TMO.
James Smart13815c82008-01-11 01:52:48 -05001286 */
James Smartdcf2a4e2010-09-29 11:18:53 -04001287 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1288 "0459 Adapter heartbeat still out"
1289 "standing:last compl time was %d ms.\n",
1290 jiffies_to_msecs(jiffies
1291 - phba->last_completion_time));
1292 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001293 jiffies +
1294 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001295 }
James Smart4258e982015-12-16 18:11:58 -05001296 } else {
1297 mod_timer(&phba->hb_tmofunc,
1298 jiffies +
1299 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001300 }
1301}
1302
James Smarte59058c2008-08-24 21:49:00 -04001303/**
James Smart3621a712009-04-06 18:47:14 -04001304 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -04001305 * @phba: pointer to lpfc hba data structure.
1306 *
1307 * This routine is called to bring the HBA offline when HBA hardware error
1308 * other than Port Error 6 has been detected.
1309 **/
James Smart09372822008-01-11 01:52:54 -05001310static void
1311lpfc_offline_eratt(struct lpfc_hba *phba)
1312{
1313 struct lpfc_sli *psli = &phba->sli;
1314
1315 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001316 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -05001317 spin_unlock_irq(&phba->hbalock);
James Smart618a5232012-06-12 13:54:36 -04001318 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart09372822008-01-11 01:52:54 -05001319
1320 lpfc_offline(phba);
1321 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001322 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001323 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001324 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001325 lpfc_hba_down_post(phba);
1326 lpfc_sli_brdready(phba, HS_MBRDY);
1327 lpfc_unblock_mgmt_io(phba);
1328 phba->link_state = LPFC_HBA_ERROR;
1329 return;
1330}
1331
James Smarte59058c2008-08-24 21:49:00 -04001332/**
James Smartda0436e2009-05-22 14:51:39 -04001333 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1334 * @phba: pointer to lpfc hba data structure.
1335 *
1336 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1337 * other than Port Error 6 has been detected.
1338 **/
James Smarta88dbb62013-04-17 20:18:39 -04001339void
James Smartda0436e2009-05-22 14:51:39 -04001340lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1341{
James Smart946727d2015-04-07 15:07:09 -04001342 spin_lock_irq(&phba->hbalock);
1343 phba->link_state = LPFC_HBA_ERROR;
1344 spin_unlock_irq(&phba->hbalock);
1345
James Smart618a5232012-06-12 13:54:36 -04001346 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smartda0436e2009-05-22 14:51:39 -04001347 lpfc_offline(phba);
James Smartda0436e2009-05-22 14:51:39 -04001348 lpfc_hba_down_post(phba);
James Smartda0436e2009-05-22 14:51:39 -04001349 lpfc_unblock_mgmt_io(phba);
James Smartda0436e2009-05-22 14:51:39 -04001350}
1351
1352/**
James Smarta257bf92009-04-06 18:48:10 -04001353 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1354 * @phba: pointer to lpfc hba data structure.
1355 *
1356 * This routine is invoked to handle the deferred HBA hardware error
1357 * conditions. This type of error is indicated by HBA by setting ER1
1358 * and another ER bit in the host status register. The driver will
1359 * wait until the ER1 bit clears before handling the error condition.
1360 **/
1361static void
1362lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1363{
1364 uint32_t old_host_status = phba->work_hs;
James Smarta257bf92009-04-06 18:48:10 -04001365 struct lpfc_sli *psli = &phba->sli;
1366
James Smartf4b4c682009-05-22 14:53:12 -04001367 /* If the pci channel is offline, ignore possible errors,
1368 * since we cannot communicate with the pci card anyway.
1369 */
1370 if (pci_channel_offline(phba->pcidev)) {
1371 spin_lock_irq(&phba->hbalock);
1372 phba->hba_flag &= ~DEFER_ERATT;
1373 spin_unlock_irq(&phba->hbalock);
1374 return;
1375 }
1376
James Smarta257bf92009-04-06 18:48:10 -04001377 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1378 "0479 Deferred Adapter Hardware Error "
1379 "Data: x%x x%x x%x\n",
1380 phba->work_hs,
1381 phba->work_status[0], phba->work_status[1]);
1382
1383 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001384 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001385 spin_unlock_irq(&phba->hbalock);
1386
1387
1388 /*
1389 * Firmware stops when it triggred erratt. That could cause the I/Os
1390 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1391 * SCSI layer retry it after re-establishing link.
1392 */
James Smartdb55fba2014-04-04 13:52:02 -04001393 lpfc_sli_abort_fcp_rings(phba);
James Smarta257bf92009-04-06 18:48:10 -04001394
1395 /*
1396 * There was a firmware error. Take the hba offline and then
1397 * attempt to restart it.
1398 */
James Smart618a5232012-06-12 13:54:36 -04001399 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smarta257bf92009-04-06 18:48:10 -04001400 lpfc_offline(phba);
1401
1402 /* Wait for the ER1 bit to clear.*/
1403 while (phba->work_hs & HS_FFER1) {
1404 msleep(100);
James Smart9940b972011-03-11 16:06:12 -05001405 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1406 phba->work_hs = UNPLUG_ERR ;
1407 break;
1408 }
James Smarta257bf92009-04-06 18:48:10 -04001409 /* If driver is unloading let the worker thread continue */
1410 if (phba->pport->load_flag & FC_UNLOADING) {
1411 phba->work_hs = 0;
1412 break;
1413 }
1414 }
1415
1416 /*
1417 * This is to ptrotect against a race condition in which
1418 * first write to the host attention register clear the
1419 * host status register.
1420 */
1421 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1422 phba->work_hs = old_host_status & ~HS_FFER1;
1423
James Smart3772a992009-05-22 14:50:54 -04001424 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001425 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001426 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001427 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1428 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1429}
1430
James Smart3772a992009-05-22 14:50:54 -04001431static void
1432lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1433{
1434 struct lpfc_board_event_header board_event;
1435 struct Scsi_Host *shost;
1436
1437 board_event.event_type = FC_REG_BOARD_EVENT;
1438 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1439 shost = lpfc_shost_from_vport(phba->pport);
1440 fc_host_post_vendor_event(shost, fc_get_event_number(),
1441 sizeof(board_event),
1442 (char *) &board_event,
1443 LPFC_NL_VENDOR_ID);
1444}
1445
James Smarta257bf92009-04-06 18:48:10 -04001446/**
James Smart3772a992009-05-22 14:50:54 -04001447 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001448 * @phba: pointer to lpfc hba data structure.
1449 *
1450 * This routine is invoked to handle the following HBA hardware error
1451 * conditions:
1452 * 1 - HBA error attention interrupt
1453 * 2 - DMA ring index out of range
1454 * 3 - Mailbox command came back as unknown
1455 **/
James Smart3772a992009-05-22 14:50:54 -04001456static void
1457lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001458{
James Smart2e0fef82007-06-17 19:56:36 -05001459 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001460 struct lpfc_sli *psli = &phba->sli;
James Smartd2873e42006-08-18 17:46:43 -04001461 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001462 unsigned long temperature;
1463 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001464 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001465
Linas Vepstas8d63f372007-02-14 14:28:36 -06001466 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001467 * since we cannot communicate with the pci card anyway.
1468 */
1469 if (pci_channel_offline(phba->pcidev)) {
1470 spin_lock_irq(&phba->hbalock);
1471 phba->hba_flag &= ~DEFER_ERATT;
1472 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001473 return;
James Smart3772a992009-05-22 14:50:54 -04001474 }
1475
James Smart13815c82008-01-11 01:52:48 -05001476 /* If resets are disabled then leave the HBA alone and return */
1477 if (!phba->cfg_enable_hba_reset)
1478 return;
dea31012005-04-17 16:05:31 -05001479
James Smartea2151b2008-09-07 11:52:10 -04001480 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001481 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001482
James Smarta257bf92009-04-06 18:48:10 -04001483 if (phba->hba_flag & DEFER_ERATT)
1484 lpfc_handle_deferred_eratt(phba);
1485
James Smartdcf2a4e2010-09-29 11:18:53 -04001486 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1487 if (phba->work_hs & HS_FFER6)
1488 /* Re-establishing Link */
1489 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1490 "1301 Re-establishing Link "
1491 "Data: x%x x%x x%x\n",
1492 phba->work_hs, phba->work_status[0],
1493 phba->work_status[1]);
1494 if (phba->work_hs & HS_FFER8)
1495 /* Device Zeroization */
1496 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1497 "2861 Host Authentication device "
1498 "zeroization Data:x%x x%x x%x\n",
1499 phba->work_hs, phba->work_status[0],
1500 phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001501
James Smart92d7f7b2007-06-17 19:56:38 -05001502 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001503 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001504 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001505
1506 /*
1507 * Firmware stops when it triggled erratt with HS_FFER6.
1508 * That could cause the I/Os dropped by the firmware.
1509 * Error iocb (I/O) on txcmplq and let the SCSI layer
1510 * retry it after re-establishing link.
1511 */
James Smartdb55fba2014-04-04 13:52:02 -04001512 lpfc_sli_abort_fcp_rings(phba);
dea31012005-04-17 16:05:31 -05001513
dea31012005-04-17 16:05:31 -05001514 /*
1515 * There was a firmware error. Take the hba offline and then
1516 * attempt to restart it.
1517 */
James Smart618a5232012-06-12 13:54:36 -04001518 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
dea31012005-04-17 16:05:31 -05001519 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001520 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001521 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001522 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001523 return;
1524 }
James Smart46fa3112007-04-25 09:51:45 -04001525 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001526 } else if (phba->work_hs & HS_CRIT_TEMP) {
1527 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1528 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1529 temp_event_data.event_code = LPFC_CRIT_TEMP;
1530 temp_event_data.data = (uint32_t)temperature;
1531
1532 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001533 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001534 "(%ld), taking this port offline "
1535 "Data: x%x x%x x%x\n",
1536 temperature, phba->work_hs,
1537 phba->work_status[0], phba->work_status[1]);
1538
1539 shost = lpfc_shost_from_vport(phba->pport);
1540 fc_host_post_vendor_event(shost, fc_get_event_number(),
1541 sizeof(temp_event_data),
1542 (char *) &temp_event_data,
1543 SCSI_NL_VID_TYPE_PCI
1544 | PCI_VENDOR_ID_EMULEX);
1545
James Smart7af67052007-10-27 13:38:11 -04001546 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001547 phba->over_temp_state = HBA_OVER_TEMP;
1548 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001549 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001550
dea31012005-04-17 16:05:31 -05001551 } else {
1552 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001553 * failure is a value other than FFER6. Do not call the offline
1554 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001555 */
1556 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001557 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001558 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001559 phba->work_hs,
dea31012005-04-17 16:05:31 -05001560 phba->work_status[0], phba->work_status[1]);
1561
James Smartd2873e42006-08-18 17:46:43 -04001562 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001563 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001564 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001565 sizeof(event_data), (char *) &event_data,
1566 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1567
James Smart09372822008-01-11 01:52:54 -05001568 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001569 }
James Smart93996272008-08-24 21:50:30 -04001570 return;
dea31012005-04-17 16:05:31 -05001571}
1572
James Smarte59058c2008-08-24 21:49:00 -04001573/**
James Smart618a5232012-06-12 13:54:36 -04001574 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1575 * @phba: pointer to lpfc hba data structure.
1576 * @mbx_action: flag for mailbox shutdown action.
1577 *
1578 * This routine is invoked to perform an SLI4 port PCI function reset in
1579 * response to port status register polling attention. It waits for port
1580 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1581 * During this process, interrupt vectors are freed and later requested
1582 * for handling possible port resource change.
1583 **/
1584static int
James Smarte10b2022014-02-20 09:57:43 -05001585lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1586 bool en_rn_msg)
James Smart618a5232012-06-12 13:54:36 -04001587{
1588 int rc;
1589 uint32_t intr_mode;
1590
James Smart65791f12016-07-06 12:35:56 -07001591 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1592 LPFC_SLI_INTF_IF_TYPE_2) {
1593 /*
1594 * On error status condition, driver need to wait for port
1595 * ready before performing reset.
1596 */
1597 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1598 if (!rc)
1599 return rc;
James Smart618a5232012-06-12 13:54:36 -04001600 }
James Smart65791f12016-07-06 12:35:56 -07001601 /* need reset: attempt for port recovery */
1602 if (en_rn_msg)
1603 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1604 "2887 Reset Needed: Attempting Port "
1605 "Recovery...\n");
1606 lpfc_offline_prep(phba, mbx_action);
1607 lpfc_offline(phba);
1608 /* release interrupt for possible resource change */
1609 lpfc_sli4_disable_intr(phba);
1610 lpfc_sli_brdrestart(phba);
1611 /* request and enable interrupt */
1612 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1613 if (intr_mode == LPFC_INTR_ERROR) {
1614 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1615 "3175 Failed to enable interrupt\n");
1616 return -EIO;
1617 }
1618 phba->intr_mode = intr_mode;
1619 rc = lpfc_online(phba);
1620 if (rc == 0)
1621 lpfc_unblock_mgmt_io(phba);
1622
James Smart618a5232012-06-12 13:54:36 -04001623 return rc;
1624}
1625
1626/**
James Smartda0436e2009-05-22 14:51:39 -04001627 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1628 * @phba: pointer to lpfc hba data structure.
1629 *
1630 * This routine is invoked to handle the SLI4 HBA hardware error attention
1631 * conditions.
1632 **/
1633static void
1634lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1635{
1636 struct lpfc_vport *vport = phba->pport;
1637 uint32_t event_data;
1638 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001639 uint32_t if_type;
James Smart2e90f4b2011-12-13 13:22:37 -05001640 struct lpfc_register portstat_reg = {0};
1641 uint32_t reg_err1, reg_err2;
1642 uint32_t uerrlo_reg, uemasklo_reg;
James Smart65791f12016-07-06 12:35:56 -07001643 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
James Smarte10b2022014-02-20 09:57:43 -05001644 bool en_rn_msg = true;
James Smart946727d2015-04-07 15:07:09 -04001645 struct temp_event temp_event_data;
James Smart65791f12016-07-06 12:35:56 -07001646 struct lpfc_register portsmphr_reg;
1647 int rc, i;
James Smartda0436e2009-05-22 14:51:39 -04001648
1649 /* If the pci channel is offline, ignore possible errors, since
1650 * we cannot communicate with the pci card anyway.
1651 */
1652 if (pci_channel_offline(phba->pcidev))
1653 return;
James Smartda0436e2009-05-22 14:51:39 -04001654
James Smart65791f12016-07-06 12:35:56 -07001655 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
James Smart2fcee4b2010-12-15 17:57:46 -05001656 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1657 switch (if_type) {
1658 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart2e90f4b2011-12-13 13:22:37 -05001659 pci_rd_rc1 = lpfc_readl(
1660 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1661 &uerrlo_reg);
1662 pci_rd_rc2 = lpfc_readl(
1663 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1664 &uemasklo_reg);
1665 /* consider PCI bus read error as pci_channel_offline */
1666 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1667 return;
James Smart65791f12016-07-06 12:35:56 -07001668 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
1669 lpfc_sli4_offline_eratt(phba);
1670 return;
1671 }
1672 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1673 "7623 Checking UE recoverable");
1674
1675 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
1676 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1677 &portsmphr_reg.word0))
1678 continue;
1679
1680 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
1681 &portsmphr_reg);
1682 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1683 LPFC_PORT_SEM_UE_RECOVERABLE)
1684 break;
1685 /*Sleep for 1Sec, before checking SEMAPHORE */
1686 msleep(1000);
1687 }
1688
1689 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1690 "4827 smphr_port_status x%x : Waited %dSec",
1691 smphr_port_status, i);
1692
1693 /* Recoverable UE, reset the HBA device */
1694 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1695 LPFC_PORT_SEM_UE_RECOVERABLE) {
1696 for (i = 0; i < 20; i++) {
1697 msleep(1000);
1698 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1699 &portsmphr_reg.word0) &&
1700 (LPFC_POST_STAGE_PORT_READY ==
1701 bf_get(lpfc_port_smphr_port_status,
1702 &portsmphr_reg))) {
1703 rc = lpfc_sli4_port_sta_fn_reset(phba,
1704 LPFC_MBX_NO_WAIT, en_rn_msg);
1705 if (rc == 0)
1706 return;
1707 lpfc_printf_log(phba,
1708 KERN_ERR, LOG_INIT,
1709 "4215 Failed to recover UE");
1710 break;
1711 }
1712 }
1713 }
1714 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1715 "7624 Firmware not ready: Failing UE recovery,"
1716 " waited %dSec", i);
James Smart2fcee4b2010-12-15 17:57:46 -05001717 lpfc_sli4_offline_eratt(phba);
1718 break;
James Smart946727d2015-04-07 15:07:09 -04001719
James Smart2fcee4b2010-12-15 17:57:46 -05001720 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2e90f4b2011-12-13 13:22:37 -05001721 pci_rd_rc1 = lpfc_readl(
1722 phba->sli4_hba.u.if_type2.STATUSregaddr,
1723 &portstat_reg.word0);
1724 /* consider PCI bus read error as pci_channel_offline */
James Smart6b5151f2012-01-18 16:24:06 -05001725 if (pci_rd_rc1 == -EIO) {
1726 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1727 "3151 PCI bus read access failure: x%x\n",
1728 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
James Smart2e90f4b2011-12-13 13:22:37 -05001729 return;
James Smart6b5151f2012-01-18 16:24:06 -05001730 }
James Smart2e90f4b2011-12-13 13:22:37 -05001731 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1732 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
James Smart2fcee4b2010-12-15 17:57:46 -05001733 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
James Smart2fcee4b2010-12-15 17:57:46 -05001734 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1735 "2889 Port Overtemperature event, "
James Smart946727d2015-04-07 15:07:09 -04001736 "taking port offline Data: x%x x%x\n",
1737 reg_err1, reg_err2);
1738
James Smart310429e2016-07-06 12:35:54 -07001739 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04001740 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1741 temp_event_data.event_code = LPFC_CRIT_TEMP;
1742 temp_event_data.data = 0xFFFFFFFF;
1743
1744 shost = lpfc_shost_from_vport(phba->pport);
1745 fc_host_post_vendor_event(shost, fc_get_event_number(),
1746 sizeof(temp_event_data),
1747 (char *)&temp_event_data,
1748 SCSI_NL_VID_TYPE_PCI
1749 | PCI_VENDOR_ID_EMULEX);
1750
James Smart2fcee4b2010-12-15 17:57:46 -05001751 spin_lock_irq(&phba->hbalock);
1752 phba->over_temp_state = HBA_OVER_TEMP;
1753 spin_unlock_irq(&phba->hbalock);
1754 lpfc_sli4_offline_eratt(phba);
James Smart946727d2015-04-07 15:07:09 -04001755 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001756 }
James Smart2e90f4b2011-12-13 13:22:37 -05001757 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smarte10b2022014-02-20 09:57:43 -05001758 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
James Smart2e90f4b2011-12-13 13:22:37 -05001759 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte10b2022014-02-20 09:57:43 -05001760 "3143 Port Down: Firmware Update "
1761 "Detected\n");
1762 en_rn_msg = false;
1763 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smart2e90f4b2011-12-13 13:22:37 -05001764 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1765 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1766 "3144 Port Down: Debug Dump\n");
1767 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1768 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1769 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1770 "3145 Port Down: Provisioning\n");
James Smart618a5232012-06-12 13:54:36 -04001771
James Smart946727d2015-04-07 15:07:09 -04001772 /* If resets are disabled then leave the HBA alone and return */
1773 if (!phba->cfg_enable_hba_reset)
1774 return;
1775
James Smart618a5232012-06-12 13:54:36 -04001776 /* Check port status register for function reset */
James Smarte10b2022014-02-20 09:57:43 -05001777 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1778 en_rn_msg);
James Smart618a5232012-06-12 13:54:36 -04001779 if (rc == 0) {
1780 /* don't report event on forced debug dump */
1781 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1782 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1783 return;
1784 else
1785 break;
James Smart2fcee4b2010-12-15 17:57:46 -05001786 }
James Smart618a5232012-06-12 13:54:36 -04001787 /* fall through for not able to recover */
James Smart6b5151f2012-01-18 16:24:06 -05001788 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1789 "3152 Unrecoverable error, bring the port "
1790 "offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05001791 lpfc_sli4_offline_eratt(phba);
1792 break;
1793 case LPFC_SLI_INTF_IF_TYPE_1:
1794 default:
1795 break;
1796 }
James Smart2e90f4b2011-12-13 13:22:37 -05001797 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1798 "3123 Report dump event to upper layer\n");
1799 /* Send an internal error event to mgmt application */
1800 lpfc_board_errevt_to_mgmt(phba);
1801
1802 event_data = FC_REG_DUMP_EVENT;
1803 shost = lpfc_shost_from_vport(vport);
1804 fc_host_post_vendor_event(shost, fc_get_event_number(),
1805 sizeof(event_data), (char *) &event_data,
1806 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
James Smartda0436e2009-05-22 14:51:39 -04001807}
1808
1809/**
1810 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1811 * @phba: pointer to lpfc HBA data structure.
1812 *
1813 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1814 * routine from the API jump table function pointer from the lpfc_hba struct.
1815 *
1816 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001817 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001818 * Any other value - error.
1819 **/
1820void
1821lpfc_handle_eratt(struct lpfc_hba *phba)
1822{
1823 (*phba->lpfc_handle_eratt)(phba);
1824}
1825
1826/**
James Smart3621a712009-04-06 18:47:14 -04001827 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04001828 * @phba: pointer to lpfc hba data structure.
1829 *
1830 * This routine is invoked from the worker thread to handle a HBA host
1831 * attention link event.
1832 **/
dea31012005-04-17 16:05:31 -05001833void
James Smart2e0fef82007-06-17 19:56:36 -05001834lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001835{
James Smart2e0fef82007-06-17 19:56:36 -05001836 struct lpfc_vport *vport = phba->pport;
1837 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001838 LPFC_MBOXQ_t *pmb;
1839 volatile uint32_t control;
1840 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05001841 int rc = 0;
dea31012005-04-17 16:05:31 -05001842
1843 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001844 if (!pmb) {
1845 rc = 1;
dea31012005-04-17 16:05:31 -05001846 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05001847 }
dea31012005-04-17 16:05:31 -05001848
1849 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001850 if (!mp) {
1851 rc = 2;
dea31012005-04-17 16:05:31 -05001852 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05001853 }
dea31012005-04-17 16:05:31 -05001854
1855 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05001856 if (!mp->virt) {
1857 rc = 3;
dea31012005-04-17 16:05:31 -05001858 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05001859 }
dea31012005-04-17 16:05:31 -05001860
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001861 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04001862 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05001863
1864 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05001865 lpfc_read_topology(phba, pmb, mp);
1866 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05001867 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04001868 /* Block ELS IOCBs until we have processed this mbox command */
1869 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04001870 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05001871 if (rc == MBX_NOT_FINISHED) {
1872 rc = 4;
James Smart14691152006-12-02 13:34:28 -05001873 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05001874 }
dea31012005-04-17 16:05:31 -05001875
1876 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05001877 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001878 writel(HA_LATT, phba->HAregaddr);
1879 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001880 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001881
1882 return;
1883
James Smart14691152006-12-02 13:34:28 -05001884lpfc_handle_latt_free_mbuf:
James Smart0d2b6b82008-06-14 22:52:47 -04001885 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05001886 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05001887lpfc_handle_latt_free_mp:
1888 kfree(mp);
1889lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04001890 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001891lpfc_handle_latt_err_exit:
1892 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001893 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001894 psli->sli_flag |= LPFC_PROCESS_LA;
1895 control = readl(phba->HCregaddr);
1896 control |= HC_LAINT_ENA;
1897 writel(control, phba->HCregaddr);
1898 readl(phba->HCregaddr); /* flush */
1899
1900 /* Clear Link Attention in HA REG */
1901 writel(HA_LATT, phba->HAregaddr);
1902 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001903 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001904 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001905 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001906
James Smart09372822008-01-11 01:52:54 -05001907 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1908 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05001909
1910 return;
1911}
1912
James Smarte59058c2008-08-24 21:49:00 -04001913/**
James Smart3621a712009-04-06 18:47:14 -04001914 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04001915 * @phba: pointer to lpfc hba data structure.
1916 * @vpd: pointer to the vital product data.
1917 * @len: length of the vital product data in bytes.
1918 *
1919 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1920 * an array of characters. In this routine, the ModelName, ProgramType, and
1921 * ModelDesc, etc. fields of the phba data structure will be populated.
1922 *
1923 * Return codes
1924 * 0 - pointer to the VPD passed in is NULL
1925 * 1 - success
1926 **/
James Smart3772a992009-05-22 14:50:54 -04001927int
James Smart2e0fef82007-06-17 19:56:36 -05001928lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05001929{
1930 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05001931 int Length;
dea31012005-04-17 16:05:31 -05001932 int i, j;
1933 int finished = 0;
1934 int index = 0;
1935
1936 if (!vpd)
1937 return 0;
1938
1939 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05001940 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001941 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001942 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
1943 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001944 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05001945 switch (vpd[index]) {
1946 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001947 case 0x91:
dea31012005-04-17 16:05:31 -05001948 index += 1;
1949 lenlo = vpd[index];
1950 index += 1;
1951 lenhi = vpd[index];
1952 index += 1;
1953 i = ((((unsigned short)lenhi) << 8) + lenlo);
1954 index += i;
1955 break;
1956 case 0x90:
1957 index += 1;
1958 lenlo = vpd[index];
1959 index += 1;
1960 lenhi = vpd[index];
1961 index += 1;
1962 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001963 if (Length > len - index)
1964 Length = len - index;
dea31012005-04-17 16:05:31 -05001965 while (Length > 0) {
1966 /* Look for Serial Number */
1967 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
1968 index += 2;
1969 i = vpd[index];
1970 index += 1;
1971 j = 0;
1972 Length -= (3+i);
1973 while(i--) {
1974 phba->SerialNumber[j++] = vpd[index++];
1975 if (j == 31)
1976 break;
1977 }
1978 phba->SerialNumber[j] = 0;
1979 continue;
1980 }
1981 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
1982 phba->vpd_flag |= VPD_MODEL_DESC;
1983 index += 2;
1984 i = vpd[index];
1985 index += 1;
1986 j = 0;
1987 Length -= (3+i);
1988 while(i--) {
1989 phba->ModelDesc[j++] = vpd[index++];
1990 if (j == 255)
1991 break;
1992 }
1993 phba->ModelDesc[j] = 0;
1994 continue;
1995 }
1996 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
1997 phba->vpd_flag |= VPD_MODEL_NAME;
1998 index += 2;
1999 i = vpd[index];
2000 index += 1;
2001 j = 0;
2002 Length -= (3+i);
2003 while(i--) {
2004 phba->ModelName[j++] = vpd[index++];
2005 if (j == 79)
2006 break;
2007 }
2008 phba->ModelName[j] = 0;
2009 continue;
2010 }
2011 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2012 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2013 index += 2;
2014 i = vpd[index];
2015 index += 1;
2016 j = 0;
2017 Length -= (3+i);
2018 while(i--) {
2019 phba->ProgramType[j++] = vpd[index++];
2020 if (j == 255)
2021 break;
2022 }
2023 phba->ProgramType[j] = 0;
2024 continue;
2025 }
2026 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2027 phba->vpd_flag |= VPD_PORT;
2028 index += 2;
2029 i = vpd[index];
2030 index += 1;
2031 j = 0;
2032 Length -= (3+i);
2033 while(i--) {
James Smartcd1c8302011-10-10 21:33:25 -04002034 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2035 (phba->sli4_hba.pport_name_sta ==
2036 LPFC_SLI4_PPNAME_GET)) {
2037 j++;
2038 index++;
2039 } else
2040 phba->Port[j++] = vpd[index++];
2041 if (j == 19)
2042 break;
dea31012005-04-17 16:05:31 -05002043 }
James Smartcd1c8302011-10-10 21:33:25 -04002044 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2045 (phba->sli4_hba.pport_name_sta ==
2046 LPFC_SLI4_PPNAME_NON))
2047 phba->Port[j] = 0;
dea31012005-04-17 16:05:31 -05002048 continue;
2049 }
2050 else {
2051 index += 2;
2052 i = vpd[index];
2053 index += 1;
2054 index += i;
2055 Length -= (3 + i);
2056 }
2057 }
2058 finished = 0;
2059 break;
2060 case 0x78:
2061 finished = 1;
2062 break;
2063 default:
2064 index ++;
2065 break;
2066 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002067 }
dea31012005-04-17 16:05:31 -05002068
2069 return(1);
2070}
2071
James Smarte59058c2008-08-24 21:49:00 -04002072/**
James Smart3621a712009-04-06 18:47:14 -04002073 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04002074 * @phba: pointer to lpfc hba data structure.
2075 * @mdp: pointer to the data structure to hold the derived model name.
2076 * @descp: pointer to the data structure to hold the derived description.
2077 *
2078 * This routine retrieves HBA's description based on its registered PCI device
2079 * ID. The @descp passed into this function points to an array of 256 chars. It
2080 * shall be returned with the model name, maximum speed, and the host bus type.
2081 * The @mdp passed into this function points to an array of 80 chars. When the
2082 * function returns, the @mdp will be filled with the model name.
2083 **/
dea31012005-04-17 16:05:31 -05002084static void
James Smart2e0fef82007-06-17 19:56:36 -05002085lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05002086{
2087 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05002088 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002089 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04002090 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04002091 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002092 struct {
James Smarta747c9c2009-11-18 15:41:10 -05002093 char *name;
2094 char *bus;
2095 char *function;
2096 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002097
2098 if (mdp && mdp[0] != '\0'
2099 && descp && descp[0] != '\0')
2100 return;
2101
James Smartd38dd522015-08-31 16:48:17 -04002102 if (phba->lmt & LMT_32Gb)
2103 max_speed = 32;
2104 else if (phba->lmt & LMT_16Gb)
James Smartc0c11512011-05-24 11:41:34 -04002105 max_speed = 16;
2106 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002107 max_speed = 10;
2108 else if (phba->lmt & LMT_8Gb)
2109 max_speed = 8;
2110 else if (phba->lmt & LMT_4Gb)
2111 max_speed = 4;
2112 else if (phba->lmt & LMT_2Gb)
2113 max_speed = 2;
James Smart4169d862012-09-29 11:32:09 -04002114 else if (phba->lmt & LMT_1Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002115 max_speed = 1;
James Smart4169d862012-09-29 11:32:09 -04002116 else
2117 max_speed = 0;
dea31012005-04-17 16:05:31 -05002118
2119 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05002120
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002121 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002122 case PCI_DEVICE_ID_FIREFLY:
James Smart12222f42014-05-21 08:05:19 -04002123 m = (typeof(m)){"LP6000", "PCI",
2124 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002125 break;
dea31012005-04-17 16:05:31 -05002126 case PCI_DEVICE_ID_SUPERFLY:
2127 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart12222f42014-05-21 08:05:19 -04002128 m = (typeof(m)){"LP7000", "PCI", ""};
dea31012005-04-17 16:05:31 -05002129 else
James Smart12222f42014-05-21 08:05:19 -04002130 m = (typeof(m)){"LP7000E", "PCI", ""};
2131 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002132 break;
2133 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002134 m = (typeof(m)){"LP8000", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002135 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002136 break;
2137 case PCI_DEVICE_ID_CENTAUR:
2138 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart12222f42014-05-21 08:05:19 -04002139 m = (typeof(m)){"LP9002", "PCI", ""};
dea31012005-04-17 16:05:31 -05002140 else
James Smart12222f42014-05-21 08:05:19 -04002141 m = (typeof(m)){"LP9000", "PCI", ""};
2142 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002143 break;
2144 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002145 m = (typeof(m)){"LP952", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002146 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002147 break;
2148 case PCI_DEVICE_ID_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05002149 m = (typeof(m)){"LP9802", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002150 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002151 break;
2152 case PCI_DEVICE_ID_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05002153 m = (typeof(m)){"LP10000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002154 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002155 break;
2156 case PCI_DEVICE_ID_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05002157 m = (typeof(m)){"LPX1000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002158 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002159 break;
2160 case PCI_DEVICE_ID_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002161 m = (typeof(m)){"LP982", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002162 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002163 break;
2164 case PCI_DEVICE_ID_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002165 m = (typeof(m)){"LP1050", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002166 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002167 break;
2168 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05002169 m = (typeof(m)){"LP11000", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002170 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002171 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002172 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002173 m = (typeof(m)){"LP11000-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002174 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002175 break;
2176 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002177 m = (typeof(m)){"LP11002-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002178 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002179 break;
2180 case PCI_DEVICE_ID_NEPTUNE:
James Smart12222f42014-05-21 08:05:19 -04002181 m = (typeof(m)){"LPe1000", "PCIe",
2182 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002183 break;
2184 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart12222f42014-05-21 08:05:19 -04002185 m = (typeof(m)){"LPe1000-SP", "PCIe",
2186 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002187 break;
2188 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart12222f42014-05-21 08:05:19 -04002189 m = (typeof(m)){"LPe1002-SP", "PCIe",
2190 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002191 break;
dea31012005-04-17 16:05:31 -05002192 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05002193 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002194 break;
2195 case PCI_DEVICE_ID_BSMB:
James Smart12222f42014-05-21 08:05:19 -04002196 m = (typeof(m)){"LP111", "PCI-X2",
2197 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002198 break;
2199 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05002200 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002201 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002202 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002203 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002204 break;
2205 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002206 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04002207 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002208 break;
dea31012005-04-17 16:05:31 -05002209 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05002210 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002211 break;
2212 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05002213 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002214 break;
2215 case PCI_DEVICE_ID_LP101:
James Smart12222f42014-05-21 08:05:19 -04002216 m = (typeof(m)){"LP101", "PCI-X",
2217 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002218 break;
2219 case PCI_DEVICE_ID_LP10000S:
James Smart12222f42014-05-21 08:05:19 -04002220 m = (typeof(m)){"LP10000-S", "PCI",
2221 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002222 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002223 case PCI_DEVICE_ID_LP11000S:
James Smart12222f42014-05-21 08:05:19 -04002224 m = (typeof(m)){"LP11000-S", "PCI-X2",
2225 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05002226 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002227 case PCI_DEVICE_ID_LPE11000S:
James Smart12222f42014-05-21 08:05:19 -04002228 m = (typeof(m)){"LPe11000-S", "PCIe",
2229 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002230 break;
James Smartb87eab32007-04-25 09:53:28 -04002231 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05002232 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002233 break;
2234 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05002235 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002236 break;
2237 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05002238 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002239 break;
2240 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002241 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002242 break;
2243 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002244 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002245 break;
2246 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05002247 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002248 break;
James Smart84774a42008-08-24 21:50:06 -04002249 case PCI_DEVICE_ID_HORNET:
James Smart12222f42014-05-21 08:05:19 -04002250 m = (typeof(m)){"LP21000", "PCIe",
2251 "Obsolete, Unsupported FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002252 GE = 1;
2253 break;
2254 case PCI_DEVICE_ID_PROTEUS_VF:
James Smarta747c9c2009-11-18 15:41:10 -05002255 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002256 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002257 break;
2258 case PCI_DEVICE_ID_PROTEUS_PF:
James Smarta747c9c2009-11-18 15:41:10 -05002259 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002260 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002261 break;
2262 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05002263 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002264 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002265 break;
James Smartda0436e2009-05-22 14:51:39 -04002266 case PCI_DEVICE_ID_TIGERSHARK:
2267 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002268 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04002269 break;
James Smarta747c9c2009-11-18 15:41:10 -05002270 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04002271 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002272 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2273 break;
2274 case PCI_DEVICE_ID_FALCON:
2275 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2276 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04002277 break;
James Smart98fc5dd2010-06-07 15:24:29 -04002278 case PCI_DEVICE_ID_BALIUS:
2279 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
James Smart12222f42014-05-21 08:05:19 -04002280 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart98fc5dd2010-06-07 15:24:29 -04002281 break;
James Smart085c6472010-11-20 23:11:37 -05002282 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04002283 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05002284 break;
James Smart12222f42014-05-21 08:05:19 -04002285 case PCI_DEVICE_ID_LANCER_FC_VF:
2286 m = (typeof(m)){"LPe16000", "PCIe",
2287 "Obsolete, Unsupported Fibre Channel Adapter"};
2288 break;
James Smart085c6472010-11-20 23:11:37 -05002289 case PCI_DEVICE_ID_LANCER_FCOE:
2290 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04002291 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05002292 break;
James Smart12222f42014-05-21 08:05:19 -04002293 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2294 oneConnect = 1;
2295 m = (typeof(m)){"OCe15100", "PCIe",
2296 "Obsolete, Unsupported FCoE"};
2297 break;
James Smartd38dd522015-08-31 16:48:17 -04002298 case PCI_DEVICE_ID_LANCER_G6_FC:
2299 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2300 break;
James Smartf8cafd32012-08-03 12:42:51 -04002301 case PCI_DEVICE_ID_SKYHAWK:
2302 case PCI_DEVICE_ID_SKYHAWK_VF:
2303 oneConnect = 1;
2304 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2305 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002306 default:
James Smarta747c9c2009-11-18 15:41:10 -05002307 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002308 break;
dea31012005-04-17 16:05:31 -05002309 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002310
2311 if (mdp && mdp[0] == '\0')
2312 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04002313 /*
2314 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04002315 * and we put the port number on the end
2316 */
2317 if (descp && descp[0] == '\0') {
2318 if (oneConnect)
2319 snprintf(descp, 255,
James Smart4169d862012-09-29 11:32:09 -04002320 "Emulex OneConnect %s, %s Initiator %s",
James Smarta747c9c2009-11-18 15:41:10 -05002321 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04002322 phba->Port);
James Smart4169d862012-09-29 11:32:09 -04002323 else if (max_speed == 0)
2324 snprintf(descp, 255,
Sebastian Herbszt290237d2015-08-31 16:48:08 -04002325 "Emulex %s %s %s",
James Smart4169d862012-09-29 11:32:09 -04002326 m.name, m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002327 else
2328 snprintf(descp, 255,
2329 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05002330 m.name, max_speed, (GE) ? "GE" : "Gb",
2331 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002332 }
dea31012005-04-17 16:05:31 -05002333}
2334
James Smarte59058c2008-08-24 21:49:00 -04002335/**
James Smart3621a712009-04-06 18:47:14 -04002336 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04002337 * @phba: pointer to lpfc hba data structure.
2338 * @pring: pointer to a IOCB ring.
2339 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2340 *
2341 * This routine posts a given number of IOCBs with the associated DMA buffer
2342 * descriptors specified by the cnt argument to the given IOCB ring.
2343 *
2344 * Return codes
2345 * The number of IOCBs NOT able to be posted to the IOCB ring.
2346 **/
dea31012005-04-17 16:05:31 -05002347int
James Smart495a7142008-06-14 22:52:59 -04002348lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002349{
2350 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002351 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002352 struct lpfc_dmabuf *mp1, *mp2;
2353
2354 cnt += pring->missbufcnt;
2355
2356 /* While there are buffers to post */
2357 while (cnt > 0) {
2358 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002359 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002360 if (iocb == NULL) {
2361 pring->missbufcnt = cnt;
2362 return cnt;
2363 }
dea31012005-04-17 16:05:31 -05002364 icmd = &iocb->iocb;
2365
2366 /* 2 buffers can be posted per command */
2367 /* Allocate buffer to post */
2368 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2369 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002370 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2371 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002372 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002373 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002374 pring->missbufcnt = cnt;
2375 return cnt;
2376 }
2377
2378 INIT_LIST_HEAD(&mp1->list);
2379 /* Allocate buffer to post */
2380 if (cnt > 1) {
2381 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2382 if (mp2)
2383 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2384 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002385 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002386 kfree(mp2);
dea31012005-04-17 16:05:31 -05002387 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2388 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002389 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002390 pring->missbufcnt = cnt;
2391 return cnt;
2392 }
2393
2394 INIT_LIST_HEAD(&mp2->list);
2395 } else {
2396 mp2 = NULL;
2397 }
2398
2399 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2400 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2401 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2402 icmd->ulpBdeCount = 1;
2403 cnt--;
2404 if (mp2) {
2405 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2406 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2407 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2408 cnt--;
2409 icmd->ulpBdeCount = 2;
2410 }
2411
2412 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2413 icmd->ulpLe = 1;
2414
James Smart3772a992009-05-22 14:50:54 -04002415 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2416 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002417 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2418 kfree(mp1);
2419 cnt++;
2420 if (mp2) {
2421 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2422 kfree(mp2);
2423 cnt++;
2424 }
James Bottomley604a3e32005-10-29 10:28:33 -05002425 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002426 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002427 return cnt;
2428 }
dea31012005-04-17 16:05:31 -05002429 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002430 if (mp2)
dea31012005-04-17 16:05:31 -05002431 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002432 }
2433 pring->missbufcnt = 0;
2434 return 0;
2435}
2436
James Smarte59058c2008-08-24 21:49:00 -04002437/**
James Smart3621a712009-04-06 18:47:14 -04002438 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002439 * @phba: pointer to lpfc hba data structure.
2440 *
2441 * This routine posts initial receive IOCB buffers to the ELS ring. The
2442 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2443 * set to 64 IOCBs.
2444 *
2445 * Return codes
2446 * 0 - success (currently always success)
2447 **/
dea31012005-04-17 16:05:31 -05002448static int
James Smart2e0fef82007-06-17 19:56:36 -05002449lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002450{
2451 struct lpfc_sli *psli = &phba->sli;
2452
2453 /* Ring 0, ELS / CT buffers */
James Smart495a7142008-06-14 22:52:59 -04002454 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002455 /* Ring 2 - FCP no buffers needed */
2456
2457 return 0;
2458}
2459
2460#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2461
James Smarte59058c2008-08-24 21:49:00 -04002462/**
James Smart3621a712009-04-06 18:47:14 -04002463 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002464 * @HashResultPointer: pointer to an array as hash table.
2465 *
2466 * This routine sets up the initial values to the array of hash table entries
2467 * for the LC HBAs.
2468 **/
dea31012005-04-17 16:05:31 -05002469static void
2470lpfc_sha_init(uint32_t * HashResultPointer)
2471{
2472 HashResultPointer[0] = 0x67452301;
2473 HashResultPointer[1] = 0xEFCDAB89;
2474 HashResultPointer[2] = 0x98BADCFE;
2475 HashResultPointer[3] = 0x10325476;
2476 HashResultPointer[4] = 0xC3D2E1F0;
2477}
2478
James Smarte59058c2008-08-24 21:49:00 -04002479/**
James Smart3621a712009-04-06 18:47:14 -04002480 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002481 * @HashResultPointer: pointer to an initial/result hash table.
2482 * @HashWorkingPointer: pointer to an working hash table.
2483 *
2484 * This routine iterates an initial hash table pointed by @HashResultPointer
2485 * with the values from the working hash table pointeed by @HashWorkingPointer.
2486 * The results are putting back to the initial hash table, returned through
2487 * the @HashResultPointer as the result hash table.
2488 **/
dea31012005-04-17 16:05:31 -05002489static void
2490lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2491{
2492 int t;
2493 uint32_t TEMP;
2494 uint32_t A, B, C, D, E;
2495 t = 16;
2496 do {
2497 HashWorkingPointer[t] =
2498 S(1,
2499 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2500 8] ^
2501 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2502 } while (++t <= 79);
2503 t = 0;
2504 A = HashResultPointer[0];
2505 B = HashResultPointer[1];
2506 C = HashResultPointer[2];
2507 D = HashResultPointer[3];
2508 E = HashResultPointer[4];
2509
2510 do {
2511 if (t < 20) {
2512 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2513 } else if (t < 40) {
2514 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2515 } else if (t < 60) {
2516 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2517 } else {
2518 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2519 }
2520 TEMP += S(5, A) + E + HashWorkingPointer[t];
2521 E = D;
2522 D = C;
2523 C = S(30, B);
2524 B = A;
2525 A = TEMP;
2526 } while (++t <= 79);
2527
2528 HashResultPointer[0] += A;
2529 HashResultPointer[1] += B;
2530 HashResultPointer[2] += C;
2531 HashResultPointer[3] += D;
2532 HashResultPointer[4] += E;
2533
2534}
2535
James Smarte59058c2008-08-24 21:49:00 -04002536/**
James Smart3621a712009-04-06 18:47:14 -04002537 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002538 * @RandomChallenge: pointer to the entry of host challenge random number array.
2539 * @HashWorking: pointer to the entry of the working hash array.
2540 *
2541 * This routine calculates the working hash array referred by @HashWorking
2542 * from the challenge random numbers associated with the host, referred by
2543 * @RandomChallenge. The result is put into the entry of the working hash
2544 * array and returned by reference through @HashWorking.
2545 **/
dea31012005-04-17 16:05:31 -05002546static void
2547lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2548{
2549 *HashWorking = (*RandomChallenge ^ *HashWorking);
2550}
2551
James Smarte59058c2008-08-24 21:49:00 -04002552/**
James Smart3621a712009-04-06 18:47:14 -04002553 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002554 * @phba: pointer to lpfc hba data structure.
2555 * @hbainit: pointer to an array of unsigned 32-bit integers.
2556 *
2557 * This routine performs the special handling for LC HBA initialization.
2558 **/
dea31012005-04-17 16:05:31 -05002559void
2560lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2561{
2562 int t;
2563 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002564 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002565
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002566 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002567 if (!HashWorking)
2568 return;
2569
dea31012005-04-17 16:05:31 -05002570 HashWorking[0] = HashWorking[78] = *pwwnn++;
2571 HashWorking[1] = HashWorking[79] = *pwwnn;
2572
2573 for (t = 0; t < 7; t++)
2574 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2575
2576 lpfc_sha_init(hbainit);
2577 lpfc_sha_iterate(hbainit, HashWorking);
2578 kfree(HashWorking);
2579}
2580
James Smarte59058c2008-08-24 21:49:00 -04002581/**
James Smart3621a712009-04-06 18:47:14 -04002582 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002583 * @vport: pointer to a virtual N_Port data structure.
2584 *
2585 * This routine performs the necessary cleanups before deleting the @vport.
2586 * It invokes the discovery state machine to perform necessary state
2587 * transitions and to release the ndlps associated with the @vport. Note,
2588 * the physical port is treated as @vport 0.
2589 **/
James Smart87af33f2007-10-27 13:37:43 -04002590void
James Smart2e0fef82007-06-17 19:56:36 -05002591lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002592{
James Smart87af33f2007-10-27 13:37:43 -04002593 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002594 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002595 int i = 0;
dea31012005-04-17 16:05:31 -05002596
James Smart87af33f2007-10-27 13:37:43 -04002597 if (phba->link_state > LPFC_LINK_DOWN)
2598 lpfc_port_link_failure(vport);
2599
2600 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002601 if (!NLP_CHK_NODE_ACT(ndlp)) {
2602 ndlp = lpfc_enable_node(vport, ndlp,
2603 NLP_STE_UNUSED_NODE);
2604 if (!ndlp)
2605 continue;
2606 spin_lock_irq(&phba->ndlp_lock);
2607 NLP_SET_FREE_REQ(ndlp);
2608 spin_unlock_irq(&phba->ndlp_lock);
2609 /* Trigger the release of the ndlp memory */
2610 lpfc_nlp_put(ndlp);
2611 continue;
2612 }
2613 spin_lock_irq(&phba->ndlp_lock);
2614 if (NLP_CHK_FREE_REQ(ndlp)) {
2615 /* The ndlp should not be in memory free mode already */
2616 spin_unlock_irq(&phba->ndlp_lock);
2617 continue;
2618 } else
2619 /* Indicate request for freeing ndlp memory */
2620 NLP_SET_FREE_REQ(ndlp);
2621 spin_unlock_irq(&phba->ndlp_lock);
2622
James Smart58da1ff2008-04-07 10:15:56 -04002623 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2624 ndlp->nlp_DID == Fabric_DID) {
2625 /* Just free up ndlp with Fabric_DID for vports */
2626 lpfc_nlp_put(ndlp);
2627 continue;
2628 }
2629
James Smarteff4a012012-01-18 16:25:25 -05002630 /* take care of nodes in unused state before the state
2631 * machine taking action.
2632 */
2633 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2634 lpfc_nlp_put(ndlp);
2635 continue;
2636 }
2637
James Smart87af33f2007-10-27 13:37:43 -04002638 if (ndlp->nlp_type & NLP_FABRIC)
2639 lpfc_disc_state_machine(vport, ndlp, NULL,
2640 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002641
James Smart87af33f2007-10-27 13:37:43 -04002642 lpfc_disc_state_machine(vport, ndlp, NULL,
2643 NLP_EVT_DEVICE_RM);
2644 }
2645
James Smarta8adb832007-10-27 13:37:53 -04002646 /* At this point, ALL ndlp's should be gone
2647 * because of the previous NLP_EVT_DEVICE_RM.
2648 * Lets wait for this to happen, if needed.
2649 */
James Smart87af33f2007-10-27 13:37:43 -04002650 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002651 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04002652 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04002653 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002654 list_for_each_entry_safe(ndlp, next_ndlp,
2655 &vport->fc_nodes, nlp_listp) {
2656 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2657 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04002658 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05002659 "usgmap:x%x refcnt:%d\n",
2660 ndlp->nlp_DID, (void *)ndlp,
2661 ndlp->nlp_usg_map,
2662 atomic_read(
2663 &ndlp->kref.refcount));
2664 }
James Smarta8adb832007-10-27 13:37:53 -04002665 break;
James Smart87af33f2007-10-27 13:37:43 -04002666 }
James Smarta8adb832007-10-27 13:37:53 -04002667
2668 /* Wait for any activity on ndlps to settle */
2669 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002670 }
James Smart1151e3e2011-02-16 12:39:35 -05002671 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002672}
2673
James Smarte59058c2008-08-24 21:49:00 -04002674/**
James Smart3621a712009-04-06 18:47:14 -04002675 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002676 * @vport: pointer to a virtual N_Port data structure.
2677 *
2678 * This routine stops all the timers associated with a @vport. This function
2679 * is invoked before disabling or deleting a @vport. Note that the physical
2680 * port is treated as @vport 0.
2681 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002682void
2683lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002684{
James Smart92d7f7b2007-06-17 19:56:38 -05002685 del_timer_sync(&vport->els_tmofunc);
James Smart92494142011-02-16 12:39:44 -05002686 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002687 lpfc_can_disctmo(vport);
2688 return;
dea31012005-04-17 16:05:31 -05002689}
2690
James Smarte59058c2008-08-24 21:49:00 -04002691/**
James Smartecfd03c2010-02-12 14:41:27 -05002692 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2693 * @phba: pointer to lpfc hba data structure.
2694 *
2695 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2696 * caller of this routine should already hold the host lock.
2697 **/
2698void
2699__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2700{
James Smart5ac6b302010-10-22 11:05:36 -04002701 /* Clear pending FCF rediscovery wait flag */
2702 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2703
James Smartecfd03c2010-02-12 14:41:27 -05002704 /* Now, try to stop the timer */
2705 del_timer(&phba->fcf.redisc_wait);
2706}
2707
2708/**
2709 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2710 * @phba: pointer to lpfc hba data structure.
2711 *
2712 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2713 * checks whether the FCF rediscovery wait timer is pending with the host
2714 * lock held before proceeding with disabling the timer and clearing the
2715 * wait timer pendig flag.
2716 **/
2717void
2718lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2719{
2720 spin_lock_irq(&phba->hbalock);
2721 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2722 /* FCF rediscovery timer already fired or stopped */
2723 spin_unlock_irq(&phba->hbalock);
2724 return;
2725 }
2726 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002727 /* Clear failover in progress flags */
2728 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002729 spin_unlock_irq(&phba->hbalock);
2730}
2731
2732/**
James Smart3772a992009-05-22 14:50:54 -04002733 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002734 * @phba: pointer to lpfc hba data structure.
2735 *
2736 * This routine stops all the timers associated with a HBA. This function is
2737 * invoked before either putting a HBA offline or unloading the driver.
2738 **/
James Smart3772a992009-05-22 14:50:54 -04002739void
2740lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002741{
James Smart51ef4c22007-08-02 11:10:31 -04002742 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05002743 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002744 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002745 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002746 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002747 if (phba->sli_rev == LPFC_SLI_REV4) {
2748 del_timer_sync(&phba->rrq_tmr);
2749 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2750 }
James Smart3772a992009-05-22 14:50:54 -04002751 phba->hb_outstanding = 0;
2752
2753 switch (phba->pci_dev_grp) {
2754 case LPFC_PCI_DEV_LP:
2755 /* Stop any LightPulse device specific driver timers */
2756 del_timer_sync(&phba->fcp_poll_timer);
2757 break;
2758 case LPFC_PCI_DEV_OC:
2759 /* Stop any OneConnect device sepcific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002760 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002761 break;
2762 default:
2763 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2764 "0297 Invalid device group (x%x)\n",
2765 phba->pci_dev_grp);
2766 break;
2767 }
James Smart2e0fef82007-06-17 19:56:36 -05002768 return;
dea31012005-04-17 16:05:31 -05002769}
2770
James Smarte59058c2008-08-24 21:49:00 -04002771/**
James Smart3621a712009-04-06 18:47:14 -04002772 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002773 * @phba: pointer to lpfc hba data structure.
2774 *
2775 * This routine marks a HBA's management interface as blocked. Once the HBA's
2776 * management interface is marked as blocked, all the user space access to
2777 * the HBA, whether they are from sysfs interface or libdfc interface will
2778 * all be blocked. The HBA is set to block the management interface when the
2779 * driver prepares the HBA interface for online or offline.
2780 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01002781static void
James Smart618a5232012-06-12 13:54:36 -04002782lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
Adrian Bunka6ababd2007-11-05 18:07:33 +01002783{
2784 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04002785 uint8_t actcmd = MBX_HEARTBEAT;
2786 unsigned long timeout;
2787
Adrian Bunka6ababd2007-11-05 18:07:33 +01002788 spin_lock_irqsave(&phba->hbalock, iflag);
2789 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart618a5232012-06-12 13:54:36 -04002790 spin_unlock_irqrestore(&phba->hbalock, iflag);
2791 if (mbx_action == LPFC_MBX_NO_WAIT)
2792 return;
2793 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2794 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002795 if (phba->sli.mbox_active) {
James Smart6e7288d2010-06-07 15:23:35 -04002796 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
James Smarta183a152011-10-10 21:32:43 -04002797 /* Determine how long we might wait for the active mailbox
2798 * command to be gracefully completed by firmware.
2799 */
2800 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
2801 phba->sli.mbox_active) * 1000) + jiffies;
2802 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002803 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002804
James Smart6e7288d2010-06-07 15:23:35 -04002805 /* Wait for the outstnading mailbox command to complete */
2806 while (phba->sli.mbox_active) {
2807 /* Check active mailbox complete status every 2ms */
2808 msleep(2);
2809 if (time_after(jiffies, timeout)) {
2810 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2811 "2813 Mgmt IO is Blocked %x "
2812 "- mbox cmd %x still active\n",
2813 phba->sli.sli_flag, actcmd);
2814 break;
2815 }
2816 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002817}
2818
James Smarte59058c2008-08-24 21:49:00 -04002819/**
James Smart6b5151f2012-01-18 16:24:06 -05002820 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
2821 * @phba: pointer to lpfc hba data structure.
2822 *
2823 * Allocate RPIs for all active remote nodes. This is needed whenever
2824 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
2825 * is to fixup the temporary rpi assignments.
2826 **/
2827void
2828lpfc_sli4_node_prep(struct lpfc_hba *phba)
2829{
2830 struct lpfc_nodelist *ndlp, *next_ndlp;
2831 struct lpfc_vport **vports;
2832 int i;
2833
2834 if (phba->sli_rev != LPFC_SLI_REV4)
2835 return;
2836
2837 vports = lpfc_create_vport_work_array(phba);
2838 if (vports != NULL) {
2839 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2840 if (vports[i]->load_flag & FC_UNLOADING)
2841 continue;
2842
2843 list_for_each_entry_safe(ndlp, next_ndlp,
2844 &vports[i]->fc_nodes,
2845 nlp_listp) {
James Smartbe6bb942015-04-07 15:07:22 -04002846 if (NLP_CHK_NODE_ACT(ndlp)) {
James Smart6b5151f2012-01-18 16:24:06 -05002847 ndlp->nlp_rpi =
2848 lpfc_sli4_alloc_rpi(phba);
James Smartbe6bb942015-04-07 15:07:22 -04002849 lpfc_printf_vlog(ndlp->vport, KERN_INFO,
2850 LOG_NODE,
2851 "0009 rpi:%x DID:%x "
2852 "flg:%x map:%x %p\n",
2853 ndlp->nlp_rpi,
2854 ndlp->nlp_DID,
2855 ndlp->nlp_flag,
2856 ndlp->nlp_usg_map,
2857 ndlp);
2858 }
James Smart6b5151f2012-01-18 16:24:06 -05002859 }
2860 }
2861 }
2862 lpfc_destroy_vport_work_array(phba, vports);
2863}
2864
2865/**
James Smart3621a712009-04-06 18:47:14 -04002866 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04002867 * @phba: pointer to lpfc hba data structure.
2868 *
2869 * This routine initializes the HBA and brings a HBA online. During this
2870 * process, the management interface is blocked to prevent user space access
2871 * to the HBA interfering with the driver initialization.
2872 *
2873 * Return codes
2874 * 0 - successful
2875 * 1 - failed
2876 **/
dea31012005-04-17 16:05:31 -05002877int
James Smart2e0fef82007-06-17 19:56:36 -05002878lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002879{
Julia Lawall372bd282008-12-16 16:15:08 +01002880 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04002881 struct lpfc_vport **vports;
2882 int i;
James Smart16a3a202013-04-17 20:14:38 -04002883 bool vpis_cleared = false;
James Smart2e0fef82007-06-17 19:56:36 -05002884
dea31012005-04-17 16:05:31 -05002885 if (!phba)
2886 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01002887 vport = phba->pport;
dea31012005-04-17 16:05:31 -05002888
James Smart2e0fef82007-06-17 19:56:36 -05002889 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05002890 return 0;
2891
James Smarted957682007-06-17 19:56:37 -05002892 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002893 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05002894
James Smart618a5232012-06-12 13:54:36 -04002895 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05002896
James Smart46fa3112007-04-25 09:51:45 -04002897 if (!lpfc_sli_queue_setup(phba)) {
2898 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002899 return 1;
James Smart46fa3112007-04-25 09:51:45 -04002900 }
2901
James Smartda0436e2009-05-22 14:51:39 -04002902 if (phba->sli_rev == LPFC_SLI_REV4) {
2903 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
2904 lpfc_unblock_mgmt_io(phba);
2905 return 1;
2906 }
James Smart16a3a202013-04-17 20:14:38 -04002907 spin_lock_irq(&phba->hbalock);
2908 if (!phba->sli4_hba.max_cfg_param.vpi_used)
2909 vpis_cleared = true;
2910 spin_unlock_irq(&phba->hbalock);
James Smartda0436e2009-05-22 14:51:39 -04002911 } else {
2912 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
2913 lpfc_unblock_mgmt_io(phba);
2914 return 1;
2915 }
James Smart46fa3112007-04-25 09:51:45 -04002916 }
dea31012005-04-17 16:05:31 -05002917
James Smart549e55c2007-08-02 11:09:51 -04002918 vports = lpfc_create_vport_work_array(phba);
Arnd Bergmannaeb66412016-03-14 15:29:44 +01002919 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04002920 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002921 struct Scsi_Host *shost;
2922 shost = lpfc_shost_from_vport(vports[i]);
2923 spin_lock_irq(shost->host_lock);
2924 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
2925 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2926 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart16a3a202013-04-17 20:14:38 -04002927 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart1c6834a2009-07-19 10:01:26 -04002928 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart16a3a202013-04-17 20:14:38 -04002929 if ((vpis_cleared) &&
2930 (vports[i]->port_type !=
2931 LPFC_PHYSICAL_PORT))
2932 vports[i]->vpi = 0;
2933 }
James Smart549e55c2007-08-02 11:09:51 -04002934 spin_unlock_irq(shost->host_lock);
2935 }
Arnd Bergmannaeb66412016-03-14 15:29:44 +01002936 }
2937 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002938
James Smart46fa3112007-04-25 09:51:45 -04002939 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002940 return 0;
2941}
2942
James Smarte59058c2008-08-24 21:49:00 -04002943/**
James Smart3621a712009-04-06 18:47:14 -04002944 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04002945 * @phba: pointer to lpfc hba data structure.
2946 *
2947 * This routine marks a HBA's management interface as not blocked. Once the
2948 * HBA's management interface is marked as not blocked, all the user space
2949 * access to the HBA, whether they are from sysfs interface or libdfc
2950 * interface will be allowed. The HBA is set to block the management interface
2951 * when the driver prepares the HBA interface for online or offline and then
2952 * set to unblock the management interface afterwards.
2953 **/
James Smart46fa3112007-04-25 09:51:45 -04002954void
James Smart46fa3112007-04-25 09:51:45 -04002955lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
2956{
2957 unsigned long iflag;
2958
James Smart2e0fef82007-06-17 19:56:36 -05002959 spin_lock_irqsave(&phba->hbalock, iflag);
2960 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
2961 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04002962}
2963
James Smarte59058c2008-08-24 21:49:00 -04002964/**
James Smart3621a712009-04-06 18:47:14 -04002965 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04002966 * @phba: pointer to lpfc hba data structure.
2967 *
2968 * This routine is invoked to prepare a HBA to be brought offline. It performs
2969 * unregistration login to all the nodes on all vports and flushes the mailbox
2970 * queue to make it ready to be brought offline.
2971 **/
James Smart46fa3112007-04-25 09:51:45 -04002972void
James Smart618a5232012-06-12 13:54:36 -04002973lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04002974{
James Smart2e0fef82007-06-17 19:56:36 -05002975 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04002976 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04002977 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05002978 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04002979 int i;
dea31012005-04-17 16:05:31 -05002980
James Smart2e0fef82007-06-17 19:56:36 -05002981 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002982 return;
dea31012005-04-17 16:05:31 -05002983
James Smart618a5232012-06-12 13:54:36 -04002984 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05002985
2986 lpfc_linkdown(phba);
2987
James Smart87af33f2007-10-27 13:37:43 -04002988 /* Issue an unreg_login to all nodes on all vports */
2989 vports = lpfc_create_vport_work_array(phba);
2990 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04002991 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04002992 if (vports[i]->load_flag & FC_UNLOADING)
2993 continue;
James Smart72100cc2010-02-12 14:43:01 -05002994 shost = lpfc_shost_from_vport(vports[i]);
2995 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05002996 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002997 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2998 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05002999 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05003000
James Smart87af33f2007-10-27 13:37:43 -04003001 shost = lpfc_shost_from_vport(vports[i]);
3002 list_for_each_entry_safe(ndlp, next_ndlp,
3003 &vports[i]->fc_nodes,
3004 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003005 if (!NLP_CHK_NODE_ACT(ndlp))
3006 continue;
James Smart87af33f2007-10-27 13:37:43 -04003007 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3008 continue;
3009 if (ndlp->nlp_type & NLP_FABRIC) {
3010 lpfc_disc_state_machine(vports[i], ndlp,
3011 NULL, NLP_EVT_DEVICE_RECOVERY);
3012 lpfc_disc_state_machine(vports[i], ndlp,
3013 NULL, NLP_EVT_DEVICE_RM);
3014 }
3015 spin_lock_irq(shost->host_lock);
3016 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart401ee0c2012-03-01 22:35:34 -05003017 spin_unlock_irq(shost->host_lock);
James Smart6b5151f2012-01-18 16:24:06 -05003018 /*
3019 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05003020 * RPI. Get a new RPI when the adapter port
3021 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05003022 */
James Smartbe6bb942015-04-07 15:07:22 -04003023 if (phba->sli_rev == LPFC_SLI_REV4) {
3024 lpfc_printf_vlog(ndlp->vport,
3025 KERN_INFO, LOG_NODE,
3026 "0011 lpfc_offline: "
3027 "ndlp:x%p did %x "
3028 "usgmap:x%x rpi:%x\n",
3029 ndlp, ndlp->nlp_DID,
3030 ndlp->nlp_usg_map,
3031 ndlp->nlp_rpi);
3032
James Smart6b5151f2012-01-18 16:24:06 -05003033 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smartbe6bb942015-04-07 15:07:22 -04003034 }
James Smart87af33f2007-10-27 13:37:43 -04003035 lpfc_unreg_rpi(vports[i], ndlp);
3036 }
3037 }
3038 }
James Smart09372822008-01-11 01:52:54 -05003039 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003040
James Smart618a5232012-06-12 13:54:36 -04003041 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
James Smart46fa3112007-04-25 09:51:45 -04003042}
3043
James Smarte59058c2008-08-24 21:49:00 -04003044/**
James Smart3621a712009-04-06 18:47:14 -04003045 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04003046 * @phba: pointer to lpfc hba data structure.
3047 *
3048 * This routine actually brings a HBA offline. It stops all the timers
3049 * associated with the HBA, brings down the SLI layer, and eventually
3050 * marks the HBA as in offline state for the upper layer protocol.
3051 **/
James Smart46fa3112007-04-25 09:51:45 -04003052void
James Smart2e0fef82007-06-17 19:56:36 -05003053lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04003054{
James Smart549e55c2007-08-02 11:09:51 -04003055 struct Scsi_Host *shost;
3056 struct lpfc_vport **vports;
3057 int i;
James Smart46fa3112007-04-25 09:51:45 -04003058
James Smart549e55c2007-08-02 11:09:51 -04003059 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003060 return;
James Smart688a8862006-07-06 15:49:56 -04003061
James Smartda0436e2009-05-22 14:51:39 -04003062 /* stop port and all timers associated with this hba */
3063 lpfc_stop_port(phba);
James Smart51ef4c22007-08-02 11:10:31 -04003064 vports = lpfc_create_vport_work_array(phba);
3065 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003066 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04003067 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05003068 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05003069 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003070 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05003071 /* Bring down the SLI Layer and cleanup. The HBA is offline
3072 now. */
3073 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003074 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04003075 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003076 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04003077 vports = lpfc_create_vport_work_array(phba);
3078 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003079 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003080 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04003081 spin_lock_irq(shost->host_lock);
3082 vports[i]->work_port_events = 0;
3083 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3084 spin_unlock_irq(shost->host_lock);
3085 }
James Smart09372822008-01-11 01:52:54 -05003086 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003087}
3088
James Smarte59058c2008-08-24 21:49:00 -04003089/**
James Smart3621a712009-04-06 18:47:14 -04003090 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04003091 * @phba: pointer to lpfc hba data structure.
3092 *
3093 * This routine is to free all the SCSI buffers and IOCBs from the driver
3094 * list back to kernel. It is called from lpfc_pci_remove_one to free
3095 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04003096 **/
James Smart8a9d2e82012-05-09 21:16:12 -04003097static void
James Smart2e0fef82007-06-17 19:56:36 -05003098lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003099{
3100 struct lpfc_scsi_buf *sb, *sb_next;
3101 struct lpfc_iocbq *io, *io_next;
3102
James Smart2e0fef82007-06-17 19:56:36 -05003103 spin_lock_irq(&phba->hbalock);
James Smarta40fc5f2013-04-17 20:17:40 -04003104
dea31012005-04-17 16:05:31 -05003105 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smarta40fc5f2013-04-17 20:17:40 -04003106
3107 spin_lock(&phba->scsi_buf_list_put_lock);
3108 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3109 list) {
dea31012005-04-17 16:05:31 -05003110 list_del(&sb->list);
3111 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05003112 sb->dma_handle);
dea31012005-04-17 16:05:31 -05003113 kfree(sb);
3114 phba->total_scsi_bufs--;
3115 }
James Smarta40fc5f2013-04-17 20:17:40 -04003116 spin_unlock(&phba->scsi_buf_list_put_lock);
3117
3118 spin_lock(&phba->scsi_buf_list_get_lock);
3119 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3120 list) {
3121 list_del(&sb->list);
3122 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
3123 sb->dma_handle);
3124 kfree(sb);
3125 phba->total_scsi_bufs--;
3126 }
3127 spin_unlock(&phba->scsi_buf_list_get_lock);
dea31012005-04-17 16:05:31 -05003128
3129 /* Release all the lpfc_iocbq entries maintained by this host. */
3130 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
3131 list_del(&io->list);
3132 kfree(io);
3133 phba->total_iocbq_bufs--;
3134 }
James Smart6d368e52011-05-24 11:44:12 -04003135
James Smart2e0fef82007-06-17 19:56:36 -05003136 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003137}
3138
3139/**
3140 * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping
3141 * @phba: pointer to lpfc hba data structure.
3142 *
3143 * This routine first calculates the sizes of the current els and allocated
3144 * scsi sgl lists, and then goes through all sgls to updates the physical
3145 * XRIs assigned due to port function reset. During port initialization, the
3146 * current els and allocated scsi sgl lists are 0s.
3147 *
3148 * Return codes
3149 * 0 - successful (for now, it always returns 0)
3150 **/
3151int
3152lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba)
3153{
3154 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3155 struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL;
3156 uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt;
3157 LIST_HEAD(els_sgl_list);
3158 LIST_HEAD(scsi_sgl_list);
3159 int rc;
James Smartdafe8ce2014-09-03 12:56:40 -04003160 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart8a9d2e82012-05-09 21:16:12 -04003161
3162 /*
3163 * update on pci function's els xri-sgl list
3164 */
3165 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3166 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3167 /* els xri-sgl expanded */
3168 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3169 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3170 "3157 ELS xri-sgl count increased from "
3171 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3172 els_xri_cnt);
3173 /* allocate the additional els sgls */
3174 for (i = 0; i < xri_cnt; i++) {
3175 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3176 GFP_KERNEL);
3177 if (sglq_entry == NULL) {
3178 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3179 "2562 Failure to allocate an "
3180 "ELS sgl entry:%d\n", i);
3181 rc = -ENOMEM;
3182 goto out_free_mem;
3183 }
3184 sglq_entry->buff_type = GEN_BUFF_TYPE;
3185 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3186 &sglq_entry->phys);
3187 if (sglq_entry->virt == NULL) {
3188 kfree(sglq_entry);
3189 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3190 "2563 Failure to allocate an "
3191 "ELS mbuf:%d\n", i);
3192 rc = -ENOMEM;
3193 goto out_free_mem;
3194 }
3195 sglq_entry->sgl = sglq_entry->virt;
3196 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3197 sglq_entry->state = SGL_FREED;
3198 list_add_tail(&sglq_entry->list, &els_sgl_list);
3199 }
James Smart38c20672013-03-01 16:37:44 -05003200 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04003201 spin_lock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003202 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04003203 spin_unlock(&pring->ring_lock);
James Smart38c20672013-03-01 16:37:44 -05003204 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003205 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3206 /* els xri-sgl shrinked */
3207 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3208 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3209 "3158 ELS xri-sgl count decreased from "
3210 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3211 els_xri_cnt);
3212 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04003213 spin_lock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003214 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04003215 spin_unlock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003216 spin_unlock_irq(&phba->hbalock);
3217 /* release extra els sgls from list */
3218 for (i = 0; i < xri_cnt; i++) {
3219 list_remove_head(&els_sgl_list,
3220 sglq_entry, struct lpfc_sglq, list);
3221 if (sglq_entry) {
3222 lpfc_mbuf_free(phba, sglq_entry->virt,
3223 sglq_entry->phys);
3224 kfree(sglq_entry);
3225 }
3226 }
3227 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04003228 spin_lock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003229 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04003230 spin_unlock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003231 spin_unlock_irq(&phba->hbalock);
3232 } else
3233 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3234 "3163 ELS xri-sgl count unchanged: %d\n",
3235 els_xri_cnt);
3236 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3237
3238 /* update xris to els sgls on the list */
3239 sglq_entry = NULL;
3240 sglq_entry_next = NULL;
3241 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3242 &phba->sli4_hba.lpfc_sgl_list, list) {
3243 lxri = lpfc_sli4_next_xritag(phba);
3244 if (lxri == NO_XRI) {
3245 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3246 "2400 Failed to allocate xri for "
3247 "ELS sgl\n");
3248 rc = -ENOMEM;
3249 goto out_free_mem;
3250 }
3251 sglq_entry->sli4_lxritag = lxri;
3252 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3253 }
3254
3255 /*
3256 * update on pci function's allocated scsi xri-sgl list
3257 */
3258 phba->total_scsi_bufs = 0;
3259
3260 /* maximum number of xris available for scsi buffers */
3261 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3262 els_xri_cnt;
3263
3264 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3265 "2401 Current allocated SCSI xri-sgl count:%d, "
3266 "maximum SCSI xri count:%d\n",
3267 phba->sli4_hba.scsi_xri_cnt,
3268 phba->sli4_hba.scsi_xri_max);
3269
James Smarta40fc5f2013-04-17 20:17:40 -04003270 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003271 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003272 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3273 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
James Smart164cecd2013-09-06 12:22:38 -04003274 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003275 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003276
3277 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3278 /* max scsi xri shrinked below the allocated scsi buffers */
3279 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3280 phba->sli4_hba.scsi_xri_max;
3281 /* release the extra allocated scsi buffers */
3282 for (i = 0; i < scsi_xri_cnt; i++) {
3283 list_remove_head(&scsi_sgl_list, psb,
3284 struct lpfc_scsi_buf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04003285 if (psb) {
3286 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
3287 psb->data, psb->dma_handle);
3288 kfree(psb);
3289 }
James Smart8a9d2e82012-05-09 21:16:12 -04003290 }
James Smarta40fc5f2013-04-17 20:17:40 -04003291 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003292 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
James Smarta40fc5f2013-04-17 20:17:40 -04003293 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003294 }
3295
3296 /* update xris associated to remaining allocated scsi buffers */
3297 psb = NULL;
3298 psb_next = NULL;
3299 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3300 lxri = lpfc_sli4_next_xritag(phba);
3301 if (lxri == NO_XRI) {
3302 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3303 "2560 Failed to allocate xri for "
3304 "scsi buffer\n");
3305 rc = -ENOMEM;
3306 goto out_free_mem;
3307 }
3308 psb->cur_iocbq.sli4_lxritag = lxri;
3309 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3310 }
James Smarta40fc5f2013-04-17 20:17:40 -04003311 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003312 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003313 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3314 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
James Smart164cecd2013-09-06 12:22:38 -04003315 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003316 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003317
dea31012005-04-17 16:05:31 -05003318 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003319
3320out_free_mem:
3321 lpfc_free_els_sgl_list(phba);
3322 lpfc_scsi_free(phba);
3323 return rc;
dea31012005-04-17 16:05:31 -05003324}
3325
James Smarte59058c2008-08-24 21:49:00 -04003326/**
James Smart3621a712009-04-06 18:47:14 -04003327 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04003328 * @phba: pointer to lpfc hba data structure.
3329 * @instance: a unique integer ID to this FC port.
3330 * @dev: pointer to the device data structure.
3331 *
3332 * This routine creates a FC port for the upper layer protocol. The FC port
3333 * can be created on top of either a physical port or a virtual port provided
3334 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3335 * and associates the FC port created before adding the shost into the SCSI
3336 * layer.
3337 *
3338 * Return codes
3339 * @vport - pointer to the virtual N_Port data structure.
3340 * NULL - port create failed.
3341 **/
James Smart2e0fef82007-06-17 19:56:36 -05003342struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04003343lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04003344{
James Smart2e0fef82007-06-17 19:56:36 -05003345 struct lpfc_vport *vport;
3346 struct Scsi_Host *shost;
3347 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04003348
James Smartea4142f2015-04-07 15:07:13 -04003349 if (dev != &phba->pcidev->dev) {
James Smart3de2a652007-08-02 11:09:59 -04003350 shost = scsi_host_alloc(&lpfc_vport_template,
3351 sizeof(struct lpfc_vport));
James Smartea4142f2015-04-07 15:07:13 -04003352 } else {
3353 if (phba->sli_rev == LPFC_SLI_REV4)
3354 shost = scsi_host_alloc(&lpfc_template,
James Smart3de2a652007-08-02 11:09:59 -04003355 sizeof(struct lpfc_vport));
James Smartea4142f2015-04-07 15:07:13 -04003356 else
3357 shost = scsi_host_alloc(&lpfc_template_s3,
3358 sizeof(struct lpfc_vport));
3359 }
James Smart2e0fef82007-06-17 19:56:36 -05003360 if (!shost)
3361 goto out;
James Smart47a86172007-04-25 09:53:22 -04003362
James Smart2e0fef82007-06-17 19:56:36 -05003363 vport = (struct lpfc_vport *) shost->hostdata;
3364 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05003365 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05003366 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05003367 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04003368
James Smart3de2a652007-08-02 11:09:59 -04003369 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05003370 shost->unique_id = instance;
3371 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04003372 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05003373 shost->this_id = -1;
3374 shost->max_cmd_len = 16;
James Smart8b0dff12015-05-22 10:42:38 -04003375 shost->nr_hw_queues = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04003376 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05003377 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04003378 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smartda0436e2009-05-22 14:51:39 -04003379 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
3380 }
James Smart81301a92008-12-04 22:39:46 -05003381
James Smart47a86172007-04-25 09:53:22 -04003382 /*
James Smart2e0fef82007-06-17 19:56:36 -05003383 * Set initial can_queue value since 0 is no longer supported and
3384 * scsi_add_host will fail. This will be adjusted later based on the
3385 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04003386 */
James Smart2e0fef82007-06-17 19:56:36 -05003387 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04003388 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05003389 shost->transportt = lpfc_vport_transport_template;
3390 vport->port_type = LPFC_NPIV_PORT;
3391 } else {
3392 shost->transportt = lpfc_transport_template;
3393 vport->port_type = LPFC_PHYSICAL_PORT;
3394 }
James Smart47a86172007-04-25 09:53:22 -04003395
James Smart2e0fef82007-06-17 19:56:36 -05003396 /* Initialize all internally managed lists. */
3397 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04003398 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05003399 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04003400
James Smart2e0fef82007-06-17 19:56:36 -05003401 init_timer(&vport->fc_disctmo);
3402 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003403 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04003404
James Smart2e0fef82007-06-17 19:56:36 -05003405 init_timer(&vport->els_tmofunc);
3406 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003407 vport->els_tmofunc.data = (unsigned long)vport;
James Smart92494142011-02-16 12:39:44 -05003408
3409 init_timer(&vport->delayed_disc_tmo);
3410 vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
3411 vport->delayed_disc_tmo.data = (unsigned long)vport;
3412
James Bottomleyd139b9b2009-11-05 13:33:12 -06003413 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05003414 if (error)
3415 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04003416
James Smart549e55c2007-08-02 11:09:51 -04003417 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003418 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04003419 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003420 return vport;
James Smart47a86172007-04-25 09:53:22 -04003421
James Smart2e0fef82007-06-17 19:56:36 -05003422out_put_shost:
3423 scsi_host_put(shost);
3424out:
3425 return NULL;
James Smart47a86172007-04-25 09:53:22 -04003426}
3427
James Smarte59058c2008-08-24 21:49:00 -04003428/**
James Smart3621a712009-04-06 18:47:14 -04003429 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04003430 * @vport: pointer to an lpfc virtual N_Port data structure.
3431 *
3432 * This routine destroys a FC port from the upper layer protocol. All the
3433 * resources associated with the port are released.
3434 **/
James Smart2e0fef82007-06-17 19:56:36 -05003435void
3436destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04003437{
James Smart92d7f7b2007-06-17 19:56:38 -05003438 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3439 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003440
James Smart858c9f62007-06-17 19:56:39 -05003441 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05003442 fc_remove_host(shost);
3443 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04003444
James Smart92d7f7b2007-06-17 19:56:38 -05003445 spin_lock_irq(&phba->hbalock);
3446 list_del_init(&vport->listentry);
3447 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04003448
James Smart92d7f7b2007-06-17 19:56:38 -05003449 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04003450 return;
James Smart47a86172007-04-25 09:53:22 -04003451}
3452
James Smarte59058c2008-08-24 21:49:00 -04003453/**
James Smart3621a712009-04-06 18:47:14 -04003454 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04003455 *
3456 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3457 * uses the kernel idr facility to perform the task.
3458 *
3459 * Return codes:
3460 * instance - a unique integer ID allocated as the new instance.
3461 * -1 - lpfc get instance failed.
3462 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003463int
3464lpfc_get_instance(void)
3465{
Tejun Heoab516032013-02-27 17:04:44 -08003466 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003467
Tejun Heoab516032013-02-27 17:04:44 -08003468 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
3469 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003470}
3471
James Smarte59058c2008-08-24 21:49:00 -04003472/**
James Smart3621a712009-04-06 18:47:14 -04003473 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04003474 * @shost: pointer to SCSI host data structure.
3475 * @time: elapsed time of the scan in jiffies.
3476 *
3477 * This routine is called by the SCSI layer with a SCSI host to determine
3478 * whether the scan host is finished.
3479 *
3480 * Note: there is no scan_start function as adapter initialization will have
3481 * asynchronously kicked off the link initialization.
3482 *
3483 * Return codes
3484 * 0 - SCSI host scan is not over yet.
3485 * 1 - SCSI host scan is over.
3486 **/
James Smart47a86172007-04-25 09:53:22 -04003487int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
3488{
James Smart2e0fef82007-06-17 19:56:36 -05003489 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3490 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05003491 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04003492
James Smart858c9f62007-06-17 19:56:39 -05003493 spin_lock_irq(shost->host_lock);
3494
James Smart51ef4c22007-08-02 11:10:31 -04003495 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05003496 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003497 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05003498 }
James Smart256ec0d2013-04-17 20:14:58 -04003499 if (time >= msecs_to_jiffies(30 * 1000)) {
James Smart2e0fef82007-06-17 19:56:36 -05003500 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003501 "0461 Scanning longer than 30 "
3502 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003503 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003504 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003505 }
James Smart256ec0d2013-04-17 20:14:58 -04003506 if (time >= msecs_to_jiffies(15 * 1000) &&
3507 phba->link_state <= LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05003508 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003509 "0465 Link down longer than 15 "
3510 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003511 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05003512 goto finished;
James Smart47a86172007-04-25 09:53:22 -04003513 }
3514
James Smart2e0fef82007-06-17 19:56:36 -05003515 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05003516 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003517 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05003518 goto finished;
James Smart256ec0d2013-04-17 20:14:58 -04003519 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
James Smart858c9f62007-06-17 19:56:39 -05003520 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003521 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05003522 goto finished;
3523
3524 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003525
3526finished:
James Smart858c9f62007-06-17 19:56:39 -05003527 spin_unlock_irq(shost->host_lock);
3528 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003529}
3530
James Smarte59058c2008-08-24 21:49:00 -04003531/**
James Smart3621a712009-04-06 18:47:14 -04003532 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04003533 * @shost: pointer to SCSI host data structure.
3534 *
3535 * This routine initializes a given SCSI host attributes on a FC port. The
3536 * SCSI host can be either on top of a physical port or a virtual port.
3537 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003538void lpfc_host_attrib_init(struct Scsi_Host *shost)
3539{
3540 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3541 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003542 /*
James Smart2e0fef82007-06-17 19:56:36 -05003543 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04003544 */
3545
James Smart2e0fef82007-06-17 19:56:36 -05003546 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
3547 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04003548 fc_host_supported_classes(shost) = FC_COS_CLASS3;
3549
3550 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003551 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003552 fc_host_supported_fc4s(shost)[2] = 1;
3553 fc_host_supported_fc4s(shost)[7] = 1;
3554
James Smart92d7f7b2007-06-17 19:56:38 -05003555 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
3556 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04003557
3558 fc_host_supported_speeds(shost) = 0;
James Smartd38dd522015-08-31 16:48:17 -04003559 if (phba->lmt & LMT_32Gb)
3560 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
James Smart88a2cfb2011-07-22 18:36:33 -04003561 if (phba->lmt & LMT_16Gb)
3562 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
James Smart47a86172007-04-25 09:53:22 -04003563 if (phba->lmt & LMT_10Gb)
3564 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04003565 if (phba->lmt & LMT_8Gb)
3566 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04003567 if (phba->lmt & LMT_4Gb)
3568 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
3569 if (phba->lmt & LMT_2Gb)
3570 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
3571 if (phba->lmt & LMT_1Gb)
3572 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
3573
3574 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05003575 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
3576 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04003577
Mike Christie0af5d702010-09-15 16:52:31 -05003578 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
3579
James Smart47a86172007-04-25 09:53:22 -04003580 /* This value is also unchanging */
3581 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003582 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003583 fc_host_active_fc4s(shost)[2] = 1;
3584 fc_host_active_fc4s(shost)[7] = 1;
3585
James Smart92d7f7b2007-06-17 19:56:38 -05003586 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04003587 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04003588 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04003589 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04003590}
dea31012005-04-17 16:05:31 -05003591
James Smarte59058c2008-08-24 21:49:00 -04003592/**
James Smartda0436e2009-05-22 14:51:39 -04003593 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04003594 * @phba: pointer to lpfc hba data structure.
3595 *
James Smartda0436e2009-05-22 14:51:39 -04003596 * This routine is invoked to stop an SLI3 device port, it stops the device
3597 * from generating interrupts and stops the device driver's timers for the
3598 * device.
James Smarte59058c2008-08-24 21:49:00 -04003599 **/
James Smartdb2378e2008-02-08 18:49:51 -05003600static void
James Smartda0436e2009-05-22 14:51:39 -04003601lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05003602{
James Smartda0436e2009-05-22 14:51:39 -04003603 /* Clear all interrupt enable conditions */
3604 writel(0, phba->HCregaddr);
3605 readl(phba->HCregaddr); /* flush */
3606 /* Clear all pending interrupts */
3607 writel(0xffffffff, phba->HAregaddr);
3608 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04003609
James Smartda0436e2009-05-22 14:51:39 -04003610 /* Reset some HBA SLI setup states */
3611 lpfc_stop_hba_timers(phba);
3612 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05003613}
3614
James Smarte59058c2008-08-24 21:49:00 -04003615/**
James Smartda0436e2009-05-22 14:51:39 -04003616 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05003617 * @phba: pointer to lpfc hba data structure.
3618 *
James Smartda0436e2009-05-22 14:51:39 -04003619 * This routine is invoked to stop an SLI4 device port, it stops the device
3620 * from generating interrupts and stops the device driver's timers for the
3621 * device.
3622 **/
3623static void
3624lpfc_stop_port_s4(struct lpfc_hba *phba)
3625{
3626 /* Reset some HBA SLI4 setup states */
3627 lpfc_stop_hba_timers(phba);
3628 phba->pport->work_port_events = 0;
3629 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04003630}
3631
3632/**
3633 * lpfc_stop_port - Wrapper function for stopping hba port
3634 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05003635 *
James Smartda0436e2009-05-22 14:51:39 -04003636 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3637 * the API jump table function pointer from the lpfc_hba struct.
3638 **/
3639void
3640lpfc_stop_port(struct lpfc_hba *phba)
3641{
3642 phba->lpfc_stop_port(phba);
3643}
3644
3645/**
James Smartecfd03c2010-02-12 14:41:27 -05003646 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3647 * @phba: Pointer to hba for which this call is being executed.
3648 *
3649 * This routine starts the timer waiting for the FCF rediscovery to complete.
3650 **/
3651void
3652lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
3653{
3654 unsigned long fcf_redisc_wait_tmo =
3655 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
3656 /* Start fcf rediscovery wait period timer */
3657 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
3658 spin_lock_irq(&phba->hbalock);
3659 /* Allow action to new fcf asynchronous event */
3660 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
3661 /* Mark the FCF rediscovery pending state */
3662 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
3663 spin_unlock_irq(&phba->hbalock);
3664}
3665
3666/**
3667 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
3668 * @ptr: Map to lpfc_hba data structure pointer.
3669 *
3670 * This routine is invoked when waiting for FCF table rediscover has been
3671 * timed out. If new FCF record(s) has (have) been discovered during the
3672 * wait period, a new FCF event shall be added to the FCOE async event
3673 * list, and then worker thread shall be waked up for processing from the
3674 * worker thread context.
3675 **/
Rashika Kheriae399b222014-09-03 12:55:28 -04003676static void
James Smartecfd03c2010-02-12 14:41:27 -05003677lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
3678{
3679 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
3680
3681 /* Don't send FCF rediscovery event if timer cancelled */
3682 spin_lock_irq(&phba->hbalock);
3683 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
3684 spin_unlock_irq(&phba->hbalock);
3685 return;
3686 }
3687 /* Clear FCF rediscovery timer pending flag */
3688 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
3689 /* FCF rediscovery event to worker thread */
3690 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
3691 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003692 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04003693 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05003694 /* wake up worker thread */
3695 lpfc_worker_wake_up(phba);
3696}
3697
3698/**
James Smartda0436e2009-05-22 14:51:39 -04003699 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
3700 * @phba: pointer to lpfc hba data structure.
3701 * @acqe_link: pointer to the async link completion queue entry.
3702 *
3703 * This routine is to parse the SLI4 link-attention link fault code and
3704 * translate it into the base driver's read link attention mailbox command
3705 * status.
3706 *
3707 * Return: Link-attention status in terms of base driver's coding.
3708 **/
3709static uint16_t
3710lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
3711 struct lpfc_acqe_link *acqe_link)
3712{
3713 uint16_t latt_fault;
3714
3715 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
3716 case LPFC_ASYNC_LINK_FAULT_NONE:
3717 case LPFC_ASYNC_LINK_FAULT_LOCAL:
3718 case LPFC_ASYNC_LINK_FAULT_REMOTE:
3719 latt_fault = 0;
3720 break;
3721 default:
3722 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3723 "0398 Invalid link fault code: x%x\n",
3724 bf_get(lpfc_acqe_link_fault, acqe_link));
3725 latt_fault = MBXERR_ERROR;
3726 break;
3727 }
3728 return latt_fault;
3729}
3730
3731/**
3732 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
3733 * @phba: pointer to lpfc hba data structure.
3734 * @acqe_link: pointer to the async link completion queue entry.
3735 *
3736 * This routine is to parse the SLI4 link attention type and translate it
3737 * into the base driver's link attention type coding.
3738 *
3739 * Return: Link attention type in terms of base driver's coding.
3740 **/
3741static uint8_t
3742lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
3743 struct lpfc_acqe_link *acqe_link)
3744{
3745 uint8_t att_type;
3746
3747 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
3748 case LPFC_ASYNC_LINK_STATUS_DOWN:
3749 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05003750 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04003751 break;
3752 case LPFC_ASYNC_LINK_STATUS_UP:
3753 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05003754 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003755 break;
3756 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05003757 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04003758 break;
3759 default:
3760 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3761 "0399 Invalid link attention type: x%x\n",
3762 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003763 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003764 break;
3765 }
3766 return att_type;
3767}
3768
3769/**
James Smart8b68cd52012-09-29 11:32:37 -04003770 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
3771 * @phba: pointer to lpfc hba data structure.
3772 *
3773 * This routine is to get an SLI3 FC port's link speed in Mbps.
3774 *
3775 * Return: link speed in terms of Mbps.
3776 **/
3777uint32_t
3778lpfc_sli_port_speed_get(struct lpfc_hba *phba)
3779{
3780 uint32_t link_speed;
3781
3782 if (!lpfc_is_link_up(phba))
3783 return 0;
3784
James Smarta085e872015-12-16 18:12:02 -05003785 if (phba->sli_rev <= LPFC_SLI_REV3) {
3786 switch (phba->fc_linkspeed) {
3787 case LPFC_LINK_SPEED_1GHZ:
3788 link_speed = 1000;
3789 break;
3790 case LPFC_LINK_SPEED_2GHZ:
3791 link_speed = 2000;
3792 break;
3793 case LPFC_LINK_SPEED_4GHZ:
3794 link_speed = 4000;
3795 break;
3796 case LPFC_LINK_SPEED_8GHZ:
3797 link_speed = 8000;
3798 break;
3799 case LPFC_LINK_SPEED_10GHZ:
3800 link_speed = 10000;
3801 break;
3802 case LPFC_LINK_SPEED_16GHZ:
3803 link_speed = 16000;
3804 break;
3805 default:
3806 link_speed = 0;
3807 }
3808 } else {
3809 if (phba->sli4_hba.link_state.logical_speed)
3810 link_speed =
3811 phba->sli4_hba.link_state.logical_speed;
3812 else
3813 link_speed = phba->sli4_hba.link_state.speed;
James Smart8b68cd52012-09-29 11:32:37 -04003814 }
3815 return link_speed;
3816}
3817
3818/**
3819 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
3820 * @phba: pointer to lpfc hba data structure.
3821 * @evt_code: asynchronous event code.
3822 * @speed_code: asynchronous event link speed code.
3823 *
3824 * This routine is to parse the giving SLI4 async event link speed code into
3825 * value of Mbps for the link speed.
3826 *
3827 * Return: link speed in terms of Mbps.
3828 **/
3829static uint32_t
3830lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
3831 uint8_t speed_code)
3832{
3833 uint32_t port_speed;
3834
3835 switch (evt_code) {
3836 case LPFC_TRAILER_CODE_LINK:
3837 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04003838 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smart8b68cd52012-09-29 11:32:37 -04003839 port_speed = 0;
3840 break;
James Smart26d830e2015-04-07 15:07:17 -04003841 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04003842 port_speed = 10;
3843 break;
James Smart26d830e2015-04-07 15:07:17 -04003844 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04003845 port_speed = 100;
3846 break;
James Smart26d830e2015-04-07 15:07:17 -04003847 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04003848 port_speed = 1000;
3849 break;
James Smart26d830e2015-04-07 15:07:17 -04003850 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04003851 port_speed = 10000;
3852 break;
James Smart26d830e2015-04-07 15:07:17 -04003853 case LPFC_ASYNC_LINK_SPEED_20GBPS:
3854 port_speed = 20000;
3855 break;
3856 case LPFC_ASYNC_LINK_SPEED_25GBPS:
3857 port_speed = 25000;
3858 break;
3859 case LPFC_ASYNC_LINK_SPEED_40GBPS:
3860 port_speed = 40000;
3861 break;
James Smart8b68cd52012-09-29 11:32:37 -04003862 default:
3863 port_speed = 0;
3864 }
3865 break;
3866 case LPFC_TRAILER_CODE_FC:
3867 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04003868 case LPFC_FC_LA_SPEED_UNKNOWN:
James Smart8b68cd52012-09-29 11:32:37 -04003869 port_speed = 0;
3870 break;
James Smart26d830e2015-04-07 15:07:17 -04003871 case LPFC_FC_LA_SPEED_1G:
James Smart8b68cd52012-09-29 11:32:37 -04003872 port_speed = 1000;
3873 break;
James Smart26d830e2015-04-07 15:07:17 -04003874 case LPFC_FC_LA_SPEED_2G:
James Smart8b68cd52012-09-29 11:32:37 -04003875 port_speed = 2000;
3876 break;
James Smart26d830e2015-04-07 15:07:17 -04003877 case LPFC_FC_LA_SPEED_4G:
James Smart8b68cd52012-09-29 11:32:37 -04003878 port_speed = 4000;
3879 break;
James Smart26d830e2015-04-07 15:07:17 -04003880 case LPFC_FC_LA_SPEED_8G:
James Smart8b68cd52012-09-29 11:32:37 -04003881 port_speed = 8000;
3882 break;
James Smart26d830e2015-04-07 15:07:17 -04003883 case LPFC_FC_LA_SPEED_10G:
James Smart8b68cd52012-09-29 11:32:37 -04003884 port_speed = 10000;
3885 break;
James Smart26d830e2015-04-07 15:07:17 -04003886 case LPFC_FC_LA_SPEED_16G:
James Smart8b68cd52012-09-29 11:32:37 -04003887 port_speed = 16000;
3888 break;
James Smartd38dd522015-08-31 16:48:17 -04003889 case LPFC_FC_LA_SPEED_32G:
3890 port_speed = 32000;
3891 break;
James Smart8b68cd52012-09-29 11:32:37 -04003892 default:
3893 port_speed = 0;
3894 }
3895 break;
3896 default:
3897 port_speed = 0;
3898 }
3899 return port_speed;
3900}
3901
3902/**
James Smart70f3c072010-12-15 17:57:33 -05003903 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04003904 * @phba: pointer to lpfc hba data structure.
3905 * @acqe_link: pointer to the async link completion queue entry.
3906 *
James Smart70f3c072010-12-15 17:57:33 -05003907 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04003908 **/
3909static void
3910lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
3911 struct lpfc_acqe_link *acqe_link)
3912{
3913 struct lpfc_dmabuf *mp;
3914 LPFC_MBOXQ_t *pmb;
3915 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05003916 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04003917 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05003918 int rc;
James Smartda0436e2009-05-22 14:51:39 -04003919
3920 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05003921 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04003922 return;
James Smart32b97932009-07-19 10:01:21 -04003923 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04003924 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3925 if (!pmb) {
3926 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3927 "0395 The mboxq allocation failed\n");
3928 return;
3929 }
3930 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3931 if (!mp) {
3932 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3933 "0396 The lpfc_dmabuf allocation failed\n");
3934 goto out_free_pmb;
3935 }
3936 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
3937 if (!mp->virt) {
3938 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3939 "0397 The mbuf allocation failed\n");
3940 goto out_free_dmabuf;
3941 }
3942
3943 /* Cleanup any outstanding ELS commands */
3944 lpfc_els_flush_all_cmd(phba);
3945
3946 /* Block ELS IOCBs until we have done process link event */
3947 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
3948
3949 /* Update link event statistics */
3950 phba->sli.slistat.link_event++;
3951
James Smart76a95d72010-11-20 23:11:48 -05003952 /* Create lpfc_handle_latt mailbox command from link ACQE */
3953 lpfc_read_topology(phba, pmb, mp);
3954 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04003955 pmb->vport = phba->pport;
3956
James Smartda0436e2009-05-22 14:51:39 -04003957 /* Keep the link status for extra SLI4 state machine reference */
3958 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04003959 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
3960 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04003961 phba->sli4_hba.link_state.duplex =
3962 bf_get(lpfc_acqe_link_duplex, acqe_link);
3963 phba->sli4_hba.link_state.status =
3964 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05003965 phba->sli4_hba.link_state.type =
3966 bf_get(lpfc_acqe_link_type, acqe_link);
3967 phba->sli4_hba.link_state.number =
3968 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04003969 phba->sli4_hba.link_state.fault =
3970 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05003971 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04003972 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
3973
James Smart70f3c072010-12-15 17:57:33 -05003974 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04003975 "2900 Async FC/FCoE Link event - Speed:%dGBit "
3976 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
3977 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05003978 phba->sli4_hba.link_state.speed,
3979 phba->sli4_hba.link_state.topology,
3980 phba->sli4_hba.link_state.status,
3981 phba->sli4_hba.link_state.type,
3982 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04003983 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05003984 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05003985 /*
3986 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
3987 * topology info. Note: Optional for non FC-AL ports.
3988 */
3989 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3990 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3991 if (rc == MBX_NOT_FINISHED)
3992 goto out_free_dmabuf;
3993 return;
3994 }
3995 /*
3996 * For FCoE Mode: fill in all the topology information we need and call
3997 * the READ_TOPOLOGY completion routine to continue without actually
3998 * sending the READ_TOPOLOGY mailbox command to the port.
3999 */
4000 /* Parse and translate status field */
4001 mb = &pmb->u.mb;
4002 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
4003
4004 /* Parse and translate link attention fields */
4005 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
4006 la->eventTag = acqe_link->event_tag;
4007 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
4008 bf_set(lpfc_mbx_read_top_link_spd, la,
James Smarta085e872015-12-16 18:12:02 -05004009 (bf_get(lpfc_acqe_link_speed, acqe_link)));
James Smart76a95d72010-11-20 23:11:48 -05004010
4011 /* Fake the the following irrelvant fields */
4012 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
4013 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
4014 bf_set(lpfc_mbx_read_top_il, la, 0);
4015 bf_set(lpfc_mbx_read_top_pb, la, 0);
4016 bf_set(lpfc_mbx_read_top_fa, la, 0);
4017 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04004018
4019 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05004020 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04004021
4022 return;
4023
4024out_free_dmabuf:
4025 kfree(mp);
4026out_free_pmb:
4027 mempool_free(pmb, phba->mbox_mem_pool);
4028}
4029
4030/**
James Smart70f3c072010-12-15 17:57:33 -05004031 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
4032 * @phba: pointer to lpfc hba data structure.
4033 * @acqe_fc: pointer to the async fc completion queue entry.
4034 *
4035 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
4036 * that the event was received and then issue a read_topology mailbox command so
4037 * that the rest of the driver will treat it the same as SLI3.
4038 **/
4039static void
4040lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
4041{
4042 struct lpfc_dmabuf *mp;
4043 LPFC_MBOXQ_t *pmb;
James Smart7bdedb32016-07-06 12:36:00 -07004044 MAILBOX_t *mb;
4045 struct lpfc_mbx_read_top *la;
James Smart70f3c072010-12-15 17:57:33 -05004046 int rc;
4047
4048 if (bf_get(lpfc_trailer_type, acqe_fc) !=
4049 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
4050 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4051 "2895 Non FC link Event detected.(%d)\n",
4052 bf_get(lpfc_trailer_type, acqe_fc));
4053 return;
4054 }
4055 /* Keep the link status for extra SLI4 state machine reference */
4056 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004057 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
4058 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05004059 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
4060 phba->sli4_hba.link_state.topology =
4061 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
4062 phba->sli4_hba.link_state.status =
4063 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
4064 phba->sli4_hba.link_state.type =
4065 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
4066 phba->sli4_hba.link_state.number =
4067 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
4068 phba->sli4_hba.link_state.fault =
4069 bf_get(lpfc_acqe_link_fault, acqe_fc);
4070 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004071 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart70f3c072010-12-15 17:57:33 -05004072 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4073 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4074 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4075 "%dMbps Fault:%d\n",
4076 phba->sli4_hba.link_state.speed,
4077 phba->sli4_hba.link_state.topology,
4078 phba->sli4_hba.link_state.status,
4079 phba->sli4_hba.link_state.type,
4080 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004081 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004082 phba->sli4_hba.link_state.fault);
4083 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4084 if (!pmb) {
4085 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4086 "2897 The mboxq allocation failed\n");
4087 return;
4088 }
4089 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4090 if (!mp) {
4091 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4092 "2898 The lpfc_dmabuf allocation failed\n");
4093 goto out_free_pmb;
4094 }
4095 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4096 if (!mp->virt) {
4097 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4098 "2899 The mbuf allocation failed\n");
4099 goto out_free_dmabuf;
4100 }
4101
4102 /* Cleanup any outstanding ELS commands */
4103 lpfc_els_flush_all_cmd(phba);
4104
4105 /* Block ELS IOCBs until we have done process link event */
4106 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
4107
4108 /* Update link event statistics */
4109 phba->sli.slistat.link_event++;
4110
4111 /* Create lpfc_handle_latt mailbox command from link ACQE */
4112 lpfc_read_topology(phba, pmb, mp);
4113 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4114 pmb->vport = phba->pport;
4115
James Smart7bdedb32016-07-06 12:36:00 -07004116 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
4117 /* Parse and translate status field */
4118 mb = &pmb->u.mb;
4119 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba,
4120 (void *)acqe_fc);
4121
4122 /* Parse and translate link attention fields */
4123 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
4124 la->eventTag = acqe_fc->event_tag;
4125 bf_set(lpfc_mbx_read_top_att_type, la,
4126 LPFC_FC_LA_TYPE_LINK_DOWN);
4127
4128 /* Invoke the mailbox command callback function */
4129 lpfc_mbx_cmpl_read_topology(phba, pmb);
4130
4131 return;
4132 }
4133
James Smart70f3c072010-12-15 17:57:33 -05004134 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4135 if (rc == MBX_NOT_FINISHED)
4136 goto out_free_dmabuf;
4137 return;
4138
4139out_free_dmabuf:
4140 kfree(mp);
4141out_free_pmb:
4142 mempool_free(pmb, phba->mbox_mem_pool);
4143}
4144
4145/**
4146 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4147 * @phba: pointer to lpfc hba data structure.
4148 * @acqe_fc: pointer to the async SLI completion queue entry.
4149 *
4150 * This routine is to handle the SLI4 asynchronous SLI events.
4151 **/
4152static void
4153lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
4154{
James Smart4b8bae02012-06-12 13:55:07 -04004155 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04004156 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04004157 uint8_t status;
James Smart946727d2015-04-07 15:07:09 -04004158 uint8_t evt_type;
James Smart448193b2015-12-16 18:12:05 -05004159 uint8_t operational = 0;
James Smart946727d2015-04-07 15:07:09 -04004160 struct temp_event temp_event_data;
James Smart4b8bae02012-06-12 13:55:07 -04004161 struct lpfc_acqe_misconfigured_event *misconfigured;
James Smart946727d2015-04-07 15:07:09 -04004162 struct Scsi_Host *shost;
James Smart4b8bae02012-06-12 13:55:07 -04004163
James Smart946727d2015-04-07 15:07:09 -04004164 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
4165
James Smart448193b2015-12-16 18:12:05 -05004166 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4167 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4168 "x%08x SLI Event Type:%d\n",
4169 acqe_sli->event_data1, acqe_sli->event_data2,
4170 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004171
4172 port_name = phba->Port[0];
4173 if (port_name == 0x00)
4174 port_name = '?'; /* get port name is empty */
4175
James Smart946727d2015-04-07 15:07:09 -04004176 switch (evt_type) {
4177 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
4178 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4179 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
4180 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4181
4182 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4183 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4184 acqe_sli->event_data1, port_name);
4185
James Smart310429e2016-07-06 12:35:54 -07004186 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04004187 shost = lpfc_shost_from_vport(phba->pport);
4188 fc_host_post_vendor_event(shost, fc_get_event_number(),
4189 sizeof(temp_event_data),
4190 (char *)&temp_event_data,
4191 SCSI_NL_VID_TYPE_PCI
4192 | PCI_VENDOR_ID_EMULEX);
4193 break;
4194 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
4195 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4196 temp_event_data.event_code = LPFC_NORMAL_TEMP;
4197 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4198
4199 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4200 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4201 acqe_sli->event_data1, port_name);
4202
4203 shost = lpfc_shost_from_vport(phba->pport);
4204 fc_host_post_vendor_event(shost, fc_get_event_number(),
4205 sizeof(temp_event_data),
4206 (char *)&temp_event_data,
4207 SCSI_NL_VID_TYPE_PCI
4208 | PCI_VENDOR_ID_EMULEX);
4209 break;
4210 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
4211 misconfigured = (struct lpfc_acqe_misconfigured_event *)
James Smart4b8bae02012-06-12 13:55:07 -04004212 &acqe_sli->event_data1;
4213
James Smart946727d2015-04-07 15:07:09 -04004214 /* fetch the status for this port */
4215 switch (phba->sli4_hba.lnk_info.lnk_no) {
4216 case LPFC_LINK_NUMBER_0:
James Smart448193b2015-12-16 18:12:05 -05004217 status = bf_get(lpfc_sli_misconfigured_port0_state,
4218 &misconfigured->theEvent);
4219 operational = bf_get(lpfc_sli_misconfigured_port0_op,
James Smart4b8bae02012-06-12 13:55:07 -04004220 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004221 break;
4222 case LPFC_LINK_NUMBER_1:
James Smart448193b2015-12-16 18:12:05 -05004223 status = bf_get(lpfc_sli_misconfigured_port1_state,
4224 &misconfigured->theEvent);
4225 operational = bf_get(lpfc_sli_misconfigured_port1_op,
James Smart4b8bae02012-06-12 13:55:07 -04004226 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004227 break;
4228 case LPFC_LINK_NUMBER_2:
James Smart448193b2015-12-16 18:12:05 -05004229 status = bf_get(lpfc_sli_misconfigured_port2_state,
4230 &misconfigured->theEvent);
4231 operational = bf_get(lpfc_sli_misconfigured_port2_op,
James Smart4b8bae02012-06-12 13:55:07 -04004232 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004233 break;
4234 case LPFC_LINK_NUMBER_3:
James Smart448193b2015-12-16 18:12:05 -05004235 status = bf_get(lpfc_sli_misconfigured_port3_state,
4236 &misconfigured->theEvent);
4237 operational = bf_get(lpfc_sli_misconfigured_port3_op,
James Smart4b8bae02012-06-12 13:55:07 -04004238 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004239 break;
4240 default:
James Smart448193b2015-12-16 18:12:05 -05004241 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4242 "3296 "
4243 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
4244 "event: Invalid link %d",
4245 phba->sli4_hba.lnk_info.lnk_no);
4246 return;
James Smart946727d2015-04-07 15:07:09 -04004247 }
James Smart4b8bae02012-06-12 13:55:07 -04004248
James Smart448193b2015-12-16 18:12:05 -05004249 /* Skip if optic state unchanged */
4250 if (phba->sli4_hba.lnk_info.optic_state == status)
4251 return;
4252
James Smart946727d2015-04-07 15:07:09 -04004253 switch (status) {
4254 case LPFC_SLI_EVENT_STATUS_VALID:
James Smart448193b2015-12-16 18:12:05 -05004255 sprintf(message, "Physical Link is functional");
4256 break;
James Smart946727d2015-04-07 15:07:09 -04004257 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
4258 sprintf(message, "Optics faulted/incorrectly "
4259 "installed/not installed - Reseat optics, "
4260 "if issue not resolved, replace.");
4261 break;
4262 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
4263 sprintf(message,
4264 "Optics of two types installed - Remove one "
4265 "optic or install matching pair of optics.");
4266 break;
4267 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
4268 sprintf(message, "Incompatible optics - Replace with "
James Smart292098b2012-09-29 11:31:41 -04004269 "compatible optics for card to function.");
James Smart946727d2015-04-07 15:07:09 -04004270 break;
James Smart448193b2015-12-16 18:12:05 -05004271 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
4272 sprintf(message, "Unqualified optics - Replace with "
4273 "Avago optics for Warranty and Technical "
4274 "Support - Link is%s operational",
4275 (operational) ? "" : " not");
4276 break;
4277 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
4278 sprintf(message, "Uncertified optics - Replace with "
4279 "Avago-certified optics to enable link "
4280 "operation - Link is%s operational",
4281 (operational) ? "" : " not");
4282 break;
James Smart946727d2015-04-07 15:07:09 -04004283 default:
4284 /* firmware is reporting a status we don't know about */
4285 sprintf(message, "Unknown event status x%02x", status);
4286 break;
4287 }
James Smart448193b2015-12-16 18:12:05 -05004288 phba->sli4_hba.lnk_info.optic_state = status;
James Smart946727d2015-04-07 15:07:09 -04004289 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart448193b2015-12-16 18:12:05 -05004290 "3176 Port Name %c %s\n", port_name, message);
James Smart946727d2015-04-07 15:07:09 -04004291 break;
4292 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
4293 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4294 "3192 Remote DPort Test Initiated - "
4295 "Event Data1:x%08x Event Data2: x%08x\n",
4296 acqe_sli->event_data1, acqe_sli->event_data2);
James Smart4b8bae02012-06-12 13:55:07 -04004297 break;
4298 default:
James Smart946727d2015-04-07 15:07:09 -04004299 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4300 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
4301 "x%08x SLI Event Type:%d\n",
4302 acqe_sli->event_data1, acqe_sli->event_data2,
4303 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004304 break;
4305 }
James Smart70f3c072010-12-15 17:57:33 -05004306}
4307
4308/**
James Smartfc2b9892010-02-26 14:15:29 -05004309 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
4310 * @vport: pointer to vport data structure.
4311 *
4312 * This routine is to perform Clear Virtual Link (CVL) on a vport in
4313 * response to a CVL event.
4314 *
4315 * Return the pointer to the ndlp with the vport if successful, otherwise
4316 * return NULL.
4317 **/
4318static struct lpfc_nodelist *
4319lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
4320{
4321 struct lpfc_nodelist *ndlp;
4322 struct Scsi_Host *shost;
4323 struct lpfc_hba *phba;
4324
4325 if (!vport)
4326 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05004327 phba = vport->phba;
4328 if (!phba)
4329 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04004330 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4331 if (!ndlp) {
4332 /* Cannot find existing Fabric ndlp, so allocate a new one */
4333 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4334 if (!ndlp)
4335 return 0;
4336 lpfc_nlp_init(vport, ndlp, Fabric_DID);
4337 /* Set the node type */
4338 ndlp->nlp_type |= NLP_FABRIC;
4339 /* Put ndlp onto node list */
4340 lpfc_enqueue_node(vport, ndlp);
4341 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4342 /* re-setup ndlp without removing from node list */
4343 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4344 if (!ndlp)
4345 return 0;
4346 }
James Smart63e801c2010-11-20 23:14:19 -05004347 if ((phba->pport->port_state < LPFC_FLOGI) &&
4348 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004349 return NULL;
4350 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05004351 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
4352 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004353 return NULL;
4354 shost = lpfc_shost_from_vport(vport);
4355 if (!shost)
4356 return NULL;
4357 lpfc_linkdown_port(vport);
4358 lpfc_cleanup_pending_mbox(vport);
4359 spin_lock_irq(shost->host_lock);
4360 vport->fc_flag |= FC_VPORT_CVL_RCVD;
4361 spin_unlock_irq(shost->host_lock);
4362
4363 return ndlp;
4364}
4365
4366/**
4367 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4368 * @vport: pointer to lpfc hba data structure.
4369 *
4370 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4371 * response to a FCF dead event.
4372 **/
4373static void
4374lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
4375{
4376 struct lpfc_vport **vports;
4377 int i;
4378
4379 vports = lpfc_create_vport_work_array(phba);
4380 if (vports)
4381 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4382 lpfc_sli4_perform_vport_cvl(vports[i]);
4383 lpfc_destroy_vport_work_array(phba, vports);
4384}
4385
4386/**
James Smart76a95d72010-11-20 23:11:48 -05004387 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04004388 * @phba: pointer to lpfc hba data structure.
4389 * @acqe_link: pointer to the async fcoe completion queue entry.
4390 *
4391 * This routine is to handle the SLI4 asynchronous fcoe event.
4392 **/
4393static void
James Smart76a95d72010-11-20 23:11:48 -05004394lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05004395 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04004396{
James Smart70f3c072010-12-15 17:57:33 -05004397 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004398 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04004399 struct lpfc_vport *vport;
4400 struct lpfc_nodelist *ndlp;
4401 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05004402 int active_vlink_present;
4403 struct lpfc_vport **vports;
4404 int i;
James Smartda0436e2009-05-22 14:51:39 -04004405
James Smart70f3c072010-12-15 17:57:33 -05004406 phba->fc_eventTag = acqe_fip->event_tag;
4407 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004408 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05004409 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
4410 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
4411 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04004412 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4413 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004414 "2546 New FCF event, evt_tag:x%x, "
4415 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004416 acqe_fip->event_tag,
4417 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04004418 else
4419 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
4420 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004421 "2788 FCF param modified event, "
4422 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004423 acqe_fip->event_tag,
4424 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04004425 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004426 /*
4427 * During period of FCF discovery, read the FCF
4428 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04004429 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05004430 */
4431 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4432 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004433 "2779 Read FCF (x%x) for updating "
4434 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05004435 acqe_fip->index);
4436 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004437 }
James Smart38b92ef2010-08-04 16:11:39 -04004438
4439 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04004440 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04004441 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04004442 spin_unlock_irq(&phba->hbalock);
4443 break;
4444 }
4445 /* If fast FCF failover rescan event is pending, do nothing */
4446 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
4447 spin_unlock_irq(&phba->hbalock);
4448 break;
4449 }
4450
James Smartc2b97122013-05-31 17:05:36 -04004451 /* If the FCF has been in discovered state, do nothing. */
4452 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
James Smart3804dc82010-07-14 15:31:37 -04004453 spin_unlock_irq(&phba->hbalock);
4454 break;
4455 }
4456 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04004457
James Smart0c9ab6f2010-02-26 14:15:57 -05004458 /* Otherwise, scan the entire FCF table and re-discover SAN */
4459 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004460 "2770 Start FCF table scan per async FCF "
4461 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004462 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004463 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
4464 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04004465 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004466 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4467 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04004468 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04004469 break;
4470
James Smart70f3c072010-12-15 17:57:33 -05004471 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04004472 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04004473 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004474 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
4475 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004476 break;
4477
James Smart70f3c072010-12-15 17:57:33 -05004478 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05004479 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004480 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004481 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05004482 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04004483 /*
4484 * If we are in the middle of FCF failover process, clear
4485 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04004486 */
James Smartfc2b9892010-02-26 14:15:29 -05004487 spin_lock_irq(&phba->hbalock);
James Smarta1cadfe2016-07-06 12:36:02 -07004488 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
4489 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
James Smartfc2b9892010-02-26 14:15:29 -05004490 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004491 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05004492 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004493 break;
4494 }
James Smart38b92ef2010-08-04 16:11:39 -04004495 spin_unlock_irq(&phba->hbalock);
4496
4497 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05004498 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04004499 break;
4500
4501 /*
4502 * Otherwise, request the port to rediscover the entire FCF
4503 * table for a fast recovery from case that the current FCF
4504 * is no longer valid as we are not in the middle of FCF
4505 * failover process already.
4506 */
James Smartc2b97122013-05-31 17:05:36 -04004507 spin_lock_irq(&phba->hbalock);
4508 /* Mark the fast failover process in progress */
4509 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
4510 spin_unlock_irq(&phba->hbalock);
4511
4512 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
4513 "2771 Start FCF fast failover process due to "
4514 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
4515 "\n", acqe_fip->event_tag, acqe_fip->index);
4516 rc = lpfc_sli4_redisc_fcf_table(phba);
4517 if (rc) {
4518 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4519 LOG_DISCOVERY,
4520 "2772 Issue FCF rediscover mabilbox "
4521 "command failed, fail through to FCF "
4522 "dead event\n");
4523 spin_lock_irq(&phba->hbalock);
4524 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
4525 spin_unlock_irq(&phba->hbalock);
4526 /*
4527 * Last resort will fail over by treating this
4528 * as a link down to FCF registration.
4529 */
4530 lpfc_sli4_fcf_dead_failthrough(phba);
4531 } else {
4532 /* Reset FCF roundrobin bmask for new discovery */
4533 lpfc_sli4_clear_fcf_rr_bmask(phba);
4534 /*
4535 * Handling fast FCF failover to a DEAD FCF event is
4536 * considered equalivant to receiving CVL to all vports.
4537 */
4538 lpfc_sli4_perform_all_vport_cvl(phba);
4539 }
James Smartda0436e2009-05-22 14:51:39 -04004540 break;
James Smart70f3c072010-12-15 17:57:33 -05004541 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05004542 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004543 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04004544 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05004545 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04004546
James Smart6669f9b2009-10-02 15:16:45 -04004547 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04004548 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004549 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004550 if (!ndlp)
4551 break;
James Smart695a8142010-01-26 23:08:03 -05004552 active_vlink_present = 0;
4553
4554 vports = lpfc_create_vport_work_array(phba);
4555 if (vports) {
4556 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
4557 i++) {
4558 if ((!(vports[i]->fc_flag &
4559 FC_VPORT_CVL_RCVD)) &&
4560 (vports[i]->port_state > LPFC_FDISC)) {
4561 active_vlink_present = 1;
4562 break;
4563 }
4564 }
4565 lpfc_destroy_vport_work_array(phba, vports);
4566 }
4567
James Smartcc823552015-05-21 13:55:26 -04004568 /*
4569 * Don't re-instantiate if vport is marked for deletion.
4570 * If we are here first then vport_delete is going to wait
4571 * for discovery to complete.
4572 */
4573 if (!(vport->load_flag & FC_UNLOADING) &&
4574 active_vlink_present) {
James Smart695a8142010-01-26 23:08:03 -05004575 /*
4576 * If there are other active VLinks present,
4577 * re-instantiate the Vlink using FDISC.
4578 */
James Smart256ec0d2013-04-17 20:14:58 -04004579 mod_timer(&ndlp->nlp_delayfunc,
4580 jiffies + msecs_to_jiffies(1000));
James Smartfc2b9892010-02-26 14:15:29 -05004581 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004582 spin_lock_irq(shost->host_lock);
4583 ndlp->nlp_flag |= NLP_DELAY_TMO;
4584 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05004585 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
4586 vport->port_state = LPFC_FDISC;
4587 } else {
James Smartecfd03c2010-02-12 14:41:27 -05004588 /*
4589 * Otherwise, we request port to rediscover
4590 * the entire FCF table for a fast recovery
4591 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05004592 * is no longer valid if we are not already
4593 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05004594 */
James Smartfc2b9892010-02-26 14:15:29 -05004595 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004596 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05004597 spin_unlock_irq(&phba->hbalock);
4598 break;
4599 }
4600 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05004601 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004602 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004603 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4604 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004605 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05004606 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05004607 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05004608 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004609 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4610 LOG_DISCOVERY,
4611 "2774 Issue FCF rediscover "
4612 "mabilbox command failed, "
4613 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05004614 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004615 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004616 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05004617 /*
4618 * Last resort will be re-try on the
4619 * the current registered FCF entry.
4620 */
4621 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04004622 } else
4623 /*
4624 * Reset FCF roundrobin bmask for new
4625 * discovery.
4626 */
James Smart7d791df2011-07-22 18:37:52 -04004627 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04004628 }
4629 break;
James Smartda0436e2009-05-22 14:51:39 -04004630 default:
4631 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4632 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05004633 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004634 break;
4635 }
4636}
4637
4638/**
4639 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
4640 * @phba: pointer to lpfc hba data structure.
4641 * @acqe_link: pointer to the async dcbx completion queue entry.
4642 *
4643 * This routine is to handle the SLI4 asynchronous dcbx event.
4644 **/
4645static void
4646lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
4647 struct lpfc_acqe_dcbx *acqe_dcbx)
4648{
James Smart4d9ab992009-10-02 15:16:39 -04004649 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004650 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4651 "0290 The SLI4 DCBX asynchronous event is not "
4652 "handled yet\n");
4653}
4654
4655/**
James Smartb19a0612010-04-06 14:48:51 -04004656 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
4657 * @phba: pointer to lpfc hba data structure.
4658 * @acqe_link: pointer to the async grp5 completion queue entry.
4659 *
4660 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
4661 * is an asynchronous notified of a logical link speed change. The Port
4662 * reports the logical link speed in units of 10Mbps.
4663 **/
4664static void
4665lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
4666 struct lpfc_acqe_grp5 *acqe_grp5)
4667{
4668 uint16_t prev_ll_spd;
4669
4670 phba->fc_eventTag = acqe_grp5->event_tag;
4671 phba->fcoe_eventtag = acqe_grp5->event_tag;
4672 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
4673 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004674 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04004675 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4676 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04004677 "from %dMbps to %dMbps\n", prev_ll_spd,
4678 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04004679}
4680
4681/**
James Smartda0436e2009-05-22 14:51:39 -04004682 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
4683 * @phba: pointer to lpfc hba data structure.
4684 *
4685 * This routine is invoked by the worker thread to process all the pending
4686 * SLI4 asynchronous events.
4687 **/
4688void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
4689{
4690 struct lpfc_cq_event *cq_event;
4691
4692 /* First, declare the async event has been handled */
4693 spin_lock_irq(&phba->hbalock);
4694 phba->hba_flag &= ~ASYNC_EVENT;
4695 spin_unlock_irq(&phba->hbalock);
4696 /* Now, handle all the async events */
4697 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
4698 /* Get the first event from the head of the event queue */
4699 spin_lock_irq(&phba->hbalock);
4700 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
4701 cq_event, struct lpfc_cq_event, list);
4702 spin_unlock_irq(&phba->hbalock);
4703 /* Process the asynchronous event */
4704 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
4705 case LPFC_TRAILER_CODE_LINK:
4706 lpfc_sli4_async_link_evt(phba,
4707 &cq_event->cqe.acqe_link);
4708 break;
4709 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05004710 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004711 break;
4712 case LPFC_TRAILER_CODE_DCBX:
4713 lpfc_sli4_async_dcbx_evt(phba,
4714 &cq_event->cqe.acqe_dcbx);
4715 break;
James Smartb19a0612010-04-06 14:48:51 -04004716 case LPFC_TRAILER_CODE_GRP5:
4717 lpfc_sli4_async_grp5_evt(phba,
4718 &cq_event->cqe.acqe_grp5);
4719 break;
James Smart70f3c072010-12-15 17:57:33 -05004720 case LPFC_TRAILER_CODE_FC:
4721 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
4722 break;
4723 case LPFC_TRAILER_CODE_SLI:
4724 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
4725 break;
James Smartda0436e2009-05-22 14:51:39 -04004726 default:
4727 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4728 "1804 Invalid asynchrous event code: "
4729 "x%x\n", bf_get(lpfc_trailer_code,
4730 &cq_event->cqe.mcqe_cmpl));
4731 break;
4732 }
4733 /* Free the completion event processed to the free pool */
4734 lpfc_sli4_cq_event_release(phba, cq_event);
4735 }
4736}
4737
4738/**
James Smartecfd03c2010-02-12 14:41:27 -05004739 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
4740 * @phba: pointer to lpfc hba data structure.
4741 *
4742 * This routine is invoked by the worker thread to process FCF table
4743 * rediscovery pending completion event.
4744 **/
4745void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
4746{
4747 int rc;
4748
4749 spin_lock_irq(&phba->hbalock);
4750 /* Clear FCF rediscovery timeout event */
4751 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
4752 /* Clear driver fast failover FCF record flag */
4753 phba->fcf.failover_rec.flag = 0;
4754 /* Set state for FCF fast failover */
4755 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
4756 spin_unlock_irq(&phba->hbalock);
4757
4758 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05004759 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004760 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05004761 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05004762 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004763 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4764 "2747 Issue FCF scan read FCF mailbox "
4765 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05004766}
4767
4768/**
James Smartda0436e2009-05-22 14:51:39 -04004769 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
4770 * @phba: pointer to lpfc hba data structure.
4771 * @dev_grp: The HBA PCI-Device group number.
4772 *
4773 * This routine is invoked to set up the per HBA PCI-Device group function
4774 * API jump table entries.
4775 *
4776 * Return: 0 if success, otherwise -ENODEV
4777 **/
4778int
4779lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05004780{
4781 int rc;
4782
James Smartda0436e2009-05-22 14:51:39 -04004783 /* Set up lpfc PCI-device group */
4784 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05004785
James Smartda0436e2009-05-22 14:51:39 -04004786 /* The LPFC_PCI_DEV_OC uses SLI4 */
4787 if (dev_grp == LPFC_PCI_DEV_OC)
4788 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05004789
James Smartda0436e2009-05-22 14:51:39 -04004790 /* Set up device INIT API function jump table */
4791 rc = lpfc_init_api_table_setup(phba, dev_grp);
4792 if (rc)
4793 return -ENODEV;
4794 /* Set up SCSI API function jump table */
4795 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
4796 if (rc)
4797 return -ENODEV;
4798 /* Set up SLI API function jump table */
4799 rc = lpfc_sli_api_table_setup(phba, dev_grp);
4800 if (rc)
4801 return -ENODEV;
4802 /* Set up MBOX API function jump table */
4803 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
4804 if (rc)
4805 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05004806
James Smartda0436e2009-05-22 14:51:39 -04004807 return 0;
James Smart5b75da22008-12-04 22:39:35 -05004808}
4809
4810/**
James Smart3621a712009-04-06 18:47:14 -04004811 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05004812 * @phba: pointer to lpfc hba data structure.
4813 * @intr_mode: active interrupt mode adopted.
4814 *
4815 * This routine it invoked to log the currently used active interrupt mode
4816 * to the device.
James Smart3772a992009-05-22 14:50:54 -04004817 **/
4818static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05004819{
4820 switch (intr_mode) {
4821 case 0:
4822 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4823 "0470 Enable INTx interrupt mode.\n");
4824 break;
4825 case 1:
4826 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4827 "0481 Enabled MSI interrupt mode.\n");
4828 break;
4829 case 2:
4830 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4831 "0480 Enabled MSI-X interrupt mode.\n");
4832 break;
4833 default:
4834 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4835 "0482 Illegal interrupt mode.\n");
4836 break;
4837 }
4838 return;
4839}
4840
James Smart5b75da22008-12-04 22:39:35 -05004841/**
James Smart3772a992009-05-22 14:50:54 -04004842 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05004843 * @phba: pointer to lpfc hba data structure.
4844 *
James Smart3772a992009-05-22 14:50:54 -04004845 * This routine is invoked to enable the PCI device that is common to all
4846 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05004847 *
4848 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004849 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004850 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05004851 **/
James Smart3772a992009-05-22 14:50:54 -04004852static int
4853lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05004854{
James Smart3772a992009-05-22 14:50:54 -04004855 struct pci_dev *pdev;
James Smart079b5c92011-08-21 21:48:49 -04004856 int bars = 0;
James Smart5b75da22008-12-04 22:39:35 -05004857
James Smart3772a992009-05-22 14:50:54 -04004858 /* Obtain PCI device reference */
4859 if (!phba->pcidev)
4860 goto out_error;
4861 else
4862 pdev = phba->pcidev;
4863 /* Select PCI BARs */
4864 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4865 /* Enable PCI device */
4866 if (pci_enable_device_mem(pdev))
4867 goto out_error;
4868 /* Request PCI resource for the device */
4869 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
4870 goto out_disable_device;
4871 /* Set up device as PCI master and save state for EEH */
4872 pci_set_master(pdev);
4873 pci_try_set_mwi(pdev);
4874 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05004875
James Smart05580562011-05-24 11:40:48 -04004876 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
Jon Mason453193e2013-09-11 15:38:13 -07004877 if (pci_is_pcie(pdev))
James Smart05580562011-05-24 11:40:48 -04004878 pdev->needs_freset = 1;
4879
James Smart3772a992009-05-22 14:50:54 -04004880 return 0;
James Smart5b75da22008-12-04 22:39:35 -05004881
James Smart3772a992009-05-22 14:50:54 -04004882out_disable_device:
4883 pci_disable_device(pdev);
4884out_error:
James Smart079b5c92011-08-21 21:48:49 -04004885 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4886 "1401 Failed to enable pci device, bars:x%x\n", bars);
James Smart3772a992009-05-22 14:50:54 -04004887 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05004888}
4889
4890/**
James Smart3772a992009-05-22 14:50:54 -04004891 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05004892 * @phba: pointer to lpfc hba data structure.
4893 *
James Smart3772a992009-05-22 14:50:54 -04004894 * This routine is invoked to disable the PCI device that is common to all
4895 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05004896 **/
4897static void
James Smart3772a992009-05-22 14:50:54 -04004898lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05004899{
James Smart3772a992009-05-22 14:50:54 -04004900 struct pci_dev *pdev;
4901 int bars;
James Smart5b75da22008-12-04 22:39:35 -05004902
James Smart3772a992009-05-22 14:50:54 -04004903 /* Obtain PCI device reference */
4904 if (!phba->pcidev)
4905 return;
4906 else
4907 pdev = phba->pcidev;
4908 /* Select PCI BARs */
4909 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4910 /* Release PCI resource and disable PCI device */
4911 pci_release_selected_regions(pdev, bars);
4912 pci_disable_device(pdev);
James Smart5b75da22008-12-04 22:39:35 -05004913
4914 return;
4915}
4916
4917/**
James Smart3772a992009-05-22 14:50:54 -04004918 * lpfc_reset_hba - Reset a hba
4919 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04004920 *
James Smart3772a992009-05-22 14:50:54 -04004921 * This routine is invoked to reset a hba device. It brings the HBA
4922 * offline, performs a board restart, and then brings the board back
4923 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
4924 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04004925 **/
James Smart3772a992009-05-22 14:50:54 -04004926void
4927lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05004928{
James Smart3772a992009-05-22 14:50:54 -04004929 /* If resets are disabled then set error state and return. */
4930 if (!phba->cfg_enable_hba_reset) {
4931 phba->link_state = LPFC_HBA_ERROR;
4932 return;
4933 }
James Smartee620212014-04-04 13:51:53 -04004934 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
4935 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
4936 else
4937 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart3772a992009-05-22 14:50:54 -04004938 lpfc_offline(phba);
4939 lpfc_sli_brdrestart(phba);
4940 lpfc_online(phba);
4941 lpfc_unblock_mgmt_io(phba);
4942}
dea31012005-04-17 16:05:31 -05004943
James Smart3772a992009-05-22 14:50:54 -04004944/**
James Smart0a96e972011-07-22 18:37:28 -04004945 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
4946 * @phba: pointer to lpfc hba data structure.
4947 *
4948 * This function enables the PCI SR-IOV virtual functions to a physical
4949 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4950 * enable the number of virtual functions to the physical function. As
4951 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4952 * API call does not considered as an error condition for most of the device.
4953 **/
4954uint16_t
4955lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
4956{
4957 struct pci_dev *pdev = phba->pcidev;
4958 uint16_t nr_virtfn;
4959 int pos;
4960
James Smart0a96e972011-07-22 18:37:28 -04004961 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4962 if (pos == 0)
4963 return 0;
4964
4965 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
4966 return nr_virtfn;
4967}
4968
4969/**
James Smart912e3ac2011-05-24 11:42:11 -04004970 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
4971 * @phba: pointer to lpfc hba data structure.
4972 * @nr_vfn: number of virtual functions to be enabled.
4973 *
4974 * This function enables the PCI SR-IOV virtual functions to a physical
4975 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4976 * enable the number of virtual functions to the physical function. As
4977 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4978 * API call does not considered as an error condition for most of the device.
4979 **/
4980int
4981lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
4982{
4983 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04004984 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04004985 int rc;
4986
James Smart0a96e972011-07-22 18:37:28 -04004987 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
4988 if (nr_vfn > max_nr_vfn) {
4989 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4990 "3057 Requested vfs (%d) greater than "
4991 "supported vfs (%d)", nr_vfn, max_nr_vfn);
4992 return -EINVAL;
4993 }
4994
James Smart912e3ac2011-05-24 11:42:11 -04004995 rc = pci_enable_sriov(pdev, nr_vfn);
4996 if (rc) {
4997 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4998 "2806 Failed to enable sriov on this device "
4999 "with vfn number nr_vf:%d, rc:%d\n",
5000 nr_vfn, rc);
5001 } else
5002 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5003 "2807 Successful enable sriov on this device "
5004 "with vfn number nr_vf:%d\n", nr_vfn);
5005 return rc;
5006}
5007
5008/**
James Smart3772a992009-05-22 14:50:54 -04005009 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
5010 * @phba: pointer to lpfc hba data structure.
5011 *
5012 * This routine is invoked to set up the driver internal resources specific to
5013 * support the SLI-3 HBA device it attached to.
5014 *
5015 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005016 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005017 * other values - error
5018 **/
5019static int
5020lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
5021{
5022 struct lpfc_sli *psli;
James Smart912e3ac2011-05-24 11:42:11 -04005023 int rc;
dea31012005-04-17 16:05:31 -05005024
James Smart3772a992009-05-22 14:50:54 -04005025 /*
5026 * Initialize timers used by driver
5027 */
dea31012005-04-17 16:05:31 -05005028
James Smart3772a992009-05-22 14:50:54 -04005029 /* Heartbeat timer */
5030 init_timer(&phba->hb_tmofunc);
5031 phba->hb_tmofunc.function = lpfc_hb_timeout;
5032 phba->hb_tmofunc.data = (unsigned long)phba;
5033
5034 psli = &phba->sli;
5035 /* MBOX heartbeat timer */
5036 init_timer(&psli->mbox_tmo);
5037 psli->mbox_tmo.function = lpfc_mbox_timeout;
5038 psli->mbox_tmo.data = (unsigned long) phba;
5039 /* FCP polling mode timer */
5040 init_timer(&phba->fcp_poll_timer);
5041 phba->fcp_poll_timer.function = lpfc_poll_timeout;
5042 phba->fcp_poll_timer.data = (unsigned long) phba;
5043 /* Fabric block timer */
5044 init_timer(&phba->fabric_block_timer);
5045 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
5046 phba->fabric_block_timer.data = (unsigned long) phba;
5047 /* EA polling mode timer */
5048 init_timer(&phba->eratt_poll);
5049 phba->eratt_poll.function = lpfc_poll_eratt;
5050 phba->eratt_poll.data = (unsigned long) phba;
5051
5052 /* Host attention work mask setup */
5053 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
5054 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
5055
5056 /* Get all the module params for configuring this host */
5057 lpfc_get_cfgparam(phba);
James Smart49198b32010-04-06 15:04:33 -04005058 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
5059 phba->menlo_flag |= HBA_MENLO_SUPPORT;
5060 /* check for menlo minimum sg count */
5061 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
5062 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
5063 }
5064
James Smart2a76a282012-08-03 12:35:54 -04005065 if (!phba->sli.ring)
Firo Yangc6cb9b42015-08-31 16:48:09 -04005066 phba->sli.ring = kzalloc(LPFC_SLI3_MAX_RING *
James Smart2a76a282012-08-03 12:35:54 -04005067 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
5068 if (!phba->sli.ring)
5069 return -ENOMEM;
5070
James Smart3772a992009-05-22 14:50:54 -04005071 /*
James Smart96f70772013-04-17 20:16:15 -04005072 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smart3772a992009-05-22 14:50:54 -04005073 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart3772a992009-05-22 14:50:54 -04005074 */
James Smart3772a992009-05-22 14:50:54 -04005075
James Smart96f70772013-04-17 20:16:15 -04005076 /* Initialize the host templates the configured values. */
James Smart3772a992009-05-22 14:50:54 -04005077 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
Bodo Stroesser5f406fa2015-08-31 16:48:10 -04005078 lpfc_template_s3.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart3772a992009-05-22 14:50:54 -04005079
James Smart96f70772013-04-17 20:16:15 -04005080 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
5081 if (phba->cfg_enable_bg) {
5082 /*
5083 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5084 * the FCP rsp, and a BDE for each. Sice we have no control
5085 * over how many protection data segments the SCSI Layer
5086 * will hand us (ie: there could be one for every block
5087 * in the IO), we just allocate enough BDEs to accomidate
5088 * our max amount and we need to limit lpfc_sg_seg_cnt to
5089 * minimize the risk of running out.
5090 */
5091 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5092 sizeof(struct fcp_rsp) +
5093 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
5094
5095 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
5096 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
5097
5098 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
5099 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
5100 } else {
5101 /*
5102 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5103 * the FCP rsp, a BDE for each, and a BDE for up to
5104 * cfg_sg_seg_cnt data segments.
5105 */
5106 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5107 sizeof(struct fcp_rsp) +
5108 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
5109
5110 /* Total BDEs in BPL for scsi_sg_list */
5111 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5112 }
5113
5114 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5115 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
5116 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5117 phba->cfg_total_seg_cnt);
5118
James Smart3772a992009-05-22 14:50:54 -04005119 phba->max_vpi = LPFC_MAX_VPI;
5120 /* This will be set to correct value after config_port mbox */
5121 phba->max_vports = 0;
5122
5123 /*
5124 * Initialize the SLI Layer to run with lpfc HBAs.
5125 */
5126 lpfc_sli_setup(phba);
5127 lpfc_sli_queue_setup(phba);
5128
5129 /* Allocate device driver memory */
5130 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
5131 return -ENOMEM;
5132
James Smart912e3ac2011-05-24 11:42:11 -04005133 /*
5134 * Enable sr-iov virtual functions if supported and configured
5135 * through the module parameter.
5136 */
5137 if (phba->cfg_sriov_nr_virtfn > 0) {
5138 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5139 phba->cfg_sriov_nr_virtfn);
5140 if (rc) {
5141 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5142 "2808 Requested number of SR-IOV "
5143 "virtual functions (%d) is not "
5144 "supported\n",
5145 phba->cfg_sriov_nr_virtfn);
5146 phba->cfg_sriov_nr_virtfn = 0;
5147 }
5148 }
5149
James Smart3772a992009-05-22 14:50:54 -04005150 return 0;
5151}
5152
5153/**
5154 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
5155 * @phba: pointer to lpfc hba data structure.
5156 *
5157 * This routine is invoked to unset the driver internal resources set up
5158 * specific for supporting the SLI-3 HBA device it attached to.
5159 **/
5160static void
5161lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
5162{
5163 /* Free device driver memory allocated */
5164 lpfc_mem_free_all(phba);
5165
5166 return;
5167}
5168
5169/**
James Smartda0436e2009-05-22 14:51:39 -04005170 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
5171 * @phba: pointer to lpfc hba data structure.
5172 *
5173 * This routine is invoked to set up the driver internal resources specific to
5174 * support the SLI-4 HBA device it attached to.
5175 *
5176 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005177 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04005178 * other values - error
5179 **/
5180static int
5181lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5182{
James Smart7bb03bb2013-04-17 20:19:16 -04005183 struct lpfc_vector_map_info *cpup;
James Smartda0436e2009-05-22 14:51:39 -04005184 struct lpfc_sli *psli;
James Smart28baac72010-02-12 14:42:03 -05005185 LPFC_MBOXQ_t *mboxq;
James Smart96f70772013-04-17 20:16:15 -04005186 int rc, i, hbq_count, max_buf_size;
James Smart28baac72010-02-12 14:42:03 -05005187 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
5188 struct lpfc_mqe *mqe;
James Smart09294d42013-04-17 20:16:05 -04005189 int longs;
James Smart1ba981f2014-02-20 09:56:45 -05005190 int fof_vectors = 0;
James Smartda0436e2009-05-22 14:51:39 -04005191
James Smart716d3bc2013-09-06 12:18:28 -04005192 /* Get all the module params for configuring this host */
5193 lpfc_get_cfgparam(phba);
5194
James Smartda0436e2009-05-22 14:51:39 -04005195 /* Before proceed, wait for POST done and device ready */
5196 rc = lpfc_sli4_post_status_check(phba);
5197 if (rc)
5198 return -ENODEV;
5199
5200 /*
5201 * Initialize timers used by driver
5202 */
5203
5204 /* Heartbeat timer */
5205 init_timer(&phba->hb_tmofunc);
5206 phba->hb_tmofunc.function = lpfc_hb_timeout;
5207 phba->hb_tmofunc.data = (unsigned long)phba;
James Smart19ca7602010-11-20 23:11:55 -05005208 init_timer(&phba->rrq_tmr);
5209 phba->rrq_tmr.function = lpfc_rrq_timeout;
5210 phba->rrq_tmr.data = (unsigned long)phba;
James Smartda0436e2009-05-22 14:51:39 -04005211
5212 psli = &phba->sli;
5213 /* MBOX heartbeat timer */
5214 init_timer(&psli->mbox_tmo);
5215 psli->mbox_tmo.function = lpfc_mbox_timeout;
5216 psli->mbox_tmo.data = (unsigned long) phba;
5217 /* Fabric block timer */
5218 init_timer(&phba->fabric_block_timer);
5219 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
5220 phba->fabric_block_timer.data = (unsigned long) phba;
5221 /* EA polling mode timer */
5222 init_timer(&phba->eratt_poll);
5223 phba->eratt_poll.function = lpfc_poll_eratt;
5224 phba->eratt_poll.data = (unsigned long) phba;
James Smartecfd03c2010-02-12 14:41:27 -05005225 /* FCF rediscover timer */
5226 init_timer(&phba->fcf.redisc_wait);
5227 phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
5228 phba->fcf.redisc_wait.data = (unsigned long)phba;
5229
James Smartda0436e2009-05-22 14:51:39 -04005230 /*
James Smart7ad20aa2011-05-24 11:44:28 -04005231 * Control structure for handling external multi-buffer mailbox
5232 * command pass-through.
5233 */
5234 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
5235 sizeof(struct lpfc_mbox_ext_buf_ctx));
5236 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
5237
James Smartda0436e2009-05-22 14:51:39 -04005238 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04005239
James Smartda0436e2009-05-22 14:51:39 -04005240 /* This will be set to correct value after the read_config mbox */
5241 phba->max_vports = 0;
5242
5243 /* Program the default value of vlan_id and fc_map */
5244 phba->valid_vlan = 0;
5245 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5246 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5247 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5248
5249 /*
James Smart2a76a282012-08-03 12:35:54 -04005250 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
5251 * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple.
5252 */
5253 if (!phba->sli.ring)
5254 phba->sli.ring = kzalloc(
James Smart67d12732012-08-03 12:36:13 -04005255 (LPFC_SLI3_MAX_RING + phba->cfg_fcp_io_channel) *
James Smart2a76a282012-08-03 12:35:54 -04005256 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
5257 if (!phba->sli.ring)
5258 return -ENOMEM;
James Smart085c6472010-11-20 23:11:37 -05005259
James Smart09294d42013-04-17 20:16:05 -04005260 /*
5261 * It doesn't matter what family our adapter is in, we are
5262 * limited to 2 Pages, 512 SGEs, for our SGL.
5263 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
5264 */
5265 max_buf_size = (2 * SLI4_PAGE_SIZE);
5266 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2)
5267 phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2;
James Smart09294d42013-04-17 20:16:05 -04005268
James Smartda0436e2009-05-22 14:51:39 -04005269 /*
James Smart96f70772013-04-17 20:16:15 -04005270 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smartda0436e2009-05-22 14:51:39 -04005271 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart28baac72010-02-12 14:42:03 -05005272 */
James Smart085c6472010-11-20 23:11:37 -05005273
James Smart96f70772013-04-17 20:16:15 -04005274 if (phba->cfg_enable_bg) {
5275 /*
5276 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5277 * the FCP rsp, and a SGE for each. Sice we have no control
5278 * over how many protection data segments the SCSI Layer
5279 * will hand us (ie: there could be one for every block
5280 * in the IO), we just allocate enough SGEs to accomidate
5281 * our max amount and we need to limit lpfc_sg_seg_cnt to
5282 * minimize the risk of running out.
5283 */
5284 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5285 sizeof(struct fcp_rsp) + max_buf_size;
5286
5287 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
5288 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
5289
5290 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
5291 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
5292 } else {
5293 /*
5294 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5295 * the FCP rsp, a SGE for each, and a SGE for up to
5296 * cfg_sg_seg_cnt data segments.
5297 */
5298 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5299 sizeof(struct fcp_rsp) +
5300 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge));
5301
5302 /* Total SGEs for scsi_sg_list */
5303 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5304 /*
5305 * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only need
5306 * to post 1 page for the SGL.
5307 */
James Smart085c6472010-11-20 23:11:37 -05005308 }
James Smartacd68592012-01-18 16:25:09 -05005309
James Smart96f70772013-04-17 20:16:15 -04005310 /* Initialize the host templates with the updated values. */
5311 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5312 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5313
5314 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
5315 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
5316 else
5317 phba->cfg_sg_dma_buf_size =
5318 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
5319
5320 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5321 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
5322 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5323 phba->cfg_total_seg_cnt);
James Smartda0436e2009-05-22 14:51:39 -04005324
5325 /* Initialize buffer queue management fields */
5326 hbq_count = lpfc_sli_hbq_count();
5327 for (i = 0; i < hbq_count; ++i)
5328 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
5329 INIT_LIST_HEAD(&phba->rb_pend_list);
5330 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
5331 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
5332
5333 /*
5334 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
5335 */
5336 /* Initialize the Abort scsi buffer list used by driver */
5337 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
5338 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
5339 /* This abort list used by worker thread */
5340 spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
5341
5342 /*
James Smart6d368e52011-05-24 11:44:12 -04005343 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04005344 */
5345
5346 /* Driver internel slow-path CQ Event pool */
5347 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
5348 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04005349 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04005350 /* Asynchronous event CQ Event work queue list */
5351 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
5352 /* Fast-path XRI aborted CQ Event work queue list */
5353 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
5354 /* Slow-path XRI aborted CQ Event work queue list */
5355 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
5356 /* Receive queue CQ Event work queue list */
5357 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
5358
James Smart6d368e52011-05-24 11:44:12 -04005359 /* Initialize extent block lists. */
5360 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
5361 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
5362 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
5363 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
5364
James Smart448193b2015-12-16 18:12:05 -05005365 /* initialize optic_state to 0xFF */
5366 phba->sli4_hba.lnk_info.optic_state = 0xff;
5367
James Smartda0436e2009-05-22 14:51:39 -04005368 /* Initialize the driver internal SLI layer lists. */
5369 lpfc_sli_setup(phba);
5370 lpfc_sli_queue_setup(phba);
5371
5372 /* Allocate device driver memory */
5373 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
5374 if (rc)
5375 return -ENOMEM;
5376
James Smart2fcee4b2010-12-15 17:57:46 -05005377 /* IF Type 2 ports get initialized now. */
5378 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5379 LPFC_SLI_INTF_IF_TYPE_2) {
5380 rc = lpfc_pci_function_reset(phba);
5381 if (unlikely(rc))
5382 return -ENODEV;
James Smart946727d2015-04-07 15:07:09 -04005383 phba->temp_sensor_support = 1;
James Smart2fcee4b2010-12-15 17:57:46 -05005384 }
5385
James Smartda0436e2009-05-22 14:51:39 -04005386 /* Create the bootstrap mailbox command */
5387 rc = lpfc_create_bootstrap_mbox(phba);
5388 if (unlikely(rc))
5389 goto out_free_mem;
5390
5391 /* Set up the host's endian order with the device. */
5392 rc = lpfc_setup_endian_order(phba);
5393 if (unlikely(rc))
5394 goto out_free_bsmbx;
5395
5396 /* Set up the hba's configuration parameters. */
5397 rc = lpfc_sli4_read_config(phba);
5398 if (unlikely(rc))
5399 goto out_free_bsmbx;
James Smartcff261f2013-12-17 20:29:47 -05005400 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
5401 if (unlikely(rc))
5402 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005403
James Smart2fcee4b2010-12-15 17:57:46 -05005404 /* IF Type 0 ports get initialized now. */
5405 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5406 LPFC_SLI_INTF_IF_TYPE_0) {
5407 rc = lpfc_pci_function_reset(phba);
5408 if (unlikely(rc))
5409 goto out_free_bsmbx;
5410 }
James Smartda0436e2009-05-22 14:51:39 -04005411
James Smartcb5172e2010-03-15 11:25:07 -04005412 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
5413 GFP_KERNEL);
5414 if (!mboxq) {
5415 rc = -ENOMEM;
5416 goto out_free_bsmbx;
5417 }
5418
James Smartfedd3b72011-02-16 12:39:24 -05005419 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04005420 lpfc_supported_pages(mboxq);
5421 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05005422 if (!rc) {
5423 mqe = &mboxq->u.mqe;
5424 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
5425 LPFC_MAX_SUPPORTED_PAGES);
5426 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
5427 switch (pn_page[i]) {
5428 case LPFC_SLI4_PARAMETERS:
5429 phba->sli4_hba.pc_sli4_params.supported = 1;
5430 break;
5431 default:
5432 break;
5433 }
5434 }
5435 /* Read the port's SLI4 Parameters capabilities if supported. */
5436 if (phba->sli4_hba.pc_sli4_params.supported)
5437 rc = lpfc_pc_sli4_params_get(phba, mboxq);
5438 if (rc) {
5439 mempool_free(mboxq, phba->mbox_mem_pool);
5440 rc = -EIO;
5441 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04005442 }
5443 }
James Smart65791f12016-07-06 12:35:56 -07005444
James Smartfedd3b72011-02-16 12:39:24 -05005445 /*
5446 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04005447 * If this call fails, it isn't critical unless the SLI4 parameters come
5448 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05005449 */
James Smart6d368e52011-05-24 11:44:12 -04005450 rc = lpfc_get_sli4_parameters(phba, mboxq);
5451 if (rc) {
5452 if (phba->sli4_hba.extents_in_use &&
5453 phba->sli4_hba.rpi_hdrs_in_use) {
5454 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5455 "2999 Unsupported SLI4 Parameters "
5456 "Extents and RPI headers enabled.\n");
5457 goto out_free_bsmbx;
5458 }
5459 }
James Smartcb5172e2010-03-15 11:25:07 -04005460 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -05005461
5462 /* Verify OAS is supported */
5463 lpfc_sli4_oas_verify(phba);
5464 if (phba->cfg_fof)
5465 fof_vectors = 1;
5466
James Smart5350d872011-10-10 21:33:49 -04005467 /* Verify all the SLI4 queues */
5468 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04005469 if (rc)
5470 goto out_free_bsmbx;
5471
5472 /* Create driver internal CQE event pool */
5473 rc = lpfc_sli4_cq_event_pool_create(phba);
5474 if (rc)
James Smart5350d872011-10-10 21:33:49 -04005475 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005476
James Smart8a9d2e82012-05-09 21:16:12 -04005477 /* Initialize sgl lists per host */
5478 lpfc_init_sgl_list(phba);
5479
5480 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04005481 rc = lpfc_init_active_sgl_array(phba);
5482 if (rc) {
5483 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5484 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04005485 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04005486 }
James Smartda0436e2009-05-22 14:51:39 -04005487 rc = lpfc_sli4_init_rpi_hdrs(phba);
5488 if (rc) {
5489 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5490 "1432 Failed to initialize rpi headers.\n");
5491 goto out_free_active_sgl;
5492 }
5493
James Smarta93ff372010-10-22 11:06:08 -04005494 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05005495 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
5496 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
5497 GFP_KERNEL);
5498 if (!phba->fcf.fcf_rr_bmask) {
5499 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5500 "2759 Failed allocate memory for FCF round "
5501 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04005502 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05005503 goto out_remove_rpi_hdrs;
5504 }
5505
James Smart67d12732012-08-03 12:36:13 -04005506 phba->sli4_hba.fcp_eq_hdl =
5507 kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
James Smart1ba981f2014-02-20 09:56:45 -05005508 (fof_vectors + phba->cfg_fcp_io_channel)),
5509 GFP_KERNEL);
James Smart67d12732012-08-03 12:36:13 -04005510 if (!phba->sli4_hba.fcp_eq_hdl) {
5511 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5512 "2572 Failed allocate memory for "
5513 "fast-path per-EQ handle array\n");
5514 rc = -ENOMEM;
5515 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04005516 }
5517
5518 phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
James Smart1ba981f2014-02-20 09:56:45 -05005519 (fof_vectors +
5520 phba->cfg_fcp_io_channel)), GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04005521 if (!phba->sli4_hba.msix_entries) {
5522 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5523 "2573 Failed allocate memory for msi-x "
5524 "interrupt vector entries\n");
James Smart05580562011-05-24 11:40:48 -04005525 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04005526 goto out_free_fcp_eq_hdl;
5527 }
5528
James Smart7bb03bb2013-04-17 20:19:16 -04005529 phba->sli4_hba.cpu_map = kzalloc((sizeof(struct lpfc_vector_map_info) *
5530 phba->sli4_hba.num_present_cpu),
5531 GFP_KERNEL);
5532 if (!phba->sli4_hba.cpu_map) {
5533 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5534 "3327 Failed allocate memory for msi-x "
5535 "interrupt vector mapping\n");
5536 rc = -ENOMEM;
5537 goto out_free_msix;
5538 }
James Smartb246de12013-05-31 17:03:07 -04005539 if (lpfc_used_cpu == NULL) {
5540 lpfc_used_cpu = kzalloc((sizeof(uint16_t) * lpfc_present_cpu),
5541 GFP_KERNEL);
5542 if (!lpfc_used_cpu) {
5543 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5544 "3335 Failed allocate memory for msi-x "
5545 "interrupt vector mapping\n");
5546 kfree(phba->sli4_hba.cpu_map);
5547 rc = -ENOMEM;
5548 goto out_free_msix;
5549 }
5550 for (i = 0; i < lpfc_present_cpu; i++)
5551 lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
5552 }
5553
James Smart7bb03bb2013-04-17 20:19:16 -04005554 /* Initialize io channels for round robin */
5555 cpup = phba->sli4_hba.cpu_map;
5556 rc = 0;
5557 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
5558 cpup->channel_id = rc;
5559 rc++;
5560 if (rc >= phba->cfg_fcp_io_channel)
5561 rc = 0;
5562 }
5563
James Smart912e3ac2011-05-24 11:42:11 -04005564 /*
5565 * Enable sr-iov virtual functions if supported and configured
5566 * through the module parameter.
5567 */
5568 if (phba->cfg_sriov_nr_virtfn > 0) {
5569 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5570 phba->cfg_sriov_nr_virtfn);
5571 if (rc) {
5572 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5573 "3020 Requested number of SR-IOV "
5574 "virtual functions (%d) is not "
5575 "supported\n",
5576 phba->cfg_sriov_nr_virtfn);
5577 phba->cfg_sriov_nr_virtfn = 0;
5578 }
5579 }
5580
James Smart5248a742011-07-22 18:37:06 -04005581 return 0;
James Smartda0436e2009-05-22 14:51:39 -04005582
James Smart7bb03bb2013-04-17 20:19:16 -04005583out_free_msix:
5584 kfree(phba->sli4_hba.msix_entries);
James Smartda0436e2009-05-22 14:51:39 -04005585out_free_fcp_eq_hdl:
5586 kfree(phba->sli4_hba.fcp_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05005587out_free_fcf_rr_bmask:
5588 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04005589out_remove_rpi_hdrs:
5590 lpfc_sli4_remove_rpi_hdrs(phba);
5591out_free_active_sgl:
5592 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04005593out_destroy_cq_event_pool:
5594 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04005595out_free_bsmbx:
5596 lpfc_destroy_bootstrap_mbox(phba);
5597out_free_mem:
5598 lpfc_mem_free(phba);
5599 return rc;
5600}
5601
5602/**
5603 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
5604 * @phba: pointer to lpfc hba data structure.
5605 *
5606 * This routine is invoked to unset the driver internal resources set up
5607 * specific for supporting the SLI-4 HBA device it attached to.
5608 **/
5609static void
5610lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
5611{
5612 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
5613
James Smart7bb03bb2013-04-17 20:19:16 -04005614 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
5615 kfree(phba->sli4_hba.cpu_map);
5616 phba->sli4_hba.num_present_cpu = 0;
5617 phba->sli4_hba.num_online_cpu = 0;
James Smart76fd07a2014-02-20 09:57:18 -05005618 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04005619
James Smartda0436e2009-05-22 14:51:39 -04005620 /* Free memory allocated for msi-x interrupt vector entries */
5621 kfree(phba->sli4_hba.msix_entries);
5622
5623 /* Free memory allocated for fast-path work queue handles */
5624 kfree(phba->sli4_hba.fcp_eq_hdl);
5625
5626 /* Free the allocated rpi headers. */
5627 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04005628 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04005629
James Smart0c9ab6f2010-02-26 14:15:57 -05005630 /* Free eligible FCF index bmask */
5631 kfree(phba->fcf.fcf_rr_bmask);
5632
James Smartda0436e2009-05-22 14:51:39 -04005633 /* Free the ELS sgl list */
5634 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04005635 lpfc_free_els_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04005636
James Smartda0436e2009-05-22 14:51:39 -04005637 /* Free the completion queue EQ event pool */
5638 lpfc_sli4_cq_event_release_all(phba);
5639 lpfc_sli4_cq_event_pool_destroy(phba);
5640
James Smart6d368e52011-05-24 11:44:12 -04005641 /* Release resource identifiers. */
5642 lpfc_sli4_dealloc_resource_identifiers(phba);
5643
James Smartda0436e2009-05-22 14:51:39 -04005644 /* Free the bsmbx region. */
5645 lpfc_destroy_bootstrap_mbox(phba);
5646
5647 /* Free the SLI Layer memory with SLI4 HBAs */
5648 lpfc_mem_free_all(phba);
5649
5650 /* Free the current connect table */
5651 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04005652 &phba->fcf_conn_rec_list, list) {
5653 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04005654 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04005655 }
James Smartda0436e2009-05-22 14:51:39 -04005656
5657 return;
5658}
5659
5660/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005661 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04005662 * @phba: The hba struct for which this call is being executed.
5663 * @dev_grp: The HBA PCI-Device group number.
5664 *
5665 * This routine sets up the device INIT interface API function jump table
5666 * in @phba struct.
5667 *
5668 * Returns: 0 - success, -ENODEV - failure.
5669 **/
5670int
5671lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5672{
James Smart84d1b002010-02-12 14:42:33 -05005673 phba->lpfc_hba_init_link = lpfc_hba_init_link;
5674 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05005675 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04005676 switch (dev_grp) {
5677 case LPFC_PCI_DEV_LP:
5678 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
5679 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
5680 phba->lpfc_stop_port = lpfc_stop_port_s3;
5681 break;
James Smartda0436e2009-05-22 14:51:39 -04005682 case LPFC_PCI_DEV_OC:
5683 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
5684 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
5685 phba->lpfc_stop_port = lpfc_stop_port_s4;
5686 break;
James Smart3772a992009-05-22 14:50:54 -04005687 default:
5688 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5689 "1431 Invalid HBA PCI-device group: 0x%x\n",
5690 dev_grp);
5691 return -ENODEV;
5692 break;
5693 }
5694 return 0;
5695}
5696
5697/**
5698 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
5699 * @phba: pointer to lpfc hba data structure.
5700 *
5701 * This routine is invoked to set up the driver internal resources before the
5702 * device specific resource setup to support the HBA device it attached to.
5703 *
5704 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005705 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005706 * other values - error
5707 **/
5708static int
5709lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
5710{
5711 /*
5712 * Driver resources common to all SLI revisions
5713 */
James Smartea2151b2008-09-07 11:52:10 -04005714 atomic_set(&phba->fast_event_count, 0);
James Smart2e0fef82007-06-17 19:56:36 -05005715 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005716
James Smarte47c9092008-02-08 18:49:26 -05005717 /* Initialize ndlp management spinlock */
5718 spin_lock_init(&phba->ndlp_lock);
5719
James Smart2e0fef82007-06-17 19:56:36 -05005720 INIT_LIST_HEAD(&phba->port_list);
James Smart3772a992009-05-22 14:50:54 -04005721 INIT_LIST_HEAD(&phba->work_list);
James Smart84774a42008-08-24 21:50:06 -04005722 init_waitqueue_head(&phba->wait_4_mlo_m_q);
dea31012005-04-17 16:05:31 -05005723
James Smart3772a992009-05-22 14:50:54 -04005724 /* Initialize the wait queue head for the kernel thread */
5725 init_waitqueue_head(&phba->work_waitq);
James Smart858c9f62007-06-17 19:56:39 -05005726
James Smart3772a992009-05-22 14:50:54 -04005727 /* Initialize the scsi buffer list used by driver for scsi IO */
James Smarta40fc5f2013-04-17 20:17:40 -04005728 spin_lock_init(&phba->scsi_buf_list_get_lock);
5729 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5730 spin_lock_init(&phba->scsi_buf_list_put_lock);
5731 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
dea31012005-04-17 16:05:31 -05005732
James Smart3772a992009-05-22 14:50:54 -04005733 /* Initialize the fabric iocb list */
5734 INIT_LIST_HEAD(&phba->fabric_iocb_list);
dea31012005-04-17 16:05:31 -05005735
James Smart3772a992009-05-22 14:50:54 -04005736 /* Initialize list to save ELS buffers */
5737 INIT_LIST_HEAD(&phba->elsbuf);
dea31012005-04-17 16:05:31 -05005738
James Smart3772a992009-05-22 14:50:54 -04005739 /* Initialize FCF connection rec list */
5740 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
dea31012005-04-17 16:05:31 -05005741
James Smart1ba981f2014-02-20 09:56:45 -05005742 /* Initialize OAS configuration list */
5743 spin_lock_init(&phba->devicelock);
5744 INIT_LIST_HEAD(&phba->luns);
5745
James Smart3772a992009-05-22 14:50:54 -04005746 return 0;
5747}
dea31012005-04-17 16:05:31 -05005748
James Smart3772a992009-05-22 14:50:54 -04005749/**
5750 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
5751 * @phba: pointer to lpfc hba data structure.
5752 *
5753 * This routine is invoked to set up the driver internal resources after the
5754 * device specific resource setup to support the HBA device it attached to.
5755 *
5756 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005757 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005758 * other values - error
5759 **/
5760static int
5761lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
5762{
5763 int error;
5764
5765 /* Startup the kernel thread for this host adapter. */
5766 phba->worker_thread = kthread_run(lpfc_do_work, phba,
5767 "lpfc_worker_%d", phba->brd_no);
5768 if (IS_ERR(phba->worker_thread)) {
5769 error = PTR_ERR(phba->worker_thread);
5770 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005771 }
5772
James Smart3772a992009-05-22 14:50:54 -04005773 return 0;
5774}
5775
5776/**
5777 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
5778 * @phba: pointer to lpfc hba data structure.
5779 *
5780 * This routine is invoked to unset the driver internal resources set up after
5781 * the device specific resource setup for supporting the HBA device it
5782 * attached to.
5783 **/
5784static void
5785lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
5786{
5787 /* Stop kernel worker thread */
5788 kthread_stop(phba->worker_thread);
5789}
5790
5791/**
5792 * lpfc_free_iocb_list - Free iocb list.
5793 * @phba: pointer to lpfc hba data structure.
5794 *
5795 * This routine is invoked to free the driver's IOCB list and memory.
5796 **/
5797static void
5798lpfc_free_iocb_list(struct lpfc_hba *phba)
5799{
5800 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
5801
5802 spin_lock_irq(&phba->hbalock);
5803 list_for_each_entry_safe(iocbq_entry, iocbq_next,
5804 &phba->lpfc_iocb_list, list) {
5805 list_del(&iocbq_entry->list);
5806 kfree(iocbq_entry);
5807 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005808 }
James Smart3772a992009-05-22 14:50:54 -04005809 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005810
James Smart3772a992009-05-22 14:50:54 -04005811 return;
5812}
dea31012005-04-17 16:05:31 -05005813
James Smart3772a992009-05-22 14:50:54 -04005814/**
5815 * lpfc_init_iocb_list - Allocate and initialize iocb list.
5816 * @phba: pointer to lpfc hba data structure.
5817 *
5818 * This routine is invoked to allocate and initizlize the driver's IOCB
5819 * list and set up the IOCB tag array accordingly.
5820 *
5821 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005822 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005823 * other values - error
5824 **/
5825static int
5826lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
5827{
5828 struct lpfc_iocbq *iocbq_entry = NULL;
5829 uint16_t iotag;
5830 int i;
dea31012005-04-17 16:05:31 -05005831
5832 /* Initialize and populate the iocb list per host. */
5833 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04005834 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07005835 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05005836 if (iocbq_entry == NULL) {
5837 printk(KERN_ERR "%s: only allocated %d iocbs of "
5838 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07005839 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05005840 goto out_free_iocbq;
5841 }
5842
James Bottomley604a3e32005-10-29 10:28:33 -05005843 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
5844 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04005845 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05005846 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04005847 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05005848 goto out_free_iocbq;
5849 }
James Smart6d368e52011-05-24 11:44:12 -04005850 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04005851 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05005852
5853 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005854 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
5855 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05005856 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005857 }
5858
James Smart3772a992009-05-22 14:50:54 -04005859 return 0;
5860
5861out_free_iocbq:
5862 lpfc_free_iocb_list(phba);
5863
5864 return -ENOMEM;
5865}
5866
5867/**
James Smart8a9d2e82012-05-09 21:16:12 -04005868 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04005869 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04005870 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04005871 *
James Smart8a9d2e82012-05-09 21:16:12 -04005872 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04005873 **/
James Smart8a9d2e82012-05-09 21:16:12 -04005874void
5875lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04005876{
5877 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04005878
5879 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
5880 list_del(&sglq_entry->list);
5881 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
5882 kfree(sglq_entry);
5883 }
5884}
5885
5886/**
5887 * lpfc_free_els_sgl_list - Free els sgl list.
5888 * @phba: pointer to lpfc hba data structure.
5889 *
5890 * This routine is invoked to free the driver's els sgl list and memory.
5891 **/
5892static void
5893lpfc_free_els_sgl_list(struct lpfc_hba *phba)
5894{
James Smartda0436e2009-05-22 14:51:39 -04005895 LIST_HEAD(sglq_list);
James Smartdafe8ce2014-09-03 12:56:40 -04005896 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smartda0436e2009-05-22 14:51:39 -04005897
James Smart8a9d2e82012-05-09 21:16:12 -04005898 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04005899 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04005900 spin_lock(&pring->ring_lock);
James Smartda0436e2009-05-22 14:51:39 -04005901 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
James Smartdafe8ce2014-09-03 12:56:40 -04005902 spin_unlock(&pring->ring_lock);
James Smartda0436e2009-05-22 14:51:39 -04005903 spin_unlock_irq(&phba->hbalock);
5904
James Smart8a9d2e82012-05-09 21:16:12 -04005905 /* Now free the sgl list */
5906 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04005907}
5908
5909/**
5910 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
5911 * @phba: pointer to lpfc hba data structure.
5912 *
5913 * This routine is invoked to allocate the driver's active sgl memory.
5914 * This array will hold the sglq_entry's for active IOs.
5915 **/
5916static int
5917lpfc_init_active_sgl_array(struct lpfc_hba *phba)
5918{
5919 int size;
5920 size = sizeof(struct lpfc_sglq *);
5921 size *= phba->sli4_hba.max_cfg_param.max_xri;
5922
5923 phba->sli4_hba.lpfc_sglq_active_list =
5924 kzalloc(size, GFP_KERNEL);
5925 if (!phba->sli4_hba.lpfc_sglq_active_list)
5926 return -ENOMEM;
5927 return 0;
5928}
5929
5930/**
5931 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
5932 * @phba: pointer to lpfc hba data structure.
5933 *
5934 * This routine is invoked to walk through the array of active sglq entries
5935 * and free all of the resources.
5936 * This is just a place holder for now.
5937 **/
5938static void
5939lpfc_free_active_sgl(struct lpfc_hba *phba)
5940{
5941 kfree(phba->sli4_hba.lpfc_sglq_active_list);
5942}
5943
5944/**
5945 * lpfc_init_sgl_list - Allocate and initialize sgl list.
5946 * @phba: pointer to lpfc hba data structure.
5947 *
5948 * This routine is invoked to allocate and initizlize the driver's sgl
5949 * list and set up the sgl xritag tag array accordingly.
5950 *
James Smartda0436e2009-05-22 14:51:39 -04005951 **/
James Smart8a9d2e82012-05-09 21:16:12 -04005952static void
James Smartda0436e2009-05-22 14:51:39 -04005953lpfc_init_sgl_list(struct lpfc_hba *phba)
5954{
James Smartda0436e2009-05-22 14:51:39 -04005955 /* Initialize and populate the sglq list per host/VF. */
5956 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
5957 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
5958
James Smart8a9d2e82012-05-09 21:16:12 -04005959 /* els xri-sgl book keeping */
5960 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04005961
James Smart8a9d2e82012-05-09 21:16:12 -04005962 /* scsi xri-buffer book keeping */
James Smartda0436e2009-05-22 14:51:39 -04005963 phba->sli4_hba.scsi_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04005964}
5965
5966/**
5967 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
5968 * @phba: pointer to lpfc hba data structure.
5969 *
5970 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04005971 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04005972 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04005973 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
5974 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04005975 *
5976 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005977 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04005978 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04005979 **/
5980int
5981lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
5982{
5983 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04005984 struct lpfc_rpi_hdr *rpi_hdr;
5985
5986 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05005987 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04005988 return rc;
James Smart6d368e52011-05-24 11:44:12 -04005989 if (phba->sli4_hba.extents_in_use)
5990 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04005991
5992 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
5993 if (!rpi_hdr) {
5994 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5995 "0391 Error during rpi post operation\n");
5996 lpfc_sli4_remove_rpis(phba);
5997 rc = -ENODEV;
5998 }
5999
6000 return rc;
6001}
6002
6003/**
6004 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
6005 * @phba: pointer to lpfc hba data structure.
6006 *
6007 * This routine is invoked to allocate a single 4KB memory region to
6008 * support rpis and stores them in the phba. This single region
6009 * provides support for up to 64 rpis. The region is used globally
6010 * by the device.
6011 *
6012 * Returns:
6013 * A valid rpi hdr on success.
6014 * A NULL pointer on any failure.
6015 **/
6016struct lpfc_rpi_hdr *
6017lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
6018{
6019 uint16_t rpi_limit, curr_rpi_range;
6020 struct lpfc_dmabuf *dmabuf;
6021 struct lpfc_rpi_hdr *rpi_hdr;
James Smart9589b0622011-04-16 11:03:17 -04006022 uint32_t rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04006023
James Smart6d368e52011-05-24 11:44:12 -04006024 /*
6025 * If the SLI4 port supports extents, posting the rpi header isn't
6026 * required. Set the expected maximum count and let the actual value
6027 * get set when extents are fully allocated.
6028 */
6029 if (!phba->sli4_hba.rpi_hdrs_in_use)
6030 return NULL;
6031 if (phba->sli4_hba.extents_in_use)
6032 return NULL;
6033
6034 /* The limit on the logical index is just the max_rpi count. */
James Smartda0436e2009-05-22 14:51:39 -04006035 rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
James Smart6d368e52011-05-24 11:44:12 -04006036 phba->sli4_hba.max_cfg_param.max_rpi - 1;
James Smartda0436e2009-05-22 14:51:39 -04006037
6038 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006039 /*
6040 * Establish the starting RPI in this header block. The starting
6041 * rpi is normalized to a zero base because the physical rpi is
6042 * port based.
6043 */
James Smart97f2ecf2012-03-01 22:35:23 -05006044 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04006045 spin_unlock_irq(&phba->hbalock);
6046
6047 /*
6048 * The port has a limited number of rpis. The increment here
6049 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
6050 * and to allow the full max_rpi range per port.
6051 */
6052 if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
James Smart9589b0622011-04-16 11:03:17 -04006053 rpi_count = rpi_limit - curr_rpi_range;
6054 else
6055 rpi_count = LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04006056
James Smart6d368e52011-05-24 11:44:12 -04006057 if (!rpi_count)
6058 return NULL;
James Smartda0436e2009-05-22 14:51:39 -04006059 /*
6060 * First allocate the protocol header region for the port. The
6061 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
6062 */
6063 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6064 if (!dmabuf)
6065 return NULL;
6066
Joe Perches1aee3832014-09-03 12:56:12 -04006067 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
6068 LPFC_HDR_TEMPLATE_SIZE,
6069 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04006070 if (!dmabuf->virt) {
6071 rpi_hdr = NULL;
6072 goto err_free_dmabuf;
6073 }
6074
James Smartda0436e2009-05-22 14:51:39 -04006075 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
6076 rpi_hdr = NULL;
6077 goto err_free_coherent;
6078 }
6079
6080 /* Save the rpi header data for cleanup later. */
6081 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
6082 if (!rpi_hdr)
6083 goto err_free_coherent;
6084
6085 rpi_hdr->dmabuf = dmabuf;
6086 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
6087 rpi_hdr->page_count = 1;
6088 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006089
6090 /* The rpi_hdr stores the logical index only. */
6091 rpi_hdr->start_rpi = curr_rpi_range;
James Smartda0436e2009-05-22 14:51:39 -04006092 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
6093
6094 /*
James Smart6d368e52011-05-24 11:44:12 -04006095 * The next_rpi stores the next logical module-64 rpi value used
6096 * to post physical rpis in subsequent rpi postings.
James Smartda0436e2009-05-22 14:51:39 -04006097 */
James Smart9589b0622011-04-16 11:03:17 -04006098 phba->sli4_hba.next_rpi += rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04006099 spin_unlock_irq(&phba->hbalock);
6100 return rpi_hdr;
6101
6102 err_free_coherent:
6103 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
6104 dmabuf->virt, dmabuf->phys);
6105 err_free_dmabuf:
6106 kfree(dmabuf);
6107 return NULL;
6108}
6109
6110/**
6111 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
6112 * @phba: pointer to lpfc hba data structure.
6113 *
6114 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04006115 * to support rpis for SLI4 ports not supporting extents. This routine
6116 * presumes the caller has released all rpis consumed by fabric or port
6117 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04006118 **/
6119void
6120lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
6121{
6122 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
6123
James Smart6d368e52011-05-24 11:44:12 -04006124 if (!phba->sli4_hba.rpi_hdrs_in_use)
6125 goto exit;
6126
James Smartda0436e2009-05-22 14:51:39 -04006127 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
6128 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
6129 list_del(&rpi_hdr->list);
6130 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
6131 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
6132 kfree(rpi_hdr->dmabuf);
6133 kfree(rpi_hdr);
6134 }
James Smart6d368e52011-05-24 11:44:12 -04006135 exit:
6136 /* There are no rpis available to the port now. */
6137 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04006138}
6139
6140/**
James Smart3772a992009-05-22 14:50:54 -04006141 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
6142 * @pdev: pointer to pci device data structure.
6143 *
6144 * This routine is invoked to allocate the driver hba data structure for an
6145 * HBA device. If the allocation is successful, the phba reference to the
6146 * PCI device data structure is set.
6147 *
6148 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006149 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04006150 * NULL - error
6151 **/
6152static struct lpfc_hba *
6153lpfc_hba_alloc(struct pci_dev *pdev)
6154{
6155 struct lpfc_hba *phba;
6156
6157 /* Allocate memory for HBA structure */
6158 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
6159 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02006160 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04006161 return NULL;
6162 }
6163
6164 /* Set reference to PCI device in HBA structure */
6165 phba->pcidev = pdev;
6166
6167 /* Assign an unused board number */
6168 phba->brd_no = lpfc_get_instance();
6169 if (phba->brd_no < 0) {
6170 kfree(phba);
6171 return NULL;
6172 }
James Smart65791f12016-07-06 12:35:56 -07006173 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
James Smart3772a992009-05-22 14:50:54 -04006174
James Smart4fede782010-01-26 23:08:55 -05006175 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04006176 INIT_LIST_HEAD(&phba->ct_ev_waiters);
6177
James Smart3772a992009-05-22 14:50:54 -04006178 return phba;
6179}
6180
6181/**
6182 * lpfc_hba_free - Free driver hba data structure with a device.
6183 * @phba: pointer to lpfc hba data structure.
6184 *
6185 * This routine is invoked to free the driver hba data structure with an
6186 * HBA device.
6187 **/
6188static void
6189lpfc_hba_free(struct lpfc_hba *phba)
6190{
6191 /* Release the driver assigned board number */
6192 idr_remove(&lpfc_hba_index, phba->brd_no);
6193
James Smart2a76a282012-08-03 12:35:54 -04006194 /* Free memory allocated with sli rings */
6195 kfree(phba->sli.ring);
6196 phba->sli.ring = NULL;
6197
James Smart3772a992009-05-22 14:50:54 -04006198 kfree(phba);
6199 return;
6200}
6201
6202/**
6203 * lpfc_create_shost - Create hba physical port with associated scsi host.
6204 * @phba: pointer to lpfc hba data structure.
6205 *
6206 * This routine is invoked to create HBA physical port and associate a SCSI
6207 * host with it.
6208 *
6209 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006210 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006211 * other values - error
6212 **/
6213static int
6214lpfc_create_shost(struct lpfc_hba *phba)
6215{
6216 struct lpfc_vport *vport;
6217 struct Scsi_Host *shost;
6218
6219 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05006220 phba->fc_edtov = FF_DEF_EDTOV;
6221 phba->fc_ratov = FF_DEF_RATOV;
6222 phba->fc_altov = FF_DEF_ALTOV;
6223 phba->fc_arbtov = FF_DEF_ARBTOV;
6224
James Smartd7c47992010-06-08 18:31:54 -04006225 atomic_set(&phba->sdev_cnt, 0);
James Smart3de2a652007-08-02 11:09:59 -04006226 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05006227 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04006228 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05006229
6230 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05006231 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05006232 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04006233 /* Put reference to SCSI host to driver's device private data */
6234 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05006235
James Smart4258e982015-12-16 18:11:58 -05006236 /*
6237 * At this point we are fully registered with PSA. In addition,
6238 * any initial discovery should be completed.
6239 */
6240 vport->load_flag |= FC_ALLOW_FDMI;
James Smart8663cbb2016-03-31 14:12:33 -07006241 if (phba->cfg_enable_SmartSAN ||
6242 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -05006243
6244 /* Setup appropriate attribute masks */
6245 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -07006246 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -05006247 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
6248 else
6249 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
6250 }
James Smart3772a992009-05-22 14:50:54 -04006251 return 0;
6252}
dea31012005-04-17 16:05:31 -05006253
James Smart3772a992009-05-22 14:50:54 -04006254/**
6255 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
6256 * @phba: pointer to lpfc hba data structure.
6257 *
6258 * This routine is invoked to destroy HBA physical port and the associated
6259 * SCSI host.
6260 **/
6261static void
6262lpfc_destroy_shost(struct lpfc_hba *phba)
6263{
6264 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04006265
James Smart3772a992009-05-22 14:50:54 -04006266 /* Destroy physical port that associated with the SCSI host */
6267 destroy_port(vport);
6268
6269 return;
6270}
6271
6272/**
6273 * lpfc_setup_bg - Setup Block guard structures and debug areas.
6274 * @phba: pointer to lpfc hba data structure.
6275 * @shost: the shost to be used to detect Block guard settings.
6276 *
6277 * This routine sets up the local Block guard protocol settings for @shost.
6278 * This routine also allocates memory for debugging bg buffers.
6279 **/
6280static void
6281lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
6282{
James Smartbbeb79b2012-06-12 13:54:27 -04006283 uint32_t old_mask;
6284 uint32_t old_guard;
6285
James Smart3772a992009-05-22 14:50:54 -04006286 int pagecnt = 10;
6287 if (lpfc_prot_mask && lpfc_prot_guard) {
6288 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6289 "1478 Registering BlockGuard with the "
6290 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04006291
6292 old_mask = lpfc_prot_mask;
6293 old_guard = lpfc_prot_guard;
6294
6295 /* Only allow supported values */
6296 lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
6297 SHOST_DIX_TYPE0_PROTECTION |
6298 SHOST_DIX_TYPE1_PROTECTION);
6299 lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC);
6300
6301 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
6302 if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
6303 lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
6304
6305 if (lpfc_prot_mask && lpfc_prot_guard) {
6306 if ((old_mask != lpfc_prot_mask) ||
6307 (old_guard != lpfc_prot_guard))
6308 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6309 "1475 Registering BlockGuard with the "
6310 "SCSI layer: mask %d guard %d\n",
6311 lpfc_prot_mask, lpfc_prot_guard);
6312
6313 scsi_host_set_prot(shost, lpfc_prot_mask);
6314 scsi_host_set_guard(shost, lpfc_prot_guard);
6315 } else
6316 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6317 "1479 Not Registering BlockGuard with the SCSI "
6318 "layer, Bad protection parameters: %d %d\n",
6319 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04006320 }
James Smartbbeb79b2012-06-12 13:54:27 -04006321
James Smart81301a92008-12-04 22:39:46 -05006322 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05006323 while (pagecnt) {
6324 spin_lock_init(&_dump_buf_lock);
6325 _dump_buf_data =
6326 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6327 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04006328 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6329 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04006330 "_dump_buf_data at 0x%p\n",
6331 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05006332 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04006333 memset(_dump_buf_data, 0,
6334 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05006335 break;
James Smart3772a992009-05-22 14:50:54 -04006336 } else
James Smart81301a92008-12-04 22:39:46 -05006337 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05006338 }
James Smart81301a92008-12-04 22:39:46 -05006339 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04006340 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6341 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04006342 "memory for hexdump\n");
6343 } else
James Smart6a9c52c2009-10-02 15:16:51 -04006344 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6345 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05006346 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05006347 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05006348 while (pagecnt) {
6349 _dump_buf_dif =
6350 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6351 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04006352 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6353 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04006354 "_dump_buf_dif at 0x%p\n",
6355 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05006356 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04006357 memset(_dump_buf_dif, 0,
6358 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05006359 break;
James Smart3772a992009-05-22 14:50:54 -04006360 } else
James Smart81301a92008-12-04 22:39:46 -05006361 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05006362 }
James Smart81301a92008-12-04 22:39:46 -05006363 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04006364 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6365 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04006366 "memory for hexdump\n");
6367 } else
James Smart6a9c52c2009-10-02 15:16:51 -04006368 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6369 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04006370 _dump_buf_dif);
6371}
6372
6373/**
6374 * lpfc_post_init_setup - Perform necessary device post initialization setup.
6375 * @phba: pointer to lpfc hba data structure.
6376 *
6377 * This routine is invoked to perform all the necessary post initialization
6378 * setup for the device.
6379 **/
6380static void
6381lpfc_post_init_setup(struct lpfc_hba *phba)
6382{
6383 struct Scsi_Host *shost;
6384 struct lpfc_adapter_event_header adapter_event;
6385
6386 /* Get the default values for Model Name and Description */
6387 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
6388
6389 /*
6390 * hba setup may have changed the hba_queue_depth so we need to
6391 * adjust the value of can_queue.
6392 */
6393 shost = pci_get_drvdata(phba->pcidev);
6394 shost->can_queue = phba->cfg_hba_queue_depth - 10;
6395 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
6396 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05006397
6398 lpfc_host_attrib_init(shost);
6399
James Smart2e0fef82007-06-17 19:56:36 -05006400 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
6401 spin_lock_irq(shost->host_lock);
6402 lpfc_poll_start_timer(phba);
6403 spin_unlock_irq(shost->host_lock);
6404 }
James Smart8f6d98d2006-08-01 07:34:00 -04006405
James Smart93996272008-08-24 21:50:30 -04006406 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6407 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04006408 /* Send board arrival event to upper layer */
6409 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
6410 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
6411 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04006412 sizeof(adapter_event),
6413 (char *) &adapter_event,
6414 LPFC_NL_VENDOR_ID);
6415 return;
6416}
6417
6418/**
6419 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
6420 * @phba: pointer to lpfc hba data structure.
6421 *
6422 * This routine is invoked to set up the PCI device memory space for device
6423 * with SLI-3 interface spec.
6424 *
6425 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006426 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006427 * other values - error
6428 **/
6429static int
6430lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
6431{
6432 struct pci_dev *pdev;
6433 unsigned long bar0map_len, bar2map_len;
6434 int i, hbq_count;
6435 void *ptr;
6436 int error = -ENODEV;
6437
6438 /* Obtain PCI device reference */
6439 if (!phba->pcidev)
6440 return error;
6441 else
6442 pdev = phba->pcidev;
6443
6444 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05006445 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
6446 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
6447 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
6448 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smart3772a992009-05-22 14:50:54 -04006449 return error;
Michael Reed8e685972009-09-18 12:02:05 -05006450 }
6451 }
James Smart3772a992009-05-22 14:50:54 -04006452
6453 /* Get the bus address of Bar0 and Bar2 and the number of bytes
6454 * required by each mapping.
6455 */
6456 phba->pci_bar0_map = pci_resource_start(pdev, 0);
6457 bar0map_len = pci_resource_len(pdev, 0);
6458
6459 phba->pci_bar2_map = pci_resource_start(pdev, 2);
6460 bar2map_len = pci_resource_len(pdev, 2);
6461
6462 /* Map HBA SLIM to a kernel virtual address. */
6463 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
6464 if (!phba->slim_memmap_p) {
6465 dev_printk(KERN_ERR, &pdev->dev,
6466 "ioremap failed for SLIM memory.\n");
6467 goto out;
6468 }
6469
6470 /* Map HBA Control Registers to a kernel virtual address. */
6471 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
6472 if (!phba->ctrl_regs_memmap_p) {
6473 dev_printk(KERN_ERR, &pdev->dev,
6474 "ioremap failed for HBA control registers.\n");
6475 goto out_iounmap_slim;
6476 }
6477
6478 /* Allocate memory for SLI-2 structures */
Joe Perches1aee3832014-09-03 12:56:12 -04006479 phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6480 &phba->slim2p.phys, GFP_KERNEL);
James Smart3772a992009-05-22 14:50:54 -04006481 if (!phba->slim2p.virt)
6482 goto out_iounmap;
6483
James Smart3772a992009-05-22 14:50:54 -04006484 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04006485 phba->mbox_ext = (phba->slim2p.virt +
6486 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04006487 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
6488 phba->IOCBs = (phba->slim2p.virt +
6489 offsetof(struct lpfc_sli2_slim, IOCBs));
6490
6491 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
6492 lpfc_sli_hbq_size(),
6493 &phba->hbqslimp.phys,
6494 GFP_KERNEL);
6495 if (!phba->hbqslimp.virt)
6496 goto out_free_slim;
6497
6498 hbq_count = lpfc_sli_hbq_count();
6499 ptr = phba->hbqslimp.virt;
6500 for (i = 0; i < hbq_count; ++i) {
6501 phba->hbqs[i].hbq_virt = ptr;
6502 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
6503 ptr += (lpfc_hbq_defs[i]->entry_count *
6504 sizeof(struct lpfc_hbq_entry));
6505 }
6506 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
6507 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
6508
6509 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
6510
6511 INIT_LIST_HEAD(&phba->rb_pend_list);
6512
6513 phba->MBslimaddr = phba->slim_memmap_p;
6514 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
6515 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
6516 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
6517 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04006518
dea31012005-04-17 16:05:31 -05006519 return 0;
6520
dea31012005-04-17 16:05:31 -05006521out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04006522 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6523 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05006524out_iounmap:
6525 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006526out_iounmap_slim:
dea31012005-04-17 16:05:31 -05006527 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05006528out:
6529 return error;
6530}
6531
James Smarte59058c2008-08-24 21:49:00 -04006532/**
James Smart3772a992009-05-22 14:50:54 -04006533 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
6534 * @phba: pointer to lpfc hba data structure.
6535 *
6536 * This routine is invoked to unset the PCI device memory space for device
6537 * with SLI-3 interface spec.
6538 **/
6539static void
6540lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
6541{
6542 struct pci_dev *pdev;
6543
6544 /* Obtain PCI device reference */
6545 if (!phba->pcidev)
6546 return;
6547 else
6548 pdev = phba->pcidev;
6549
6550 /* Free coherent DMA memory allocated */
6551 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
6552 phba->hbqslimp.virt, phba->hbqslimp.phys);
6553 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6554 phba->slim2p.virt, phba->slim2p.phys);
6555
6556 /* I/O memory unmap */
6557 iounmap(phba->ctrl_regs_memmap_p);
6558 iounmap(phba->slim_memmap_p);
6559
6560 return;
6561}
6562
6563/**
James Smartda0436e2009-05-22 14:51:39 -04006564 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
6565 * @phba: pointer to lpfc hba data structure.
6566 *
6567 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
6568 * done and check status.
6569 *
6570 * Return 0 if successful, otherwise -ENODEV.
6571 **/
6572int
6573lpfc_sli4_post_status_check(struct lpfc_hba *phba)
6574{
James Smart2fcee4b2010-12-15 17:57:46 -05006575 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
6576 struct lpfc_register reg_data;
6577 int i, port_error = 0;
6578 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04006579
James Smart9940b972011-03-11 16:06:12 -05006580 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
6581 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05006582 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04006583 return -ENODEV;
6584
James Smartda0436e2009-05-22 14:51:39 -04006585 /* Wait up to 30 seconds for the SLI Port POST done and ready */
6586 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05006587 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
6588 &portsmphr_reg.word0) ||
6589 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006590 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04006591 port_error = -ENODEV;
6592 break;
6593 }
James Smart2fcee4b2010-12-15 17:57:46 -05006594 if (LPFC_POST_STAGE_PORT_READY ==
6595 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04006596 break;
James Smartda0436e2009-05-22 14:51:39 -04006597 msleep(10);
6598 }
6599
James Smart2fcee4b2010-12-15 17:57:46 -05006600 /*
6601 * If there was a port error during POST, then don't proceed with
6602 * other register reads as the data may not be valid. Just exit.
6603 */
6604 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04006605 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006606 "1408 Port Failed POST - portsmphr=0x%x, "
6607 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
6608 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
6609 portsmphr_reg.word0,
6610 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
6611 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
6612 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
6613 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
6614 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
6615 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
6616 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
6617 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
6618 } else {
James Smart28baac72010-02-12 14:42:03 -05006619 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006620 "2534 Device Info: SLIFamily=0x%x, "
6621 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
6622 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05006623 bf_get(lpfc_sli_intf_sli_family,
6624 &phba->sli4_hba.sli_intf),
6625 bf_get(lpfc_sli_intf_slirev,
6626 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006627 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05006628 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006629 bf_get(lpfc_sli_intf_sli_hint1,
6630 &phba->sli4_hba.sli_intf),
6631 bf_get(lpfc_sli_intf_sli_hint2,
6632 &phba->sli4_hba.sli_intf),
6633 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05006634 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05006635 /*
6636 * Check for other Port errors during the initialization
6637 * process. Fail the load if the port did not come up
6638 * correctly.
6639 */
6640 if_type = bf_get(lpfc_sli_intf_if_type,
6641 &phba->sli4_hba.sli_intf);
6642 switch (if_type) {
6643 case LPFC_SLI_INTF_IF_TYPE_0:
6644 phba->sli4_hba.ue_mask_lo =
6645 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
6646 phba->sli4_hba.ue_mask_hi =
6647 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
6648 uerrlo_reg.word0 =
6649 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
6650 uerrhi_reg.word0 =
6651 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
6652 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
6653 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
6654 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6655 "1422 Unrecoverable Error "
6656 "Detected during POST "
6657 "uerr_lo_reg=0x%x, "
6658 "uerr_hi_reg=0x%x, "
6659 "ue_mask_lo_reg=0x%x, "
6660 "ue_mask_hi_reg=0x%x\n",
6661 uerrlo_reg.word0,
6662 uerrhi_reg.word0,
6663 phba->sli4_hba.ue_mask_lo,
6664 phba->sli4_hba.ue_mask_hi);
6665 port_error = -ENODEV;
6666 }
6667 break;
6668 case LPFC_SLI_INTF_IF_TYPE_2:
6669 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05006670 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
6671 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04006672 (bf_get(lpfc_sliport_status_err, &reg_data) &&
6673 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006674 phba->work_status[0] =
6675 readl(phba->sli4_hba.u.if_type2.
6676 ERR1regaddr);
6677 phba->work_status[1] =
6678 readl(phba->sli4_hba.u.if_type2.
6679 ERR2regaddr);
6680 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05006681 "2888 Unrecoverable port error "
6682 "following POST: port status reg "
6683 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05006684 "error 1=0x%x, error 2=0x%x\n",
6685 reg_data.word0,
6686 portsmphr_reg.word0,
6687 phba->work_status[0],
6688 phba->work_status[1]);
6689 port_error = -ENODEV;
6690 }
6691 break;
6692 case LPFC_SLI_INTF_IF_TYPE_1:
6693 default:
6694 break;
6695 }
James Smart28baac72010-02-12 14:42:03 -05006696 }
James Smartda0436e2009-05-22 14:51:39 -04006697 return port_error;
6698}
6699
6700/**
6701 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
6702 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05006703 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04006704 *
6705 * This routine is invoked to set up SLI4 BAR0 PCI config space register
6706 * memory map.
6707 **/
6708static void
James Smart2fcee4b2010-12-15 17:57:46 -05006709lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04006710{
James Smart2fcee4b2010-12-15 17:57:46 -05006711 switch (if_type) {
6712 case LPFC_SLI_INTF_IF_TYPE_0:
6713 phba->sli4_hba.u.if_type0.UERRLOregaddr =
6714 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
6715 phba->sli4_hba.u.if_type0.UERRHIregaddr =
6716 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
6717 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
6718 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
6719 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
6720 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
6721 phba->sli4_hba.SLIINTFregaddr =
6722 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6723 break;
6724 case LPFC_SLI_INTF_IF_TYPE_2:
6725 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006726 phba->sli4_hba.conf_regs_memmap_p +
6727 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006728 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006729 phba->sli4_hba.conf_regs_memmap_p +
6730 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006731 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006732 phba->sli4_hba.conf_regs_memmap_p +
6733 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006734 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006735 phba->sli4_hba.conf_regs_memmap_p +
6736 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006737 phba->sli4_hba.SLIINTFregaddr =
6738 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6739 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006740 phba->sli4_hba.conf_regs_memmap_p +
6741 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006742 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006743 phba->sli4_hba.conf_regs_memmap_p +
6744 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006745 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006746 phba->sli4_hba.conf_regs_memmap_p +
6747 LPFC_ULP0_WQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006748 phba->sli4_hba.EQCQDBregaddr =
6749 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
6750 phba->sli4_hba.MQDBregaddr =
6751 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
6752 phba->sli4_hba.BMBXregaddr =
6753 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
6754 break;
6755 case LPFC_SLI_INTF_IF_TYPE_1:
6756 default:
6757 dev_printk(KERN_ERR, &phba->pcidev->dev,
6758 "FATAL - unsupported SLI4 interface type - %d\n",
6759 if_type);
6760 break;
6761 }
James Smartda0436e2009-05-22 14:51:39 -04006762}
6763
6764/**
6765 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
6766 * @phba: pointer to lpfc hba data structure.
6767 *
6768 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
6769 * memory map.
6770 **/
6771static void
6772lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
6773{
James Smart2fcee4b2010-12-15 17:57:46 -05006774 phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
6775 LPFC_SLIPORT_IF0_SMPHR;
James Smartda0436e2009-05-22 14:51:39 -04006776 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006777 LPFC_HST_ISR0;
James Smartda0436e2009-05-22 14:51:39 -04006778 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006779 LPFC_HST_IMR0;
James Smartda0436e2009-05-22 14:51:39 -04006780 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006781 LPFC_HST_ISCR0;
James Smartda0436e2009-05-22 14:51:39 -04006782}
6783
6784/**
6785 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
6786 * @phba: pointer to lpfc hba data structure.
6787 * @vf: virtual function number
6788 *
6789 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
6790 * based on the given viftual function number, @vf.
6791 *
6792 * Return 0 if successful, otherwise -ENODEV.
6793 **/
6794static int
6795lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
6796{
6797 if (vf > LPFC_VIR_FUNC_MAX)
6798 return -ENODEV;
6799
6800 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05006801 vf * LPFC_VFR_PAGE_SIZE +
6802 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04006803 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05006804 vf * LPFC_VFR_PAGE_SIZE +
6805 LPFC_ULP0_WQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04006806 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6807 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
6808 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6809 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
6810 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6811 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
6812 return 0;
6813}
6814
6815/**
6816 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
6817 * @phba: pointer to lpfc hba data structure.
6818 *
6819 * This routine is invoked to create the bootstrap mailbox
6820 * region consistent with the SLI-4 interface spec. This
6821 * routine allocates all memory necessary to communicate
6822 * mailbox commands to the port and sets up all alignment
6823 * needs. No locks are expected to be held when calling
6824 * this routine.
6825 *
6826 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006827 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04006828 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04006829 **/
6830static int
6831lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
6832{
6833 uint32_t bmbx_size;
6834 struct lpfc_dmabuf *dmabuf;
6835 struct dma_address *dma_address;
6836 uint32_t pa_addr;
6837 uint64_t phys_addr;
6838
6839 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6840 if (!dmabuf)
6841 return -ENOMEM;
6842
6843 /*
6844 * The bootstrap mailbox region is comprised of 2 parts
6845 * plus an alignment restriction of 16 bytes.
6846 */
6847 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
Joe Perches1aee3832014-09-03 12:56:12 -04006848 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
6849 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04006850 if (!dmabuf->virt) {
6851 kfree(dmabuf);
6852 return -ENOMEM;
6853 }
James Smartda0436e2009-05-22 14:51:39 -04006854
6855 /*
6856 * Initialize the bootstrap mailbox pointers now so that the register
6857 * operations are simple later. The mailbox dma address is required
6858 * to be 16-byte aligned. Also align the virtual memory as each
6859 * maibox is copied into the bmbx mailbox region before issuing the
6860 * command to the port.
6861 */
6862 phba->sli4_hba.bmbx.dmabuf = dmabuf;
6863 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
6864
6865 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
6866 LPFC_ALIGN_16_BYTE);
6867 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
6868 LPFC_ALIGN_16_BYTE);
6869
6870 /*
6871 * Set the high and low physical addresses now. The SLI4 alignment
6872 * requirement is 16 bytes and the mailbox is posted to the port
6873 * as two 30-bit addresses. The other data is a bit marking whether
6874 * the 30-bit address is the high or low address.
6875 * Upcast bmbx aphys to 64bits so shift instruction compiles
6876 * clean on 32 bit machines.
6877 */
6878 dma_address = &phba->sli4_hba.bmbx.dma_address;
6879 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
6880 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
6881 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
6882 LPFC_BMBX_BIT1_ADDR_HI);
6883
6884 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
6885 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
6886 LPFC_BMBX_BIT1_ADDR_LO);
6887 return 0;
6888}
6889
6890/**
6891 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
6892 * @phba: pointer to lpfc hba data structure.
6893 *
6894 * This routine is invoked to teardown the bootstrap mailbox
6895 * region and release all host resources. This routine requires
6896 * the caller to ensure all mailbox commands recovered, no
6897 * additional mailbox comands are sent, and interrupts are disabled
6898 * before calling this routine.
6899 *
6900 **/
6901static void
6902lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
6903{
6904 dma_free_coherent(&phba->pcidev->dev,
6905 phba->sli4_hba.bmbx.bmbx_size,
6906 phba->sli4_hba.bmbx.dmabuf->virt,
6907 phba->sli4_hba.bmbx.dmabuf->phys);
6908
6909 kfree(phba->sli4_hba.bmbx.dmabuf);
6910 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
6911}
6912
6913/**
6914 * lpfc_sli4_read_config - Get the config parameters.
6915 * @phba: pointer to lpfc hba data structure.
6916 *
6917 * This routine is invoked to read the configuration parameters from the HBA.
6918 * The configuration parameters are used to set the base and maximum values
6919 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
6920 * allocation for the port.
6921 *
6922 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006923 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006924 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006925 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006926 **/
James Smartff78d8f2011-12-13 13:21:35 -05006927int
James Smartda0436e2009-05-22 14:51:39 -04006928lpfc_sli4_read_config(struct lpfc_hba *phba)
6929{
6930 LPFC_MBOXQ_t *pmb;
6931 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04006932 union lpfc_sli4_cfg_shdr *shdr;
6933 uint32_t shdr_status, shdr_add_status;
6934 struct lpfc_mbx_get_func_cfg *get_func_cfg;
6935 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04006936 char *pdesc_0;
James Smart8aa134a2012-08-14 14:25:29 -04006937 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04006938
6939 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6940 if (!pmb) {
6941 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6942 "2011 Unable to allocate memory for issuing "
6943 "SLI_CONFIG_SPECIAL mailbox command\n");
6944 return -ENOMEM;
6945 }
6946
6947 lpfc_read_config(phba, pmb);
6948
6949 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
6950 if (rc != MBX_SUCCESS) {
6951 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6952 "2012 Mailbox failed , mbxCmd x%x "
6953 "READ_CONFIG, mbxStatus x%x\n",
6954 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6955 bf_get(lpfc_mqe_status, &pmb->u.mqe));
6956 rc = -EIO;
6957 } else {
6958 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05006959 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
6960 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
6961 phba->sli4_hba.lnk_info.lnk_tp =
6962 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
6963 phba->sli4_hba.lnk_info.lnk_no =
6964 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
6965 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6966 "3081 lnk_type:%d, lnk_numb:%d\n",
6967 phba->sli4_hba.lnk_info.lnk_tp,
6968 phba->sli4_hba.lnk_info.lnk_no);
6969 } else
6970 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6971 "3082 Mailbox (x%x) returned ldv:x0\n",
6972 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart6d368e52011-05-24 11:44:12 -04006973 phba->sli4_hba.extents_in_use =
6974 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04006975 phba->sli4_hba.max_cfg_param.max_xri =
6976 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
6977 phba->sli4_hba.max_cfg_param.xri_base =
6978 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
6979 phba->sli4_hba.max_cfg_param.max_vpi =
6980 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
6981 phba->sli4_hba.max_cfg_param.vpi_base =
6982 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
6983 phba->sli4_hba.max_cfg_param.max_rpi =
6984 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
6985 phba->sli4_hba.max_cfg_param.rpi_base =
6986 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
6987 phba->sli4_hba.max_cfg_param.max_vfi =
6988 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
6989 phba->sli4_hba.max_cfg_param.vfi_base =
6990 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
6991 phba->sli4_hba.max_cfg_param.max_fcfi =
6992 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04006993 phba->sli4_hba.max_cfg_param.max_eq =
6994 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
6995 phba->sli4_hba.max_cfg_param.max_rq =
6996 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
6997 phba->sli4_hba.max_cfg_param.max_wq =
6998 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
6999 phba->sli4_hba.max_cfg_param.max_cq =
7000 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
7001 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
7002 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
7003 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
7004 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05007005 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
7006 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04007007 phba->max_vports = phba->max_vpi;
7008 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04007009 "2003 cfg params Extents? %d "
7010 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04007011 "VPI(B:%d M:%d) "
7012 "VFI(B:%d M:%d) "
7013 "RPI(B:%d M:%d) "
James Smart6d368e52011-05-24 11:44:12 -04007014 "FCFI(Count:%d)\n",
7015 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04007016 phba->sli4_hba.max_cfg_param.xri_base,
7017 phba->sli4_hba.max_cfg_param.max_xri,
7018 phba->sli4_hba.max_cfg_param.vpi_base,
7019 phba->sli4_hba.max_cfg_param.max_vpi,
7020 phba->sli4_hba.max_cfg_param.vfi_base,
7021 phba->sli4_hba.max_cfg_param.max_vfi,
7022 phba->sli4_hba.max_cfg_param.rpi_base,
7023 phba->sli4_hba.max_cfg_param.max_rpi,
James Smartda0436e2009-05-22 14:51:39 -04007024 phba->sli4_hba.max_cfg_param.max_fcfi);
7025 }
James Smart912e3ac2011-05-24 11:42:11 -04007026
7027 if (rc)
7028 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04007029
7030 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -04007031 length = phba->sli4_hba.max_cfg_param.max_xri -
7032 lpfc_sli4_get_els_iocb_cnt(phba);
7033 if (phba->cfg_hba_queue_depth > length) {
7034 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7035 "3361 HBA queue depth changed from %d to %d\n",
7036 phba->cfg_hba_queue_depth, length);
7037 phba->cfg_hba_queue_depth = length;
7038 }
James Smart912e3ac2011-05-24 11:42:11 -04007039
7040 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
7041 LPFC_SLI_INTF_IF_TYPE_2)
7042 goto read_cfg_out;
7043
7044 /* get the pf# and vf# for SLI4 if_type 2 port */
7045 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
7046 sizeof(struct lpfc_sli4_cfg_mhdr));
7047 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
7048 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
7049 length, LPFC_SLI4_MBX_EMBED);
7050
James Smart8aa134a2012-08-14 14:25:29 -04007051 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04007052 shdr = (union lpfc_sli4_cfg_shdr *)
7053 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
7054 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7055 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04007056 if (rc2 || shdr_status || shdr_add_status) {
James Smart912e3ac2011-05-24 11:42:11 -04007057 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7058 "3026 Mailbox failed , mbxCmd x%x "
7059 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
7060 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7061 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04007062 goto read_cfg_out;
7063 }
7064
7065 /* search for fc_fcoe resrouce descriptor */
7066 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
James Smart912e3ac2011-05-24 11:42:11 -04007067
James Smart8aa134a2012-08-14 14:25:29 -04007068 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
7069 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
7070 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
7071 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
7072 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
7073 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
7074 goto read_cfg_out;
7075
James Smart912e3ac2011-05-24 11:42:11 -04007076 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04007077 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04007078 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04007079 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04007080 phba->sli4_hba.iov.pf_number =
7081 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
7082 phba->sli4_hba.iov.vf_number =
7083 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
7084 break;
7085 }
7086 }
7087
7088 if (i < LPFC_RSRC_DESC_MAX_NUM)
7089 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7090 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
7091 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
7092 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04007093 else
James Smart912e3ac2011-05-24 11:42:11 -04007094 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7095 "3028 GET_FUNCTION_CONFIG: failed to find "
7096 "Resrouce Descriptor:x%x\n",
7097 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04007098
7099read_cfg_out:
7100 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04007101 return rc;
7102}
7103
7104/**
James Smart2fcee4b2010-12-15 17:57:46 -05007105 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04007106 * @phba: pointer to lpfc hba data structure.
7107 *
James Smart2fcee4b2010-12-15 17:57:46 -05007108 * This routine is invoked to setup the port-side endian order when
7109 * the port if_type is 0. This routine has no function for other
7110 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04007111 *
7112 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007113 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007114 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007115 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007116 **/
7117static int
7118lpfc_setup_endian_order(struct lpfc_hba *phba)
7119{
7120 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05007121 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04007122 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
7123 HOST_ENDIAN_HIGH_WORD1};
7124
James Smart2fcee4b2010-12-15 17:57:46 -05007125 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7126 switch (if_type) {
7127 case LPFC_SLI_INTF_IF_TYPE_0:
7128 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7129 GFP_KERNEL);
7130 if (!mboxq) {
7131 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7132 "0492 Unable to allocate memory for "
7133 "issuing SLI_CONFIG_SPECIAL mailbox "
7134 "command\n");
7135 return -ENOMEM;
7136 }
James Smartda0436e2009-05-22 14:51:39 -04007137
James Smart2fcee4b2010-12-15 17:57:46 -05007138 /*
7139 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
7140 * two words to contain special data values and no other data.
7141 */
7142 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
7143 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
7144 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7145 if (rc != MBX_SUCCESS) {
7146 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7147 "0493 SLI_CONFIG_SPECIAL mailbox "
7148 "failed with status x%x\n",
7149 rc);
7150 rc = -EIO;
7151 }
7152 mempool_free(mboxq, phba->mbox_mem_pool);
7153 break;
7154 case LPFC_SLI_INTF_IF_TYPE_2:
7155 case LPFC_SLI_INTF_IF_TYPE_1:
7156 default:
7157 break;
James Smartda0436e2009-05-22 14:51:39 -04007158 }
James Smartda0436e2009-05-22 14:51:39 -04007159 return rc;
7160}
7161
7162/**
James Smart5350d872011-10-10 21:33:49 -04007163 * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts
James Smartda0436e2009-05-22 14:51:39 -04007164 * @phba: pointer to lpfc hba data structure.
7165 *
James Smart5350d872011-10-10 21:33:49 -04007166 * This routine is invoked to check the user settable queue counts for EQs and
7167 * CQs. after this routine is called the counts will be set to valid values that
7168 * adhere to the constraints of the system's interrupt vectors and the port's
7169 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04007170 *
7171 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007172 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007173 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007174 **/
7175static int
James Smart5350d872011-10-10 21:33:49 -04007176lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04007177{
James Smart67d12732012-08-03 12:36:13 -04007178 int cfg_fcp_io_channel;
James Smart90695ee2012-08-14 14:25:36 -04007179 uint32_t cpu;
7180 uint32_t i = 0;
James Smart1ba981f2014-02-20 09:56:45 -05007181 int fof_vectors = phba->cfg_fof ? 1 : 0;
James Smartda0436e2009-05-22 14:51:39 -04007182
7183 /*
James Smart67d12732012-08-03 12:36:13 -04007184 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04007185 * device parameters
7186 */
7187
James Smart67d12732012-08-03 12:36:13 -04007188 /* Sanity check on HBA EQ parameters */
7189 cfg_fcp_io_channel = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04007190
James Smart7bb03bb2013-04-17 20:19:16 -04007191 /* It doesn't make sense to have more io channels then online CPUs */
7192 for_each_present_cpu(cpu) {
7193 if (cpu_online(cpu))
7194 i++;
James Smart90695ee2012-08-14 14:25:36 -04007195 }
James Smart7bb03bb2013-04-17 20:19:16 -04007196 phba->sli4_hba.num_online_cpu = i;
James Smartb246de12013-05-31 17:03:07 -04007197 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
James Smart76fd07a2014-02-20 09:57:18 -05007198 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04007199
James Smart90695ee2012-08-14 14:25:36 -04007200 if (i < cfg_fcp_io_channel) {
James Smart82c3e9b2012-09-29 11:29:50 -04007201 lpfc_printf_log(phba,
7202 KERN_ERR, LOG_INIT,
James Smart90695ee2012-08-14 14:25:36 -04007203 "3188 Reducing IO channels to match number of "
James Smart7bb03bb2013-04-17 20:19:16 -04007204 "online CPUs: from %d to %d\n",
7205 cfg_fcp_io_channel, i);
James Smart90695ee2012-08-14 14:25:36 -04007206 cfg_fcp_io_channel = i;
7207 }
7208
James Smart1ba981f2014-02-20 09:56:45 -05007209 if (cfg_fcp_io_channel + fof_vectors >
James Smart67d12732012-08-03 12:36:13 -04007210 phba->sli4_hba.max_cfg_param.max_eq) {
James Smart82c3e9b2012-09-29 11:29:50 -04007211 if (phba->sli4_hba.max_cfg_param.max_eq <
7212 LPFC_FCP_IO_CHAN_MIN) {
James Smartda0436e2009-05-22 14:51:39 -04007213 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7214 "2574 Not enough EQs (%d) from the "
7215 "pci function for supporting FCP "
7216 "EQs (%d)\n",
7217 phba->sli4_hba.max_cfg_param.max_eq,
James Smart67d12732012-08-03 12:36:13 -04007218 phba->cfg_fcp_io_channel);
James Smartda0436e2009-05-22 14:51:39 -04007219 goto out_error;
7220 }
James Smart82c3e9b2012-09-29 11:29:50 -04007221 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7222 "2575 Reducing IO channels to match number of "
7223 "available EQs: from %d to %d\n",
7224 cfg_fcp_io_channel,
7225 phba->sli4_hba.max_cfg_param.max_eq);
James Smart1ba981f2014-02-20 09:56:45 -05007226 cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq -
7227 fof_vectors;
James Smartda0436e2009-05-22 14:51:39 -04007228 }
James Smart67d12732012-08-03 12:36:13 -04007229
James Smartda0436e2009-05-22 14:51:39 -04007230 /* The actual number of FCP event queues adopted */
James Smart67d12732012-08-03 12:36:13 -04007231 phba->cfg_fcp_io_channel = cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04007232
James Smartda0436e2009-05-22 14:51:39 -04007233 /* Get EQ depth from module parameter, fake the default for now */
7234 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
7235 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
7236
James Smart5350d872011-10-10 21:33:49 -04007237 /* Get CQ depth from module parameter, fake the default for now */
7238 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
7239 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
7240
7241 return 0;
7242out_error:
7243 return -ENOMEM;
7244}
7245
7246/**
7247 * lpfc_sli4_queue_create - Create all the SLI4 queues
7248 * @phba: pointer to lpfc hba data structure.
7249 *
7250 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
7251 * operation. For each SLI4 queue type, the parameters such as queue entry
7252 * count (queue depth) shall be taken from the module parameter. For now,
7253 * we just use some constant number as place holder.
7254 *
7255 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07007256 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04007257 * -ENOMEM - No availble memory
7258 * -EIO - The mailbox failed to complete successfully.
7259 **/
7260int
7261lpfc_sli4_queue_create(struct lpfc_hba *phba)
7262{
7263 struct lpfc_queue *qdesc;
James Smart67d12732012-08-03 12:36:13 -04007264 int idx;
James Smart5350d872011-10-10 21:33:49 -04007265
7266 /*
James Smart67d12732012-08-03 12:36:13 -04007267 * Create HBA Record arrays.
James Smart5350d872011-10-10 21:33:49 -04007268 */
James Smart67d12732012-08-03 12:36:13 -04007269 if (!phba->cfg_fcp_io_channel)
7270 return -ERANGE;
James Smart5350d872011-10-10 21:33:49 -04007271
James Smart67d12732012-08-03 12:36:13 -04007272 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
7273 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
7274 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
7275 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
7276 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
7277 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
7278
7279 phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) *
7280 phba->cfg_fcp_io_channel), GFP_KERNEL);
7281 if (!phba->sli4_hba.hba_eq) {
James Smartda0436e2009-05-22 14:51:39 -04007282 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007283 "2576 Failed allocate memory for "
7284 "fast-path EQ record array\n");
James Smartda0436e2009-05-22 14:51:39 -04007285 goto out_error;
7286 }
James Smart67d12732012-08-03 12:36:13 -04007287
7288 phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
7289 phba->cfg_fcp_io_channel), GFP_KERNEL);
7290 if (!phba->sli4_hba.fcp_cq) {
7291 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7292 "2577 Failed allocate memory for fast-path "
7293 "CQ record array\n");
7294 goto out_error;
7295 }
7296
7297 phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
7298 phba->cfg_fcp_io_channel), GFP_KERNEL);
7299 if (!phba->sli4_hba.fcp_wq) {
7300 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7301 "2578 Failed allocate memory for fast-path "
7302 "WQ record array\n");
7303 goto out_error;
7304 }
James Smartda0436e2009-05-22 14:51:39 -04007305
James Smart5350d872011-10-10 21:33:49 -04007306 /*
James Smart67d12732012-08-03 12:36:13 -04007307 * Since the first EQ can have multiple CQs associated with it,
7308 * this array is used to quickly see if we have a FCP fast-path
7309 * CQ match.
James Smart5350d872011-10-10 21:33:49 -04007310 */
James Smart67d12732012-08-03 12:36:13 -04007311 phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) *
7312 phba->cfg_fcp_io_channel), GFP_KERNEL);
7313 if (!phba->sli4_hba.fcp_cq_map) {
7314 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7315 "2545 Failed allocate memory for fast-path "
7316 "CQ map\n");
7317 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007318 }
James Smart67d12732012-08-03 12:36:13 -04007319
7320 /*
7321 * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies
7322 * how many EQs to create.
7323 */
7324 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7325
7326 /* Create EQs */
James Smartda0436e2009-05-22 14:51:39 -04007327 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
7328 phba->sli4_hba.eq_ecount);
7329 if (!qdesc) {
7330 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007331 "0497 Failed allocate EQ (%d)\n", idx);
7332 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007333 }
James Smart67d12732012-08-03 12:36:13 -04007334 phba->sli4_hba.hba_eq[idx] = qdesc;
7335
7336 /* Create Fast Path FCP CQs */
7337 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7338 phba->sli4_hba.cq_ecount);
7339 if (!qdesc) {
7340 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7341 "0499 Failed allocate fast-path FCP "
7342 "CQ (%d)\n", idx);
7343 goto out_error;
7344 }
7345 phba->sli4_hba.fcp_cq[idx] = qdesc;
7346
7347 /* Create Fast Path FCP WQs */
James Smartb5c53952016-03-31 14:12:30 -07007348 if (phba->fcp_embed_io) {
7349 qdesc = lpfc_sli4_queue_alloc(phba,
7350 LPFC_WQE128_SIZE,
7351 LPFC_WQE128_DEF_COUNT);
7352 } else {
7353 qdesc = lpfc_sli4_queue_alloc(phba,
7354 phba->sli4_hba.wq_esize,
7355 phba->sli4_hba.wq_ecount);
7356 }
James Smart67d12732012-08-03 12:36:13 -04007357 if (!qdesc) {
7358 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7359 "0503 Failed allocate fast-path FCP "
7360 "WQ (%d)\n", idx);
7361 goto out_error;
7362 }
7363 phba->sli4_hba.fcp_wq[idx] = qdesc;
James Smartda0436e2009-05-22 14:51:39 -04007364 }
7365
James Smart67d12732012-08-03 12:36:13 -04007366
James Smartda0436e2009-05-22 14:51:39 -04007367 /*
James Smart67d12732012-08-03 12:36:13 -04007368 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04007369 */
7370
James Smartda0436e2009-05-22 14:51:39 -04007371 /* Create slow-path Mailbox Command Complete Queue */
7372 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7373 phba->sli4_hba.cq_ecount);
7374 if (!qdesc) {
7375 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7376 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04007377 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007378 }
7379 phba->sli4_hba.mbx_cq = qdesc;
7380
7381 /* Create slow-path ELS Complete Queue */
7382 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7383 phba->sli4_hba.cq_ecount);
7384 if (!qdesc) {
7385 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7386 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -04007387 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007388 }
7389 phba->sli4_hba.els_cq = qdesc;
7390
James Smartda0436e2009-05-22 14:51:39 -04007391
James Smart5350d872011-10-10 21:33:49 -04007392 /*
James Smart67d12732012-08-03 12:36:13 -04007393 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04007394 */
James Smartda0436e2009-05-22 14:51:39 -04007395
7396 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04007397
7398 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
7399 phba->sli4_hba.mq_ecount);
7400 if (!qdesc) {
7401 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7402 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04007403 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007404 }
7405 phba->sli4_hba.mbx_wq = qdesc;
7406
7407 /*
James Smart67d12732012-08-03 12:36:13 -04007408 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04007409 */
James Smartda0436e2009-05-22 14:51:39 -04007410
7411 /* Create slow-path ELS Work Queue */
7412 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
7413 phba->sli4_hba.wq_ecount);
7414 if (!qdesc) {
7415 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7416 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04007417 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007418 }
7419 phba->sli4_hba.els_wq = qdesc;
7420
James Smartda0436e2009-05-22 14:51:39 -04007421 /*
7422 * Create Receive Queue (RQ)
7423 */
James Smartda0436e2009-05-22 14:51:39 -04007424
7425 /* Create Receive Queue for header */
7426 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
7427 phba->sli4_hba.rq_ecount);
7428 if (!qdesc) {
7429 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7430 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04007431 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007432 }
7433 phba->sli4_hba.hdr_rq = qdesc;
7434
7435 /* Create Receive Queue for data */
7436 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
7437 phba->sli4_hba.rq_ecount);
7438 if (!qdesc) {
7439 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7440 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04007441 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007442 }
7443 phba->sli4_hba.dat_rq = qdesc;
7444
James Smart1ba981f2014-02-20 09:56:45 -05007445 /* Create the Queues needed for Flash Optimized Fabric operations */
7446 if (phba->cfg_fof)
7447 lpfc_fof_queue_create(phba);
James Smartda0436e2009-05-22 14:51:39 -04007448 return 0;
7449
James Smartda0436e2009-05-22 14:51:39 -04007450out_error:
James Smart67d12732012-08-03 12:36:13 -04007451 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04007452 return -ENOMEM;
7453}
7454
7455/**
7456 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
7457 * @phba: pointer to lpfc hba data structure.
7458 *
7459 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
7460 * operation.
7461 *
7462 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007463 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007464 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007465 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007466 **/
James Smart5350d872011-10-10 21:33:49 -04007467void
James Smartda0436e2009-05-22 14:51:39 -04007468lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
7469{
James Smart67d12732012-08-03 12:36:13 -04007470 int idx;
7471
James Smart1ba981f2014-02-20 09:56:45 -05007472 if (phba->cfg_fof)
7473 lpfc_fof_queue_destroy(phba);
7474
James Smart67d12732012-08-03 12:36:13 -04007475 if (phba->sli4_hba.hba_eq != NULL) {
7476 /* Release HBA event queue */
7477 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7478 if (phba->sli4_hba.hba_eq[idx] != NULL) {
7479 lpfc_sli4_queue_free(
7480 phba->sli4_hba.hba_eq[idx]);
7481 phba->sli4_hba.hba_eq[idx] = NULL;
7482 }
7483 }
7484 kfree(phba->sli4_hba.hba_eq);
7485 phba->sli4_hba.hba_eq = NULL;
7486 }
7487
7488 if (phba->sli4_hba.fcp_cq != NULL) {
7489 /* Release FCP completion queue */
7490 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7491 if (phba->sli4_hba.fcp_cq[idx] != NULL) {
7492 lpfc_sli4_queue_free(
7493 phba->sli4_hba.fcp_cq[idx]);
7494 phba->sli4_hba.fcp_cq[idx] = NULL;
7495 }
7496 }
7497 kfree(phba->sli4_hba.fcp_cq);
7498 phba->sli4_hba.fcp_cq = NULL;
7499 }
7500
7501 if (phba->sli4_hba.fcp_wq != NULL) {
7502 /* Release FCP work queue */
7503 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7504 if (phba->sli4_hba.fcp_wq[idx] != NULL) {
7505 lpfc_sli4_queue_free(
7506 phba->sli4_hba.fcp_wq[idx]);
7507 phba->sli4_hba.fcp_wq[idx] = NULL;
7508 }
7509 }
7510 kfree(phba->sli4_hba.fcp_wq);
7511 phba->sli4_hba.fcp_wq = NULL;
7512 }
7513
7514 /* Release FCP CQ mapping array */
7515 if (phba->sli4_hba.fcp_cq_map != NULL) {
7516 kfree(phba->sli4_hba.fcp_cq_map);
7517 phba->sli4_hba.fcp_cq_map = NULL;
7518 }
James Smartda0436e2009-05-22 14:51:39 -04007519
7520 /* Release mailbox command work queue */
James Smart67d12732012-08-03 12:36:13 -04007521 if (phba->sli4_hba.mbx_wq != NULL) {
7522 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
7523 phba->sli4_hba.mbx_wq = NULL;
7524 }
James Smartda0436e2009-05-22 14:51:39 -04007525
7526 /* Release ELS work queue */
James Smart67d12732012-08-03 12:36:13 -04007527 if (phba->sli4_hba.els_wq != NULL) {
7528 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
7529 phba->sli4_hba.els_wq = NULL;
7530 }
James Smartda0436e2009-05-22 14:51:39 -04007531
7532 /* Release unsolicited receive queue */
James Smart67d12732012-08-03 12:36:13 -04007533 if (phba->sli4_hba.hdr_rq != NULL) {
7534 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
7535 phba->sli4_hba.hdr_rq = NULL;
7536 }
7537 if (phba->sli4_hba.dat_rq != NULL) {
7538 lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
7539 phba->sli4_hba.dat_rq = NULL;
7540 }
James Smartda0436e2009-05-22 14:51:39 -04007541
James Smartda0436e2009-05-22 14:51:39 -04007542 /* Release ELS complete queue */
James Smart67d12732012-08-03 12:36:13 -04007543 if (phba->sli4_hba.els_cq != NULL) {
7544 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
7545 phba->sli4_hba.els_cq = NULL;
7546 }
James Smartda0436e2009-05-22 14:51:39 -04007547
7548 /* Release mailbox command complete queue */
James Smart67d12732012-08-03 12:36:13 -04007549 if (phba->sli4_hba.mbx_cq != NULL) {
7550 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
7551 phba->sli4_hba.mbx_cq = NULL;
7552 }
James Smartda0436e2009-05-22 14:51:39 -04007553
7554 return;
7555}
7556
7557/**
7558 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
7559 * @phba: pointer to lpfc hba data structure.
7560 *
7561 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
7562 * operation.
7563 *
7564 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007565 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007566 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007567 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007568 **/
7569int
7570lpfc_sli4_queue_setup(struct lpfc_hba *phba)
7571{
James Smart2a76a282012-08-03 12:35:54 -04007572 struct lpfc_sli *psli = &phba->sli;
7573 struct lpfc_sli_ring *pring;
James Smartda0436e2009-05-22 14:51:39 -04007574 int rc = -ENOMEM;
7575 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
7576 int fcp_cq_index = 0;
James Smart962bc512013-01-03 15:44:00 -05007577 uint32_t shdr_status, shdr_add_status;
7578 union lpfc_sli4_cfg_shdr *shdr;
7579 LPFC_MBOXQ_t *mboxq;
7580 uint32_t length;
7581
7582 /* Check for dual-ULP support */
7583 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7584 if (!mboxq) {
7585 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7586 "3249 Unable to allocate memory for "
7587 "QUERY_FW_CFG mailbox command\n");
7588 return -ENOMEM;
7589 }
7590 length = (sizeof(struct lpfc_mbx_query_fw_config) -
7591 sizeof(struct lpfc_sli4_cfg_mhdr));
7592 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
7593 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
7594 length, LPFC_SLI4_MBX_EMBED);
7595
7596 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7597
7598 shdr = (union lpfc_sli4_cfg_shdr *)
7599 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
7600 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7601 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7602 if (shdr_status || shdr_add_status || rc) {
7603 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7604 "3250 QUERY_FW_CFG mailbox failed with status "
7605 "x%x add_status x%x, mbx status x%x\n",
7606 shdr_status, shdr_add_status, rc);
7607 if (rc != MBX_TIMEOUT)
7608 mempool_free(mboxq, phba->mbox_mem_pool);
7609 rc = -ENXIO;
7610 goto out_error;
7611 }
7612
7613 phba->sli4_hba.fw_func_mode =
7614 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
7615 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
7616 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
James Smart8b017a32015-05-21 13:55:18 -04007617 phba->sli4_hba.physical_port =
7618 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
James Smart962bc512013-01-03 15:44:00 -05007619 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7620 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
7621 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
7622 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
7623
7624 if (rc != MBX_TIMEOUT)
7625 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04007626
7627 /*
James Smart67d12732012-08-03 12:36:13 -04007628 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04007629 */
7630
James Smart67d12732012-08-03 12:36:13 -04007631 /* Set up HBA event queue */
7632 if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) {
James Smart2e90f4b2011-12-13 13:22:37 -05007633 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7634 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007635 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007636 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05007637 }
James Smart67d12732012-08-03 12:36:13 -04007638 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
7639 if (!phba->sli4_hba.hba_eq[fcp_eqidx]) {
James Smartda0436e2009-05-22 14:51:39 -04007640 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7641 "0522 Fast-path EQ (%d) not "
7642 "allocated\n", fcp_eqidx);
James Smart1b511972011-12-13 13:23:09 -05007643 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007644 goto out_destroy_hba_eq;
James Smartda0436e2009-05-22 14:51:39 -04007645 }
James Smart67d12732012-08-03 12:36:13 -04007646 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx],
James Smartbf8dae82012-08-03 12:36:24 -04007647 (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel));
James Smartda0436e2009-05-22 14:51:39 -04007648 if (rc) {
7649 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7650 "0523 Failed setup of fast-path EQ "
James Smarta2fc4aef2014-09-03 12:57:55 -04007651 "(%d), rc = 0x%x\n", fcp_eqidx,
7652 (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007653 goto out_destroy_hba_eq;
James Smartda0436e2009-05-22 14:51:39 -04007654 }
7655 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007656 "2584 HBA EQ setup: "
James Smartda0436e2009-05-22 14:51:39 -04007657 "queue[%d]-id=%d\n", fcp_eqidx,
James Smart67d12732012-08-03 12:36:13 -04007658 phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007659 }
7660
James Smart67d12732012-08-03 12:36:13 -04007661 /* Set up fast-path FCP Response Complete Queue */
7662 if (!phba->sli4_hba.fcp_cq) {
7663 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7664 "3148 Fast-path FCP CQ array not "
7665 "allocated\n");
7666 rc = -ENOMEM;
7667 goto out_destroy_hba_eq;
7668 }
7669
7670 for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) {
7671 if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
7672 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7673 "0526 Fast-path FCP CQ (%d) not "
7674 "allocated\n", fcp_cqidx);
7675 rc = -ENOMEM;
7676 goto out_destroy_fcp_cq;
7677 }
7678 rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
7679 phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP);
7680 if (rc) {
7681 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7682 "0527 Failed setup of fast-path FCP "
James Smarta2fc4aef2014-09-03 12:57:55 -04007683 "CQ (%d), rc = 0x%x\n", fcp_cqidx,
7684 (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007685 goto out_destroy_fcp_cq;
7686 }
7687
7688 /* Setup fcp_cq_map for fast lookup */
7689 phba->sli4_hba.fcp_cq_map[fcp_cqidx] =
7690 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id;
7691
7692 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7693 "2588 FCP CQ setup: cq[%d]-id=%d, "
7694 "parent seq[%d]-id=%d\n",
7695 fcp_cqidx,
7696 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
7697 fcp_cqidx,
7698 phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id);
7699 }
7700
7701 /* Set up fast-path FCP Work Queue */
7702 if (!phba->sli4_hba.fcp_wq) {
7703 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7704 "3149 Fast-path FCP WQ array not "
7705 "allocated\n");
7706 rc = -ENOMEM;
7707 goto out_destroy_fcp_cq;
7708 }
7709
7710 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) {
7711 if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
7712 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7713 "0534 Fast-path FCP WQ (%d) not "
7714 "allocated\n", fcp_wqidx);
7715 rc = -ENOMEM;
7716 goto out_destroy_fcp_wq;
7717 }
7718 rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
7719 phba->sli4_hba.fcp_cq[fcp_wqidx],
7720 LPFC_FCP);
7721 if (rc) {
7722 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7723 "0535 Failed setup of fast-path FCP "
James Smarta2fc4aef2014-09-03 12:57:55 -04007724 "WQ (%d), rc = 0x%x\n", fcp_wqidx,
7725 (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007726 goto out_destroy_fcp_wq;
7727 }
7728
7729 /* Bind this WQ to the next FCP ring */
7730 pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx];
7731 pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx];
7732 phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring;
7733
7734 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7735 "2591 FCP WQ setup: wq[%d]-id=%d, "
7736 "parent cq[%d]-id=%d\n",
7737 fcp_wqidx,
7738 phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
7739 fcp_cq_index,
7740 phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id);
7741 }
James Smartda0436e2009-05-22 14:51:39 -04007742 /*
7743 * Set up Complete Queues (CQs)
7744 */
7745
7746 /* Set up slow-path MBOX Complete Queue as the first CQ */
7747 if (!phba->sli4_hba.mbx_cq) {
7748 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7749 "0528 Mailbox CQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007750 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007751 goto out_destroy_fcp_wq;
James Smartda0436e2009-05-22 14:51:39 -04007752 }
James Smart67d12732012-08-03 12:36:13 -04007753 rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq,
7754 phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04007755 if (rc) {
7756 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7757 "0529 Failed setup of slow-path mailbox CQ: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007758 "rc = 0x%x\n", (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007759 goto out_destroy_fcp_wq;
James Smartda0436e2009-05-22 14:51:39 -04007760 }
7761 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7762 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
7763 phba->sli4_hba.mbx_cq->queue_id,
James Smart67d12732012-08-03 12:36:13 -04007764 phba->sli4_hba.hba_eq[0]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007765
7766 /* Set up slow-path ELS Complete Queue */
7767 if (!phba->sli4_hba.els_cq) {
7768 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7769 "0530 ELS CQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007770 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007771 goto out_destroy_mbx_cq;
7772 }
James Smart67d12732012-08-03 12:36:13 -04007773 rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq,
7774 phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04007775 if (rc) {
7776 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7777 "0531 Failed setup of slow-path ELS CQ: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007778 "rc = 0x%x\n", (uint32_t)rc);
James Smartda0436e2009-05-22 14:51:39 -04007779 goto out_destroy_mbx_cq;
7780 }
7781 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7782 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
7783 phba->sli4_hba.els_cq->queue_id,
James Smart67d12732012-08-03 12:36:13 -04007784 phba->sli4_hba.hba_eq[0]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007785
7786 /*
7787 * Set up all the Work Queues (WQs)
7788 */
7789
7790 /* Set up Mailbox Command Queue */
7791 if (!phba->sli4_hba.mbx_wq) {
7792 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7793 "0538 Slow-path MQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007794 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007795 goto out_destroy_els_cq;
James Smartda0436e2009-05-22 14:51:39 -04007796 }
7797 rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
7798 phba->sli4_hba.mbx_cq, LPFC_MBOX);
7799 if (rc) {
7800 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7801 "0539 Failed setup of slow-path MQ: "
7802 "rc = 0x%x\n", rc);
James Smart67d12732012-08-03 12:36:13 -04007803 goto out_destroy_els_cq;
James Smartda0436e2009-05-22 14:51:39 -04007804 }
7805 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7806 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
7807 phba->sli4_hba.mbx_wq->queue_id,
7808 phba->sli4_hba.mbx_cq->queue_id);
7809
7810 /* Set up slow-path ELS Work Queue */
7811 if (!phba->sli4_hba.els_wq) {
7812 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7813 "0536 Slow-path ELS WQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007814 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007815 goto out_destroy_mbx_wq;
7816 }
7817 rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
7818 phba->sli4_hba.els_cq, LPFC_ELS);
7819 if (rc) {
7820 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7821 "0537 Failed setup of slow-path ELS WQ: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007822 "rc = 0x%x\n", (uint32_t)rc);
James Smartda0436e2009-05-22 14:51:39 -04007823 goto out_destroy_mbx_wq;
7824 }
James Smart2a76a282012-08-03 12:35:54 -04007825
7826 /* Bind this WQ to the ELS ring */
7827 pring = &psli->ring[LPFC_ELS_RING];
7828 pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq;
7829 phba->sli4_hba.els_cq->pring = pring;
7830
James Smartda0436e2009-05-22 14:51:39 -04007831 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7832 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
7833 phba->sli4_hba.els_wq->queue_id,
7834 phba->sli4_hba.els_cq->queue_id);
7835
James Smartda0436e2009-05-22 14:51:39 -04007836 /*
7837 * Create Receive Queue (RQ)
7838 */
7839 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
7840 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7841 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007842 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007843 goto out_destroy_els_wq;
James Smartda0436e2009-05-22 14:51:39 -04007844 }
James Smart73d91e52011-10-10 21:32:10 -04007845
7846 lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
7847 lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
7848
James Smartda0436e2009-05-22 14:51:39 -04007849 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04007850 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04007851 if (rc) {
7852 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7853 "0541 Failed setup of Receive Queue: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007854 "rc = 0x%x\n", (uint32_t)rc);
James Smartda0436e2009-05-22 14:51:39 -04007855 goto out_destroy_fcp_wq;
7856 }
James Smart73d91e52011-10-10 21:32:10 -04007857
James Smartda0436e2009-05-22 14:51:39 -04007858 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7859 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
7860 "parent cq-id=%d\n",
7861 phba->sli4_hba.hdr_rq->queue_id,
7862 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04007863 phba->sli4_hba.els_cq->queue_id);
James Smart1ba981f2014-02-20 09:56:45 -05007864
7865 if (phba->cfg_fof) {
7866 rc = lpfc_fof_queue_setup(phba);
7867 if (rc) {
7868 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7869 "0549 Failed setup of FOF Queues: "
7870 "rc = 0x%x\n", rc);
7871 goto out_destroy_els_rq;
7872 }
7873 }
James Smart2c9c5a02015-04-07 15:07:15 -04007874
7875 /*
7876 * Configure EQ delay multipier for interrupt coalescing using
7877 * MODIFY_EQ_DELAY for all EQs created, LPFC_MAX_EQ_DELAY at a time.
7878 */
7879 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel;
7880 fcp_eqidx += LPFC_MAX_EQ_DELAY)
7881 lpfc_modify_fcp_eq_delay(phba, fcp_eqidx);
James Smartda0436e2009-05-22 14:51:39 -04007882 return 0;
7883
James Smart1ba981f2014-02-20 09:56:45 -05007884out_destroy_els_rq:
7885 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
James Smart2e90f4b2011-12-13 13:22:37 -05007886out_destroy_els_wq:
James Smartda0436e2009-05-22 14:51:39 -04007887 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7888out_destroy_mbx_wq:
7889 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
James Smart2e90f4b2011-12-13 13:22:37 -05007890out_destroy_els_cq:
James Smartda0436e2009-05-22 14:51:39 -04007891 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
7892out_destroy_mbx_cq:
7893 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
James Smart67d12732012-08-03 12:36:13 -04007894out_destroy_fcp_wq:
7895 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
7896 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
7897out_destroy_fcp_cq:
7898 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
7899 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
7900out_destroy_hba_eq:
James Smartda0436e2009-05-22 14:51:39 -04007901 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
James Smart67d12732012-08-03 12:36:13 -04007902 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]);
James Smartda0436e2009-05-22 14:51:39 -04007903out_error:
7904 return rc;
7905}
7906
7907/**
7908 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
7909 * @phba: pointer to lpfc hba data structure.
7910 *
7911 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
7912 * operation.
7913 *
7914 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007915 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007916 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007917 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007918 **/
7919void
7920lpfc_sli4_queue_unset(struct lpfc_hba *phba)
7921{
7922 int fcp_qidx;
7923
James Smart1ba981f2014-02-20 09:56:45 -05007924 /* Unset the queues created for Flash Optimized Fabric operations */
7925 if (phba->cfg_fof)
7926 lpfc_fof_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04007927 /* Unset mailbox command work queue */
7928 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
7929 /* Unset ELS work queue */
7930 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7931 /* Unset unsolicited receive queue */
7932 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
7933 /* Unset FCP work queue */
James Smart67d12732012-08-03 12:36:13 -04007934 if (phba->sli4_hba.fcp_wq) {
7935 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
7936 fcp_qidx++)
7937 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
7938 }
James Smartda0436e2009-05-22 14:51:39 -04007939 /* Unset mailbox command complete queue */
7940 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
7941 /* Unset ELS complete queue */
7942 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
James Smartda0436e2009-05-22 14:51:39 -04007943 /* Unset FCP response complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05007944 if (phba->sli4_hba.fcp_cq) {
James Smart67d12732012-08-03 12:36:13 -04007945 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
7946 fcp_qidx++)
James Smart2e90f4b2011-12-13 13:22:37 -05007947 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
James Smart2e90f4b2011-12-13 13:22:37 -05007948 }
James Smartda0436e2009-05-22 14:51:39 -04007949 /* Unset fast-path event queue */
James Smart67d12732012-08-03 12:36:13 -04007950 if (phba->sli4_hba.hba_eq) {
7951 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
James Smart2e90f4b2011-12-13 13:22:37 -05007952 fcp_qidx++)
James Smart67d12732012-08-03 12:36:13 -04007953 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_qidx]);
James Smart2e90f4b2011-12-13 13:22:37 -05007954 }
James Smartda0436e2009-05-22 14:51:39 -04007955}
7956
7957/**
7958 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
7959 * @phba: pointer to lpfc hba data structure.
7960 *
7961 * This routine is invoked to allocate and set up a pool of completion queue
7962 * events. The body of the completion queue event is a completion queue entry
7963 * CQE. For now, this pool is used for the interrupt service routine to queue
7964 * the following HBA completion queue events for the worker thread to process:
7965 * - Mailbox asynchronous events
7966 * - Receive queue completion unsolicited events
7967 * Later, this can be used for all the slow-path events.
7968 *
7969 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007970 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007971 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007972 **/
7973static int
7974lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
7975{
7976 struct lpfc_cq_event *cq_event;
7977 int i;
7978
7979 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
7980 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
7981 if (!cq_event)
7982 goto out_pool_create_fail;
7983 list_add_tail(&cq_event->list,
7984 &phba->sli4_hba.sp_cqe_event_pool);
7985 }
7986 return 0;
7987
7988out_pool_create_fail:
7989 lpfc_sli4_cq_event_pool_destroy(phba);
7990 return -ENOMEM;
7991}
7992
7993/**
7994 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
7995 * @phba: pointer to lpfc hba data structure.
7996 *
7997 * This routine is invoked to free the pool of completion queue events at
7998 * driver unload time. Note that, it is the responsibility of the driver
7999 * cleanup routine to free all the outstanding completion-queue events
8000 * allocated from this pool back into the pool before invoking this routine
8001 * to destroy the pool.
8002 **/
8003static void
8004lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
8005{
8006 struct lpfc_cq_event *cq_event, *next_cq_event;
8007
8008 list_for_each_entry_safe(cq_event, next_cq_event,
8009 &phba->sli4_hba.sp_cqe_event_pool, list) {
8010 list_del(&cq_event->list);
8011 kfree(cq_event);
8012 }
8013}
8014
8015/**
8016 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
8017 * @phba: pointer to lpfc hba data structure.
8018 *
8019 * This routine is the lock free version of the API invoked to allocate a
8020 * completion-queue event from the free pool.
8021 *
8022 * Return: Pointer to the newly allocated completion-queue event if successful
8023 * NULL otherwise.
8024 **/
8025struct lpfc_cq_event *
8026__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
8027{
8028 struct lpfc_cq_event *cq_event = NULL;
8029
8030 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
8031 struct lpfc_cq_event, list);
8032 return cq_event;
8033}
8034
8035/**
8036 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
8037 * @phba: pointer to lpfc hba data structure.
8038 *
8039 * This routine is the lock version of the API invoked to allocate a
8040 * completion-queue event from the free pool.
8041 *
8042 * Return: Pointer to the newly allocated completion-queue event if successful
8043 * NULL otherwise.
8044 **/
8045struct lpfc_cq_event *
8046lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
8047{
8048 struct lpfc_cq_event *cq_event;
8049 unsigned long iflags;
8050
8051 spin_lock_irqsave(&phba->hbalock, iflags);
8052 cq_event = __lpfc_sli4_cq_event_alloc(phba);
8053 spin_unlock_irqrestore(&phba->hbalock, iflags);
8054 return cq_event;
8055}
8056
8057/**
8058 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
8059 * @phba: pointer to lpfc hba data structure.
8060 * @cq_event: pointer to the completion queue event to be freed.
8061 *
8062 * This routine is the lock free version of the API invoked to release a
8063 * completion-queue event back into the free pool.
8064 **/
8065void
8066__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
8067 struct lpfc_cq_event *cq_event)
8068{
8069 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
8070}
8071
8072/**
8073 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
8074 * @phba: pointer to lpfc hba data structure.
8075 * @cq_event: pointer to the completion queue event to be freed.
8076 *
8077 * This routine is the lock version of the API invoked to release a
8078 * completion-queue event back into the free pool.
8079 **/
8080void
8081lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
8082 struct lpfc_cq_event *cq_event)
8083{
8084 unsigned long iflags;
8085 spin_lock_irqsave(&phba->hbalock, iflags);
8086 __lpfc_sli4_cq_event_release(phba, cq_event);
8087 spin_unlock_irqrestore(&phba->hbalock, iflags);
8088}
8089
8090/**
8091 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
8092 * @phba: pointer to lpfc hba data structure.
8093 *
8094 * This routine is to free all the pending completion-queue events to the
8095 * back into the free pool for device reset.
8096 **/
8097static void
8098lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
8099{
8100 LIST_HEAD(cqelist);
8101 struct lpfc_cq_event *cqe;
8102 unsigned long iflags;
8103
8104 /* Retrieve all the pending WCQEs from pending WCQE lists */
8105 spin_lock_irqsave(&phba->hbalock, iflags);
8106 /* Pending FCP XRI abort events */
8107 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
8108 &cqelist);
8109 /* Pending ELS XRI abort events */
8110 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
8111 &cqelist);
8112 /* Pending asynnc events */
8113 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
8114 &cqelist);
8115 spin_unlock_irqrestore(&phba->hbalock, iflags);
8116
8117 while (!list_empty(&cqelist)) {
8118 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
8119 lpfc_sli4_cq_event_release(phba, cqe);
8120 }
8121}
8122
8123/**
8124 * lpfc_pci_function_reset - Reset pci function.
8125 * @phba: pointer to lpfc hba data structure.
8126 *
8127 * This routine is invoked to request a PCI function reset. It will destroys
8128 * all resources assigned to the PCI function which originates this request.
8129 *
8130 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008131 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008132 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008133 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008134 **/
8135int
8136lpfc_pci_function_reset(struct lpfc_hba *phba)
8137{
8138 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05008139 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04008140 uint32_t shdr_status, shdr_add_status;
James Smart2f6fa2c2014-09-03 12:57:08 -04008141 uint32_t rdy_chk;
8142 uint32_t port_reset = 0;
James Smartda0436e2009-05-22 14:51:39 -04008143 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05008144 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -05008145 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -04008146
James Smart2fcee4b2010-12-15 17:57:46 -05008147 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8148 switch (if_type) {
8149 case LPFC_SLI_INTF_IF_TYPE_0:
8150 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8151 GFP_KERNEL);
8152 if (!mboxq) {
8153 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8154 "0494 Unable to allocate memory for "
8155 "issuing SLI_FUNCTION_RESET mailbox "
8156 "command\n");
8157 return -ENOMEM;
8158 }
8159
8160 /* Setup PCI function reset mailbox-ioctl command */
8161 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8162 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
8163 LPFC_SLI4_MBX_EMBED);
8164 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8165 shdr = (union lpfc_sli4_cfg_shdr *)
8166 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
8167 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8168 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
8169 &shdr->response);
8170 if (rc != MBX_TIMEOUT)
8171 mempool_free(mboxq, phba->mbox_mem_pool);
8172 if (shdr_status || shdr_add_status || rc) {
8173 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8174 "0495 SLI_FUNCTION_RESET mailbox "
8175 "failed with status x%x add_status x%x,"
8176 " mbx status x%x\n",
8177 shdr_status, shdr_add_status, rc);
8178 rc = -ENXIO;
8179 }
8180 break;
8181 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2f6fa2c2014-09-03 12:57:08 -04008182wait:
8183 /*
8184 * Poll the Port Status Register and wait for RDY for
8185 * up to 30 seconds. If the port doesn't respond, treat
8186 * it as an error.
8187 */
James Smart77d093f2015-04-07 15:07:08 -04008188 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
James Smart2f6fa2c2014-09-03 12:57:08 -04008189 if (lpfc_readl(phba->sli4_hba.u.if_type2.
8190 STATUSregaddr, &reg_data.word0)) {
8191 rc = -ENODEV;
8192 goto out;
8193 }
8194 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
8195 break;
8196 msleep(20);
8197 }
8198
8199 if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
8200 phba->work_status[0] = readl(
8201 phba->sli4_hba.u.if_type2.ERR1regaddr);
8202 phba->work_status[1] = readl(
8203 phba->sli4_hba.u.if_type2.ERR2regaddr);
8204 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8205 "2890 Port not ready, port status reg "
8206 "0x%x error 1=0x%x, error 2=0x%x\n",
8207 reg_data.word0,
8208 phba->work_status[0],
8209 phba->work_status[1]);
8210 rc = -ENODEV;
8211 goto out;
8212 }
8213
8214 if (!port_reset) {
8215 /*
8216 * Reset the port now
8217 */
James Smart2fcee4b2010-12-15 17:57:46 -05008218 reg_data.word0 = 0;
8219 bf_set(lpfc_sliport_ctrl_end, &reg_data,
8220 LPFC_SLIPORT_LITTLE_ENDIAN);
8221 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
8222 LPFC_SLIPORT_INIT_PORT);
8223 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
8224 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -05008225 /* flush */
James Smart2b81f942012-03-01 22:37:18 -05008226 pci_read_config_word(phba->pcidev,
8227 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -05008228
James Smart2f6fa2c2014-09-03 12:57:08 -04008229 port_reset = 1;
8230 msleep(20);
8231 goto wait;
8232 } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
8233 rc = -ENODEV;
8234 goto out;
James Smart2fcee4b2010-12-15 17:57:46 -05008235 }
8236 break;
James Smart2f6fa2c2014-09-03 12:57:08 -04008237
James Smart2fcee4b2010-12-15 17:57:46 -05008238 case LPFC_SLI_INTF_IF_TYPE_1:
8239 default:
8240 break;
James Smartda0436e2009-05-22 14:51:39 -04008241 }
8242
James Smart73d91e52011-10-10 21:32:10 -04008243out:
James Smart2fcee4b2010-12-15 17:57:46 -05008244 /* Catch the not-ready port failure after a port reset. */
James Smart2f6fa2c2014-09-03 12:57:08 -04008245 if (rc) {
James Smart229adb02013-04-17 20:16:51 -04008246 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8247 "3317 HBA not functional: IP Reset Failed "
James Smart2f6fa2c2014-09-03 12:57:08 -04008248 "try: echo fw_reset > board_mode\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008249 rc = -ENODEV;
James Smart229adb02013-04-17 20:16:51 -04008250 }
James Smart2fcee4b2010-12-15 17:57:46 -05008251
James Smartda0436e2009-05-22 14:51:39 -04008252 return rc;
8253}
8254
8255/**
James Smartda0436e2009-05-22 14:51:39 -04008256 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
8257 * @phba: pointer to lpfc hba data structure.
8258 *
8259 * This routine is invoked to set up the PCI device memory space for device
8260 * with SLI-4 interface spec.
8261 *
8262 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008263 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008264 * other values - error
8265 **/
8266static int
8267lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
8268{
8269 struct pci_dev *pdev;
8270 unsigned long bar0map_len, bar1map_len, bar2map_len;
8271 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05008272 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04008273
8274 /* Obtain PCI device reference */
8275 if (!phba->pcidev)
8276 return error;
8277 else
8278 pdev = phba->pcidev;
8279
8280 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05008281 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
8282 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
8283 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
8284 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smartda0436e2009-05-22 14:51:39 -04008285 return error;
Michael Reed8e685972009-09-18 12:02:05 -05008286 }
8287 }
James Smartda0436e2009-05-22 14:51:39 -04008288
James Smart2fcee4b2010-12-15 17:57:46 -05008289 /*
8290 * The BARs and register set definitions and offset locations are
8291 * dependent on the if_type.
8292 */
8293 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
8294 &phba->sli4_hba.sli_intf.word0)) {
8295 return error;
8296 }
8297
8298 /* There is no SLI3 failback for SLI4 devices. */
8299 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
8300 LPFC_SLI_INTF_VALID) {
8301 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8302 "2894 SLI_INTF reg contents invalid "
8303 "sli_intf reg 0x%x\n",
8304 phba->sli4_hba.sli_intf.word0);
8305 return error;
8306 }
8307
8308 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8309 /*
8310 * Get the bus address of SLI4 device Bar regions and the
8311 * number of bytes required by each mapping. The mapping of the
8312 * particular PCI BARs regions is dependent on the type of
8313 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04008314 */
James Smartf5ca6f22013-09-06 12:21:09 -04008315 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
8316 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
8317 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
James Smart2fcee4b2010-12-15 17:57:46 -05008318
8319 /*
8320 * Map SLI4 PCI Config Space Register base to a kernel virtual
8321 * addr
8322 */
8323 phba->sli4_hba.conf_regs_memmap_p =
8324 ioremap(phba->pci_bar0_map, bar0map_len);
8325 if (!phba->sli4_hba.conf_regs_memmap_p) {
8326 dev_printk(KERN_ERR, &pdev->dev,
8327 "ioremap failed for SLI4 PCI config "
8328 "registers.\n");
8329 goto out;
8330 }
James Smartf5ca6f22013-09-06 12:21:09 -04008331 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008332 /* Set up BAR0 PCI config space register memory map */
8333 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05008334 } else {
8335 phba->pci_bar0_map = pci_resource_start(pdev, 1);
8336 bar0map_len = pci_resource_len(pdev, 1);
James Smart2fcee4b2010-12-15 17:57:46 -05008337 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
8338 dev_printk(KERN_ERR, &pdev->dev,
8339 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
8340 goto out;
8341 }
8342 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008343 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008344 if (!phba->sli4_hba.conf_regs_memmap_p) {
8345 dev_printk(KERN_ERR, &pdev->dev,
8346 "ioremap failed for SLI4 PCI config "
8347 "registers.\n");
8348 goto out;
8349 }
8350 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04008351 }
8352
James Smartc31098c2011-04-16 11:03:33 -04008353 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04008354 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
James Smart2fcee4b2010-12-15 17:57:46 -05008355 /*
8356 * Map SLI4 if type 0 HBA Control Register base to a kernel
8357 * virtual address and setup the registers.
8358 */
James Smartf5ca6f22013-09-06 12:21:09 -04008359 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
8360 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
James Smart2fcee4b2010-12-15 17:57:46 -05008361 phba->sli4_hba.ctrl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008362 ioremap(phba->pci_bar1_map, bar1map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008363 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
8364 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04008365 "ioremap failed for SLI4 HBA control registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008366 goto out_iounmap_conf;
8367 }
James Smartf5ca6f22013-09-06 12:21:09 -04008368 phba->pci_bar2_memmap_p = phba->sli4_hba.ctrl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008369 lpfc_sli4_bar1_register_memmap(phba);
James Smartda0436e2009-05-22 14:51:39 -04008370 }
8371
James Smartc31098c2011-04-16 11:03:33 -04008372 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04008373 (pci_resource_start(pdev, PCI_64BIT_BAR4))) {
James Smart2fcee4b2010-12-15 17:57:46 -05008374 /*
8375 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
8376 * virtual address and setup the registers.
8377 */
James Smartf5ca6f22013-09-06 12:21:09 -04008378 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
8379 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
James Smart2fcee4b2010-12-15 17:57:46 -05008380 phba->sli4_hba.drbl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008381 ioremap(phba->pci_bar2_map, bar2map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008382 if (!phba->sli4_hba.drbl_regs_memmap_p) {
8383 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04008384 "ioremap failed for SLI4 HBA doorbell registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008385 goto out_iounmap_ctrl;
8386 }
James Smartf5ca6f22013-09-06 12:21:09 -04008387 phba->pci_bar4_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008388 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
8389 if (error)
8390 goto out_iounmap_all;
James Smartda0436e2009-05-22 14:51:39 -04008391 }
8392
James Smartda0436e2009-05-22 14:51:39 -04008393 return 0;
8394
8395out_iounmap_all:
8396 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
8397out_iounmap_ctrl:
8398 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
8399out_iounmap_conf:
8400 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8401out:
8402 return error;
8403}
8404
8405/**
8406 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
8407 * @phba: pointer to lpfc hba data structure.
8408 *
8409 * This routine is invoked to unset the PCI device memory space for device
8410 * with SLI-4 interface spec.
8411 **/
8412static void
8413lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
8414{
James Smart2e90f4b2011-12-13 13:22:37 -05008415 uint32_t if_type;
8416 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -04008417
James Smart2e90f4b2011-12-13 13:22:37 -05008418 switch (if_type) {
8419 case LPFC_SLI_INTF_IF_TYPE_0:
8420 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
8421 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
8422 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8423 break;
8424 case LPFC_SLI_INTF_IF_TYPE_2:
8425 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8426 break;
8427 case LPFC_SLI_INTF_IF_TYPE_1:
8428 default:
8429 dev_printk(KERN_ERR, &phba->pcidev->dev,
8430 "FATAL - unsupported SLI4 interface type - %d\n",
8431 if_type);
8432 break;
8433 }
James Smartda0436e2009-05-22 14:51:39 -04008434}
8435
8436/**
James Smart3772a992009-05-22 14:50:54 -04008437 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
8438 * @phba: pointer to lpfc hba data structure.
8439 *
8440 * This routine is invoked to enable the MSI-X interrupt vectors to device
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008441 * with SLI-3 interface specs. The kernel function pci_enable_msix_exact()
8442 * is called to enable the MSI-X vectors. Note that pci_enable_msix_exact(),
8443 * once invoked, enables either all or nothing, depending on the current
James Smart3772a992009-05-22 14:50:54 -04008444 * availability of PCI vector resources. The device driver is responsible
8445 * for calling the individual request_irq() to register each MSI-X vector
8446 * with a interrupt handler, which is done in this function. Note that
8447 * later when device is unloading, the driver should always call free_irq()
8448 * on all MSI-X vectors it has done request_irq() on before calling
8449 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
8450 * will be left with MSI-X enabled and leaks its vectors.
8451 *
8452 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008453 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008454 * other values - error
8455 **/
8456static int
8457lpfc_sli_enable_msix(struct lpfc_hba *phba)
8458{
8459 int rc, i;
8460 LPFC_MBOXQ_t *pmb;
8461
8462 /* Set up MSI-X multi-message vectors */
8463 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8464 phba->msix_entries[i].entry = i;
8465
8466 /* Configure MSI-X capability structure */
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008467 rc = pci_enable_msix_exact(phba->pcidev, phba->msix_entries,
8468 LPFC_MSIX_VECTORS);
James Smart3772a992009-05-22 14:50:54 -04008469 if (rc) {
8470 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8471 "0420 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02008472 goto vec_fail_out;
James Smart3772a992009-05-22 14:50:54 -04008473 }
8474 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8475 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8476 "0477 MSI-X entry[%d]: vector=x%x "
8477 "message=%d\n", i,
8478 phba->msix_entries[i].vector,
8479 phba->msix_entries[i].entry);
8480 /*
8481 * Assign MSI-X vectors to interrupt handlers
8482 */
8483
8484 /* vector-0 is associated to slow-path handler */
8485 rc = request_irq(phba->msix_entries[0].vector,
James Smarted243d32015-05-21 13:55:25 -04008486 &lpfc_sli_sp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04008487 LPFC_SP_DRIVER_HANDLER_NAME, phba);
8488 if (rc) {
8489 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8490 "0421 MSI-X slow-path request_irq failed "
8491 "(%d)\n", rc);
8492 goto msi_fail_out;
8493 }
8494
8495 /* vector-1 is associated to fast-path handler */
8496 rc = request_irq(phba->msix_entries[1].vector,
James Smarted243d32015-05-21 13:55:25 -04008497 &lpfc_sli_fp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04008498 LPFC_FP_DRIVER_HANDLER_NAME, phba);
8499
8500 if (rc) {
8501 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8502 "0429 MSI-X fast-path request_irq failed "
8503 "(%d)\n", rc);
8504 goto irq_fail_out;
8505 }
8506
8507 /*
8508 * Configure HBA MSI-X attention conditions to messages
8509 */
8510 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8511
8512 if (!pmb) {
8513 rc = -ENOMEM;
8514 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8515 "0474 Unable to allocate memory for issuing "
8516 "MBOX_CONFIG_MSI command\n");
8517 goto mem_fail_out;
8518 }
8519 rc = lpfc_config_msi(phba, pmb);
8520 if (rc)
8521 goto mbx_fail_out;
8522 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
8523 if (rc != MBX_SUCCESS) {
8524 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
8525 "0351 Config MSI mailbox command failed, "
8526 "mbxCmd x%x, mbxStatus x%x\n",
8527 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
8528 goto mbx_fail_out;
8529 }
8530
8531 /* Free memory allocated for mailbox command */
8532 mempool_free(pmb, phba->mbox_mem_pool);
8533 return rc;
8534
8535mbx_fail_out:
8536 /* Free memory allocated for mailbox command */
8537 mempool_free(pmb, phba->mbox_mem_pool);
8538
8539mem_fail_out:
8540 /* free the irq already requested */
8541 free_irq(phba->msix_entries[1].vector, phba);
8542
8543irq_fail_out:
8544 /* free the irq already requested */
8545 free_irq(phba->msix_entries[0].vector, phba);
8546
8547msi_fail_out:
8548 /* Unconfigure MSI-X capability structure */
8549 pci_disable_msix(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02008550
8551vec_fail_out:
James Smart3772a992009-05-22 14:50:54 -04008552 return rc;
8553}
8554
8555/**
8556 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
8557 * @phba: pointer to lpfc hba data structure.
8558 *
8559 * This routine is invoked to release the MSI-X vectors and then disable the
8560 * MSI-X interrupt mode to device with SLI-3 interface spec.
8561 **/
8562static void
8563lpfc_sli_disable_msix(struct lpfc_hba *phba)
8564{
8565 int i;
8566
8567 /* Free up MSI-X multi-message vectors */
8568 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8569 free_irq(phba->msix_entries[i].vector, phba);
8570 /* Disable MSI-X */
8571 pci_disable_msix(phba->pcidev);
8572
8573 return;
8574}
8575
8576/**
8577 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
8578 * @phba: pointer to lpfc hba data structure.
8579 *
8580 * This routine is invoked to enable the MSI interrupt mode to device with
8581 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
8582 * enable the MSI vector. The device driver is responsible for calling the
8583 * request_irq() to register MSI vector with a interrupt the handler, which
8584 * is done in this function.
8585 *
8586 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008587 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008588 * other values - error
8589 */
8590static int
8591lpfc_sli_enable_msi(struct lpfc_hba *phba)
8592{
8593 int rc;
8594
8595 rc = pci_enable_msi(phba->pcidev);
8596 if (!rc)
8597 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8598 "0462 PCI enable MSI mode success.\n");
8599 else {
8600 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8601 "0471 PCI enable MSI mode failed (%d)\n", rc);
8602 return rc;
8603 }
8604
8605 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04008606 0, LPFC_DRIVER_NAME, phba);
James Smart3772a992009-05-22 14:50:54 -04008607 if (rc) {
8608 pci_disable_msi(phba->pcidev);
8609 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8610 "0478 MSI request_irq failed (%d)\n", rc);
8611 }
8612 return rc;
8613}
8614
8615/**
8616 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
8617 * @phba: pointer to lpfc hba data structure.
8618 *
8619 * This routine is invoked to disable the MSI interrupt mode to device with
8620 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
8621 * done request_irq() on before calling pci_disable_msi(). Failure to do so
8622 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
8623 * its vector.
8624 */
8625static void
8626lpfc_sli_disable_msi(struct lpfc_hba *phba)
8627{
8628 free_irq(phba->pcidev->irq, phba);
8629 pci_disable_msi(phba->pcidev);
8630 return;
8631}
8632
8633/**
8634 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
8635 * @phba: pointer to lpfc hba data structure.
8636 *
8637 * This routine is invoked to enable device interrupt and associate driver's
8638 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
8639 * spec. Depends on the interrupt mode configured to the driver, the driver
8640 * will try to fallback from the configured interrupt mode to an interrupt
8641 * mode which is supported by the platform, kernel, and device in the order
8642 * of:
8643 * MSI-X -> MSI -> IRQ.
8644 *
8645 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008646 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008647 * other values - error
8648 **/
8649static uint32_t
8650lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
8651{
8652 uint32_t intr_mode = LPFC_INTR_ERROR;
8653 int retval;
8654
8655 if (cfg_mode == 2) {
8656 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
8657 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
8658 if (!retval) {
8659 /* Now, try to enable MSI-X interrupt mode */
8660 retval = lpfc_sli_enable_msix(phba);
8661 if (!retval) {
8662 /* Indicate initialization to MSI-X mode */
8663 phba->intr_type = MSIX;
8664 intr_mode = 2;
8665 }
8666 }
8667 }
8668
8669 /* Fallback to MSI if MSI-X initialization failed */
8670 if (cfg_mode >= 1 && phba->intr_type == NONE) {
8671 retval = lpfc_sli_enable_msi(phba);
8672 if (!retval) {
8673 /* Indicate initialization to MSI mode */
8674 phba->intr_type = MSI;
8675 intr_mode = 1;
8676 }
8677 }
8678
8679 /* Fallback to INTx if both MSI-X/MSI initalization failed */
8680 if (phba->intr_type == NONE) {
8681 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
8682 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8683 if (!retval) {
8684 /* Indicate initialization to INTx mode */
8685 phba->intr_type = INTx;
8686 intr_mode = 0;
8687 }
8688 }
8689 return intr_mode;
8690}
8691
8692/**
8693 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
8694 * @phba: pointer to lpfc hba data structure.
8695 *
8696 * This routine is invoked to disable device interrupt and disassociate the
8697 * driver's interrupt handler(s) from interrupt vector(s) to device with
8698 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
8699 * release the interrupt vector(s) for the message signaled interrupt.
8700 **/
8701static void
8702lpfc_sli_disable_intr(struct lpfc_hba *phba)
8703{
8704 /* Disable the currently initialized interrupt mode */
8705 if (phba->intr_type == MSIX)
8706 lpfc_sli_disable_msix(phba);
8707 else if (phba->intr_type == MSI)
8708 lpfc_sli_disable_msi(phba);
8709 else if (phba->intr_type == INTx)
8710 free_irq(phba->pcidev->irq, phba);
8711
8712 /* Reset interrupt management states */
8713 phba->intr_type = NONE;
8714 phba->sli.slistat.sli_intr = 0;
8715
8716 return;
8717}
8718
8719/**
James Smart7bb03bb2013-04-17 20:19:16 -04008720 * lpfc_find_next_cpu - Find next available CPU that matches the phys_id
8721 * @phba: pointer to lpfc hba data structure.
8722 *
8723 * Find next available CPU to use for IRQ to CPU affinity.
8724 */
8725static int
8726lpfc_find_next_cpu(struct lpfc_hba *phba, uint32_t phys_id)
8727{
8728 struct lpfc_vector_map_info *cpup;
8729 int cpu;
8730
8731 cpup = phba->sli4_hba.cpu_map;
8732 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8733 /* CPU must be online */
8734 if (cpu_online(cpu)) {
8735 if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
8736 (lpfc_used_cpu[cpu] == LPFC_VECTOR_MAP_EMPTY) &&
8737 (cpup->phys_id == phys_id)) {
8738 return cpu;
8739 }
8740 }
8741 cpup++;
8742 }
8743
8744 /*
8745 * If we get here, we have used ALL CPUs for the specific
8746 * phys_id. Now we need to clear out lpfc_used_cpu and start
8747 * reusing CPUs.
8748 */
8749
8750 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8751 if (lpfc_used_cpu[cpu] == phys_id)
8752 lpfc_used_cpu[cpu] = LPFC_VECTOR_MAP_EMPTY;
8753 }
8754
8755 cpup = phba->sli4_hba.cpu_map;
8756 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8757 /* CPU must be online */
8758 if (cpu_online(cpu)) {
8759 if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
8760 (cpup->phys_id == phys_id)) {
8761 return cpu;
8762 }
8763 }
8764 cpup++;
8765 }
8766 return LPFC_VECTOR_MAP_EMPTY;
8767}
8768
8769/**
8770 * lpfc_sli4_set_affinity - Set affinity for HBA IRQ vectors
8771 * @phba: pointer to lpfc hba data structure.
8772 * @vectors: number of HBA vectors
8773 *
8774 * Affinitize MSIX IRQ vectors to CPUs. Try to equally spread vector
8775 * affinization across multple physical CPUs (numa nodes).
8776 * In addition, this routine will assign an IO channel for each CPU
8777 * to use when issuing I/Os.
8778 */
8779static int
8780lpfc_sli4_set_affinity(struct lpfc_hba *phba, int vectors)
8781{
8782 int i, idx, saved_chann, used_chann, cpu, phys_id;
James Smartec2087a2013-09-06 12:20:36 -04008783 int max_phys_id, min_phys_id;
8784 int num_io_channel, first_cpu, chan;
James Smart7bb03bb2013-04-17 20:19:16 -04008785 struct lpfc_vector_map_info *cpup;
8786#ifdef CONFIG_X86
8787 struct cpuinfo_x86 *cpuinfo;
8788#endif
James Smart7bb03bb2013-04-17 20:19:16 -04008789 uint8_t chann[LPFC_FCP_IO_CHAN_MAX+1];
8790
8791 /* If there is no mapping, just return */
8792 if (!phba->cfg_fcp_cpu_map)
8793 return 1;
8794
8795 /* Init cpu_map array */
8796 memset(phba->sli4_hba.cpu_map, 0xff,
8797 (sizeof(struct lpfc_vector_map_info) *
8798 phba->sli4_hba.num_present_cpu));
8799
8800 max_phys_id = 0;
James Smartec2087a2013-09-06 12:20:36 -04008801 min_phys_id = 0xff;
James Smart7bb03bb2013-04-17 20:19:16 -04008802 phys_id = 0;
8803 num_io_channel = 0;
8804 first_cpu = LPFC_VECTOR_MAP_EMPTY;
8805
8806 /* Update CPU map with physical id and core id of each CPU */
8807 cpup = phba->sli4_hba.cpu_map;
8808 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8809#ifdef CONFIG_X86
8810 cpuinfo = &cpu_data(cpu);
8811 cpup->phys_id = cpuinfo->phys_proc_id;
8812 cpup->core_id = cpuinfo->cpu_core_id;
8813#else
8814 /* No distinction between CPUs for other platforms */
8815 cpup->phys_id = 0;
8816 cpup->core_id = 0;
8817#endif
8818
8819 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8820 "3328 CPU physid %d coreid %d\n",
8821 cpup->phys_id, cpup->core_id);
8822
8823 if (cpup->phys_id > max_phys_id)
8824 max_phys_id = cpup->phys_id;
James Smartec2087a2013-09-06 12:20:36 -04008825 if (cpup->phys_id < min_phys_id)
8826 min_phys_id = cpup->phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008827 cpup++;
8828 }
8829
James Smartec2087a2013-09-06 12:20:36 -04008830 phys_id = min_phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008831 /* Now associate the HBA vectors with specific CPUs */
8832 for (idx = 0; idx < vectors; idx++) {
8833 cpup = phba->sli4_hba.cpu_map;
8834 cpu = lpfc_find_next_cpu(phba, phys_id);
8835 if (cpu == LPFC_VECTOR_MAP_EMPTY) {
8836
8837 /* Try for all phys_id's */
8838 for (i = 1; i < max_phys_id; i++) {
8839 phys_id++;
8840 if (phys_id > max_phys_id)
James Smartec2087a2013-09-06 12:20:36 -04008841 phys_id = min_phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008842 cpu = lpfc_find_next_cpu(phba, phys_id);
8843 if (cpu == LPFC_VECTOR_MAP_EMPTY)
8844 continue;
8845 goto found;
8846 }
8847
James Smartec2087a2013-09-06 12:20:36 -04008848 /* Use round robin for scheduling */
8849 phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_ROUND_ROBIN;
8850 chan = 0;
8851 cpup = phba->sli4_hba.cpu_map;
8852 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
8853 cpup->channel_id = chan;
8854 cpup++;
8855 chan++;
8856 if (chan >= phba->cfg_fcp_io_channel)
8857 chan = 0;
8858 }
8859
James Smart7bb03bb2013-04-17 20:19:16 -04008860 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8861 "3329 Cannot set affinity:"
8862 "Error mapping vector %d (%d)\n",
8863 idx, vectors);
8864 return 0;
8865 }
8866found:
8867 cpup += cpu;
8868 if (phba->cfg_fcp_cpu_map == LPFC_DRIVER_CPU_MAP)
8869 lpfc_used_cpu[cpu] = phys_id;
8870
8871 /* Associate vector with selected CPU */
8872 cpup->irq = phba->sli4_hba.msix_entries[idx].vector;
8873
8874 /* Associate IO channel with selected CPU */
8875 cpup->channel_id = idx;
8876 num_io_channel++;
8877
8878 if (first_cpu == LPFC_VECTOR_MAP_EMPTY)
8879 first_cpu = cpu;
8880
8881 /* Now affinitize to the selected CPU */
James Smart7bb03bb2013-04-17 20:19:16 -04008882 i = irq_set_affinity_hint(phba->sli4_hba.msix_entries[idx].
Ian Mitchellc0365c02015-08-31 16:48:12 -04008883 vector, get_cpu_mask(cpu));
James Smart7bb03bb2013-04-17 20:19:16 -04008884
8885 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8886 "3330 Set Affinity: CPU %d channel %d "
8887 "irq %d (%x)\n",
8888 cpu, cpup->channel_id,
8889 phba->sli4_hba.msix_entries[idx].vector, i);
8890
8891 /* Spread vector mapping across multple physical CPU nodes */
8892 phys_id++;
8893 if (phys_id > max_phys_id)
James Smartec2087a2013-09-06 12:20:36 -04008894 phys_id = min_phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008895 }
8896
8897 /*
8898 * Finally fill in the IO channel for any remaining CPUs.
8899 * At this point, all IO channels have been assigned to a specific
8900 * MSIx vector, mapped to a specific CPU.
8901 * Base the remaining IO channel assigned, to IO channels already
8902 * assigned to other CPUs on the same phys_id.
8903 */
James Smartec2087a2013-09-06 12:20:36 -04008904 for (i = min_phys_id; i <= max_phys_id; i++) {
James Smart7bb03bb2013-04-17 20:19:16 -04008905 /*
8906 * If there are no io channels already mapped to
8907 * this phys_id, just round robin thru the io_channels.
8908 * Setup chann[] for round robin.
8909 */
8910 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
8911 chann[idx] = idx;
8912
8913 saved_chann = 0;
8914 used_chann = 0;
8915
8916 /*
8917 * First build a list of IO channels already assigned
8918 * to this phys_id before reassigning the same IO
8919 * channels to the remaining CPUs.
8920 */
8921 cpup = phba->sli4_hba.cpu_map;
8922 cpu = first_cpu;
8923 cpup += cpu;
8924 for (idx = 0; idx < phba->sli4_hba.num_present_cpu;
8925 idx++) {
8926 if (cpup->phys_id == i) {
8927 /*
8928 * Save any IO channels that are
8929 * already mapped to this phys_id.
8930 */
8931 if (cpup->irq != LPFC_VECTOR_MAP_EMPTY) {
James Smart6690e0d2015-12-16 18:11:56 -05008932 if (saved_chann <=
8933 LPFC_FCP_IO_CHAN_MAX) {
8934 chann[saved_chann] =
8935 cpup->channel_id;
8936 saved_chann++;
8937 }
James Smart7bb03bb2013-04-17 20:19:16 -04008938 goto out;
8939 }
8940
8941 /* See if we are using round-robin */
8942 if (saved_chann == 0)
8943 saved_chann =
8944 phba->cfg_fcp_io_channel;
8945
8946 /* Associate next IO channel with CPU */
8947 cpup->channel_id = chann[used_chann];
8948 num_io_channel++;
8949 used_chann++;
8950 if (used_chann == saved_chann)
8951 used_chann = 0;
8952
8953 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8954 "3331 Set IO_CHANN "
8955 "CPU %d channel %d\n",
8956 idx, cpup->channel_id);
8957 }
8958out:
8959 cpu++;
8960 if (cpu >= phba->sli4_hba.num_present_cpu) {
8961 cpup = phba->sli4_hba.cpu_map;
8962 cpu = 0;
8963 } else {
8964 cpup++;
8965 }
8966 }
8967 }
8968
8969 if (phba->sli4_hba.num_online_cpu != phba->sli4_hba.num_present_cpu) {
8970 cpup = phba->sli4_hba.cpu_map;
8971 for (idx = 0; idx < phba->sli4_hba.num_present_cpu; idx++) {
8972 if (cpup->channel_id == LPFC_VECTOR_MAP_EMPTY) {
8973 cpup->channel_id = 0;
8974 num_io_channel++;
8975
8976 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8977 "3332 Assign IO_CHANN "
8978 "CPU %d channel %d\n",
8979 idx, cpup->channel_id);
8980 }
8981 cpup++;
8982 }
8983 }
8984
8985 /* Sanity check */
8986 if (num_io_channel != phba->sli4_hba.num_present_cpu)
8987 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8988 "3333 Set affinity mismatch:"
James Smartec2087a2013-09-06 12:20:36 -04008989 "%d chann != %d cpus: %d vectors\n",
James Smart7bb03bb2013-04-17 20:19:16 -04008990 num_io_channel, phba->sli4_hba.num_present_cpu,
8991 vectors);
8992
James Smartec2087a2013-09-06 12:20:36 -04008993 /* Enable using cpu affinity for scheduling */
James Smart7bb03bb2013-04-17 20:19:16 -04008994 phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_BY_CPU;
8995 return 1;
8996}
8997
8998
8999/**
James Smartda0436e2009-05-22 14:51:39 -04009000 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
9001 * @phba: pointer to lpfc hba data structure.
9002 *
9003 * This routine is invoked to enable the MSI-X interrupt vectors to device
Alexander Gordeev4f871e12014-09-03 12:56:29 -04009004 * with SLI-4 interface spec. The kernel function pci_enable_msix_range()
9005 * is called to enable the MSI-X vectors. The device driver is responsible
9006 * for calling the individual request_irq() to register each MSI-X vector
9007 * with a interrupt handler, which is done in this function. Note that
9008 * later when device is unloading, the driver should always call free_irq()
9009 * on all MSI-X vectors it has done request_irq() on before calling
9010 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
9011 * will be left with MSI-X enabled and leaks its vectors.
James Smartda0436e2009-05-22 14:51:39 -04009012 *
9013 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009014 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009015 * other values - error
9016 **/
9017static int
9018lpfc_sli4_enable_msix(struct lpfc_hba *phba)
9019{
James Smart75baf692010-06-08 18:31:21 -04009020 int vectors, rc, index;
James Smartda0436e2009-05-22 14:51:39 -04009021
9022 /* Set up MSI-X multi-message vectors */
James Smart82c3e9b2012-09-29 11:29:50 -04009023 for (index = 0; index < phba->cfg_fcp_io_channel; index++)
James Smartda0436e2009-05-22 14:51:39 -04009024 phba->sli4_hba.msix_entries[index].entry = index;
9025
9026 /* Configure MSI-X capability structure */
James Smart82c3e9b2012-09-29 11:29:50 -04009027 vectors = phba->cfg_fcp_io_channel;
James Smart1ba981f2014-02-20 09:56:45 -05009028 if (phba->cfg_fof) {
9029 phba->sli4_hba.msix_entries[index].entry = index;
9030 vectors++;
9031 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -04009032 rc = pci_enable_msix_range(phba->pcidev, phba->sli4_hba.msix_entries,
9033 2, vectors);
9034 if (rc < 0) {
James Smartda0436e2009-05-22 14:51:39 -04009035 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9036 "0484 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009037 goto vec_fail_out;
James Smartda0436e2009-05-22 14:51:39 -04009038 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -04009039 vectors = rc;
James Smart75baf692010-06-08 18:31:21 -04009040
James Smartda0436e2009-05-22 14:51:39 -04009041 /* Log MSI-X vector assignment */
James Smart75baf692010-06-08 18:31:21 -04009042 for (index = 0; index < vectors; index++)
James Smartda0436e2009-05-22 14:51:39 -04009043 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9044 "0489 MSI-X entry[%d]: vector=x%x "
9045 "message=%d\n", index,
9046 phba->sli4_hba.msix_entries[index].vector,
9047 phba->sli4_hba.msix_entries[index].entry);
James Smart67d12732012-08-03 12:36:13 -04009048
James Smart7bb03bb2013-04-17 20:19:16 -04009049 /* Assign MSI-X vectors to interrupt handlers */
James Smart67d12732012-08-03 12:36:13 -04009050 for (index = 0; index < vectors; index++) {
James Smart4305f182012-08-03 12:36:33 -04009051 memset(&phba->sli4_hba.handler_name[index], 0, 16);
James Smarta2fc4aef2014-09-03 12:57:55 -04009052 snprintf((char *)&phba->sli4_hba.handler_name[index],
9053 LPFC_SLI4_HANDLER_NAME_SZ,
James Smart4305f182012-08-03 12:36:33 -04009054 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -04009055
James Smart67d12732012-08-03 12:36:13 -04009056 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9057 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
James Smartba20c852012-08-03 12:36:52 -04009058 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].fcp_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -05009059 if (phba->cfg_fof && (index == (vectors - 1)))
9060 rc = request_irq(
9061 phba->sli4_hba.msix_entries[index].vector,
James Smarted243d32015-05-21 13:55:25 -04009062 &lpfc_sli4_fof_intr_handler, 0,
James Smart1ba981f2014-02-20 09:56:45 -05009063 (char *)&phba->sli4_hba.handler_name[index],
9064 &phba->sli4_hba.fcp_eq_hdl[index]);
9065 else
9066 rc = request_irq(
9067 phba->sli4_hba.msix_entries[index].vector,
James Smarted243d32015-05-21 13:55:25 -04009068 &lpfc_sli4_hba_intr_handler, 0,
James Smart4305f182012-08-03 12:36:33 -04009069 (char *)&phba->sli4_hba.handler_name[index],
James Smart67d12732012-08-03 12:36:13 -04009070 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -04009071 if (rc) {
9072 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9073 "0486 MSI-X fast-path (%d) "
9074 "request_irq failed (%d)\n", index, rc);
9075 goto cfg_fail_out;
9076 }
9077 }
9078
James Smart1ba981f2014-02-20 09:56:45 -05009079 if (phba->cfg_fof)
9080 vectors--;
9081
James Smart82c3e9b2012-09-29 11:29:50 -04009082 if (vectors != phba->cfg_fcp_io_channel) {
9083 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9084 "3238 Reducing IO channels to match number of "
9085 "MSI-X vectors, requested %d got %d\n",
9086 phba->cfg_fcp_io_channel, vectors);
9087 phba->cfg_fcp_io_channel = vectors;
9088 }
James Smart7bb03bb2013-04-17 20:19:16 -04009089
James Smart8b0dff12015-05-22 10:42:38 -04009090 if (!shost_use_blk_mq(lpfc_shost_from_vport(phba->pport)))
9091 lpfc_sli4_set_affinity(phba, vectors);
James Smartda0436e2009-05-22 14:51:39 -04009092 return rc;
9093
9094cfg_fail_out:
9095 /* free the irq already requested */
James Smartacbd8612013-09-06 12:21:19 -04009096 for (--index; index >= 0; index--) {
9097 irq_set_affinity_hint(phba->sli4_hba.msix_entries[index].
9098 vector, NULL);
James Smart67d12732012-08-03 12:36:13 -04009099 free_irq(phba->sli4_hba.msix_entries[index].vector,
9100 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartacbd8612013-09-06 12:21:19 -04009101 }
James Smartda0436e2009-05-22 14:51:39 -04009102
James Smartda0436e2009-05-22 14:51:39 -04009103 /* Unconfigure MSI-X capability structure */
9104 pci_disable_msix(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009105
9106vec_fail_out:
James Smartda0436e2009-05-22 14:51:39 -04009107 return rc;
9108}
9109
9110/**
9111 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
9112 * @phba: pointer to lpfc hba data structure.
9113 *
9114 * This routine is invoked to release the MSI-X vectors and then disable the
9115 * MSI-X interrupt mode to device with SLI-4 interface spec.
9116 **/
9117static void
9118lpfc_sli4_disable_msix(struct lpfc_hba *phba)
9119{
9120 int index;
9121
9122 /* Free up MSI-X multi-message vectors */
James Smartacbd8612013-09-06 12:21:19 -04009123 for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
9124 irq_set_affinity_hint(phba->sli4_hba.msix_entries[index].
9125 vector, NULL);
James Smartda0436e2009-05-22 14:51:39 -04009126 free_irq(phba->sli4_hba.msix_entries[index].vector,
James Smart67d12732012-08-03 12:36:13 -04009127 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartacbd8612013-09-06 12:21:19 -04009128 }
James Smart1ba981f2014-02-20 09:56:45 -05009129 if (phba->cfg_fof) {
9130 free_irq(phba->sli4_hba.msix_entries[index].vector,
9131 &phba->sli4_hba.fcp_eq_hdl[index]);
9132 }
James Smartda0436e2009-05-22 14:51:39 -04009133 /* Disable MSI-X */
9134 pci_disable_msix(phba->pcidev);
9135
9136 return;
9137}
9138
9139/**
9140 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
9141 * @phba: pointer to lpfc hba data structure.
9142 *
9143 * This routine is invoked to enable the MSI interrupt mode to device with
9144 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
9145 * to enable the MSI vector. The device driver is responsible for calling
9146 * the request_irq() to register MSI vector with a interrupt the handler,
9147 * which is done in this function.
9148 *
9149 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009150 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009151 * other values - error
9152 **/
9153static int
9154lpfc_sli4_enable_msi(struct lpfc_hba *phba)
9155{
9156 int rc, index;
9157
9158 rc = pci_enable_msi(phba->pcidev);
9159 if (!rc)
9160 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9161 "0487 PCI enable MSI mode success.\n");
9162 else {
9163 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9164 "0488 PCI enable MSI mode failed (%d)\n", rc);
9165 return rc;
9166 }
9167
9168 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04009169 0, LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -04009170 if (rc) {
9171 pci_disable_msi(phba->pcidev);
9172 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9173 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -04009174 return rc;
James Smartda0436e2009-05-22 14:51:39 -04009175 }
9176
James Smart67d12732012-08-03 12:36:13 -04009177 for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
James Smartda0436e2009-05-22 14:51:39 -04009178 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9179 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9180 }
9181
James Smart1ba981f2014-02-20 09:56:45 -05009182 if (phba->cfg_fof) {
9183 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9184 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9185 }
James Smart75baf692010-06-08 18:31:21 -04009186 return 0;
James Smartda0436e2009-05-22 14:51:39 -04009187}
9188
9189/**
9190 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
9191 * @phba: pointer to lpfc hba data structure.
9192 *
9193 * This routine is invoked to disable the MSI interrupt mode to device with
9194 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
9195 * done request_irq() on before calling pci_disable_msi(). Failure to do so
9196 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
9197 * its vector.
9198 **/
9199static void
9200lpfc_sli4_disable_msi(struct lpfc_hba *phba)
9201{
9202 free_irq(phba->pcidev->irq, phba);
9203 pci_disable_msi(phba->pcidev);
9204 return;
9205}
9206
9207/**
9208 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
9209 * @phba: pointer to lpfc hba data structure.
9210 *
9211 * This routine is invoked to enable device interrupt and associate driver's
9212 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
9213 * interface spec. Depends on the interrupt mode configured to the driver,
9214 * the driver will try to fallback from the configured interrupt mode to an
9215 * interrupt mode which is supported by the platform, kernel, and device in
9216 * the order of:
9217 * MSI-X -> MSI -> IRQ.
9218 *
9219 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009220 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009221 * other values - error
9222 **/
9223static uint32_t
9224lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9225{
9226 uint32_t intr_mode = LPFC_INTR_ERROR;
9227 int retval, index;
9228
9229 if (cfg_mode == 2) {
9230 /* Preparation before conf_msi mbox cmd */
9231 retval = 0;
9232 if (!retval) {
9233 /* Now, try to enable MSI-X interrupt mode */
9234 retval = lpfc_sli4_enable_msix(phba);
9235 if (!retval) {
9236 /* Indicate initialization to MSI-X mode */
9237 phba->intr_type = MSIX;
9238 intr_mode = 2;
9239 }
9240 }
9241 }
9242
9243 /* Fallback to MSI if MSI-X initialization failed */
9244 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9245 retval = lpfc_sli4_enable_msi(phba);
9246 if (!retval) {
9247 /* Indicate initialization to MSI mode */
9248 phba->intr_type = MSI;
9249 intr_mode = 1;
9250 }
9251 }
9252
9253 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9254 if (phba->intr_type == NONE) {
9255 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
9256 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9257 if (!retval) {
9258 /* Indicate initialization to INTx mode */
9259 phba->intr_type = INTx;
9260 intr_mode = 0;
James Smart67d12732012-08-03 12:36:13 -04009261 for (index = 0; index < phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04009262 index++) {
9263 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9264 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
James Smartba20c852012-08-03 12:36:52 -04009265 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
9266 fcp_eq_in_use, 1);
James Smartda0436e2009-05-22 14:51:39 -04009267 }
James Smart1ba981f2014-02-20 09:56:45 -05009268 if (phba->cfg_fof) {
9269 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9270 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9271 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
9272 fcp_eq_in_use, 1);
9273 }
James Smartda0436e2009-05-22 14:51:39 -04009274 }
9275 }
9276 return intr_mode;
9277}
9278
9279/**
9280 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
9281 * @phba: pointer to lpfc hba data structure.
9282 *
9283 * This routine is invoked to disable device interrupt and disassociate
9284 * the driver's interrupt handler(s) from interrupt vector(s) to device
9285 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
9286 * will release the interrupt vector(s) for the message signaled interrupt.
9287 **/
9288static void
9289lpfc_sli4_disable_intr(struct lpfc_hba *phba)
9290{
9291 /* Disable the currently initialized interrupt mode */
9292 if (phba->intr_type == MSIX)
9293 lpfc_sli4_disable_msix(phba);
9294 else if (phba->intr_type == MSI)
9295 lpfc_sli4_disable_msi(phba);
9296 else if (phba->intr_type == INTx)
9297 free_irq(phba->pcidev->irq, phba);
9298
9299 /* Reset interrupt management states */
9300 phba->intr_type = NONE;
9301 phba->sli.slistat.sli_intr = 0;
9302
9303 return;
9304}
9305
9306/**
James Smart3772a992009-05-22 14:50:54 -04009307 * lpfc_unset_hba - Unset SLI3 hba device initialization
9308 * @phba: pointer to lpfc hba data structure.
9309 *
9310 * This routine is invoked to unset the HBA device initialization steps to
9311 * a device with SLI-3 interface spec.
9312 **/
9313static void
9314lpfc_unset_hba(struct lpfc_hba *phba)
9315{
9316 struct lpfc_vport *vport = phba->pport;
9317 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9318
9319 spin_lock_irq(shost->host_lock);
9320 vport->load_flag |= FC_UNLOADING;
9321 spin_unlock_irq(shost->host_lock);
9322
James Smart72859902012-01-18 16:25:38 -05009323 kfree(phba->vpi_bmask);
9324 kfree(phba->vpi_ids);
9325
James Smart3772a992009-05-22 14:50:54 -04009326 lpfc_stop_hba_timers(phba);
9327
9328 phba->pport->work_port_events = 0;
9329
9330 lpfc_sli_hba_down(phba);
9331
9332 lpfc_sli_brdrestart(phba);
9333
9334 lpfc_sli_disable_intr(phba);
9335
9336 return;
9337}
9338
9339/**
James Smart5af5eee2010-10-22 11:06:38 -04009340 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
9341 * @phba: Pointer to HBA context object.
9342 *
9343 * This function is called in the SLI4 code path to wait for completion
9344 * of device's XRIs exchange busy. It will check the XRI exchange busy
9345 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
9346 * that, it will check the XRI exchange busy on outstanding FCP and ELS
9347 * I/Os every 30 seconds, log error message, and wait forever. Only when
9348 * all XRI exchange busy complete, the driver unload shall proceed with
9349 * invoking the function reset ioctl mailbox command to the CNA and the
9350 * the rest of the driver unload resource release.
9351 **/
9352static void
9353lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
9354{
9355 int wait_time = 0;
9356 int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
9357 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9358
9359 while (!fcp_xri_cmpl || !els_xri_cmpl) {
9360 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
9361 if (!fcp_xri_cmpl)
9362 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9363 "2877 FCP XRI exchange busy "
9364 "wait time: %d seconds.\n",
9365 wait_time/1000);
9366 if (!els_xri_cmpl)
9367 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9368 "2878 ELS XRI exchange busy "
9369 "wait time: %d seconds.\n",
9370 wait_time/1000);
9371 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
9372 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
9373 } else {
9374 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
9375 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
9376 }
9377 fcp_xri_cmpl =
9378 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
9379 els_xri_cmpl =
9380 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9381 }
9382}
9383
9384/**
James Smartda0436e2009-05-22 14:51:39 -04009385 * lpfc_sli4_hba_unset - Unset the fcoe hba
9386 * @phba: Pointer to HBA context object.
9387 *
9388 * This function is called in the SLI4 code path to reset the HBA's FCoE
9389 * function. The caller is not required to hold any lock. This routine
9390 * issues PCI function reset mailbox command to reset the FCoE function.
9391 * At the end of the function, it calls lpfc_hba_down_post function to
9392 * free any pending commands.
9393 **/
9394static void
9395lpfc_sli4_hba_unset(struct lpfc_hba *phba)
9396{
9397 int wait_cnt = 0;
9398 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -04009399 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -04009400
9401 lpfc_stop_hba_timers(phba);
9402 phba->sli4_hba.intr_enable = 0;
9403
9404 /*
9405 * Gracefully wait out the potential current outstanding asynchronous
9406 * mailbox command.
9407 */
9408
9409 /* First, block any pending async mailbox command from posted */
9410 spin_lock_irq(&phba->hbalock);
9411 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
9412 spin_unlock_irq(&phba->hbalock);
9413 /* Now, trying to wait it out if we can */
9414 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9415 msleep(10);
9416 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
9417 break;
9418 }
9419 /* Forcefully release the outstanding mailbox command if timed out */
9420 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9421 spin_lock_irq(&phba->hbalock);
9422 mboxq = phba->sli.mbox_active;
9423 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
9424 __lpfc_mbox_cmpl_put(phba, mboxq);
9425 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9426 phba->sli.mbox_active = NULL;
9427 spin_unlock_irq(&phba->hbalock);
9428 }
9429
James Smart5af5eee2010-10-22 11:06:38 -04009430 /* Abort all iocbs associated with the hba */
9431 lpfc_sli_hba_iocb_abort(phba);
9432
9433 /* Wait for completion of device XRI exchange busy */
9434 lpfc_sli4_xri_exchange_busy_wait(phba);
9435
James Smartda0436e2009-05-22 14:51:39 -04009436 /* Disable PCI subsystem interrupt */
9437 lpfc_sli4_disable_intr(phba);
9438
James Smart912e3ac2011-05-24 11:42:11 -04009439 /* Disable SR-IOV if enabled */
9440 if (phba->cfg_sriov_nr_virtfn)
9441 pci_disable_sriov(pdev);
9442
James Smartda0436e2009-05-22 14:51:39 -04009443 /* Stop kthread signal shall trigger work_done one more time */
9444 kthread_stop(phba->worker_thread);
9445
James Smart3677a3a2010-09-29 11:19:14 -04009446 /* Reset SLI4 HBA FCoE function */
9447 lpfc_pci_function_reset(phba);
James Smart5350d872011-10-10 21:33:49 -04009448 lpfc_sli4_queue_destroy(phba);
James Smart3677a3a2010-09-29 11:19:14 -04009449
James Smartda0436e2009-05-22 14:51:39 -04009450 /* Stop the SLI4 device port */
9451 phba->pport->work_port_events = 0;
9452}
9453
James Smart28baac72010-02-12 14:42:03 -05009454 /**
9455 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
9456 * @phba: Pointer to HBA context object.
9457 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9458 *
9459 * This function is called in the SLI4 code path to read the port's
9460 * sli4 capabilities.
9461 *
9462 * This function may be be called from any context that can block-wait
9463 * for the completion. The expectation is that this routine is called
9464 * typically from probe_one or from the online routine.
9465 **/
9466int
9467lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9468{
9469 int rc;
9470 struct lpfc_mqe *mqe;
9471 struct lpfc_pc_sli4_params *sli4_params;
9472 uint32_t mbox_tmo;
9473
9474 rc = 0;
9475 mqe = &mboxq->u.mqe;
9476
9477 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -05009478 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -05009479 if (!phba->sli4_hba.intr_enable)
9480 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9481 else {
James Smarta183a152011-10-10 21:32:43 -04009482 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -05009483 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
9484 }
9485
9486 if (unlikely(rc))
9487 return 1;
9488
9489 sli4_params = &phba->sli4_hba.pc_sli4_params;
9490 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
9491 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
9492 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
9493 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
9494 &mqe->un.sli4_params);
9495 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
9496 &mqe->un.sli4_params);
9497 sli4_params->proto_types = mqe->un.sli4_params.word3;
9498 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
9499 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
9500 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
9501 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
9502 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
9503 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
9504 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
9505 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
9506 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
9507 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
9508 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
9509 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
9510 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
9511 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
9512 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
9513 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
9514 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
9515 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
9516 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
9517 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -04009518
9519 /* Make sure that sge_supp_len can be handled by the driver */
9520 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
9521 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
9522
James Smart28baac72010-02-12 14:42:03 -05009523 return rc;
9524}
9525
James Smartda0436e2009-05-22 14:51:39 -04009526/**
James Smartfedd3b72011-02-16 12:39:24 -05009527 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
9528 * @phba: Pointer to HBA context object.
9529 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9530 *
9531 * This function is called in the SLI4 code path to read the port's
9532 * sli4 capabilities.
9533 *
9534 * This function may be be called from any context that can block-wait
9535 * for the completion. The expectation is that this routine is called
9536 * typically from probe_one or from the online routine.
9537 **/
9538int
9539lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9540{
9541 int rc;
9542 struct lpfc_mqe *mqe = &mboxq->u.mqe;
9543 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -04009544 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -05009545 int length;
9546 struct lpfc_sli4_parameters *mbx_sli4_parameters;
9547
James Smart6d368e52011-05-24 11:44:12 -04009548 /*
9549 * By default, the driver assumes the SLI4 port requires RPI
9550 * header postings. The SLI4_PARAM response will correct this
9551 * assumption.
9552 */
9553 phba->sli4_hba.rpi_hdrs_in_use = 1;
9554
James Smartfedd3b72011-02-16 12:39:24 -05009555 /* Read the port's SLI4 Config Parameters */
9556 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
9557 sizeof(struct lpfc_sli4_cfg_mhdr));
9558 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9559 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
9560 length, LPFC_SLI4_MBX_EMBED);
9561 if (!phba->sli4_hba.intr_enable)
9562 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -04009563 else {
9564 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
9565 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
9566 }
James Smartfedd3b72011-02-16 12:39:24 -05009567 if (unlikely(rc))
9568 return rc;
9569 sli4_params = &phba->sli4_hba.pc_sli4_params;
9570 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
9571 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
9572 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
9573 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
9574 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
9575 mbx_sli4_parameters);
9576 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
9577 mbx_sli4_parameters);
9578 if (bf_get(cfg_phwq, mbx_sli4_parameters))
9579 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
9580 else
9581 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
9582 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
9583 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
James Smart1ba981f2014-02-20 09:56:45 -05009584 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -05009585 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
9586 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
9587 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
9588 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
James Smart0c651872013-07-15 18:33:23 -04009589 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -05009590 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
9591 mbx_sli4_parameters);
9592 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
9593 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -04009594 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
9595 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart05580562011-05-24 11:40:48 -04009596
9597 /* Make sure that sge_supp_len can be handled by the driver */
9598 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
9599 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
9600
James Smartb5c53952016-03-31 14:12:30 -07009601 /*
9602 * Issue IOs with CDB embedded in WQE to minimized the number
9603 * of DMAs the firmware has to do. Setting this to 1 also forces
9604 * the driver to use 128 bytes WQEs for FCP IOs.
9605 */
9606 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
9607 phba->fcp_embed_io = 1;
9608 else
9609 phba->fcp_embed_io = 0;
James Smart7bdedb32016-07-06 12:36:00 -07009610
9611 /*
9612 * Check if the SLI port supports MDS Diagnostics
9613 */
9614 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
9615 phba->mds_diags_support = 1;
9616 else
9617 phba->mds_diags_support = 0;
James Smartfedd3b72011-02-16 12:39:24 -05009618 return 0;
9619}
9620
9621/**
James Smart3772a992009-05-22 14:50:54 -04009622 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
9623 * @pdev: pointer to PCI device
9624 * @pid: pointer to PCI device identifier
9625 *
9626 * This routine is to be called to attach a device with SLI-3 interface spec
9627 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9628 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
9629 * information of the device and driver to see if the driver state that it can
9630 * support this kind of device. If the match is successful, the driver core
9631 * invokes this routine. If this routine determines it can claim the HBA, it
9632 * does all the initialization that it needs to do to handle the HBA properly.
9633 *
9634 * Return code
9635 * 0 - driver can claim the device
9636 * negative value - driver can not claim the device
9637 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009638static int
James Smart3772a992009-05-22 14:50:54 -04009639lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
9640{
9641 struct lpfc_hba *phba;
9642 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -04009643 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -04009644 int error;
9645 uint32_t cfg_mode, intr_mode;
9646
9647 /* Allocate memory for HBA structure */
9648 phba = lpfc_hba_alloc(pdev);
9649 if (!phba)
9650 return -ENOMEM;
9651
9652 /* Perform generic PCI device enabling operation */
9653 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -04009654 if (error)
James Smart3772a992009-05-22 14:50:54 -04009655 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -04009656
9657 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
9658 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
9659 if (error)
9660 goto out_disable_pci_dev;
9661
9662 /* Set up SLI-3 specific device PCI memory space */
9663 error = lpfc_sli_pci_mem_setup(phba);
9664 if (error) {
9665 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9666 "1402 Failed to set up pci memory space.\n");
9667 goto out_disable_pci_dev;
9668 }
9669
9670 /* Set up phase-1 common device driver resources */
9671 error = lpfc_setup_driver_resource_phase1(phba);
9672 if (error) {
9673 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9674 "1403 Failed to set up driver resource.\n");
9675 goto out_unset_pci_mem_s3;
9676 }
9677
9678 /* Set up SLI-3 specific device driver resources */
9679 error = lpfc_sli_driver_resource_setup(phba);
9680 if (error) {
9681 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9682 "1404 Failed to set up driver resource.\n");
9683 goto out_unset_pci_mem_s3;
9684 }
9685
9686 /* Initialize and populate the iocb list per host */
9687 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
9688 if (error) {
9689 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9690 "1405 Failed to initialize iocb list.\n");
9691 goto out_unset_driver_resource_s3;
9692 }
9693
9694 /* Set up common device driver resources */
9695 error = lpfc_setup_driver_resource_phase2(phba);
9696 if (error) {
9697 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9698 "1406 Failed to set up driver resource.\n");
9699 goto out_free_iocb_list;
9700 }
9701
James Smart079b5c92011-08-21 21:48:49 -04009702 /* Get the default values for Model Name and Description */
9703 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
9704
James Smart3772a992009-05-22 14:50:54 -04009705 /* Create SCSI host to the physical port */
9706 error = lpfc_create_shost(phba);
9707 if (error) {
9708 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9709 "1407 Failed to create scsi host.\n");
9710 goto out_unset_driver_resource;
9711 }
9712
9713 /* Configure sysfs attributes */
9714 vport = phba->pport;
9715 error = lpfc_alloc_sysfs_attr(vport);
9716 if (error) {
9717 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9718 "1476 Failed to allocate sysfs attr\n");
9719 goto out_destroy_shost;
9720 }
9721
James Smart6669f9b2009-10-02 15:16:45 -04009722 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -04009723 /* Now, trying to enable interrupt and bring up the device */
9724 cfg_mode = phba->cfg_use_msi;
9725 while (true) {
9726 /* Put device to a known state before enabling interrupt */
9727 lpfc_stop_port(phba);
9728 /* Configure and enable interrupt */
9729 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
9730 if (intr_mode == LPFC_INTR_ERROR) {
9731 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9732 "0431 Failed to enable interrupt.\n");
9733 error = -ENODEV;
9734 goto out_free_sysfs_attr;
9735 }
9736 /* SLI-3 HBA setup */
9737 if (lpfc_sli_hba_setup(phba)) {
9738 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9739 "1477 Failed to set up hba\n");
9740 error = -ENODEV;
9741 goto out_remove_device;
9742 }
9743
9744 /* Wait 50ms for the interrupts of previous mailbox commands */
9745 msleep(50);
9746 /* Check active interrupts on message signaled interrupts */
9747 if (intr_mode == 0 ||
9748 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
9749 /* Log the current active interrupt mode */
9750 phba->intr_mode = intr_mode;
9751 lpfc_log_intr_mode(phba, intr_mode);
9752 break;
9753 } else {
9754 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9755 "0447 Configure interrupt mode (%d) "
9756 "failed active interrupt test.\n",
9757 intr_mode);
9758 /* Disable the current interrupt mode */
9759 lpfc_sli_disable_intr(phba);
9760 /* Try next level of interrupt mode */
9761 cfg_mode = --intr_mode;
9762 }
9763 }
9764
9765 /* Perform post initialization setup */
9766 lpfc_post_init_setup(phba);
9767
9768 /* Check if there are static vports to be created. */
9769 lpfc_create_static_vport(phba);
9770
9771 return 0;
9772
9773out_remove_device:
9774 lpfc_unset_hba(phba);
9775out_free_sysfs_attr:
9776 lpfc_free_sysfs_attr(vport);
9777out_destroy_shost:
9778 lpfc_destroy_shost(phba);
9779out_unset_driver_resource:
9780 lpfc_unset_driver_resource_phase2(phba);
9781out_free_iocb_list:
9782 lpfc_free_iocb_list(phba);
9783out_unset_driver_resource_s3:
9784 lpfc_sli_driver_resource_unset(phba);
9785out_unset_pci_mem_s3:
9786 lpfc_sli_pci_mem_unset(phba);
9787out_disable_pci_dev:
9788 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -04009789 if (shost)
9790 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -04009791out_free_phba:
9792 lpfc_hba_free(phba);
9793 return error;
9794}
9795
9796/**
9797 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -04009798 * @pdev: pointer to PCI device
9799 *
James Smart3772a992009-05-22 14:50:54 -04009800 * This routine is to be called to disattach a device with SLI-3 interface
9801 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9802 * removed from PCI bus, it performs all the necessary cleanup for the HBA
9803 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -04009804 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009805static void
James Smart3772a992009-05-22 14:50:54 -04009806lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -05009807{
James Smart2e0fef82007-06-17 19:56:36 -05009808 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9809 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -05009810 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -05009811 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -05009812 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05009813 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
9814
James Smart549e55c2007-08-02 11:09:51 -04009815 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04009816 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04009817 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05009818
James Smart858c9f62007-06-17 19:56:39 -05009819 lpfc_free_sysfs_attr(vport);
9820
James Smarteada2722008-12-04 22:39:13 -05009821 /* Release all the vports against this physical port */
9822 vports = lpfc_create_vport_work_array(phba);
9823 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -04009824 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9825 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
9826 continue;
James Smarteada2722008-12-04 22:39:13 -05009827 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -04009828 }
James Smarteada2722008-12-04 22:39:13 -05009829 lpfc_destroy_vport_work_array(phba, vports);
9830
9831 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -05009832 fc_remove_host(shost);
9833 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04009834 lpfc_cleanup(vport);
9835
James Smart2e0fef82007-06-17 19:56:36 -05009836 /*
9837 * Bring down the SLI Layer. This step disable all interrupts,
9838 * clears the rings, discards all mailbox commands, and resets
9839 * the HBA.
9840 */
James Smarta257bf92009-04-06 18:48:10 -04009841
Justin P. Mattock48e34d02010-12-30 15:07:58 -08009842 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -05009843 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -04009844 /* Stop kthread signal shall trigger work_done one more time */
9845 kthread_stop(phba->worker_thread);
9846 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -05009847 lpfc_sli_brdrestart(phba);
9848
James Smart72859902012-01-18 16:25:38 -05009849 kfree(phba->vpi_bmask);
9850 kfree(phba->vpi_ids);
9851
James Smart3772a992009-05-22 14:50:54 -04009852 lpfc_stop_hba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05009853 spin_lock_irq(&phba->hbalock);
9854 list_del_init(&vport->listentry);
9855 spin_unlock_irq(&phba->hbalock);
9856
James Smart858c9f62007-06-17 19:56:39 -05009857 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05009858
James Smart912e3ac2011-05-24 11:42:11 -04009859 /* Disable SR-IOV if enabled */
9860 if (phba->cfg_sriov_nr_virtfn)
9861 pci_disable_sriov(pdev);
9862
James Smart5b75da22008-12-04 22:39:35 -05009863 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009864 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -05009865
James Smart858c9f62007-06-17 19:56:39 -05009866 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05009867
9868 /*
9869 * Call scsi_free before mem_free since scsi bufs are released to their
9870 * corresponding pools here.
9871 */
9872 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -04009873 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -05009874
James Smart34b02dc2008-08-24 21:49:55 -04009875 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
9876 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -05009877
James Smart2e0fef82007-06-17 19:56:36 -05009878 /* Free resources associated with SLI2 interface */
9879 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -04009880 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -05009881
9882 /* unmap adapter SLIM and Control Registers */
9883 iounmap(phba->ctrl_regs_memmap_p);
9884 iounmap(phba->slim_memmap_p);
9885
James Smart3772a992009-05-22 14:50:54 -04009886 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -05009887
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05009888 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05009889 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05009890}
9891
Linas Vepstas8d63f372007-02-14 14:28:36 -06009892/**
James Smart3772a992009-05-22 14:50:54 -04009893 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05009894 * @pdev: pointer to PCI device
9895 * @msg: power management message
9896 *
James Smart3772a992009-05-22 14:50:54 -04009897 * This routine is to be called from the kernel's PCI subsystem to support
9898 * system Power Management (PM) to device with SLI-3 interface spec. When
9899 * PM invokes this method, it quiesces the device by stopping the driver's
9900 * worker thread for the device, turning off device's interrupt and DMA,
9901 * and bring the device offline. Note that as the driver implements the
9902 * minimum PM requirements to a power-aware driver's PM support for the
9903 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
9904 * to the suspend() method call will be treated as SUSPEND and the driver will
9905 * fully reinitialize its device during resume() method call, the driver will
9906 * set device to PCI_D3hot state in PCI config space instead of setting it
9907 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -05009908 *
9909 * Return code
James Smart3772a992009-05-22 14:50:54 -04009910 * 0 - driver suspended the device
9911 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05009912 **/
9913static int
James Smart3772a992009-05-22 14:50:54 -04009914lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -05009915{
9916 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9917 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9918
9919 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9920 "0473 PCI device Power Management suspend.\n");
9921
9922 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -04009923 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -05009924 lpfc_offline(phba);
9925 kthread_stop(phba->worker_thread);
9926
9927 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -04009928 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -05009929
9930 /* Save device state to PCI config space */
9931 pci_save_state(pdev);
9932 pci_set_power_state(pdev, PCI_D3hot);
9933
9934 return 0;
9935}
9936
9937/**
James Smart3772a992009-05-22 14:50:54 -04009938 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05009939 * @pdev: pointer to PCI device
9940 *
James Smart3772a992009-05-22 14:50:54 -04009941 * This routine is to be called from the kernel's PCI subsystem to support
9942 * system Power Management (PM) to device with SLI-3 interface spec. When PM
9943 * invokes this method, it restores the device's PCI config space state and
9944 * fully reinitializes the device and brings it online. Note that as the
9945 * driver implements the minimum PM requirements to a power-aware driver's
9946 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
9947 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
9948 * driver will fully reinitialize its device during resume() method call,
9949 * the device will be set to PCI_D0 directly in PCI config space before
9950 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -05009951 *
9952 * Return code
James Smart3772a992009-05-22 14:50:54 -04009953 * 0 - driver suspended the device
9954 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05009955 **/
9956static int
James Smart3772a992009-05-22 14:50:54 -04009957lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -05009958{
9959 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9960 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -05009961 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05009962 int error;
9963
9964 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9965 "0452 PCI device Power Management resume.\n");
9966
9967 /* Restore device state from PCI config space */
9968 pci_set_power_state(pdev, PCI_D0);
9969 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -04009970
James Smart1dfb5a42010-02-12 14:40:50 -05009971 /*
9972 * As the new kernel behavior of pci_restore_state() API call clears
9973 * device saved_state flag, need to save the restored state again.
9974 */
9975 pci_save_state(pdev);
9976
James Smart3a55b532008-12-04 22:38:54 -05009977 if (pdev->is_busmaster)
9978 pci_set_master(pdev);
9979
9980 /* Startup the kernel thread for this host adapter. */
9981 phba->worker_thread = kthread_run(lpfc_do_work, phba,
9982 "lpfc_worker_%d", phba->brd_no);
9983 if (IS_ERR(phba->worker_thread)) {
9984 error = PTR_ERR(phba->worker_thread);
9985 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9986 "0434 PM resume failed to start worker "
9987 "thread: error=x%x.\n", error);
9988 return error;
9989 }
9990
James Smart5b75da22008-12-04 22:39:35 -05009991 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009992 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05009993 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -05009994 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -05009995 "0430 PM resume Failed to enable interrupt\n");
9996 return -EIO;
9997 } else
9998 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05009999
10000 /* Restart HBA and bring it online */
10001 lpfc_sli_brdrestart(phba);
10002 lpfc_online(phba);
10003
James Smart5b75da22008-12-04 22:39:35 -050010004 /* Log the current active interrupt mode */
10005 lpfc_log_intr_mode(phba, phba->intr_mode);
10006
James Smart3a55b532008-12-04 22:38:54 -050010007 return 0;
10008}
10009
10010/**
James Smart891478a2009-11-18 15:40:23 -050010011 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
10012 * @phba: pointer to lpfc hba data structure.
10013 *
10014 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -040010015 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -050010016 **/
10017static void
10018lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
10019{
10020 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10021 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -040010022
10023 /*
10024 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10025 * and let the SCSI mid-layer to retry them to recover.
10026 */
James Smartdb55fba2014-04-04 13:52:02 -040010027 lpfc_sli_abort_fcp_rings(phba);
James Smart891478a2009-11-18 15:40:23 -050010028}
10029
10030/**
James Smart0d878412009-10-02 15:16:56 -040010031 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
10032 * @phba: pointer to lpfc hba data structure.
10033 *
10034 * This routine is called to prepare the SLI3 device for PCI slot reset. It
10035 * disables the device interrupt and pci device, and aborts the internal FCP
10036 * pending I/Os.
10037 **/
10038static void
10039lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
10040{
James Smart0d878412009-10-02 15:16:56 -040010041 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050010042 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -040010043
James Smart75baf692010-06-08 18:31:21 -040010044 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040010045 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010046
James Smarte2af0d22010-03-15 11:25:32 -040010047 /* Block all SCSI devices' I/Os on the host */
10048 lpfc_scsi_dev_block(phba);
10049
James Smartea714f32013-04-17 20:18:47 -040010050 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10051 lpfc_sli_flush_fcp_rings(phba);
10052
James Smarte2af0d22010-03-15 11:25:32 -040010053 /* stop all timers */
10054 lpfc_stop_hba_timers(phba);
10055
James Smart0d878412009-10-02 15:16:56 -040010056 /* Disable interrupt and pci device */
10057 lpfc_sli_disable_intr(phba);
10058 pci_disable_device(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -040010059}
10060
10061/**
10062 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
10063 * @phba: pointer to lpfc hba data structure.
10064 *
10065 * This routine is called to prepare the SLI3 device for PCI slot permanently
10066 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10067 * pending I/Os.
10068 **/
10069static void
James Smart75baf692010-06-08 18:31:21 -040010070lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -040010071{
10072 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050010073 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -040010074 /* Block all SCSI devices' I/Os on the host */
10075 lpfc_scsi_dev_block(phba);
10076
10077 /* stop all timers */
10078 lpfc_stop_hba_timers(phba);
10079
James Smart0d878412009-10-02 15:16:56 -040010080 /* Clean up all driver's outstanding SCSI I/Os */
10081 lpfc_sli_flush_fcp_rings(phba);
10082}
10083
10084/**
James Smart3772a992009-05-22 14:50:54 -040010085 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -040010086 * @pdev: pointer to PCI device.
10087 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010088 *
James Smart3772a992009-05-22 14:50:54 -040010089 * This routine is called from the PCI subsystem for I/O error handling to
10090 * device with SLI-3 interface spec. This function is called by the PCI
10091 * subsystem after a PCI bus error affecting this device has been detected.
10092 * When this function is invoked, it will need to stop all the I/Os and
10093 * interrupt(s) to the device. Once that is done, it will return
10094 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
10095 * as desired.
James Smarte59058c2008-08-24 21:49:00 -040010096 *
10097 * Return codes
James Smart0d878412009-10-02 15:16:56 -040010098 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -040010099 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10100 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -040010101 **/
James Smart3772a992009-05-22 14:50:54 -040010102static pci_ers_result_t
10103lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010104{
James Smart51ef4c22007-08-02 11:10:31 -040010105 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10106 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010107
James Smart0d878412009-10-02 15:16:56 -040010108 switch (state) {
10109 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -050010110 /* Non-fatal error, prepare for recovery */
10111 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -040010112 return PCI_ERS_RESULT_CAN_RECOVER;
10113 case pci_channel_io_frozen:
10114 /* Fatal error, prepare for slot reset */
10115 lpfc_sli_prep_dev_for_reset(phba);
10116 return PCI_ERS_RESULT_NEED_RESET;
10117 case pci_channel_io_perm_failure:
10118 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -040010119 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010120 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -040010121 default:
10122 /* Unknown state, prepare and request slot reset */
10123 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10124 "0472 Unknown PCI error state: x%x\n", state);
10125 lpfc_sli_prep_dev_for_reset(phba);
10126 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -040010127 }
Linas Vepstas8d63f372007-02-14 14:28:36 -060010128}
10129
10130/**
James Smart3772a992009-05-22 14:50:54 -040010131 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -040010132 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010133 *
James Smart3772a992009-05-22 14:50:54 -040010134 * This routine is called from the PCI subsystem for error handling to
10135 * device with SLI-3 interface spec. This is called after PCI bus has been
10136 * reset to restart the PCI card from scratch, as if from a cold-boot.
10137 * During the PCI subsystem error recovery, after driver returns
10138 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10139 * recovery and then call this routine before calling the .resume method
10140 * to recover the device. This function will initialize the HBA device,
10141 * enable the interrupt, but it will just put the HBA to offline state
10142 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -040010143 *
10144 * Return codes
James Smart3772a992009-05-22 14:50:54 -040010145 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10146 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -060010147 */
James Smart3772a992009-05-22 14:50:54 -040010148static pci_ers_result_t
10149lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010150{
James Smart51ef4c22007-08-02 11:10:31 -040010151 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10152 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010153 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -050010154 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010155
10156 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +110010157 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -060010158 printk(KERN_ERR "lpfc: Cannot re-enable "
10159 "PCI device after reset.\n");
10160 return PCI_ERS_RESULT_DISCONNECT;
10161 }
10162
James Smart97207482008-12-04 22:39:19 -050010163 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050010164
10165 /*
10166 * As the new kernel behavior of pci_restore_state() API call clears
10167 * device saved_state flag, need to save the restored state again.
10168 */
10169 pci_save_state(pdev);
10170
James Smart97207482008-12-04 22:39:19 -050010171 if (pdev->is_busmaster)
10172 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010173
James Smart92d7f7b2007-06-17 19:56:38 -050010174 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040010175 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -050010176 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010177
James Smart5b75da22008-12-04 22:39:35 -050010178 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040010179 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050010180 if (intr_mode == LPFC_INTR_ERROR) {
10181 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10182 "0427 Cannot re-enable interrupt after "
10183 "slot reset.\n");
10184 return PCI_ERS_RESULT_DISCONNECT;
10185 } else
10186 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010187
James Smart75baf692010-06-08 18:31:21 -040010188 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -040010189 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010190 lpfc_offline(phba);
10191 lpfc_sli_brdrestart(phba);
10192
James Smart5b75da22008-12-04 22:39:35 -050010193 /* Log the current active interrupt mode */
10194 lpfc_log_intr_mode(phba, phba->intr_mode);
10195
Linas Vepstas8d63f372007-02-14 14:28:36 -060010196 return PCI_ERS_RESULT_RECOVERED;
10197}
10198
10199/**
James Smart3772a992009-05-22 14:50:54 -040010200 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -040010201 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -060010202 *
James Smart3772a992009-05-22 14:50:54 -040010203 * This routine is called from the PCI subsystem for error handling to device
10204 * with SLI-3 interface spec. It is called when kernel error recovery tells
10205 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10206 * error recovery. After this call, traffic can start to flow from this device
10207 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010208 */
James Smart3772a992009-05-22 14:50:54 -040010209static void
10210lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010211{
James Smart51ef4c22007-08-02 11:10:31 -040010212 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10213 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010214
James Smarte2af0d22010-03-15 11:25:32 -040010215 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -040010216 lpfc_online(phba);
James Smart0d878412009-10-02 15:16:56 -040010217
10218 /* Clean up Advanced Error Reporting (AER) if needed */
10219 if (phba->hba_flag & HBA_AER_ENABLED)
10220 pci_cleanup_aer_uncorrect_error_status(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010221}
10222
James Smart3772a992009-05-22 14:50:54 -040010223/**
James Smartda0436e2009-05-22 14:51:39 -040010224 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
10225 * @phba: pointer to lpfc hba data structure.
10226 *
10227 * returns the number of ELS/CT IOCBs to reserve
10228 **/
10229int
10230lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
10231{
10232 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
10233
James Smartf1126682009-06-10 17:22:44 -040010234 if (phba->sli_rev == LPFC_SLI_REV4) {
10235 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -040010236 return 10;
James Smartf1126682009-06-10 17:22:44 -040010237 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -040010238 return 25;
James Smartf1126682009-06-10 17:22:44 -040010239 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -040010240 return 50;
James Smartf1126682009-06-10 17:22:44 -040010241 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -040010242 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -040010243 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -040010244 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -040010245 else if (max_xri <= 2048)
10246 return 200;
10247 else
10248 return 250;
James Smartf1126682009-06-10 17:22:44 -040010249 } else
10250 return 0;
James Smartda0436e2009-05-22 14:51:39 -040010251}
10252
10253/**
James Smart52d52442011-05-24 11:42:45 -040010254 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -040010255 * @fw: pointer to firmware image returned from request_firmware.
James Smartce396282012-09-29 11:30:56 -040010256 * @phba: pointer to lpfc hba data structure.
James Smart52d52442011-05-24 11:42:45 -040010257 *
James Smart52d52442011-05-24 11:42:45 -040010258 **/
James Smartce396282012-09-29 11:30:56 -040010259static void
10260lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -040010261{
James Smartce396282012-09-29 11:30:56 -040010262 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -050010263 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -040010264 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -040010265 struct list_head dma_buffer_list;
10266 int i, rc = 0;
10267 struct lpfc_dmabuf *dmabuf, *next;
10268 uint32_t offset = 0, temp_offset = 0;
10269
James Smartc71ab862012-10-31 14:44:33 -040010270 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -040010271 if (!fw) {
10272 rc = -ENXIO;
10273 goto out;
10274 }
10275 image = (struct lpfc_grp_hdr *)fw->data;
10276
James Smart52d52442011-05-24 11:42:45 -040010277 INIT_LIST_HEAD(&dma_buffer_list);
James Smart079b5c92011-08-21 21:48:49 -040010278 if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) ||
10279 (bf_get_be32(lpfc_grp_hdr_file_type, image) !=
10280 LPFC_FILE_TYPE_GROUP) ||
10281 (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) ||
10282 (be32_to_cpu(image->size) != fw->size)) {
James Smart52d52442011-05-24 11:42:45 -040010283 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10284 "3022 Invalid FW image found. "
James Smart079b5c92011-08-21 21:48:49 -040010285 "Magic:%x Type:%x ID:%x\n",
10286 be32_to_cpu(image->magic_number),
10287 bf_get_be32(lpfc_grp_hdr_file_type, image),
10288 bf_get_be32(lpfc_grp_hdr_id, image));
James Smartce396282012-09-29 11:30:56 -040010289 rc = -EINVAL;
10290 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010291 }
10292 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -040010293 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -040010294 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartce396282012-09-29 11:30:56 -040010295 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -040010296 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -040010297 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -040010298 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
10299 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
10300 GFP_KERNEL);
10301 if (!dmabuf) {
10302 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040010303 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010304 }
10305 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
10306 SLI4_PAGE_SIZE,
10307 &dmabuf->phys,
10308 GFP_KERNEL);
10309 if (!dmabuf->virt) {
10310 kfree(dmabuf);
10311 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040010312 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010313 }
10314 list_add_tail(&dmabuf->list, &dma_buffer_list);
10315 }
10316 while (offset < fw->size) {
10317 temp_offset = offset;
10318 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -040010319 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -040010320 memcpy(dmabuf->virt,
10321 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -040010322 fw->size - temp_offset);
10323 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -040010324 break;
10325 }
James Smart52d52442011-05-24 11:42:45 -040010326 memcpy(dmabuf->virt, fw->data + temp_offset,
10327 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -040010328 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -040010329 }
10330 rc = lpfc_wr_object(phba, &dma_buffer_list,
10331 (fw->size - offset), &offset);
James Smartce396282012-09-29 11:30:56 -040010332 if (rc)
10333 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010334 }
10335 rc = offset;
10336 }
James Smartce396282012-09-29 11:30:56 -040010337
10338release_out:
James Smart52d52442011-05-24 11:42:45 -040010339 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
10340 list_del(&dmabuf->list);
10341 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
10342 dmabuf->virt, dmabuf->phys);
10343 kfree(dmabuf);
10344 }
James Smartce396282012-09-29 11:30:56 -040010345 release_firmware(fw);
10346out:
10347 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc71ab862012-10-31 14:44:33 -040010348 "3024 Firmware update done: %d.\n", rc);
James Smartce396282012-09-29 11:30:56 -040010349 return;
James Smart52d52442011-05-24 11:42:45 -040010350}
10351
10352/**
James Smartc71ab862012-10-31 14:44:33 -040010353 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
10354 * @phba: pointer to lpfc hba data structure.
10355 *
10356 * This routine is called to perform Linux generic firmware upgrade on device
10357 * that supports such feature.
10358 **/
10359int
10360lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
10361{
10362 uint8_t file_name[ELX_MODEL_NAME_SIZE];
10363 int ret;
10364 const struct firmware *fw;
10365
10366 /* Only supported on SLI4 interface type 2 for now */
10367 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
10368 LPFC_SLI_INTF_IF_TYPE_2)
10369 return -EPERM;
10370
10371 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
10372
10373 if (fw_upgrade == INT_FW_UPGRADE) {
10374 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
10375 file_name, &phba->pcidev->dev,
10376 GFP_KERNEL, (void *)phba,
10377 lpfc_write_firmware);
10378 } else if (fw_upgrade == RUN_FW_UPGRADE) {
10379 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
10380 if (!ret)
10381 lpfc_write_firmware(fw, (void *)phba);
10382 } else {
10383 ret = -EINVAL;
10384 }
10385
10386 return ret;
10387}
10388
10389/**
James Smartda0436e2009-05-22 14:51:39 -040010390 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
10391 * @pdev: pointer to PCI device
10392 * @pid: pointer to PCI device identifier
10393 *
10394 * This routine is called from the kernel's PCI subsystem to device with
10395 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10396 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10397 * information of the device and driver to see if the driver state that it
10398 * can support this kind of device. If the match is successful, the driver
10399 * core invokes this routine. If this routine determines it can claim the HBA,
10400 * it does all the initialization that it needs to do to handle the HBA
10401 * properly.
10402 *
10403 * Return code
10404 * 0 - driver can claim the device
10405 * negative value - driver can not claim the device
10406 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010407static int
James Smartda0436e2009-05-22 14:51:39 -040010408lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
10409{
10410 struct lpfc_hba *phba;
10411 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040010412 struct Scsi_Host *shost = NULL;
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040010413 int error;
James Smartda0436e2009-05-22 14:51:39 -040010414 uint32_t cfg_mode, intr_mode;
James Smart67d12732012-08-03 12:36:13 -040010415 int adjusted_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -040010416
10417 /* Allocate memory for HBA structure */
10418 phba = lpfc_hba_alloc(pdev);
10419 if (!phba)
10420 return -ENOMEM;
10421
10422 /* Perform generic PCI device enabling operation */
10423 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040010424 if (error)
James Smartda0436e2009-05-22 14:51:39 -040010425 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -040010426
10427 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
10428 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
10429 if (error)
10430 goto out_disable_pci_dev;
10431
10432 /* Set up SLI-4 specific device PCI memory space */
10433 error = lpfc_sli4_pci_mem_setup(phba);
10434 if (error) {
10435 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10436 "1410 Failed to set up pci memory space.\n");
10437 goto out_disable_pci_dev;
10438 }
10439
10440 /* Set up phase-1 common device driver resources */
10441 error = lpfc_setup_driver_resource_phase1(phba);
10442 if (error) {
10443 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10444 "1411 Failed to set up driver resource.\n");
10445 goto out_unset_pci_mem_s4;
10446 }
10447
10448 /* Set up SLI-4 Specific device driver resources */
10449 error = lpfc_sli4_driver_resource_setup(phba);
10450 if (error) {
10451 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10452 "1412 Failed to set up driver resource.\n");
10453 goto out_unset_pci_mem_s4;
10454 }
10455
10456 /* Initialize and populate the iocb list per host */
James Smart2a9bf3d2010-06-07 15:24:45 -040010457
10458 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10459 "2821 initialize iocb list %d.\n",
10460 phba->cfg_iocb_cnt*1024);
10461 error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
10462
James Smartda0436e2009-05-22 14:51:39 -040010463 if (error) {
10464 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10465 "1413 Failed to initialize iocb list.\n");
10466 goto out_unset_driver_resource_s4;
10467 }
10468
James Smart19ca7602010-11-20 23:11:55 -050010469 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -040010470 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -050010471
James Smartda0436e2009-05-22 14:51:39 -040010472 /* Set up common device driver resources */
10473 error = lpfc_setup_driver_resource_phase2(phba);
10474 if (error) {
10475 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10476 "1414 Failed to set up driver resource.\n");
10477 goto out_free_iocb_list;
10478 }
10479
James Smart079b5c92011-08-21 21:48:49 -040010480 /* Get the default values for Model Name and Description */
10481 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
10482
James Smartda0436e2009-05-22 14:51:39 -040010483 /* Create SCSI host to the physical port */
10484 error = lpfc_create_shost(phba);
10485 if (error) {
10486 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10487 "1415 Failed to create scsi host.\n");
10488 goto out_unset_driver_resource;
10489 }
10490
10491 /* Configure sysfs attributes */
10492 vport = phba->pport;
10493 error = lpfc_alloc_sysfs_attr(vport);
10494 if (error) {
10495 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10496 "1416 Failed to allocate sysfs attr\n");
10497 goto out_destroy_shost;
10498 }
10499
James Smart6669f9b2009-10-02 15:16:45 -040010500 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -040010501 /* Now, trying to enable interrupt and bring up the device */
10502 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -040010503
James Smart7b15db32013-01-03 15:43:29 -050010504 /* Put device to a known state before enabling interrupt */
10505 lpfc_stop_port(phba);
10506 /* Configure and enable interrupt */
10507 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
10508 if (intr_mode == LPFC_INTR_ERROR) {
10509 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10510 "0426 Failed to enable interrupt.\n");
10511 error = -ENODEV;
10512 goto out_free_sysfs_attr;
James Smartda0436e2009-05-22 14:51:39 -040010513 }
James Smart7b15db32013-01-03 15:43:29 -050010514 /* Default to single EQ for non-MSI-X */
10515 if (phba->intr_type != MSIX)
10516 adjusted_fcp_io_channel = 1;
10517 else
10518 adjusted_fcp_io_channel = phba->cfg_fcp_io_channel;
10519 phba->cfg_fcp_io_channel = adjusted_fcp_io_channel;
10520 /* Set up SLI-4 HBA */
10521 if (lpfc_sli4_hba_setup(phba)) {
10522 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10523 "1421 Failed to set up hba\n");
10524 error = -ENODEV;
10525 goto out_disable_intr;
10526 }
10527
10528 /* Log the current active interrupt mode */
10529 phba->intr_mode = intr_mode;
10530 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -040010531
10532 /* Perform post initialization setup */
10533 lpfc_post_init_setup(phba);
10534
James Smartc71ab862012-10-31 14:44:33 -040010535 /* check for firmware upgrade or downgrade */
10536 if (phba->cfg_request_firmware_upgrade)
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040010537 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -040010538
James Smart1c6834a2009-07-19 10:01:26 -040010539 /* Check if there are static vports to be created. */
10540 lpfc_create_static_vport(phba);
James Smartda0436e2009-05-22 14:51:39 -040010541 return 0;
10542
10543out_disable_intr:
10544 lpfc_sli4_disable_intr(phba);
10545out_free_sysfs_attr:
10546 lpfc_free_sysfs_attr(vport);
10547out_destroy_shost:
10548 lpfc_destroy_shost(phba);
10549out_unset_driver_resource:
10550 lpfc_unset_driver_resource_phase2(phba);
10551out_free_iocb_list:
10552 lpfc_free_iocb_list(phba);
10553out_unset_driver_resource_s4:
10554 lpfc_sli4_driver_resource_unset(phba);
10555out_unset_pci_mem_s4:
10556 lpfc_sli4_pci_mem_unset(phba);
10557out_disable_pci_dev:
10558 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040010559 if (shost)
10560 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -040010561out_free_phba:
10562 lpfc_hba_free(phba);
10563 return error;
10564}
10565
10566/**
10567 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
10568 * @pdev: pointer to PCI device
10569 *
10570 * This routine is called from the kernel's PCI subsystem to device with
10571 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10572 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10573 * device to be removed from the PCI subsystem properly.
10574 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010575static void
James Smartda0436e2009-05-22 14:51:39 -040010576lpfc_pci_remove_one_s4(struct pci_dev *pdev)
10577{
10578 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10579 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
10580 struct lpfc_vport **vports;
10581 struct lpfc_hba *phba = vport->phba;
10582 int i;
10583
10584 /* Mark the device unloading flag */
10585 spin_lock_irq(&phba->hbalock);
10586 vport->load_flag |= FC_UNLOADING;
10587 spin_unlock_irq(&phba->hbalock);
10588
10589 /* Free the HBA sysfs attributes */
10590 lpfc_free_sysfs_attr(vport);
10591
10592 /* Release all the vports against this physical port */
10593 vports = lpfc_create_vport_work_array(phba);
10594 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040010595 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10596 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
10597 continue;
James Smartda0436e2009-05-22 14:51:39 -040010598 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040010599 }
James Smartda0436e2009-05-22 14:51:39 -040010600 lpfc_destroy_vport_work_array(phba, vports);
10601
10602 /* Remove FC host and then SCSI host with the physical port */
10603 fc_remove_host(shost);
10604 scsi_remove_host(shost);
10605
10606 /* Perform cleanup on the physical port */
10607 lpfc_cleanup(vport);
10608
10609 /*
10610 * Bring down the SLI Layer. This step disables all interrupts,
10611 * clears the rings, discards all mailbox commands, and resets
10612 * the HBA FCoE function.
10613 */
10614 lpfc_debugfs_terminate(vport);
10615 lpfc_sli4_hba_unset(phba);
10616
10617 spin_lock_irq(&phba->hbalock);
10618 list_del_init(&vport->listentry);
10619 spin_unlock_irq(&phba->hbalock);
10620
James Smart3677a3a2010-09-29 11:19:14 -040010621 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -040010622 * buffers are released to their corresponding pools here.
10623 */
10624 lpfc_scsi_free(phba);
James Smart67d12732012-08-03 12:36:13 -040010625
James Smartda0436e2009-05-22 14:51:39 -040010626 lpfc_sli4_driver_resource_unset(phba);
10627
10628 /* Unmap adapter Control and Doorbell registers */
10629 lpfc_sli4_pci_mem_unset(phba);
10630
10631 /* Release PCI resources and disable device's PCI function */
10632 scsi_host_put(shost);
10633 lpfc_disable_pci_dev(phba);
10634
10635 /* Finally, free the driver's device data structure */
10636 lpfc_hba_free(phba);
10637
10638 return;
10639}
10640
10641/**
10642 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
10643 * @pdev: pointer to PCI device
10644 * @msg: power management message
10645 *
10646 * This routine is called from the kernel's PCI subsystem to support system
10647 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
10648 * this method, it quiesces the device by stopping the driver's worker
10649 * thread for the device, turning off device's interrupt and DMA, and bring
10650 * the device offline. Note that as the driver implements the minimum PM
10651 * requirements to a power-aware driver's PM support for suspend/resume -- all
10652 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
10653 * method call will be treated as SUSPEND and the driver will fully
10654 * reinitialize its device during resume() method call, the driver will set
10655 * device to PCI_D3hot state in PCI config space instead of setting it
10656 * according to the @msg provided by the PM.
10657 *
10658 * Return code
10659 * 0 - driver suspended the device
10660 * Error otherwise
10661 **/
10662static int
10663lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
10664{
10665 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10666 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10667
10668 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -040010669 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -040010670
10671 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040010672 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -040010673 lpfc_offline(phba);
10674 kthread_stop(phba->worker_thread);
10675
10676 /* Disable interrupt from device */
10677 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040010678 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040010679
10680 /* Save device state to PCI config space */
10681 pci_save_state(pdev);
10682 pci_set_power_state(pdev, PCI_D3hot);
10683
10684 return 0;
10685}
10686
10687/**
10688 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
10689 * @pdev: pointer to PCI device
10690 *
10691 * This routine is called from the kernel's PCI subsystem to support system
10692 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
10693 * this method, it restores the device's PCI config space state and fully
10694 * reinitializes the device and brings it online. Note that as the driver
10695 * implements the minimum PM requirements to a power-aware driver's PM for
10696 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10697 * to the suspend() method call will be treated as SUSPEND and the driver
10698 * will fully reinitialize its device during resume() method call, the device
10699 * will be set to PCI_D0 directly in PCI config space before restoring the
10700 * state.
10701 *
10702 * Return code
10703 * 0 - driver suspended the device
10704 * Error otherwise
10705 **/
10706static int
10707lpfc_pci_resume_one_s4(struct pci_dev *pdev)
10708{
10709 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10710 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10711 uint32_t intr_mode;
10712 int error;
10713
10714 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10715 "0292 PCI device Power Management resume.\n");
10716
10717 /* Restore device state from PCI config space */
10718 pci_set_power_state(pdev, PCI_D0);
10719 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050010720
10721 /*
10722 * As the new kernel behavior of pci_restore_state() API call clears
10723 * device saved_state flag, need to save the restored state again.
10724 */
10725 pci_save_state(pdev);
10726
James Smartda0436e2009-05-22 14:51:39 -040010727 if (pdev->is_busmaster)
10728 pci_set_master(pdev);
10729
10730 /* Startup the kernel thread for this host adapter. */
10731 phba->worker_thread = kthread_run(lpfc_do_work, phba,
10732 "lpfc_worker_%d", phba->brd_no);
10733 if (IS_ERR(phba->worker_thread)) {
10734 error = PTR_ERR(phba->worker_thread);
10735 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10736 "0293 PM resume failed to start worker "
10737 "thread: error=x%x.\n", error);
10738 return error;
10739 }
10740
10741 /* Configure and enable interrupt */
10742 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
10743 if (intr_mode == LPFC_INTR_ERROR) {
10744 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10745 "0294 PM resume Failed to enable interrupt\n");
10746 return -EIO;
10747 } else
10748 phba->intr_mode = intr_mode;
10749
10750 /* Restart HBA and bring it online */
10751 lpfc_sli_brdrestart(phba);
10752 lpfc_online(phba);
10753
10754 /* Log the current active interrupt mode */
10755 lpfc_log_intr_mode(phba, phba->intr_mode);
10756
10757 return 0;
10758}
10759
10760/**
James Smart75baf692010-06-08 18:31:21 -040010761 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
10762 * @phba: pointer to lpfc hba data structure.
10763 *
10764 * This routine is called to prepare the SLI4 device for PCI slot recover. It
10765 * aborts all the outstanding SCSI I/Os to the pci device.
10766 **/
10767static void
10768lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
10769{
James Smart75baf692010-06-08 18:31:21 -040010770 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10771 "2828 PCI channel I/O abort preparing for recovery\n");
10772 /*
10773 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10774 * and let the SCSI mid-layer to retry them to recover.
10775 */
James Smartdb55fba2014-04-04 13:52:02 -040010776 lpfc_sli_abort_fcp_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040010777}
10778
10779/**
10780 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
10781 * @phba: pointer to lpfc hba data structure.
10782 *
10783 * This routine is called to prepare the SLI4 device for PCI slot reset. It
10784 * disables the device interrupt and pci device, and aborts the internal FCP
10785 * pending I/Os.
10786 **/
10787static void
10788lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
10789{
10790 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10791 "2826 PCI channel disable preparing for reset\n");
10792
10793 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040010794 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010795
10796 /* Block all SCSI devices' I/Os on the host */
10797 lpfc_scsi_dev_block(phba);
10798
James Smartea714f32013-04-17 20:18:47 -040010799 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10800 lpfc_sli_flush_fcp_rings(phba);
10801
James Smart75baf692010-06-08 18:31:21 -040010802 /* stop all timers */
10803 lpfc_stop_hba_timers(phba);
10804
10805 /* Disable interrupt and pci device */
10806 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040010807 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -040010808 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -040010809}
10810
10811/**
10812 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
10813 * @phba: pointer to lpfc hba data structure.
10814 *
10815 * This routine is called to prepare the SLI4 device for PCI slot permanently
10816 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10817 * pending I/Os.
10818 **/
10819static void
10820lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
10821{
10822 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10823 "2827 PCI channel permanent disable for failure\n");
10824
10825 /* Block all SCSI devices' I/Os on the host */
10826 lpfc_scsi_dev_block(phba);
10827
10828 /* stop all timers */
10829 lpfc_stop_hba_timers(phba);
10830
10831 /* Clean up all driver's outstanding SCSI I/Os */
10832 lpfc_sli_flush_fcp_rings(phba);
10833}
10834
10835/**
James Smartda0436e2009-05-22 14:51:39 -040010836 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
10837 * @pdev: pointer to PCI device.
10838 * @state: the current PCI connection state.
10839 *
10840 * This routine is called from the PCI subsystem for error handling to device
10841 * with SLI-4 interface spec. This function is called by the PCI subsystem
10842 * after a PCI bus error affecting this device has been detected. When this
10843 * function is invoked, it will need to stop all the I/Os and interrupt(s)
10844 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
10845 * for the PCI subsystem to perform proper recovery as desired.
10846 *
10847 * Return codes
10848 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10849 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10850 **/
10851static pci_ers_result_t
10852lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
10853{
James Smart75baf692010-06-08 18:31:21 -040010854 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10855 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10856
10857 switch (state) {
10858 case pci_channel_io_normal:
10859 /* Non-fatal error, prepare for recovery */
10860 lpfc_sli4_prep_dev_for_recover(phba);
10861 return PCI_ERS_RESULT_CAN_RECOVER;
10862 case pci_channel_io_frozen:
10863 /* Fatal error, prepare for slot reset */
10864 lpfc_sli4_prep_dev_for_reset(phba);
10865 return PCI_ERS_RESULT_NEED_RESET;
10866 case pci_channel_io_perm_failure:
10867 /* Permanent failure, prepare for device down */
10868 lpfc_sli4_prep_dev_for_perm_failure(phba);
10869 return PCI_ERS_RESULT_DISCONNECT;
10870 default:
10871 /* Unknown state, prepare and request slot reset */
10872 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10873 "2825 Unknown PCI error state: x%x\n", state);
10874 lpfc_sli4_prep_dev_for_reset(phba);
10875 return PCI_ERS_RESULT_NEED_RESET;
10876 }
James Smartda0436e2009-05-22 14:51:39 -040010877}
10878
10879/**
10880 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
10881 * @pdev: pointer to PCI device.
10882 *
10883 * This routine is called from the PCI subsystem for error handling to device
10884 * with SLI-4 interface spec. It is called after PCI bus has been reset to
10885 * restart the PCI card from scratch, as if from a cold-boot. During the
10886 * PCI subsystem error recovery, after the driver returns
10887 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10888 * recovery and then call this routine before calling the .resume method to
10889 * recover the device. This function will initialize the HBA device, enable
10890 * the interrupt, but it will just put the HBA to offline state without
10891 * passing any I/O traffic.
10892 *
10893 * Return codes
10894 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10895 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10896 */
10897static pci_ers_result_t
10898lpfc_io_slot_reset_s4(struct pci_dev *pdev)
10899{
James Smart75baf692010-06-08 18:31:21 -040010900 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10901 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10902 struct lpfc_sli *psli = &phba->sli;
10903 uint32_t intr_mode;
10904
10905 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
10906 if (pci_enable_device_mem(pdev)) {
10907 printk(KERN_ERR "lpfc: Cannot re-enable "
10908 "PCI device after reset.\n");
10909 return PCI_ERS_RESULT_DISCONNECT;
10910 }
10911
10912 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040010913
10914 /*
10915 * As the new kernel behavior of pci_restore_state() API call clears
10916 * device saved_state flag, need to save the restored state again.
10917 */
10918 pci_save_state(pdev);
10919
James Smart75baf692010-06-08 18:31:21 -040010920 if (pdev->is_busmaster)
10921 pci_set_master(pdev);
10922
10923 spin_lock_irq(&phba->hbalock);
10924 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
10925 spin_unlock_irq(&phba->hbalock);
10926
10927 /* Configure and enable interrupt */
10928 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
10929 if (intr_mode == LPFC_INTR_ERROR) {
10930 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10931 "2824 Cannot re-enable interrupt after "
10932 "slot reset.\n");
10933 return PCI_ERS_RESULT_DISCONNECT;
10934 } else
10935 phba->intr_mode = intr_mode;
10936
10937 /* Log the current active interrupt mode */
10938 lpfc_log_intr_mode(phba, phba->intr_mode);
10939
James Smartda0436e2009-05-22 14:51:39 -040010940 return PCI_ERS_RESULT_RECOVERED;
10941}
10942
10943/**
10944 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
10945 * @pdev: pointer to PCI device
10946 *
10947 * This routine is called from the PCI subsystem for error handling to device
10948 * with SLI-4 interface spec. It is called when kernel error recovery tells
10949 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10950 * error recovery. After this call, traffic can start to flow from this device
10951 * again.
10952 **/
10953static void
10954lpfc_io_resume_s4(struct pci_dev *pdev)
10955{
James Smart75baf692010-06-08 18:31:21 -040010956 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10957 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10958
10959 /*
10960 * In case of slot reset, as function reset is performed through
10961 * mailbox command which needs DMA to be enabled, this operation
10962 * has to be moved to the io resume phase. Taking device offline
10963 * will perform the necessary cleanup.
10964 */
10965 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
10966 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040010967 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010968 lpfc_offline(phba);
10969 lpfc_sli_brdrestart(phba);
10970 /* Bring the device back online */
10971 lpfc_online(phba);
10972 }
10973
10974 /* Clean up Advanced Error Reporting (AER) if needed */
10975 if (phba->hba_flag & HBA_AER_ENABLED)
10976 pci_cleanup_aer_uncorrect_error_status(pdev);
James Smartda0436e2009-05-22 14:51:39 -040010977}
10978
10979/**
James Smart3772a992009-05-22 14:50:54 -040010980 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
10981 * @pdev: pointer to PCI device
10982 * @pid: pointer to PCI device identifier
10983 *
10984 * This routine is to be registered to the kernel's PCI subsystem. When an
10985 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
10986 * at PCI device-specific information of the device and driver to see if the
10987 * driver state that it can support this kind of device. If the match is
10988 * successful, the driver core invokes this routine. This routine dispatches
10989 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
10990 * do all the initialization that it needs to do to handle the HBA device
10991 * properly.
10992 *
10993 * Return code
10994 * 0 - driver can claim the device
10995 * negative value - driver can not claim the device
10996 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010997static int
James Smart3772a992009-05-22 14:50:54 -040010998lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
10999{
11000 int rc;
James Smart8fa38512009-07-19 10:01:03 -040011001 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040011002
James Smart28baac72010-02-12 14:42:03 -050011003 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040011004 return -ENODEV;
11005
James Smart8fa38512009-07-19 10:01:03 -040011006 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050011007 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040011008 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040011009 else
James Smart3772a992009-05-22 14:50:54 -040011010 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040011011
James Smart3772a992009-05-22 14:50:54 -040011012 return rc;
11013}
11014
11015/**
11016 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
11017 * @pdev: pointer to PCI device
11018 *
11019 * This routine is to be registered to the kernel's PCI subsystem. When an
11020 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
11021 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
11022 * remove routine, which will perform all the necessary cleanup for the
11023 * device to be removed from the PCI subsystem properly.
11024 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011025static void
James Smart3772a992009-05-22 14:50:54 -040011026lpfc_pci_remove_one(struct pci_dev *pdev)
11027{
11028 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11029 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11030
11031 switch (phba->pci_dev_grp) {
11032 case LPFC_PCI_DEV_LP:
11033 lpfc_pci_remove_one_s3(pdev);
11034 break;
James Smartda0436e2009-05-22 14:51:39 -040011035 case LPFC_PCI_DEV_OC:
11036 lpfc_pci_remove_one_s4(pdev);
11037 break;
James Smart3772a992009-05-22 14:50:54 -040011038 default:
11039 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11040 "1424 Invalid PCI device group: 0x%x\n",
11041 phba->pci_dev_grp);
11042 break;
11043 }
11044 return;
11045}
11046
11047/**
11048 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
11049 * @pdev: pointer to PCI device
11050 * @msg: power management message
11051 *
11052 * This routine is to be registered to the kernel's PCI subsystem to support
11053 * system Power Management (PM). When PM invokes this method, it dispatches
11054 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
11055 * suspend the device.
11056 *
11057 * Return code
11058 * 0 - driver suspended the device
11059 * Error otherwise
11060 **/
11061static int
11062lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
11063{
11064 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11065 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11066 int rc = -ENODEV;
11067
11068 switch (phba->pci_dev_grp) {
11069 case LPFC_PCI_DEV_LP:
11070 rc = lpfc_pci_suspend_one_s3(pdev, msg);
11071 break;
James Smartda0436e2009-05-22 14:51:39 -040011072 case LPFC_PCI_DEV_OC:
11073 rc = lpfc_pci_suspend_one_s4(pdev, msg);
11074 break;
James Smart3772a992009-05-22 14:50:54 -040011075 default:
11076 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11077 "1425 Invalid PCI device group: 0x%x\n",
11078 phba->pci_dev_grp);
11079 break;
11080 }
11081 return rc;
11082}
11083
11084/**
11085 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
11086 * @pdev: pointer to PCI device
11087 *
11088 * This routine is to be registered to the kernel's PCI subsystem to support
11089 * system Power Management (PM). When PM invokes this method, it dispatches
11090 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
11091 * resume the device.
11092 *
11093 * Return code
11094 * 0 - driver suspended the device
11095 * Error otherwise
11096 **/
11097static int
11098lpfc_pci_resume_one(struct pci_dev *pdev)
11099{
11100 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11101 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11102 int rc = -ENODEV;
11103
11104 switch (phba->pci_dev_grp) {
11105 case LPFC_PCI_DEV_LP:
11106 rc = lpfc_pci_resume_one_s3(pdev);
11107 break;
James Smartda0436e2009-05-22 14:51:39 -040011108 case LPFC_PCI_DEV_OC:
11109 rc = lpfc_pci_resume_one_s4(pdev);
11110 break;
James Smart3772a992009-05-22 14:50:54 -040011111 default:
11112 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11113 "1426 Invalid PCI device group: 0x%x\n",
11114 phba->pci_dev_grp);
11115 break;
11116 }
11117 return rc;
11118}
11119
11120/**
11121 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
11122 * @pdev: pointer to PCI device.
11123 * @state: the current PCI connection state.
11124 *
11125 * This routine is registered to the PCI subsystem for error handling. This
11126 * function is called by the PCI subsystem after a PCI bus error affecting
11127 * this device has been detected. When this routine is invoked, it dispatches
11128 * the action to the proper SLI-3 or SLI-4 device error detected handling
11129 * routine, which will perform the proper error detected operation.
11130 *
11131 * Return codes
11132 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11133 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11134 **/
11135static pci_ers_result_t
11136lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
11137{
11138 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11139 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11140 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11141
11142 switch (phba->pci_dev_grp) {
11143 case LPFC_PCI_DEV_LP:
11144 rc = lpfc_io_error_detected_s3(pdev, state);
11145 break;
James Smartda0436e2009-05-22 14:51:39 -040011146 case LPFC_PCI_DEV_OC:
11147 rc = lpfc_io_error_detected_s4(pdev, state);
11148 break;
James Smart3772a992009-05-22 14:50:54 -040011149 default:
11150 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11151 "1427 Invalid PCI device group: 0x%x\n",
11152 phba->pci_dev_grp);
11153 break;
11154 }
11155 return rc;
11156}
11157
11158/**
11159 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
11160 * @pdev: pointer to PCI device.
11161 *
11162 * This routine is registered to the PCI subsystem for error handling. This
11163 * function is called after PCI bus has been reset to restart the PCI card
11164 * from scratch, as if from a cold-boot. When this routine is invoked, it
11165 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
11166 * routine, which will perform the proper device reset.
11167 *
11168 * Return codes
11169 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11170 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11171 **/
11172static pci_ers_result_t
11173lpfc_io_slot_reset(struct pci_dev *pdev)
11174{
11175 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11176 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11177 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11178
11179 switch (phba->pci_dev_grp) {
11180 case LPFC_PCI_DEV_LP:
11181 rc = lpfc_io_slot_reset_s3(pdev);
11182 break;
James Smartda0436e2009-05-22 14:51:39 -040011183 case LPFC_PCI_DEV_OC:
11184 rc = lpfc_io_slot_reset_s4(pdev);
11185 break;
James Smart3772a992009-05-22 14:50:54 -040011186 default:
11187 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11188 "1428 Invalid PCI device group: 0x%x\n",
11189 phba->pci_dev_grp);
11190 break;
11191 }
11192 return rc;
11193}
11194
11195/**
11196 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
11197 * @pdev: pointer to PCI device
11198 *
11199 * This routine is registered to the PCI subsystem for error handling. It
11200 * is called when kernel error recovery tells the lpfc driver that it is
11201 * OK to resume normal PCI operation after PCI bus error recovery. When
11202 * this routine is invoked, it dispatches the action to the proper SLI-3
11203 * or SLI-4 device io_resume routine, which will resume the device operation.
11204 **/
11205static void
11206lpfc_io_resume(struct pci_dev *pdev)
11207{
11208 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11209 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11210
11211 switch (phba->pci_dev_grp) {
11212 case LPFC_PCI_DEV_LP:
11213 lpfc_io_resume_s3(pdev);
11214 break;
James Smartda0436e2009-05-22 14:51:39 -040011215 case LPFC_PCI_DEV_OC:
11216 lpfc_io_resume_s4(pdev);
11217 break;
James Smart3772a992009-05-22 14:50:54 -040011218 default:
11219 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11220 "1429 Invalid PCI device group: 0x%x\n",
11221 phba->pci_dev_grp);
11222 break;
11223 }
11224 return;
11225}
11226
James Smart1ba981f2014-02-20 09:56:45 -050011227/**
11228 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
11229 * @phba: pointer to lpfc hba data structure.
11230 *
11231 * This routine checks to see if OAS is supported for this adapter. If
11232 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
11233 * the enable oas flag is cleared and the pool created for OAS device data
11234 * is destroyed.
11235 *
11236 **/
11237void
11238lpfc_sli4_oas_verify(struct lpfc_hba *phba)
11239{
11240
11241 if (!phba->cfg_EnableXLane)
11242 return;
11243
11244 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
11245 phba->cfg_fof = 1;
11246 } else {
James Smartf38fa0b2014-04-04 13:52:21 -040011247 phba->cfg_fof = 0;
James Smart1ba981f2014-02-20 09:56:45 -050011248 if (phba->device_data_mem_pool)
11249 mempool_destroy(phba->device_data_mem_pool);
11250 phba->device_data_mem_pool = NULL;
11251 }
11252
11253 return;
11254}
11255
11256/**
11257 * lpfc_fof_queue_setup - Set up all the fof queues
11258 * @phba: pointer to lpfc hba data structure.
11259 *
11260 * This routine is invoked to set up all the fof queues for the FC HBA
11261 * operation.
11262 *
11263 * Return codes
11264 * 0 - successful
11265 * -ENOMEM - No available memory
11266 **/
11267int
11268lpfc_fof_queue_setup(struct lpfc_hba *phba)
11269{
11270 struct lpfc_sli *psli = &phba->sli;
11271 int rc;
11272
11273 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
11274 if (rc)
11275 return -ENOMEM;
11276
James Smartf38fa0b2014-04-04 13:52:21 -040011277 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050011278
11279 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
11280 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
11281 if (rc)
11282 goto out_oas_cq;
11283
11284 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
11285 phba->sli4_hba.oas_cq, LPFC_FCP);
11286 if (rc)
11287 goto out_oas_wq;
11288
11289 phba->sli4_hba.oas_cq->pring = &psli->ring[LPFC_FCP_OAS_RING];
11290 phba->sli4_hba.oas_ring = &psli->ring[LPFC_FCP_OAS_RING];
11291 }
11292
11293 return 0;
11294
11295out_oas_wq:
James Smartf38fa0b2014-04-04 13:52:21 -040011296 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
James Smart1ba981f2014-02-20 09:56:45 -050011297out_oas_cq:
11298 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
11299 return rc;
11300
11301}
11302
11303/**
11304 * lpfc_fof_queue_create - Create all the fof queues
11305 * @phba: pointer to lpfc hba data structure.
11306 *
11307 * This routine is invoked to allocate all the fof queues for the FC HBA
11308 * operation. For each SLI4 queue type, the parameters such as queue entry
11309 * count (queue depth) shall be taken from the module parameter. For now,
11310 * we just use some constant number as place holder.
11311 *
11312 * Return codes
11313 * 0 - successful
11314 * -ENOMEM - No availble memory
11315 * -EIO - The mailbox failed to complete successfully.
11316 **/
11317int
11318lpfc_fof_queue_create(struct lpfc_hba *phba)
11319{
11320 struct lpfc_queue *qdesc;
11321
11322 /* Create FOF EQ */
11323 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
11324 phba->sli4_hba.eq_ecount);
11325 if (!qdesc)
11326 goto out_error;
11327
11328 phba->sli4_hba.fof_eq = qdesc;
11329
James Smartf38fa0b2014-04-04 13:52:21 -040011330 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050011331
11332 /* Create OAS CQ */
11333 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
11334 phba->sli4_hba.cq_ecount);
11335 if (!qdesc)
11336 goto out_error;
11337
11338 phba->sli4_hba.oas_cq = qdesc;
11339
11340 /* Create OAS WQ */
11341 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
11342 phba->sli4_hba.wq_ecount);
11343 if (!qdesc)
11344 goto out_error;
11345
11346 phba->sli4_hba.oas_wq = qdesc;
11347
11348 }
11349 return 0;
11350
11351out_error:
11352 lpfc_fof_queue_destroy(phba);
11353 return -ENOMEM;
11354}
11355
11356/**
11357 * lpfc_fof_queue_destroy - Destroy all the fof queues
11358 * @phba: pointer to lpfc hba data structure.
11359 *
11360 * This routine is invoked to release all the SLI4 queues with the FC HBA
11361 * operation.
11362 *
11363 * Return codes
11364 * 0 - successful
11365 **/
11366int
11367lpfc_fof_queue_destroy(struct lpfc_hba *phba)
11368{
11369 /* Release FOF Event queue */
11370 if (phba->sli4_hba.fof_eq != NULL) {
11371 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
11372 phba->sli4_hba.fof_eq = NULL;
11373 }
11374
11375 /* Release OAS Completion queue */
11376 if (phba->sli4_hba.oas_cq != NULL) {
11377 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
11378 phba->sli4_hba.oas_cq = NULL;
11379 }
11380
11381 /* Release OAS Work queue */
11382 if (phba->sli4_hba.oas_wq != NULL) {
11383 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
11384 phba->sli4_hba.oas_wq = NULL;
11385 }
11386 return 0;
11387}
11388
dea31012005-04-17 16:05:31 -050011389MODULE_DEVICE_TABLE(pci, lpfc_id_table);
11390
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070011391static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060011392 .error_detected = lpfc_io_error_detected,
11393 .slot_reset = lpfc_io_slot_reset,
11394 .resume = lpfc_io_resume,
11395};
11396
dea31012005-04-17 16:05:31 -050011397static struct pci_driver lpfc_driver = {
11398 .name = LPFC_DRIVER_NAME,
11399 .id_table = lpfc_id_table,
11400 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011401 .remove = lpfc_pci_remove_one,
James Smart3a55b532008-12-04 22:38:54 -050011402 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040011403 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050011404 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050011405};
11406
James Smart3ef6d242012-01-18 16:23:48 -050011407static const struct file_operations lpfc_mgmt_fop = {
Al Viro858feac2013-04-14 22:39:37 -040011408 .owner = THIS_MODULE,
James Smart3ef6d242012-01-18 16:23:48 -050011409};
11410
11411static struct miscdevice lpfc_mgmt_dev = {
11412 .minor = MISC_DYNAMIC_MINOR,
11413 .name = "lpfcmgmt",
11414 .fops = &lpfc_mgmt_fop,
11415};
11416
James Smarte59058c2008-08-24 21:49:00 -040011417/**
James Smart3621a712009-04-06 18:47:14 -040011418 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040011419 *
11420 * This routine is to be invoked when the lpfc module is loaded into the
11421 * kernel. The special kernel macro module_init() is used to indicate the
11422 * role of this routine to the kernel as lpfc module entry point.
11423 *
11424 * Return codes
11425 * 0 - successful
11426 * -ENOMEM - FC attach transport failed
11427 * all others - failed
11428 */
dea31012005-04-17 16:05:31 -050011429static int __init
11430lpfc_init(void)
11431{
James Smart7bb03bb2013-04-17 20:19:16 -040011432 int cpu;
dea31012005-04-17 16:05:31 -050011433 int error = 0;
11434
11435 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040011436 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050011437
James Smart3ef6d242012-01-18 16:23:48 -050011438 error = misc_register(&lpfc_mgmt_dev);
11439 if (error)
11440 printk(KERN_ERR "Could not register lpfcmgmt device, "
11441 "misc_register returned with status %d", error);
11442
James Smart7ee5d432007-10-27 13:37:17 -040011443 if (lpfc_enable_npiv) {
11444 lpfc_transport_functions.vport_create = lpfc_vport_create;
11445 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
11446 }
dea31012005-04-17 16:05:31 -050011447 lpfc_transport_template =
11448 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040011449 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050011450 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040011451 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -040011452 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -040011453 fc_attach_transport(&lpfc_vport_transport_functions);
11454 if (lpfc_vport_transport_template == NULL) {
11455 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040011456 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -040011457 }
James Smart7ee5d432007-10-27 13:37:17 -040011458 }
James Smart7bb03bb2013-04-17 20:19:16 -040011459
11460 /* Initialize in case vector mapping is needed */
James Smartb246de12013-05-31 17:03:07 -040011461 lpfc_used_cpu = NULL;
11462 lpfc_present_cpu = 0;
11463 for_each_present_cpu(cpu)
11464 lpfc_present_cpu++;
James Smart7bb03bb2013-04-17 20:19:16 -040011465
dea31012005-04-17 16:05:31 -050011466 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050011467 if (error) {
dea31012005-04-17 16:05:31 -050011468 fc_release_transport(lpfc_transport_template);
James Smartd7c255b2008-08-24 21:50:00 -040011469 if (lpfc_enable_npiv)
11470 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050011471 }
dea31012005-04-17 16:05:31 -050011472
11473 return error;
11474}
11475
James Smarte59058c2008-08-24 21:49:00 -040011476/**
James Smart3621a712009-04-06 18:47:14 -040011477 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040011478 *
11479 * This routine is invoked when the lpfc module is removed from the kernel.
11480 * The special kernel macro module_exit() is used to indicate the role of
11481 * this routine to the kernel as lpfc module exit point.
11482 */
dea31012005-04-17 16:05:31 -050011483static void __exit
11484lpfc_exit(void)
11485{
James Smart3ef6d242012-01-18 16:23:48 -050011486 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050011487 pci_unregister_driver(&lpfc_driver);
11488 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040011489 if (lpfc_enable_npiv)
11490 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050011491 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040011492 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
11493 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050011494 (1L << _dump_buf_data_order), _dump_buf_data);
11495 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
11496 }
11497
11498 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040011499 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
11500 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050011501 (1L << _dump_buf_dif_order), _dump_buf_dif);
11502 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
11503 }
James Smartb246de12013-05-31 17:03:07 -040011504 kfree(lpfc_used_cpu);
Johannes Thumshirn79739672015-08-31 16:48:11 -040011505 idr_destroy(&lpfc_hba_index);
dea31012005-04-17 16:05:31 -050011506}
11507
11508module_init(lpfc_init);
11509module_exit(lpfc_exit);
11510MODULE_LICENSE("GPL");
11511MODULE_DESCRIPTION(LPFC_MODULE_DESC);
11512MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
11513MODULE_VERSION("0:" LPFC_DRIVER_VERSION);