blob: 8edef6c4d57a81f02ab39af88264ab73e13b63c8 [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 Smartd4379ac2012-03-01 22:37:07 -05004 * Copyright (C) 2004-2012 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>
dea31012005-04-17 16:05:31 -050036
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040037#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050038#include <scsi/scsi_device.h>
39#include <scsi/scsi_host.h>
40#include <scsi/scsi_transport_fc.h>
41
James Smartda0436e2009-05-22 14:51:39 -040042#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050043#include "lpfc_hw.h"
44#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040045#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040046#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050047#include "lpfc_disc.h"
48#include "lpfc_scsi.h"
49#include "lpfc.h"
50#include "lpfc_logmsg.h"
51#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050052#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050053#include "lpfc_version.h"
54
James Smart81301a92008-12-04 22:39:46 -050055char *_dump_buf_data;
56unsigned long _dump_buf_data_order;
57char *_dump_buf_dif;
58unsigned long _dump_buf_dif_order;
59spinlock_t _dump_buf_lock;
60
dea31012005-04-17 16:05:31 -050061static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
62static int lpfc_post_rcv_buf(struct lpfc_hba *);
James Smart5350d872011-10-10 21:33:49 -040063static int lpfc_sli4_queue_verify(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040064static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
65static int lpfc_setup_endian_order(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040066static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040067static void lpfc_free_els_sgl_list(struct lpfc_hba *);
68static void lpfc_init_sgl_list(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040069static int lpfc_init_active_sgl_array(struct lpfc_hba *);
70static void lpfc_free_active_sgl(struct lpfc_hba *);
71static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
72static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
73static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
74static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
75static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
James Smart618a5232012-06-12 13:54:36 -040076static void lpfc_sli4_disable_intr(struct lpfc_hba *);
77static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
dea31012005-04-17 16:05:31 -050078
79static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050080static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -050081static DEFINE_IDR(lpfc_hba_index);
82
James Smarte59058c2008-08-24 21:49:00 -040083/**
James Smart3621a712009-04-06 18:47:14 -040084 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
James Smarte59058c2008-08-24 21:49:00 -040085 * @phba: pointer to lpfc hba data structure.
86 *
87 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
88 * mailbox command. It retrieves the revision information from the HBA and
89 * collects the Vital Product Data (VPD) about the HBA for preparing the
90 * configuration of the HBA.
91 *
92 * Return codes:
93 * 0 - success.
94 * -ERESTART - requests the SLI layer to reset the HBA and try again.
95 * Any other value - indicates an error.
96 **/
dea31012005-04-17 16:05:31 -050097int
James Smart2e0fef82007-06-17 19:56:36 -050098lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -050099{
100 lpfc_vpd_t *vp = &phba->vpd;
101 int i = 0, rc;
102 LPFC_MBOXQ_t *pmb;
103 MAILBOX_t *mb;
104 char *lpfc_vpd_data = NULL;
105 uint16_t offset = 0;
106 static char licensed[56] =
107 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -0400108 static int init_key = 1;
dea31012005-04-17 16:05:31 -0500109
110 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
111 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500112 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500113 return -ENOMEM;
114 }
115
James Smart04c68492009-05-22 14:52:52 -0400116 mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -0500117 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -0500118
119 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -0400120 if (init_key) {
121 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -0500122
James Smart65a29c12006-07-06 15:50:50 -0400123 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
124 *ptext = cpu_to_be32(*ptext);
125 init_key = 0;
126 }
dea31012005-04-17 16:05:31 -0500127
128 lpfc_read_nv(phba, pmb);
129 memset((char*)mb->un.varRDnvp.rsvd3, 0,
130 sizeof (mb->un.varRDnvp.rsvd3));
131 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
132 sizeof (licensed));
133
134 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
135
136 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500137 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400138 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500139 "error, mbxCmd x%x READ_NVPARM, "
140 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500141 mb->mbxCommand, mb->mbxStatus);
142 mempool_free(pmb, phba->mbox_mem_pool);
143 return -ERESTART;
144 }
145 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500146 sizeof(phba->wwnn));
147 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
148 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500149 }
150
James Smart92d7f7b2007-06-17 19:56:38 -0500151 phba->sli3_options = 0x0;
152
dea31012005-04-17 16:05:31 -0500153 /* Setup and issue mailbox READ REV command */
154 lpfc_read_rev(phba, pmb);
155 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
156 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500157 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400158 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500159 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500160 mb->mbxCommand, mb->mbxStatus);
161 mempool_free( pmb, phba->mbox_mem_pool);
162 return -ERESTART;
163 }
164
James Smart92d7f7b2007-06-17 19:56:38 -0500165
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500166 /*
167 * The value of rr must be 1 since the driver set the cv field to 1.
168 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500169 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500170 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500171 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500172 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400173 "0440 Adapter failed to init, READ_REV has "
174 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500175 mempool_free(pmb, phba->mbox_mem_pool);
176 return -ERESTART;
dea31012005-04-17 16:05:31 -0500177 }
178
James Smart495a7142008-06-14 22:52:59 -0400179 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
180 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500181 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400182 }
James Smarted957682007-06-17 19:56:37 -0500183
dea31012005-04-17 16:05:31 -0500184 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500185 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500186 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500187 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
188 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
189 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
190 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500191 vp->rev.biuRev = mb->un.varRdRev.biuRev;
192 vp->rev.smRev = mb->un.varRdRev.smRev;
193 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
194 vp->rev.endecRev = mb->un.varRdRev.endecRev;
195 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
196 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
197 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
198 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
199 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
200 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
201
James Smart92d7f7b2007-06-17 19:56:38 -0500202 /* If the sli feature level is less then 9, we must
203 * tear down all RPIs and VPIs on link down if NPIV
204 * is enabled.
205 */
206 if (vp->rev.feaLevelHigh < 9)
207 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
208
dea31012005-04-17 16:05:31 -0500209 if (lpfc_is_LC_HBA(phba->pcidev->device))
210 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
211 sizeof (phba->RandomData));
212
dea31012005-04-17 16:05:31 -0500213 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500214 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
215 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400216 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500217 do {
James Smarta0c87cb2009-07-19 10:01:10 -0400218 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
dea31012005-04-17 16:05:31 -0500219 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
220
221 if (rc != MBX_SUCCESS) {
222 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400223 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500224 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500225 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500226 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500227 }
James Smart04c68492009-05-22 14:52:52 -0400228 /* dump mem may return a zero when finished or we got a
229 * mailbox error, either way we are done.
230 */
231 if (mb->un.varDmp.word_cnt == 0)
232 break;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500233 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
234 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400235 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
236 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500237 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500238 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500239 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
240 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500241
242 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500243out_free_mbox:
244 mempool_free(pmb, phba->mbox_mem_pool);
245 return 0;
246}
247
James Smarte59058c2008-08-24 21:49:00 -0400248/**
James Smart3621a712009-04-06 18:47:14 -0400249 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
James Smarte59058c2008-08-24 21:49:00 -0400250 * @phba: pointer to lpfc hba data structure.
251 * @pmboxq: pointer to the driver internal queue element for mailbox command.
252 *
253 * This is the completion handler for driver's configuring asynchronous event
254 * mailbox command to the device. If the mailbox command returns successfully,
255 * it will set internal async event support flag to 1; otherwise, it will
256 * set internal async event support flag to 0.
257 **/
James Smart57127f12007-10-27 13:37:05 -0400258static void
259lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
260{
James Smart04c68492009-05-22 14:52:52 -0400261 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
James Smart57127f12007-10-27 13:37:05 -0400262 phba->temp_sensor_support = 1;
263 else
264 phba->temp_sensor_support = 0;
265 mempool_free(pmboxq, phba->mbox_mem_pool);
266 return;
267}
268
James Smarte59058c2008-08-24 21:49:00 -0400269/**
James Smart3621a712009-04-06 18:47:14 -0400270 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
James Smart97207482008-12-04 22:39:19 -0500271 * @phba: pointer to lpfc hba data structure.
272 * @pmboxq: pointer to the driver internal queue element for mailbox command.
273 *
274 * This is the completion handler for dump mailbox command for getting
275 * wake up parameters. When this command complete, the response contain
276 * Option rom version of the HBA. This function translate the version number
277 * into a human readable string and store it in OptionROMVersion.
278 **/
279static void
280lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
281{
282 struct prog_id *prg;
283 uint32_t prog_id_word;
284 char dist = ' ';
285 /* character array used for decoding dist type. */
286 char dist_char[] = "nabx";
287
James Smart04c68492009-05-22 14:52:52 -0400288 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
James Smart9f1e1b52008-12-04 22:39:40 -0500289 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500290 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500291 }
James Smart97207482008-12-04 22:39:19 -0500292
293 prg = (struct prog_id *) &prog_id_word;
294
295 /* word 7 contain option rom version */
James Smart04c68492009-05-22 14:52:52 -0400296 prog_id_word = pmboxq->u.mb.un.varWords[7];
James Smart97207482008-12-04 22:39:19 -0500297
298 /* Decode the Option rom version word to a readable string */
299 if (prg->dist < 4)
300 dist = dist_char[prg->dist];
301
302 if ((prg->dist == 3) && (prg->num == 0))
303 sprintf(phba->OptionROMVersion, "%d.%d%d",
304 prg->ver, prg->rev, prg->lev);
305 else
306 sprintf(phba->OptionROMVersion, "%d.%d%d%c%d",
307 prg->ver, prg->rev, prg->lev,
308 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500309 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500310 return;
311}
312
313/**
James Smart05580562011-05-24 11:40:48 -0400314 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
315 * cfg_soft_wwnn, cfg_soft_wwpn
316 * @vport: pointer to lpfc vport data structure.
317 *
318 *
319 * Return codes
320 * None.
321 **/
322void
323lpfc_update_vport_wwn(struct lpfc_vport *vport)
324{
325 /* If the soft name exists then update it using the service params */
326 if (vport->phba->cfg_soft_wwnn)
327 u64_to_wwn(vport->phba->cfg_soft_wwnn,
328 vport->fc_sparam.nodeName.u.wwn);
329 if (vport->phba->cfg_soft_wwpn)
330 u64_to_wwn(vport->phba->cfg_soft_wwpn,
331 vport->fc_sparam.portName.u.wwn);
332
333 /*
334 * If the name is empty or there exists a soft name
335 * then copy the service params name, otherwise use the fc name
336 */
337 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
338 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
339 sizeof(struct lpfc_name));
340 else
341 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
342 sizeof(struct lpfc_name));
343
344 if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn)
345 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
346 sizeof(struct lpfc_name));
347 else
348 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
349 sizeof(struct lpfc_name));
350}
351
352/**
James Smart3621a712009-04-06 18:47:14 -0400353 * lpfc_config_port_post - Perform lpfc initialization after config port
James Smarte59058c2008-08-24 21:49:00 -0400354 * @phba: pointer to lpfc hba data structure.
355 *
356 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
357 * command call. It performs all internal resource and state setups on the
358 * port: post IOCB buffers, enable appropriate host interrupt attentions,
359 * ELS ring timers, etc.
360 *
361 * Return codes
362 * 0 - success.
363 * Any other value - error.
364 **/
dea31012005-04-17 16:05:31 -0500365int
James Smart2e0fef82007-06-17 19:56:36 -0500366lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500367{
James Smart2e0fef82007-06-17 19:56:36 -0500368 struct lpfc_vport *vport = phba->pport;
James Smarta257bf92009-04-06 18:48:10 -0400369 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500370 LPFC_MBOXQ_t *pmb;
371 MAILBOX_t *mb;
372 struct lpfc_dmabuf *mp;
373 struct lpfc_sli *psli = &phba->sli;
374 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500375 int i, j;
376 int rc;
dea31012005-04-17 16:05:31 -0500377
James Smart7af67052007-10-27 13:38:11 -0400378 spin_lock_irq(&phba->hbalock);
379 /*
380 * If the Config port completed correctly the HBA is not
381 * over heated any more.
382 */
383 if (phba->over_temp_state == HBA_OVER_TEMP)
384 phba->over_temp_state = HBA_NORMAL_TEMP;
385 spin_unlock_irq(&phba->hbalock);
386
dea31012005-04-17 16:05:31 -0500387 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
388 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500389 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500390 return -ENOMEM;
391 }
James Smart04c68492009-05-22 14:52:52 -0400392 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500393
dea31012005-04-17 16:05:31 -0500394 /* Get login parameters for NID. */
James Smart9f1177a2010-02-26 14:12:57 -0500395 rc = lpfc_read_sparam(phba, pmb, 0);
396 if (rc) {
397 mempool_free(pmb, phba->mbox_mem_pool);
398 return -ENOMEM;
399 }
400
James Smarted957682007-06-17 19:56:37 -0500401 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500402 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500403 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400404 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500405 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500406 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500407 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500408 mp = (struct lpfc_dmabuf *) pmb->context1;
James Smart9f1177a2010-02-26 14:12:57 -0500409 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500410 lpfc_mbuf_free(phba, mp->virt, mp->phys);
411 kfree(mp);
412 return -EIO;
413 }
414
415 mp = (struct lpfc_dmabuf *) pmb->context1;
416
James Smart2e0fef82007-06-17 19:56:36 -0500417 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500418 lpfc_mbuf_free(phba, mp->virt, mp->phys);
419 kfree(mp);
420 pmb->context1 = NULL;
James Smart05580562011-05-24 11:40:48 -0400421 lpfc_update_vport_wwn(vport);
James Smarta257bf92009-04-06 18:48:10 -0400422
423 /* Update the fc_host data structures with new wwn. */
424 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
425 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart21e9a0a2009-05-22 14:53:21 -0400426 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smarta257bf92009-04-06 18:48:10 -0400427
dea31012005-04-17 16:05:31 -0500428 /* If no serial number in VPD data, use low 6 bytes of WWNN */
429 /* This should be consolidated into parse_vpd ? - mr */
430 if (phba->SerialNumber[0] == 0) {
431 uint8_t *outptr;
432
James Smart2e0fef82007-06-17 19:56:36 -0500433 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500434 for (i = 0; i < 12; i++) {
435 status = *outptr++;
436 j = ((status & 0xf0) >> 4);
437 if (j <= 9)
438 phba->SerialNumber[i] =
439 (char)((uint8_t) 0x30 + (uint8_t) j);
440 else
441 phba->SerialNumber[i] =
442 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
443 i++;
444 j = (status & 0xf);
445 if (j <= 9)
446 phba->SerialNumber[i] =
447 (char)((uint8_t) 0x30 + (uint8_t) j);
448 else
449 phba->SerialNumber[i] =
450 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
451 }
452 }
453
dea31012005-04-17 16:05:31 -0500454 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500455 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500456 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500457 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400458 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500459 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500460 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500461 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500462 mempool_free( pmb, phba->mbox_mem_pool);
463 return -EIO;
464 }
465
James Smarta0c87cb2009-07-19 10:01:10 -0400466 /* Check if the port is disabled */
467 lpfc_sli_read_link_ste(phba);
468
dea31012005-04-17 16:05:31 -0500469 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
470 if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
471 phba->cfg_hba_queue_depth =
James Smartf1126682009-06-10 17:22:44 -0400472 (mb->un.varRdConfig.max_xri + 1) -
473 lpfc_sli4_get_els_iocb_cnt(phba);
dea31012005-04-17 16:05:31 -0500474
475 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500476
477 /* Get the default values for Model Name and Description */
478 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
479
James Smart2e0fef82007-06-17 19:56:36 -0500480 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500481
James Smart0b727fe2007-10-27 13:37:25 -0400482 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smart7e56aa22012-08-03 12:35:34 -0400483 if (psli->ring[psli->extra_ring].sli.sli3.cmdringaddr)
James Smarta4bc3372006-12-02 13:34:16 -0500484 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
James Smart7e56aa22012-08-03 12:35:34 -0400485 if (psli->ring[psli->fcp_ring].sli.sli3.cmdringaddr)
dea31012005-04-17 16:05:31 -0500486 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
James Smart7e56aa22012-08-03 12:35:34 -0400487 if (psli->ring[psli->next_ring].sli.sli3.cmdringaddr)
dea31012005-04-17 16:05:31 -0500488 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
489
490 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500491 if (phba->sli_rev != 3)
492 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500493
James Smart93996272008-08-24 21:50:30 -0400494 /*
495 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
496 */
497 if (phba->intr_type == MSIX) {
498 rc = lpfc_config_msi(phba, pmb);
499 if (rc) {
500 mempool_free(pmb, phba->mbox_mem_pool);
501 return -EIO;
502 }
503 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
504 if (rc != MBX_SUCCESS) {
505 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
506 "0352 Config MSI mailbox command "
507 "failed, mbxCmd x%x, mbxStatus x%x\n",
James Smart04c68492009-05-22 14:52:52 -0400508 pmb->u.mb.mbxCommand,
509 pmb->u.mb.mbxStatus);
James Smart93996272008-08-24 21:50:30 -0400510 mempool_free(pmb, phba->mbox_mem_pool);
511 return -EIO;
512 }
513 }
514
James Smart04c68492009-05-22 14:52:52 -0400515 spin_lock_irq(&phba->hbalock);
James Smart93996272008-08-24 21:50:30 -0400516 /* Initialize ERATT handling flag */
517 phba->hba_flag &= ~HBA_ERATT_HANDLED;
518
dea31012005-04-17 16:05:31 -0500519 /* Enable appropriate host interrupts */
James Smart9940b972011-03-11 16:06:12 -0500520 if (lpfc_readl(phba->HCregaddr, &status)) {
521 spin_unlock_irq(&phba->hbalock);
522 return -EIO;
523 }
dea31012005-04-17 16:05:31 -0500524 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
525 if (psli->num_rings > 0)
526 status |= HC_R0INT_ENA;
527 if (psli->num_rings > 1)
528 status |= HC_R1INT_ENA;
529 if (psli->num_rings > 2)
530 status |= HC_R2INT_ENA;
531 if (psli->num_rings > 3)
532 status |= HC_R3INT_ENA;
533
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500534 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
535 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400536 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500537
dea31012005-04-17 16:05:31 -0500538 writel(status, phba->HCregaddr);
539 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500540 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500541
James Smart93996272008-08-24 21:50:30 -0400542 /* Set up ring-0 (ELS) timer */
543 timeout = phba->fc_ratov * 2;
James Smart2e0fef82007-06-17 19:56:36 -0500544 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
James Smart93996272008-08-24 21:50:30 -0400545 /* Set up heart beat (HB) timer */
James Smart858c9f62007-06-17 19:56:39 -0500546 mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
547 phba->hb_outstanding = 0;
548 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400549 /* Set up error attention (ERATT) polling timer */
550 mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
dea31012005-04-17 16:05:31 -0500551
James Smarta0c87cb2009-07-19 10:01:10 -0400552 if (phba->hba_flag & LINK_DISABLED) {
553 lpfc_printf_log(phba,
554 KERN_ERR, LOG_INIT,
555 "2598 Adapter Link is disabled.\n");
556 lpfc_down_link(phba, pmb);
557 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
558 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
559 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
560 lpfc_printf_log(phba,
561 KERN_ERR, LOG_INIT,
562 "2599 Adapter failed to issue DOWN_LINK"
563 " mbox command rc 0x%x\n", rc);
564
565 mempool_free(pmb, phba->mbox_mem_pool);
566 return -EIO;
567 }
James Smarte40a02c2010-02-26 14:13:54 -0500568 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
James Smart026abb82011-12-13 13:20:45 -0500569 mempool_free(pmb, phba->mbox_mem_pool);
570 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
571 if (rc)
572 return rc;
dea31012005-04-17 16:05:31 -0500573 }
574 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400575 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500576 if (!pmb) {
577 phba->link_state = LPFC_HBA_ERROR;
578 return -ENOMEM;
579 }
580
James Smart57127f12007-10-27 13:37:05 -0400581 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
582 pmb->mbox_cmpl = lpfc_config_async_cmpl;
583 pmb->vport = phba->pport;
584 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500585
James Smart57127f12007-10-27 13:37:05 -0400586 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
587 lpfc_printf_log(phba,
588 KERN_ERR,
589 LOG_INIT,
590 "0456 Adapter failed to issue "
James Smarte4e74272009-07-19 10:01:38 -0400591 "ASYNCEVT_ENABLE mbox status x%x\n",
James Smart57127f12007-10-27 13:37:05 -0400592 rc);
593 mempool_free(pmb, phba->mbox_mem_pool);
594 }
James Smart97207482008-12-04 22:39:19 -0500595
596 /* Get Option rom version */
597 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 Smart97207482008-12-04 22:39:19 -0500603 lpfc_dump_wakeup_param(phba, pmb);
604 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
605 pmb->vport = phba->pport;
606 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
607
608 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
609 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
James Smarte4e74272009-07-19 10:01:38 -0400610 "to get Option ROM version status x%x\n", rc);
James Smart97207482008-12-04 22:39:19 -0500611 mempool_free(pmb, phba->mbox_mem_pool);
612 }
613
James Smartd7c255b2008-08-24 21:50:00 -0400614 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400615}
616
James Smarte59058c2008-08-24 21:49:00 -0400617/**
James Smart84d1b002010-02-12 14:42:33 -0500618 * lpfc_hba_init_link - Initialize the FC link
619 * @phba: pointer to lpfc hba data structure.
James Smart6e7288d2010-06-07 15:23:35 -0400620 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500621 *
622 * This routine will issue the INIT_LINK mailbox command call.
623 * It is available to other drivers through the lpfc_hba data
624 * structure for use as a delayed link up mechanism with the
625 * module parameter lpfc_suppress_link_up.
626 *
627 * Return code
628 * 0 - success
629 * Any other value - error
630 **/
631int
James Smart6e7288d2010-06-07 15:23:35 -0400632lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500633{
James Smart1b511972011-12-13 13:23:09 -0500634 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
635}
636
637/**
638 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
639 * @phba: pointer to lpfc hba data structure.
640 * @fc_topology: desired fc topology.
641 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
642 *
643 * This routine will issue the INIT_LINK mailbox command call.
644 * It is available to other drivers through the lpfc_hba data
645 * structure for use as a delayed link up mechanism with the
646 * module parameter lpfc_suppress_link_up.
647 *
648 * Return code
649 * 0 - success
650 * Any other value - error
651 **/
652int
653lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
654 uint32_t flag)
655{
James Smart84d1b002010-02-12 14:42:33 -0500656 struct lpfc_vport *vport = phba->pport;
657 LPFC_MBOXQ_t *pmb;
658 MAILBOX_t *mb;
659 int rc;
660
661 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
662 if (!pmb) {
663 phba->link_state = LPFC_HBA_ERROR;
664 return -ENOMEM;
665 }
666 mb = &pmb->u.mb;
667 pmb->vport = vport;
668
James Smart026abb82011-12-13 13:20:45 -0500669 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
670 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
671 !(phba->lmt & LMT_1Gb)) ||
672 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
673 !(phba->lmt & LMT_2Gb)) ||
674 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
675 !(phba->lmt & LMT_4Gb)) ||
676 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
677 !(phba->lmt & LMT_8Gb)) ||
678 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
679 !(phba->lmt & LMT_10Gb)) ||
680 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
681 !(phba->lmt & LMT_16Gb))) {
682 /* Reset link speed to auto */
683 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
684 "1302 Invalid speed for this board:%d "
685 "Reset link speed to auto.\n",
686 phba->cfg_link_speed);
687 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
688 }
James Smart1b511972011-12-13 13:23:09 -0500689 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
James Smart84d1b002010-02-12 14:42:33 -0500690 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart1b511972011-12-13 13:23:09 -0500691 if (phba->sli_rev < LPFC_SLI_REV4)
692 lpfc_set_loopback_flag(phba);
James Smart6e7288d2010-06-07 15:23:35 -0400693 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart76a95d72010-11-20 23:11:48 -0500694 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
James Smart84d1b002010-02-12 14:42:33 -0500695 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
696 "0498 Adapter failed to init, mbxCmd x%x "
697 "INIT_LINK, mbxStatus x%x\n",
698 mb->mbxCommand, mb->mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -0500699 if (phba->sli_rev <= LPFC_SLI_REV3) {
700 /* Clear all interrupt enable conditions */
701 writel(0, phba->HCregaddr);
702 readl(phba->HCregaddr); /* flush */
703 /* Clear all pending interrupts */
704 writel(0xffffffff, phba->HAregaddr);
705 readl(phba->HAregaddr); /* flush */
706 }
James Smart84d1b002010-02-12 14:42:33 -0500707 phba->link_state = LPFC_HBA_ERROR;
James Smart6e7288d2010-06-07 15:23:35 -0400708 if (rc != MBX_BUSY || flag == MBX_POLL)
James Smart84d1b002010-02-12 14:42:33 -0500709 mempool_free(pmb, phba->mbox_mem_pool);
710 return -EIO;
711 }
James Smarte40a02c2010-02-26 14:13:54 -0500712 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
James Smart6e7288d2010-06-07 15:23:35 -0400713 if (flag == MBX_POLL)
714 mempool_free(pmb, phba->mbox_mem_pool);
James Smart84d1b002010-02-12 14:42:33 -0500715
716 return 0;
717}
718
719/**
720 * lpfc_hba_down_link - this routine downs the FC link
James Smart6e7288d2010-06-07 15:23:35 -0400721 * @phba: pointer to lpfc hba data structure.
722 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500723 *
724 * This routine will issue the DOWN_LINK mailbox command call.
725 * It is available to other drivers through the lpfc_hba data
726 * structure for use to stop the link.
727 *
728 * Return code
729 * 0 - success
730 * Any other value - error
731 **/
732int
James Smart6e7288d2010-06-07 15:23:35 -0400733lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500734{
735 LPFC_MBOXQ_t *pmb;
736 int rc;
737
738 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
739 if (!pmb) {
740 phba->link_state = LPFC_HBA_ERROR;
741 return -ENOMEM;
742 }
743
744 lpfc_printf_log(phba,
745 KERN_ERR, LOG_INIT,
746 "0491 Adapter Link is disabled.\n");
747 lpfc_down_link(phba, pmb);
748 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart6e7288d2010-06-07 15:23:35 -0400749 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart84d1b002010-02-12 14:42:33 -0500750 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
751 lpfc_printf_log(phba,
752 KERN_ERR, LOG_INIT,
753 "2522 Adapter failed to issue DOWN_LINK"
754 " mbox command rc 0x%x\n", rc);
755
756 mempool_free(pmb, phba->mbox_mem_pool);
757 return -EIO;
758 }
James Smart6e7288d2010-06-07 15:23:35 -0400759 if (flag == MBX_POLL)
760 mempool_free(pmb, phba->mbox_mem_pool);
761
James Smart84d1b002010-02-12 14:42:33 -0500762 return 0;
763}
764
765/**
James Smart3621a712009-04-06 18:47:14 -0400766 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400767 * @phba: pointer to lpfc HBA data structure.
768 *
769 * This routine will do LPFC uninitialization before the HBA is reset when
770 * bringing down the SLI Layer.
771 *
772 * Return codes
773 * 0 - success.
774 * Any other value - error.
775 **/
dea31012005-04-17 16:05:31 -0500776int
James Smart2e0fef82007-06-17 19:56:36 -0500777lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500778{
James Smart1b32f6a2008-02-08 18:49:39 -0500779 struct lpfc_vport **vports;
780 int i;
James Smart3772a992009-05-22 14:50:54 -0400781
782 if (phba->sli_rev <= LPFC_SLI_REV3) {
783 /* Disable interrupts */
784 writel(0, phba->HCregaddr);
785 readl(phba->HCregaddr); /* flush */
786 }
dea31012005-04-17 16:05:31 -0500787
James Smart1b32f6a2008-02-08 18:49:39 -0500788 if (phba->pport->load_flag & FC_UNLOADING)
789 lpfc_cleanup_discovery_resources(phba->pport);
790 else {
791 vports = lpfc_create_vport_work_array(phba);
792 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -0400793 for (i = 0; i <= phba->max_vports &&
794 vports[i] != NULL; i++)
James Smart1b32f6a2008-02-08 18:49:39 -0500795 lpfc_cleanup_discovery_resources(vports[i]);
796 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500797 }
798 return 0;
dea31012005-04-17 16:05:31 -0500799}
800
James Smarte59058c2008-08-24 21:49:00 -0400801/**
James Smart3772a992009-05-22 14:50:54 -0400802 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400803 * @phba: pointer to lpfc HBA data structure.
804 *
805 * This routine will do uninitialization after the HBA is reset when bring
806 * down the SLI Layer.
807 *
808 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200809 * 0 - success.
James Smarte59058c2008-08-24 21:49:00 -0400810 * Any other value - error.
811 **/
James Smart3772a992009-05-22 14:50:54 -0400812static int
813lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500814{
815 struct lpfc_sli *psli = &phba->sli;
816 struct lpfc_sli_ring *pring;
817 struct lpfc_dmabuf *mp, *next_mp;
James Smart09372822008-01-11 01:52:54 -0500818 LIST_HEAD(completions);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500819 int i;
820
James Smart92d7f7b2007-06-17 19:56:38 -0500821 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
822 lpfc_sli_hbqbuf_free_all(phba);
823 else {
824 /* Cleanup preposted buffers on the ELS ring */
825 pring = &psli->ring[LPFC_ELS_RING];
826 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
827 list_del(&mp->list);
828 pring->postbufq_cnt--;
829 lpfc_mbuf_free(phba, mp->virt, mp->phys);
830 kfree(mp);
831 }
Jamie Wellnitz41415862006-02-28 19:25:27 -0500832 }
833
James Smart09372822008-01-11 01:52:54 -0500834 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500835 for (i = 0; i < psli->num_rings; i++) {
836 pring = &psli->ring[i];
James Smart09372822008-01-11 01:52:54 -0500837
838 /* At this point in time the HBA is either reset or DOA. Either
839 * way, nothing should be on txcmplq as it will NEVER complete.
840 */
841 list_splice_init(&pring->txcmplq, &completions);
James Smart09372822008-01-11 01:52:54 -0500842 spin_unlock_irq(&phba->hbalock);
843
James Smarta257bf92009-04-06 18:48:10 -0400844 /* Cancel all the IOCBs from the completions list */
845 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
846 IOERR_SLI_ABORTED);
James Smart09372822008-01-11 01:52:54 -0500847
Jamie Wellnitz41415862006-02-28 19:25:27 -0500848 lpfc_sli_abort_iocb_ring(phba, pring);
James Smart09372822008-01-11 01:52:54 -0500849 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500850 }
James Smart09372822008-01-11 01:52:54 -0500851 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500852
853 return 0;
854}
James Smart5af5eee2010-10-22 11:06:38 -0400855
James Smartda0436e2009-05-22 14:51:39 -0400856/**
857 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
858 * @phba: pointer to lpfc HBA data structure.
859 *
860 * This routine will do uninitialization after the HBA is reset when bring
861 * down the SLI Layer.
862 *
863 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200864 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -0400865 * Any other value - error.
866 **/
867static int
868lpfc_hba_down_post_s4(struct lpfc_hba *phba)
869{
870 struct lpfc_scsi_buf *psb, *psb_next;
871 LIST_HEAD(aborts);
872 int ret;
873 unsigned long iflag = 0;
James Smart0f65ff62010-02-26 14:14:23 -0500874 struct lpfc_sglq *sglq_entry = NULL;
875
James Smartda0436e2009-05-22 14:51:39 -0400876 ret = lpfc_hba_down_post_s3(phba);
877 if (ret)
878 return ret;
879 /* At this point in time the HBA is either reset or DOA. Either
880 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
881 * on the lpfc_sgl_list so that it can either be freed if the
882 * driver is unloading or reposted if the driver is restarting
883 * the port.
884 */
885 spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */
886 /* scsl_buf_list */
887 /* abts_sgl_list_lock required because worker thread uses this
888 * list.
889 */
890 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -0500891 list_for_each_entry(sglq_entry,
892 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
893 sglq_entry->state = SGL_FREED;
894
James Smartda0436e2009-05-22 14:51:39 -0400895 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
896 &phba->sli4_hba.lpfc_sgl_list);
897 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
898 /* abts_scsi_buf_list_lock required because worker thread uses this
899 * list.
900 */
901 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
902 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
903 &aborts);
904 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
905 spin_unlock_irq(&phba->hbalock);
906
907 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
908 psb->pCmd = NULL;
909 psb->status = IOSTAT_SUCCESS;
910 }
911 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
912 list_splice(&aborts, &phba->lpfc_scsi_buf_list);
913 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
914 return 0;
915}
916
917/**
918 * lpfc_hba_down_post - Wrapper func for hba down post routine
919 * @phba: pointer to lpfc HBA data structure.
920 *
921 * This routine wraps the actual SLI3 or SLI4 routine for performing
922 * uninitialization after the HBA is reset when bring down the SLI Layer.
923 *
924 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200925 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -0400926 * Any other value - error.
927 **/
928int
929lpfc_hba_down_post(struct lpfc_hba *phba)
930{
931 return (*phba->lpfc_hba_down_post)(phba);
932}
Jamie Wellnitz41415862006-02-28 19:25:27 -0500933
James Smarte59058c2008-08-24 21:49:00 -0400934/**
James Smart3621a712009-04-06 18:47:14 -0400935 * lpfc_hb_timeout - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -0400936 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
937 *
938 * This is the HBA-timer timeout handler registered to the lpfc driver. When
939 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
940 * work-port-events bitmap and the worker thread is notified. This timeout
941 * event will be used by the worker thread to invoke the actual timeout
942 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
943 * be performed in the timeout handler and the HBA timeout event bit shall
944 * be cleared by the worker thread after it has taken the event bitmap out.
945 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +0100946static void
James Smart858c9f62007-06-17 19:56:39 -0500947lpfc_hb_timeout(unsigned long ptr)
948{
949 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -0400950 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -0500951 unsigned long iflag;
952
953 phba = (struct lpfc_hba *)ptr;
James Smart93996272008-08-24 21:50:30 -0400954
955 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -0500956 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -0400957 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
958 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -0500959 phba->pport->work_port_events |= WORKER_HB_TMO;
960 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
961
James Smart93996272008-08-24 21:50:30 -0400962 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -0400963 if (!tmo_posted)
964 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -0500965 return;
966}
967
James Smarte59058c2008-08-24 21:49:00 -0400968/**
James Smart19ca7602010-11-20 23:11:55 -0500969 * lpfc_rrq_timeout - The RRQ-timer timeout handler
970 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
971 *
972 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
973 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
974 * work-port-events bitmap and the worker thread is notified. This timeout
975 * event will be used by the worker thread to invoke the actual timeout
976 * handler routine, lpfc_rrq_handler. Any periodical operations will
977 * be performed in the timeout handler and the RRQ timeout event bit shall
978 * be cleared by the worker thread after it has taken the event bitmap out.
979 **/
980static void
981lpfc_rrq_timeout(unsigned long ptr)
982{
983 struct lpfc_hba *phba;
James Smart19ca7602010-11-20 23:11:55 -0500984 unsigned long iflag;
985
986 phba = (struct lpfc_hba *)ptr;
987 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart1151e3e2011-02-16 12:39:35 -0500988 phba->hba_flag |= HBA_RRQ_ACTIVE;
James Smart19ca7602010-11-20 23:11:55 -0500989 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
James Smart1151e3e2011-02-16 12:39:35 -0500990 lpfc_worker_wake_up(phba);
James Smart19ca7602010-11-20 23:11:55 -0500991}
992
993/**
James Smart3621a712009-04-06 18:47:14 -0400994 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -0400995 * @phba: pointer to lpfc hba data structure.
996 * @pmboxq: pointer to the driver internal queue element for mailbox command.
997 *
998 * This is the callback function to the lpfc heart-beat mailbox command.
999 * If configured, the lpfc driver issues the heart-beat mailbox command to
1000 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1001 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1002 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1003 * heart-beat outstanding state. Once the mailbox command comes back and
1004 * no error conditions detected, the heart-beat mailbox command timer is
1005 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1006 * state is cleared for the next heart-beat. If the timer expired with the
1007 * heart-beat outstanding state set, the driver will put the HBA offline.
1008 **/
James Smart858c9f62007-06-17 19:56:39 -05001009static void
1010lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1011{
1012 unsigned long drvr_flag;
1013
1014 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1015 phba->hb_outstanding = 0;
1016 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1017
James Smart93996272008-08-24 21:50:30 -04001018 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -05001019 mempool_free(pmboxq, phba->mbox_mem_pool);
1020 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1021 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -04001022 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -05001023 mod_timer(&phba->hb_tmofunc,
1024 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
1025 return;
1026}
1027
James Smarte59058c2008-08-24 21:49:00 -04001028/**
James Smart3621a712009-04-06 18:47:14 -04001029 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001030 * @phba: pointer to lpfc hba data structure.
1031 *
1032 * This is the actual HBA-timer timeout handler to be invoked by the worker
1033 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1034 * handler performs any periodic operations needed for the device. If such
1035 * periodic event has already been attended to either in the interrupt handler
1036 * or by processing slow-ring or fast-ring events within the HBA-timer
1037 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1038 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1039 * is configured and there is no heart-beat mailbox command outstanding, a
1040 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1041 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1042 * to offline.
1043 **/
James Smart858c9f62007-06-17 19:56:39 -05001044void
1045lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1046{
James Smart45ed1192009-10-02 15:17:02 -04001047 struct lpfc_vport **vports;
James Smart858c9f62007-06-17 19:56:39 -05001048 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -05001049 struct lpfc_dmabuf *buf_ptr;
James Smart45ed1192009-10-02 15:17:02 -04001050 int retval, i;
James Smart858c9f62007-06-17 19:56:39 -05001051 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -05001052 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -05001053
James Smart45ed1192009-10-02 15:17:02 -04001054 vports = lpfc_create_vport_work_array(phba);
1055 if (vports != NULL)
1056 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
1057 lpfc_rcv_seq_check_edtov(vports[i]);
1058 lpfc_destroy_vport_work_array(phba, vports);
1059
James Smart858c9f62007-06-17 19:56:39 -05001060 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -04001061 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -05001062 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1063 return;
1064
1065 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -05001066
1067 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
1068 jiffies)) {
1069 spin_unlock_irq(&phba->pport->work_port_lock);
1070 if (!phba->hb_outstanding)
1071 mod_timer(&phba->hb_tmofunc,
1072 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
1073 else
1074 mod_timer(&phba->hb_tmofunc,
1075 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
1076 return;
1077 }
1078 spin_unlock_irq(&phba->pport->work_port_lock);
1079
James Smart0ff10d42008-01-11 01:52:36 -05001080 if (phba->elsbuf_cnt &&
1081 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1082 spin_lock_irq(&phba->hbalock);
1083 list_splice_init(&phba->elsbuf, &completions);
1084 phba->elsbuf_cnt = 0;
1085 phba->elsbuf_prev_cnt = 0;
1086 spin_unlock_irq(&phba->hbalock);
1087
1088 while (!list_empty(&completions)) {
1089 list_remove_head(&completions, buf_ptr,
1090 struct lpfc_dmabuf, list);
1091 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1092 kfree(buf_ptr);
1093 }
1094 }
1095 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1096
James Smart858c9f62007-06-17 19:56:39 -05001097 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -05001098 if (phba->cfg_enable_hba_heartbeat) {
1099 if (!phba->hb_outstanding) {
James Smartbc739052010-08-04 16:11:18 -04001100 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1101 (list_empty(&psli->mboxq))) {
1102 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1103 GFP_KERNEL);
1104 if (!pmboxq) {
1105 mod_timer(&phba->hb_tmofunc,
1106 jiffies +
1107 HZ * LPFC_HB_MBOX_INTERVAL);
1108 return;
1109 }
James Smart13815c82008-01-11 01:52:48 -05001110
James Smartbc739052010-08-04 16:11:18 -04001111 lpfc_heart_beat(phba, pmboxq);
1112 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1113 pmboxq->vport = phba->pport;
1114 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1115 MBX_NOWAIT);
James Smart13815c82008-01-11 01:52:48 -05001116
James Smartbc739052010-08-04 16:11:18 -04001117 if (retval != MBX_BUSY &&
1118 retval != MBX_SUCCESS) {
1119 mempool_free(pmboxq,
1120 phba->mbox_mem_pool);
1121 mod_timer(&phba->hb_tmofunc,
1122 jiffies +
1123 HZ * LPFC_HB_MBOX_INTERVAL);
1124 return;
1125 }
1126 phba->skipped_hb = 0;
1127 phba->hb_outstanding = 1;
1128 } else if (time_before_eq(phba->last_completion_time,
1129 phba->skipped_hb)) {
1130 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1131 "2857 Last completion time not "
1132 " updated in %d ms\n",
1133 jiffies_to_msecs(jiffies
1134 - phba->last_completion_time));
1135 } else
1136 phba->skipped_hb = jiffies;
1137
James Smart858c9f62007-06-17 19:56:39 -05001138 mod_timer(&phba->hb_tmofunc,
James Smart13815c82008-01-11 01:52:48 -05001139 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
James Smart858c9f62007-06-17 19:56:39 -05001140 return;
James Smart13815c82008-01-11 01:52:48 -05001141 } else {
1142 /*
1143 * If heart beat timeout called with hb_outstanding set
James Smartdcf2a4e2010-09-29 11:18:53 -04001144 * we need to give the hb mailbox cmd a chance to
1145 * complete or TMO.
James Smart13815c82008-01-11 01:52:48 -05001146 */
James Smartdcf2a4e2010-09-29 11:18:53 -04001147 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1148 "0459 Adapter heartbeat still out"
1149 "standing:last compl time was %d ms.\n",
1150 jiffies_to_msecs(jiffies
1151 - phba->last_completion_time));
1152 mod_timer(&phba->hb_tmofunc,
1153 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
James Smart858c9f62007-06-17 19:56:39 -05001154 }
James Smart858c9f62007-06-17 19:56:39 -05001155 }
1156}
1157
James Smarte59058c2008-08-24 21:49:00 -04001158/**
James Smart3621a712009-04-06 18:47:14 -04001159 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -04001160 * @phba: pointer to lpfc hba data structure.
1161 *
1162 * This routine is called to bring the HBA offline when HBA hardware error
1163 * other than Port Error 6 has been detected.
1164 **/
James Smart09372822008-01-11 01:52:54 -05001165static void
1166lpfc_offline_eratt(struct lpfc_hba *phba)
1167{
1168 struct lpfc_sli *psli = &phba->sli;
1169
1170 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001171 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -05001172 spin_unlock_irq(&phba->hbalock);
James Smart618a5232012-06-12 13:54:36 -04001173 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart09372822008-01-11 01:52:54 -05001174
1175 lpfc_offline(phba);
1176 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001177 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001178 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001179 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001180 lpfc_hba_down_post(phba);
1181 lpfc_sli_brdready(phba, HS_MBRDY);
1182 lpfc_unblock_mgmt_io(phba);
1183 phba->link_state = LPFC_HBA_ERROR;
1184 return;
1185}
1186
James Smarte59058c2008-08-24 21:49:00 -04001187/**
James Smartda0436e2009-05-22 14:51:39 -04001188 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1189 * @phba: pointer to lpfc hba data structure.
1190 *
1191 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1192 * other than Port Error 6 has been detected.
1193 **/
1194static void
1195lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1196{
James Smart618a5232012-06-12 13:54:36 -04001197 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smartda0436e2009-05-22 14:51:39 -04001198 lpfc_offline(phba);
1199 lpfc_sli4_brdreset(phba);
1200 lpfc_hba_down_post(phba);
1201 lpfc_sli4_post_status_check(phba);
1202 lpfc_unblock_mgmt_io(phba);
1203 phba->link_state = LPFC_HBA_ERROR;
1204}
1205
1206/**
James Smarta257bf92009-04-06 18:48:10 -04001207 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1208 * @phba: pointer to lpfc hba data structure.
1209 *
1210 * This routine is invoked to handle the deferred HBA hardware error
1211 * conditions. This type of error is indicated by HBA by setting ER1
1212 * and another ER bit in the host status register. The driver will
1213 * wait until the ER1 bit clears before handling the error condition.
1214 **/
1215static void
1216lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1217{
1218 uint32_t old_host_status = phba->work_hs;
1219 struct lpfc_sli_ring *pring;
1220 struct lpfc_sli *psli = &phba->sli;
1221
James Smartf4b4c682009-05-22 14:53:12 -04001222 /* If the pci channel is offline, ignore possible errors,
1223 * since we cannot communicate with the pci card anyway.
1224 */
1225 if (pci_channel_offline(phba->pcidev)) {
1226 spin_lock_irq(&phba->hbalock);
1227 phba->hba_flag &= ~DEFER_ERATT;
1228 spin_unlock_irq(&phba->hbalock);
1229 return;
1230 }
1231
James Smarta257bf92009-04-06 18:48:10 -04001232 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1233 "0479 Deferred Adapter Hardware Error "
1234 "Data: x%x x%x x%x\n",
1235 phba->work_hs,
1236 phba->work_status[0], phba->work_status[1]);
1237
1238 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001239 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001240 spin_unlock_irq(&phba->hbalock);
1241
1242
1243 /*
1244 * Firmware stops when it triggred erratt. That could cause the I/Os
1245 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1246 * SCSI layer retry it after re-establishing link.
1247 */
1248 pring = &psli->ring[psli->fcp_ring];
1249 lpfc_sli_abort_iocb_ring(phba, pring);
1250
1251 /*
1252 * There was a firmware error. Take the hba offline and then
1253 * attempt to restart it.
1254 */
James Smart618a5232012-06-12 13:54:36 -04001255 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smarta257bf92009-04-06 18:48:10 -04001256 lpfc_offline(phba);
1257
1258 /* Wait for the ER1 bit to clear.*/
1259 while (phba->work_hs & HS_FFER1) {
1260 msleep(100);
James Smart9940b972011-03-11 16:06:12 -05001261 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1262 phba->work_hs = UNPLUG_ERR ;
1263 break;
1264 }
James Smarta257bf92009-04-06 18:48:10 -04001265 /* If driver is unloading let the worker thread continue */
1266 if (phba->pport->load_flag & FC_UNLOADING) {
1267 phba->work_hs = 0;
1268 break;
1269 }
1270 }
1271
1272 /*
1273 * This is to ptrotect against a race condition in which
1274 * first write to the host attention register clear the
1275 * host status register.
1276 */
1277 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1278 phba->work_hs = old_host_status & ~HS_FFER1;
1279
James Smart3772a992009-05-22 14:50:54 -04001280 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001281 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001282 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001283 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1284 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1285}
1286
James Smart3772a992009-05-22 14:50:54 -04001287static void
1288lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1289{
1290 struct lpfc_board_event_header board_event;
1291 struct Scsi_Host *shost;
1292
1293 board_event.event_type = FC_REG_BOARD_EVENT;
1294 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1295 shost = lpfc_shost_from_vport(phba->pport);
1296 fc_host_post_vendor_event(shost, fc_get_event_number(),
1297 sizeof(board_event),
1298 (char *) &board_event,
1299 LPFC_NL_VENDOR_ID);
1300}
1301
James Smarta257bf92009-04-06 18:48:10 -04001302/**
James Smart3772a992009-05-22 14:50:54 -04001303 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001304 * @phba: pointer to lpfc hba data structure.
1305 *
1306 * This routine is invoked to handle the following HBA hardware error
1307 * conditions:
1308 * 1 - HBA error attention interrupt
1309 * 2 - DMA ring index out of range
1310 * 3 - Mailbox command came back as unknown
1311 **/
James Smart3772a992009-05-22 14:50:54 -04001312static void
1313lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001314{
James Smart2e0fef82007-06-17 19:56:36 -05001315 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001316 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001317 struct lpfc_sli_ring *pring;
James Smartd2873e42006-08-18 17:46:43 -04001318 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001319 unsigned long temperature;
1320 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001321 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001322
Linas Vepstas8d63f372007-02-14 14:28:36 -06001323 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001324 * since we cannot communicate with the pci card anyway.
1325 */
1326 if (pci_channel_offline(phba->pcidev)) {
1327 spin_lock_irq(&phba->hbalock);
1328 phba->hba_flag &= ~DEFER_ERATT;
1329 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001330 return;
James Smart3772a992009-05-22 14:50:54 -04001331 }
1332
James Smart13815c82008-01-11 01:52:48 -05001333 /* If resets are disabled then leave the HBA alone and return */
1334 if (!phba->cfg_enable_hba_reset)
1335 return;
dea31012005-04-17 16:05:31 -05001336
James Smartea2151b2008-09-07 11:52:10 -04001337 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001338 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001339
James Smarta257bf92009-04-06 18:48:10 -04001340 if (phba->hba_flag & DEFER_ERATT)
1341 lpfc_handle_deferred_eratt(phba);
1342
James Smartdcf2a4e2010-09-29 11:18:53 -04001343 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1344 if (phba->work_hs & HS_FFER6)
1345 /* Re-establishing Link */
1346 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1347 "1301 Re-establishing Link "
1348 "Data: x%x x%x x%x\n",
1349 phba->work_hs, phba->work_status[0],
1350 phba->work_status[1]);
1351 if (phba->work_hs & HS_FFER8)
1352 /* Device Zeroization */
1353 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1354 "2861 Host Authentication device "
1355 "zeroization Data:x%x x%x x%x\n",
1356 phba->work_hs, phba->work_status[0],
1357 phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001358
James Smart92d7f7b2007-06-17 19:56:38 -05001359 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001360 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001361 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001362
1363 /*
1364 * Firmware stops when it triggled erratt with HS_FFER6.
1365 * That could cause the I/Os dropped by the firmware.
1366 * Error iocb (I/O) on txcmplq and let the SCSI layer
1367 * retry it after re-establishing link.
1368 */
1369 pring = &psli->ring[psli->fcp_ring];
1370 lpfc_sli_abort_iocb_ring(phba, pring);
1371
dea31012005-04-17 16:05:31 -05001372 /*
1373 * There was a firmware error. Take the hba offline and then
1374 * attempt to restart it.
1375 */
James Smart618a5232012-06-12 13:54:36 -04001376 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
dea31012005-04-17 16:05:31 -05001377 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001378 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001379 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001380 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001381 return;
1382 }
James Smart46fa3112007-04-25 09:51:45 -04001383 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001384 } else if (phba->work_hs & HS_CRIT_TEMP) {
1385 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1386 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1387 temp_event_data.event_code = LPFC_CRIT_TEMP;
1388 temp_event_data.data = (uint32_t)temperature;
1389
1390 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001391 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001392 "(%ld), taking this port offline "
1393 "Data: x%x x%x x%x\n",
1394 temperature, phba->work_hs,
1395 phba->work_status[0], phba->work_status[1]);
1396
1397 shost = lpfc_shost_from_vport(phba->pport);
1398 fc_host_post_vendor_event(shost, fc_get_event_number(),
1399 sizeof(temp_event_data),
1400 (char *) &temp_event_data,
1401 SCSI_NL_VID_TYPE_PCI
1402 | PCI_VENDOR_ID_EMULEX);
1403
James Smart7af67052007-10-27 13:38:11 -04001404 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001405 phba->over_temp_state = HBA_OVER_TEMP;
1406 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001407 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001408
dea31012005-04-17 16:05:31 -05001409 } else {
1410 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001411 * failure is a value other than FFER6. Do not call the offline
1412 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001413 */
1414 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001415 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001416 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001417 phba->work_hs,
dea31012005-04-17 16:05:31 -05001418 phba->work_status[0], phba->work_status[1]);
1419
James Smartd2873e42006-08-18 17:46:43 -04001420 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001421 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001422 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001423 sizeof(event_data), (char *) &event_data,
1424 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1425
James Smart09372822008-01-11 01:52:54 -05001426 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001427 }
James Smart93996272008-08-24 21:50:30 -04001428 return;
dea31012005-04-17 16:05:31 -05001429}
1430
James Smarte59058c2008-08-24 21:49:00 -04001431/**
James Smart618a5232012-06-12 13:54:36 -04001432 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1433 * @phba: pointer to lpfc hba data structure.
1434 * @mbx_action: flag for mailbox shutdown action.
1435 *
1436 * This routine is invoked to perform an SLI4 port PCI function reset in
1437 * response to port status register polling attention. It waits for port
1438 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1439 * During this process, interrupt vectors are freed and later requested
1440 * for handling possible port resource change.
1441 **/
1442static int
1443lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action)
1444{
1445 int rc;
1446 uint32_t intr_mode;
1447
1448 /*
1449 * On error status condition, driver need to wait for port
1450 * ready before performing reset.
1451 */
1452 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1453 if (!rc) {
1454 /* need reset: attempt for port recovery */
1455 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1456 "2887 Reset Needed: Attempting Port "
1457 "Recovery...\n");
1458 lpfc_offline_prep(phba, mbx_action);
1459 lpfc_offline(phba);
1460 /* release interrupt for possible resource change */
1461 lpfc_sli4_disable_intr(phba);
1462 lpfc_sli_brdrestart(phba);
1463 /* request and enable interrupt */
1464 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1465 if (intr_mode == LPFC_INTR_ERROR) {
1466 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1467 "3175 Failed to enable interrupt\n");
1468 return -EIO;
1469 } else {
1470 phba->intr_mode = intr_mode;
1471 }
1472 rc = lpfc_online(phba);
1473 if (rc == 0)
1474 lpfc_unblock_mgmt_io(phba);
1475 }
1476 return rc;
1477}
1478
1479/**
James Smartda0436e2009-05-22 14:51:39 -04001480 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1481 * @phba: pointer to lpfc hba data structure.
1482 *
1483 * This routine is invoked to handle the SLI4 HBA hardware error attention
1484 * conditions.
1485 **/
1486static void
1487lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1488{
1489 struct lpfc_vport *vport = phba->pport;
1490 uint32_t event_data;
1491 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001492 uint32_t if_type;
James Smart2e90f4b2011-12-13 13:22:37 -05001493 struct lpfc_register portstat_reg = {0};
1494 uint32_t reg_err1, reg_err2;
1495 uint32_t uerrlo_reg, uemasklo_reg;
1496 uint32_t pci_rd_rc1, pci_rd_rc2;
James Smart73d91e52011-10-10 21:32:10 -04001497 int rc;
James Smartda0436e2009-05-22 14:51:39 -04001498
1499 /* If the pci channel is offline, ignore possible errors, since
1500 * we cannot communicate with the pci card anyway.
1501 */
1502 if (pci_channel_offline(phba->pcidev))
1503 return;
1504 /* If resets are disabled then leave the HBA alone and return */
1505 if (!phba->cfg_enable_hba_reset)
1506 return;
1507
James Smart2fcee4b2010-12-15 17:57:46 -05001508 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1509 switch (if_type) {
1510 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart2e90f4b2011-12-13 13:22:37 -05001511 pci_rd_rc1 = lpfc_readl(
1512 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1513 &uerrlo_reg);
1514 pci_rd_rc2 = lpfc_readl(
1515 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1516 &uemasklo_reg);
1517 /* consider PCI bus read error as pci_channel_offline */
1518 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1519 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001520 lpfc_sli4_offline_eratt(phba);
1521 break;
1522 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2e90f4b2011-12-13 13:22:37 -05001523 pci_rd_rc1 = lpfc_readl(
1524 phba->sli4_hba.u.if_type2.STATUSregaddr,
1525 &portstat_reg.word0);
1526 /* consider PCI bus read error as pci_channel_offline */
James Smart6b5151f2012-01-18 16:24:06 -05001527 if (pci_rd_rc1 == -EIO) {
1528 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1529 "3151 PCI bus read access failure: x%x\n",
1530 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
James Smart2e90f4b2011-12-13 13:22:37 -05001531 return;
James Smart6b5151f2012-01-18 16:24:06 -05001532 }
James Smart2e90f4b2011-12-13 13:22:37 -05001533 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1534 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
James Smart2fcee4b2010-12-15 17:57:46 -05001535 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
1536 /* TODO: Register for Overtemp async events. */
1537 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1538 "2889 Port Overtemperature event, "
James Smart026abb82011-12-13 13:20:45 -05001539 "taking port offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05001540 spin_lock_irq(&phba->hbalock);
1541 phba->over_temp_state = HBA_OVER_TEMP;
1542 spin_unlock_irq(&phba->hbalock);
1543 lpfc_sli4_offline_eratt(phba);
James Smart2e90f4b2011-12-13 13:22:37 -05001544 break;
James Smart2fcee4b2010-12-15 17:57:46 -05001545 }
James Smart2e90f4b2011-12-13 13:22:37 -05001546 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1547 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART)
1548 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1549 "3143 Port Down: Firmware Restarted\n");
1550 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1551 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1552 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1553 "3144 Port Down: Debug Dump\n");
1554 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1555 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1556 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1557 "3145 Port Down: Provisioning\n");
James Smart618a5232012-06-12 13:54:36 -04001558
1559 /* Check port status register for function reset */
1560 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT);
1561 if (rc == 0) {
1562 /* don't report event on forced debug dump */
1563 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1564 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1565 return;
1566 else
1567 break;
James Smart2fcee4b2010-12-15 17:57:46 -05001568 }
James Smart618a5232012-06-12 13:54:36 -04001569 /* fall through for not able to recover */
James Smart6b5151f2012-01-18 16:24:06 -05001570 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1571 "3152 Unrecoverable error, bring the port "
1572 "offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05001573 lpfc_sli4_offline_eratt(phba);
1574 break;
1575 case LPFC_SLI_INTF_IF_TYPE_1:
1576 default:
1577 break;
1578 }
James Smart2e90f4b2011-12-13 13:22:37 -05001579 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1580 "3123 Report dump event to upper layer\n");
1581 /* Send an internal error event to mgmt application */
1582 lpfc_board_errevt_to_mgmt(phba);
1583
1584 event_data = FC_REG_DUMP_EVENT;
1585 shost = lpfc_shost_from_vport(vport);
1586 fc_host_post_vendor_event(shost, fc_get_event_number(),
1587 sizeof(event_data), (char *) &event_data,
1588 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
James Smartda0436e2009-05-22 14:51:39 -04001589}
1590
1591/**
1592 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1593 * @phba: pointer to lpfc HBA data structure.
1594 *
1595 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1596 * routine from the API jump table function pointer from the lpfc_hba struct.
1597 *
1598 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001599 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001600 * Any other value - error.
1601 **/
1602void
1603lpfc_handle_eratt(struct lpfc_hba *phba)
1604{
1605 (*phba->lpfc_handle_eratt)(phba);
1606}
1607
1608/**
James Smart3621a712009-04-06 18:47:14 -04001609 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04001610 * @phba: pointer to lpfc hba data structure.
1611 *
1612 * This routine is invoked from the worker thread to handle a HBA host
1613 * attention link event.
1614 **/
dea31012005-04-17 16:05:31 -05001615void
James Smart2e0fef82007-06-17 19:56:36 -05001616lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001617{
James Smart2e0fef82007-06-17 19:56:36 -05001618 struct lpfc_vport *vport = phba->pport;
1619 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001620 LPFC_MBOXQ_t *pmb;
1621 volatile uint32_t control;
1622 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05001623 int rc = 0;
dea31012005-04-17 16:05:31 -05001624
1625 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001626 if (!pmb) {
1627 rc = 1;
dea31012005-04-17 16:05:31 -05001628 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05001629 }
dea31012005-04-17 16:05:31 -05001630
1631 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001632 if (!mp) {
1633 rc = 2;
dea31012005-04-17 16:05:31 -05001634 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05001635 }
dea31012005-04-17 16:05:31 -05001636
1637 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05001638 if (!mp->virt) {
1639 rc = 3;
dea31012005-04-17 16:05:31 -05001640 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05001641 }
dea31012005-04-17 16:05:31 -05001642
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001643 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04001644 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05001645
1646 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05001647 lpfc_read_topology(phba, pmb, mp);
1648 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05001649 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04001650 /* Block ELS IOCBs until we have processed this mbox command */
1651 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04001652 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05001653 if (rc == MBX_NOT_FINISHED) {
1654 rc = 4;
James Smart14691152006-12-02 13:34:28 -05001655 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05001656 }
dea31012005-04-17 16:05:31 -05001657
1658 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05001659 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001660 writel(HA_LATT, phba->HAregaddr);
1661 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001662 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001663
1664 return;
1665
James Smart14691152006-12-02 13:34:28 -05001666lpfc_handle_latt_free_mbuf:
James Smart0d2b6b82008-06-14 22:52:47 -04001667 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05001668 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05001669lpfc_handle_latt_free_mp:
1670 kfree(mp);
1671lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04001672 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001673lpfc_handle_latt_err_exit:
1674 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001675 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001676 psli->sli_flag |= LPFC_PROCESS_LA;
1677 control = readl(phba->HCregaddr);
1678 control |= HC_LAINT_ENA;
1679 writel(control, phba->HCregaddr);
1680 readl(phba->HCregaddr); /* flush */
1681
1682 /* Clear Link Attention in HA REG */
1683 writel(HA_LATT, phba->HAregaddr);
1684 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001685 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001686 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001687 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001688
James Smart09372822008-01-11 01:52:54 -05001689 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1690 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05001691
1692 return;
1693}
1694
James Smarte59058c2008-08-24 21:49:00 -04001695/**
James Smart3621a712009-04-06 18:47:14 -04001696 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04001697 * @phba: pointer to lpfc hba data structure.
1698 * @vpd: pointer to the vital product data.
1699 * @len: length of the vital product data in bytes.
1700 *
1701 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1702 * an array of characters. In this routine, the ModelName, ProgramType, and
1703 * ModelDesc, etc. fields of the phba data structure will be populated.
1704 *
1705 * Return codes
1706 * 0 - pointer to the VPD passed in is NULL
1707 * 1 - success
1708 **/
James Smart3772a992009-05-22 14:50:54 -04001709int
James Smart2e0fef82007-06-17 19:56:36 -05001710lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05001711{
1712 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05001713 int Length;
dea31012005-04-17 16:05:31 -05001714 int i, j;
1715 int finished = 0;
1716 int index = 0;
1717
1718 if (!vpd)
1719 return 0;
1720
1721 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05001722 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001723 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001724 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
1725 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001726 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05001727 switch (vpd[index]) {
1728 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001729 case 0x91:
dea31012005-04-17 16:05:31 -05001730 index += 1;
1731 lenlo = vpd[index];
1732 index += 1;
1733 lenhi = vpd[index];
1734 index += 1;
1735 i = ((((unsigned short)lenhi) << 8) + lenlo);
1736 index += i;
1737 break;
1738 case 0x90:
1739 index += 1;
1740 lenlo = vpd[index];
1741 index += 1;
1742 lenhi = vpd[index];
1743 index += 1;
1744 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001745 if (Length > len - index)
1746 Length = len - index;
dea31012005-04-17 16:05:31 -05001747 while (Length > 0) {
1748 /* Look for Serial Number */
1749 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
1750 index += 2;
1751 i = vpd[index];
1752 index += 1;
1753 j = 0;
1754 Length -= (3+i);
1755 while(i--) {
1756 phba->SerialNumber[j++] = vpd[index++];
1757 if (j == 31)
1758 break;
1759 }
1760 phba->SerialNumber[j] = 0;
1761 continue;
1762 }
1763 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
1764 phba->vpd_flag |= VPD_MODEL_DESC;
1765 index += 2;
1766 i = vpd[index];
1767 index += 1;
1768 j = 0;
1769 Length -= (3+i);
1770 while(i--) {
1771 phba->ModelDesc[j++] = vpd[index++];
1772 if (j == 255)
1773 break;
1774 }
1775 phba->ModelDesc[j] = 0;
1776 continue;
1777 }
1778 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
1779 phba->vpd_flag |= VPD_MODEL_NAME;
1780 index += 2;
1781 i = vpd[index];
1782 index += 1;
1783 j = 0;
1784 Length -= (3+i);
1785 while(i--) {
1786 phba->ModelName[j++] = vpd[index++];
1787 if (j == 79)
1788 break;
1789 }
1790 phba->ModelName[j] = 0;
1791 continue;
1792 }
1793 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
1794 phba->vpd_flag |= VPD_PROGRAM_TYPE;
1795 index += 2;
1796 i = vpd[index];
1797 index += 1;
1798 j = 0;
1799 Length -= (3+i);
1800 while(i--) {
1801 phba->ProgramType[j++] = vpd[index++];
1802 if (j == 255)
1803 break;
1804 }
1805 phba->ProgramType[j] = 0;
1806 continue;
1807 }
1808 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1809 phba->vpd_flag |= VPD_PORT;
1810 index += 2;
1811 i = vpd[index];
1812 index += 1;
1813 j = 0;
1814 Length -= (3+i);
1815 while(i--) {
James Smartcd1c8302011-10-10 21:33:25 -04001816 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1817 (phba->sli4_hba.pport_name_sta ==
1818 LPFC_SLI4_PPNAME_GET)) {
1819 j++;
1820 index++;
1821 } else
1822 phba->Port[j++] = vpd[index++];
1823 if (j == 19)
1824 break;
dea31012005-04-17 16:05:31 -05001825 }
James Smartcd1c8302011-10-10 21:33:25 -04001826 if ((phba->sli_rev != LPFC_SLI_REV4) ||
1827 (phba->sli4_hba.pport_name_sta ==
1828 LPFC_SLI4_PPNAME_NON))
1829 phba->Port[j] = 0;
dea31012005-04-17 16:05:31 -05001830 continue;
1831 }
1832 else {
1833 index += 2;
1834 i = vpd[index];
1835 index += 1;
1836 index += i;
1837 Length -= (3 + i);
1838 }
1839 }
1840 finished = 0;
1841 break;
1842 case 0x78:
1843 finished = 1;
1844 break;
1845 default:
1846 index ++;
1847 break;
1848 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001849 }
dea31012005-04-17 16:05:31 -05001850
1851 return(1);
1852}
1853
James Smarte59058c2008-08-24 21:49:00 -04001854/**
James Smart3621a712009-04-06 18:47:14 -04001855 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04001856 * @phba: pointer to lpfc hba data structure.
1857 * @mdp: pointer to the data structure to hold the derived model name.
1858 * @descp: pointer to the data structure to hold the derived description.
1859 *
1860 * This routine retrieves HBA's description based on its registered PCI device
1861 * ID. The @descp passed into this function points to an array of 256 chars. It
1862 * shall be returned with the model name, maximum speed, and the host bus type.
1863 * The @mdp passed into this function points to an array of 80 chars. When the
1864 * function returns, the @mdp will be filled with the model name.
1865 **/
dea31012005-04-17 16:05:31 -05001866static void
James Smart2e0fef82007-06-17 19:56:36 -05001867lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05001868{
1869 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05001870 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001871 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04001872 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04001873 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001874 struct {
James Smarta747c9c2009-11-18 15:41:10 -05001875 char *name;
1876 char *bus;
1877 char *function;
1878 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001879
1880 if (mdp && mdp[0] != '\0'
1881 && descp && descp[0] != '\0')
1882 return;
1883
James Smartc0c11512011-05-24 11:41:34 -04001884 if (phba->lmt & LMT_16Gb)
1885 max_speed = 16;
1886 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001887 max_speed = 10;
1888 else if (phba->lmt & LMT_8Gb)
1889 max_speed = 8;
1890 else if (phba->lmt & LMT_4Gb)
1891 max_speed = 4;
1892 else if (phba->lmt & LMT_2Gb)
1893 max_speed = 2;
James Smart4169d862012-09-29 11:32:09 -04001894 else if (phba->lmt & LMT_1Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001895 max_speed = 1;
James Smart4169d862012-09-29 11:32:09 -04001896 else
1897 max_speed = 0;
dea31012005-04-17 16:05:31 -05001898
1899 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05001900
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001901 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001902 case PCI_DEVICE_ID_FIREFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001903 m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001904 break;
dea31012005-04-17 16:05:31 -05001905 case PCI_DEVICE_ID_SUPERFLY:
1906 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smarta747c9c2009-11-18 15:41:10 -05001907 m = (typeof(m)){"LP7000", "PCI",
1908 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001909 else
James Smarta747c9c2009-11-18 15:41:10 -05001910 m = (typeof(m)){"LP7000E", "PCI",
1911 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001912 break;
1913 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001914 m = (typeof(m)){"LP8000", "PCI",
1915 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001916 break;
1917 case PCI_DEVICE_ID_CENTAUR:
1918 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smarta747c9c2009-11-18 15:41:10 -05001919 m = (typeof(m)){"LP9002", "PCI",
1920 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001921 else
James Smarta747c9c2009-11-18 15:41:10 -05001922 m = (typeof(m)){"LP9000", "PCI",
1923 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001924 break;
1925 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001926 m = (typeof(m)){"LP952", "PCI",
1927 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001928 break;
1929 case PCI_DEVICE_ID_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05001930 m = (typeof(m)){"LP9802", "PCI-X",
1931 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001932 break;
1933 case PCI_DEVICE_ID_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05001934 m = (typeof(m)){"LP10000", "PCI-X",
1935 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001936 break;
1937 case PCI_DEVICE_ID_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05001938 m = (typeof(m)){"LPX1000", "PCI-X",
1939 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001940 break;
1941 case PCI_DEVICE_ID_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001942 m = (typeof(m)){"LP982", "PCI-X",
1943 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001944 break;
1945 case PCI_DEVICE_ID_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001946 m = (typeof(m)){"LP1050", "PCI-X",
1947 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001948 break;
1949 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05001950 m = (typeof(m)){"LP11000", "PCI-X2",
1951 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001952 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001953 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001954 m = (typeof(m)){"LP11000-SP", "PCI-X2",
1955 "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001956 break;
1957 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001958 m = (typeof(m)){"LP11002-SP", "PCI-X2",
1959 "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001960 break;
1961 case PCI_DEVICE_ID_NEPTUNE:
James Smarta747c9c2009-11-18 15:41:10 -05001962 m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001963 break;
1964 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001965 m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001966 break;
1967 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001968 m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001969 break;
dea31012005-04-17 16:05:31 -05001970 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05001971 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001972 break;
1973 case PCI_DEVICE_ID_BSMB:
James Smarta747c9c2009-11-18 15:41:10 -05001974 m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001975 break;
1976 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05001977 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001978 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001979 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001980 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001981 break;
1982 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001983 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04001984 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001985 break;
dea31012005-04-17 16:05:31 -05001986 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05001987 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001988 break;
1989 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05001990 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001991 break;
1992 case PCI_DEVICE_ID_LP101:
James Smarta747c9c2009-11-18 15:41:10 -05001993 m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001994 break;
1995 case PCI_DEVICE_ID_LP10000S:
James Smarta747c9c2009-11-18 15:41:10 -05001996 m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001997 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001998 case PCI_DEVICE_ID_LP11000S:
James Smarta747c9c2009-11-18 15:41:10 -05001999 m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05002000 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002001 case PCI_DEVICE_ID_LPE11000S:
James Smarta747c9c2009-11-18 15:41:10 -05002002 m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002003 break;
James Smartb87eab32007-04-25 09:53:28 -04002004 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05002005 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002006 break;
2007 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05002008 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002009 break;
2010 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05002011 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002012 break;
2013 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002014 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002015 break;
2016 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002017 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002018 break;
2019 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05002020 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002021 break;
James Smart84774a42008-08-24 21:50:06 -04002022 case PCI_DEVICE_ID_HORNET:
James Smarta747c9c2009-11-18 15:41:10 -05002023 m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002024 GE = 1;
2025 break;
2026 case PCI_DEVICE_ID_PROTEUS_VF:
James Smarta747c9c2009-11-18 15:41:10 -05002027 m = (typeof(m)){"LPev12000", "PCIe IOV",
2028 "Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002029 break;
2030 case PCI_DEVICE_ID_PROTEUS_PF:
James Smarta747c9c2009-11-18 15:41:10 -05002031 m = (typeof(m)){"LPev12000", "PCIe IOV",
2032 "Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002033 break;
2034 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05002035 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
2036 "Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002037 break;
James Smartda0436e2009-05-22 14:51:39 -04002038 case PCI_DEVICE_ID_TIGERSHARK:
2039 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002040 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04002041 break;
James Smarta747c9c2009-11-18 15:41:10 -05002042 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04002043 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002044 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2045 break;
2046 case PCI_DEVICE_ID_FALCON:
2047 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2048 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04002049 break;
James Smart98fc5dd2010-06-07 15:24:29 -04002050 case PCI_DEVICE_ID_BALIUS:
2051 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
2052 "Fibre Channel Adapter"};
2053 break;
James Smart085c6472010-11-20 23:11:37 -05002054 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04002055 case PCI_DEVICE_ID_LANCER_FC_VF:
2056 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05002057 break;
2058 case PCI_DEVICE_ID_LANCER_FCOE:
James Smartc0c11512011-05-24 11:41:34 -04002059 case PCI_DEVICE_ID_LANCER_FCOE_VF:
James Smart085c6472010-11-20 23:11:37 -05002060 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04002061 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05002062 break;
James Smartf8cafd32012-08-03 12:42:51 -04002063 case PCI_DEVICE_ID_SKYHAWK:
2064 case PCI_DEVICE_ID_SKYHAWK_VF:
2065 oneConnect = 1;
2066 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2067 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002068 default:
James Smarta747c9c2009-11-18 15:41:10 -05002069 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002070 break;
dea31012005-04-17 16:05:31 -05002071 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002072
2073 if (mdp && mdp[0] == '\0')
2074 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04002075 /*
2076 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04002077 * and we put the port number on the end
2078 */
2079 if (descp && descp[0] == '\0') {
2080 if (oneConnect)
2081 snprintf(descp, 255,
James Smart4169d862012-09-29 11:32:09 -04002082 "Emulex OneConnect %s, %s Initiator %s",
James Smarta747c9c2009-11-18 15:41:10 -05002083 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04002084 phba->Port);
James Smart4169d862012-09-29 11:32:09 -04002085 else if (max_speed == 0)
2086 snprintf(descp, 255,
2087 "Emulex %s %s %s ",
2088 m.name, m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002089 else
2090 snprintf(descp, 255,
2091 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05002092 m.name, max_speed, (GE) ? "GE" : "Gb",
2093 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002094 }
dea31012005-04-17 16:05:31 -05002095}
2096
James Smarte59058c2008-08-24 21:49:00 -04002097/**
James Smart3621a712009-04-06 18:47:14 -04002098 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04002099 * @phba: pointer to lpfc hba data structure.
2100 * @pring: pointer to a IOCB ring.
2101 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2102 *
2103 * This routine posts a given number of IOCBs with the associated DMA buffer
2104 * descriptors specified by the cnt argument to the given IOCB ring.
2105 *
2106 * Return codes
2107 * The number of IOCBs NOT able to be posted to the IOCB ring.
2108 **/
dea31012005-04-17 16:05:31 -05002109int
James Smart495a7142008-06-14 22:52:59 -04002110lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002111{
2112 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002113 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002114 struct lpfc_dmabuf *mp1, *mp2;
2115
2116 cnt += pring->missbufcnt;
2117
2118 /* While there are buffers to post */
2119 while (cnt > 0) {
2120 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002121 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002122 if (iocb == NULL) {
2123 pring->missbufcnt = cnt;
2124 return cnt;
2125 }
dea31012005-04-17 16:05:31 -05002126 icmd = &iocb->iocb;
2127
2128 /* 2 buffers can be posted per command */
2129 /* Allocate buffer to post */
2130 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2131 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002132 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2133 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002134 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002135 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002136 pring->missbufcnt = cnt;
2137 return cnt;
2138 }
2139
2140 INIT_LIST_HEAD(&mp1->list);
2141 /* Allocate buffer to post */
2142 if (cnt > 1) {
2143 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2144 if (mp2)
2145 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2146 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002147 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002148 kfree(mp2);
dea31012005-04-17 16:05:31 -05002149 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2150 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002151 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002152 pring->missbufcnt = cnt;
2153 return cnt;
2154 }
2155
2156 INIT_LIST_HEAD(&mp2->list);
2157 } else {
2158 mp2 = NULL;
2159 }
2160
2161 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2162 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2163 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2164 icmd->ulpBdeCount = 1;
2165 cnt--;
2166 if (mp2) {
2167 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2168 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2169 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2170 cnt--;
2171 icmd->ulpBdeCount = 2;
2172 }
2173
2174 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2175 icmd->ulpLe = 1;
2176
James Smart3772a992009-05-22 14:50:54 -04002177 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2178 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002179 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2180 kfree(mp1);
2181 cnt++;
2182 if (mp2) {
2183 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2184 kfree(mp2);
2185 cnt++;
2186 }
James Bottomley604a3e32005-10-29 10:28:33 -05002187 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002188 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002189 return cnt;
2190 }
dea31012005-04-17 16:05:31 -05002191 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002192 if (mp2)
dea31012005-04-17 16:05:31 -05002193 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002194 }
2195 pring->missbufcnt = 0;
2196 return 0;
2197}
2198
James Smarte59058c2008-08-24 21:49:00 -04002199/**
James Smart3621a712009-04-06 18:47:14 -04002200 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002201 * @phba: pointer to lpfc hba data structure.
2202 *
2203 * This routine posts initial receive IOCB buffers to the ELS ring. The
2204 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2205 * set to 64 IOCBs.
2206 *
2207 * Return codes
2208 * 0 - success (currently always success)
2209 **/
dea31012005-04-17 16:05:31 -05002210static int
James Smart2e0fef82007-06-17 19:56:36 -05002211lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002212{
2213 struct lpfc_sli *psli = &phba->sli;
2214
2215 /* Ring 0, ELS / CT buffers */
James Smart495a7142008-06-14 22:52:59 -04002216 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002217 /* Ring 2 - FCP no buffers needed */
2218
2219 return 0;
2220}
2221
2222#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2223
James Smarte59058c2008-08-24 21:49:00 -04002224/**
James Smart3621a712009-04-06 18:47:14 -04002225 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002226 * @HashResultPointer: pointer to an array as hash table.
2227 *
2228 * This routine sets up the initial values to the array of hash table entries
2229 * for the LC HBAs.
2230 **/
dea31012005-04-17 16:05:31 -05002231static void
2232lpfc_sha_init(uint32_t * HashResultPointer)
2233{
2234 HashResultPointer[0] = 0x67452301;
2235 HashResultPointer[1] = 0xEFCDAB89;
2236 HashResultPointer[2] = 0x98BADCFE;
2237 HashResultPointer[3] = 0x10325476;
2238 HashResultPointer[4] = 0xC3D2E1F0;
2239}
2240
James Smarte59058c2008-08-24 21:49:00 -04002241/**
James Smart3621a712009-04-06 18:47:14 -04002242 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002243 * @HashResultPointer: pointer to an initial/result hash table.
2244 * @HashWorkingPointer: pointer to an working hash table.
2245 *
2246 * This routine iterates an initial hash table pointed by @HashResultPointer
2247 * with the values from the working hash table pointeed by @HashWorkingPointer.
2248 * The results are putting back to the initial hash table, returned through
2249 * the @HashResultPointer as the result hash table.
2250 **/
dea31012005-04-17 16:05:31 -05002251static void
2252lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2253{
2254 int t;
2255 uint32_t TEMP;
2256 uint32_t A, B, C, D, E;
2257 t = 16;
2258 do {
2259 HashWorkingPointer[t] =
2260 S(1,
2261 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2262 8] ^
2263 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2264 } while (++t <= 79);
2265 t = 0;
2266 A = HashResultPointer[0];
2267 B = HashResultPointer[1];
2268 C = HashResultPointer[2];
2269 D = HashResultPointer[3];
2270 E = HashResultPointer[4];
2271
2272 do {
2273 if (t < 20) {
2274 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2275 } else if (t < 40) {
2276 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2277 } else if (t < 60) {
2278 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2279 } else {
2280 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2281 }
2282 TEMP += S(5, A) + E + HashWorkingPointer[t];
2283 E = D;
2284 D = C;
2285 C = S(30, B);
2286 B = A;
2287 A = TEMP;
2288 } while (++t <= 79);
2289
2290 HashResultPointer[0] += A;
2291 HashResultPointer[1] += B;
2292 HashResultPointer[2] += C;
2293 HashResultPointer[3] += D;
2294 HashResultPointer[4] += E;
2295
2296}
2297
James Smarte59058c2008-08-24 21:49:00 -04002298/**
James Smart3621a712009-04-06 18:47:14 -04002299 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002300 * @RandomChallenge: pointer to the entry of host challenge random number array.
2301 * @HashWorking: pointer to the entry of the working hash array.
2302 *
2303 * This routine calculates the working hash array referred by @HashWorking
2304 * from the challenge random numbers associated with the host, referred by
2305 * @RandomChallenge. The result is put into the entry of the working hash
2306 * array and returned by reference through @HashWorking.
2307 **/
dea31012005-04-17 16:05:31 -05002308static void
2309lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2310{
2311 *HashWorking = (*RandomChallenge ^ *HashWorking);
2312}
2313
James Smarte59058c2008-08-24 21:49:00 -04002314/**
James Smart3621a712009-04-06 18:47:14 -04002315 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002316 * @phba: pointer to lpfc hba data structure.
2317 * @hbainit: pointer to an array of unsigned 32-bit integers.
2318 *
2319 * This routine performs the special handling for LC HBA initialization.
2320 **/
dea31012005-04-17 16:05:31 -05002321void
2322lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2323{
2324 int t;
2325 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002326 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002327
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002328 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002329 if (!HashWorking)
2330 return;
2331
dea31012005-04-17 16:05:31 -05002332 HashWorking[0] = HashWorking[78] = *pwwnn++;
2333 HashWorking[1] = HashWorking[79] = *pwwnn;
2334
2335 for (t = 0; t < 7; t++)
2336 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2337
2338 lpfc_sha_init(hbainit);
2339 lpfc_sha_iterate(hbainit, HashWorking);
2340 kfree(HashWorking);
2341}
2342
James Smarte59058c2008-08-24 21:49:00 -04002343/**
James Smart3621a712009-04-06 18:47:14 -04002344 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002345 * @vport: pointer to a virtual N_Port data structure.
2346 *
2347 * This routine performs the necessary cleanups before deleting the @vport.
2348 * It invokes the discovery state machine to perform necessary state
2349 * transitions and to release the ndlps associated with the @vport. Note,
2350 * the physical port is treated as @vport 0.
2351 **/
James Smart87af33f2007-10-27 13:37:43 -04002352void
James Smart2e0fef82007-06-17 19:56:36 -05002353lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002354{
James Smart87af33f2007-10-27 13:37:43 -04002355 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002356 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002357 int i = 0;
dea31012005-04-17 16:05:31 -05002358
James Smart87af33f2007-10-27 13:37:43 -04002359 if (phba->link_state > LPFC_LINK_DOWN)
2360 lpfc_port_link_failure(vport);
2361
2362 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002363 if (!NLP_CHK_NODE_ACT(ndlp)) {
2364 ndlp = lpfc_enable_node(vport, ndlp,
2365 NLP_STE_UNUSED_NODE);
2366 if (!ndlp)
2367 continue;
2368 spin_lock_irq(&phba->ndlp_lock);
2369 NLP_SET_FREE_REQ(ndlp);
2370 spin_unlock_irq(&phba->ndlp_lock);
2371 /* Trigger the release of the ndlp memory */
2372 lpfc_nlp_put(ndlp);
2373 continue;
2374 }
2375 spin_lock_irq(&phba->ndlp_lock);
2376 if (NLP_CHK_FREE_REQ(ndlp)) {
2377 /* The ndlp should not be in memory free mode already */
2378 spin_unlock_irq(&phba->ndlp_lock);
2379 continue;
2380 } else
2381 /* Indicate request for freeing ndlp memory */
2382 NLP_SET_FREE_REQ(ndlp);
2383 spin_unlock_irq(&phba->ndlp_lock);
2384
James Smart58da1ff2008-04-07 10:15:56 -04002385 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2386 ndlp->nlp_DID == Fabric_DID) {
2387 /* Just free up ndlp with Fabric_DID for vports */
2388 lpfc_nlp_put(ndlp);
2389 continue;
2390 }
2391
James Smarteff4a012012-01-18 16:25:25 -05002392 /* take care of nodes in unused state before the state
2393 * machine taking action.
2394 */
2395 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2396 lpfc_nlp_put(ndlp);
2397 continue;
2398 }
2399
James Smart87af33f2007-10-27 13:37:43 -04002400 if (ndlp->nlp_type & NLP_FABRIC)
2401 lpfc_disc_state_machine(vport, ndlp, NULL,
2402 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002403
James Smart87af33f2007-10-27 13:37:43 -04002404 lpfc_disc_state_machine(vport, ndlp, NULL,
2405 NLP_EVT_DEVICE_RM);
2406 }
2407
James Smarta8adb832007-10-27 13:37:53 -04002408 /* At this point, ALL ndlp's should be gone
2409 * because of the previous NLP_EVT_DEVICE_RM.
2410 * Lets wait for this to happen, if needed.
2411 */
James Smart87af33f2007-10-27 13:37:43 -04002412 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002413 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04002414 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04002415 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002416 list_for_each_entry_safe(ndlp, next_ndlp,
2417 &vport->fc_nodes, nlp_listp) {
2418 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2419 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04002420 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05002421 "usgmap:x%x refcnt:%d\n",
2422 ndlp->nlp_DID, (void *)ndlp,
2423 ndlp->nlp_usg_map,
2424 atomic_read(
2425 &ndlp->kref.refcount));
2426 }
James Smarta8adb832007-10-27 13:37:53 -04002427 break;
James Smart87af33f2007-10-27 13:37:43 -04002428 }
James Smarta8adb832007-10-27 13:37:53 -04002429
2430 /* Wait for any activity on ndlps to settle */
2431 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002432 }
James Smart1151e3e2011-02-16 12:39:35 -05002433 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002434}
2435
James Smarte59058c2008-08-24 21:49:00 -04002436/**
James Smart3621a712009-04-06 18:47:14 -04002437 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002438 * @vport: pointer to a virtual N_Port data structure.
2439 *
2440 * This routine stops all the timers associated with a @vport. This function
2441 * is invoked before disabling or deleting a @vport. Note that the physical
2442 * port is treated as @vport 0.
2443 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002444void
2445lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002446{
James Smart92d7f7b2007-06-17 19:56:38 -05002447 del_timer_sync(&vport->els_tmofunc);
2448 del_timer_sync(&vport->fc_fdmitmo);
James Smart92494142011-02-16 12:39:44 -05002449 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002450 lpfc_can_disctmo(vport);
2451 return;
dea31012005-04-17 16:05:31 -05002452}
2453
James Smarte59058c2008-08-24 21:49:00 -04002454/**
James Smartecfd03c2010-02-12 14:41:27 -05002455 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2456 * @phba: pointer to lpfc hba data structure.
2457 *
2458 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2459 * caller of this routine should already hold the host lock.
2460 **/
2461void
2462__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2463{
James Smart5ac6b302010-10-22 11:05:36 -04002464 /* Clear pending FCF rediscovery wait flag */
2465 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2466
James Smartecfd03c2010-02-12 14:41:27 -05002467 /* Now, try to stop the timer */
2468 del_timer(&phba->fcf.redisc_wait);
2469}
2470
2471/**
2472 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2473 * @phba: pointer to lpfc hba data structure.
2474 *
2475 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2476 * checks whether the FCF rediscovery wait timer is pending with the host
2477 * lock held before proceeding with disabling the timer and clearing the
2478 * wait timer pendig flag.
2479 **/
2480void
2481lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2482{
2483 spin_lock_irq(&phba->hbalock);
2484 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2485 /* FCF rediscovery timer already fired or stopped */
2486 spin_unlock_irq(&phba->hbalock);
2487 return;
2488 }
2489 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002490 /* Clear failover in progress flags */
2491 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002492 spin_unlock_irq(&phba->hbalock);
2493}
2494
2495/**
James Smart3772a992009-05-22 14:50:54 -04002496 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002497 * @phba: pointer to lpfc hba data structure.
2498 *
2499 * This routine stops all the timers associated with a HBA. This function is
2500 * invoked before either putting a HBA offline or unloading the driver.
2501 **/
James Smart3772a992009-05-22 14:50:54 -04002502void
2503lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002504{
James Smart51ef4c22007-08-02 11:10:31 -04002505 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05002506 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002507 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002508 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002509 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002510 if (phba->sli_rev == LPFC_SLI_REV4) {
2511 del_timer_sync(&phba->rrq_tmr);
2512 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2513 }
James Smart3772a992009-05-22 14:50:54 -04002514 phba->hb_outstanding = 0;
2515
2516 switch (phba->pci_dev_grp) {
2517 case LPFC_PCI_DEV_LP:
2518 /* Stop any LightPulse device specific driver timers */
2519 del_timer_sync(&phba->fcp_poll_timer);
2520 break;
2521 case LPFC_PCI_DEV_OC:
2522 /* Stop any OneConnect device sepcific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002523 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002524 break;
2525 default:
2526 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2527 "0297 Invalid device group (x%x)\n",
2528 phba->pci_dev_grp);
2529 break;
2530 }
James Smart2e0fef82007-06-17 19:56:36 -05002531 return;
dea31012005-04-17 16:05:31 -05002532}
2533
James Smarte59058c2008-08-24 21:49:00 -04002534/**
James Smart3621a712009-04-06 18:47:14 -04002535 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002536 * @phba: pointer to lpfc hba data structure.
2537 *
2538 * This routine marks a HBA's management interface as blocked. Once the HBA's
2539 * management interface is marked as blocked, all the user space access to
2540 * the HBA, whether they are from sysfs interface or libdfc interface will
2541 * all be blocked. The HBA is set to block the management interface when the
2542 * driver prepares the HBA interface for online or offline.
2543 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01002544static void
James Smart618a5232012-06-12 13:54:36 -04002545lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
Adrian Bunka6ababd2007-11-05 18:07:33 +01002546{
2547 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04002548 uint8_t actcmd = MBX_HEARTBEAT;
2549 unsigned long timeout;
2550
Adrian Bunka6ababd2007-11-05 18:07:33 +01002551 spin_lock_irqsave(&phba->hbalock, iflag);
2552 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart618a5232012-06-12 13:54:36 -04002553 spin_unlock_irqrestore(&phba->hbalock, iflag);
2554 if (mbx_action == LPFC_MBX_NO_WAIT)
2555 return;
2556 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2557 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002558 if (phba->sli.mbox_active) {
James Smart6e7288d2010-06-07 15:23:35 -04002559 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
James Smarta183a152011-10-10 21:32:43 -04002560 /* Determine how long we might wait for the active mailbox
2561 * command to be gracefully completed by firmware.
2562 */
2563 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
2564 phba->sli.mbox_active) * 1000) + jiffies;
2565 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002566 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002567
James Smart6e7288d2010-06-07 15:23:35 -04002568 /* Wait for the outstnading mailbox command to complete */
2569 while (phba->sli.mbox_active) {
2570 /* Check active mailbox complete status every 2ms */
2571 msleep(2);
2572 if (time_after(jiffies, timeout)) {
2573 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2574 "2813 Mgmt IO is Blocked %x "
2575 "- mbox cmd %x still active\n",
2576 phba->sli.sli_flag, actcmd);
2577 break;
2578 }
2579 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002580}
2581
James Smarte59058c2008-08-24 21:49:00 -04002582/**
James Smart6b5151f2012-01-18 16:24:06 -05002583 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
2584 * @phba: pointer to lpfc hba data structure.
2585 *
2586 * Allocate RPIs for all active remote nodes. This is needed whenever
2587 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
2588 * is to fixup the temporary rpi assignments.
2589 **/
2590void
2591lpfc_sli4_node_prep(struct lpfc_hba *phba)
2592{
2593 struct lpfc_nodelist *ndlp, *next_ndlp;
2594 struct lpfc_vport **vports;
2595 int i;
2596
2597 if (phba->sli_rev != LPFC_SLI_REV4)
2598 return;
2599
2600 vports = lpfc_create_vport_work_array(phba);
2601 if (vports != NULL) {
2602 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2603 if (vports[i]->load_flag & FC_UNLOADING)
2604 continue;
2605
2606 list_for_each_entry_safe(ndlp, next_ndlp,
2607 &vports[i]->fc_nodes,
2608 nlp_listp) {
2609 if (NLP_CHK_NODE_ACT(ndlp))
2610 ndlp->nlp_rpi =
2611 lpfc_sli4_alloc_rpi(phba);
2612 }
2613 }
2614 }
2615 lpfc_destroy_vport_work_array(phba, vports);
2616}
2617
2618/**
James Smart3621a712009-04-06 18:47:14 -04002619 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04002620 * @phba: pointer to lpfc hba data structure.
2621 *
2622 * This routine initializes the HBA and brings a HBA online. During this
2623 * process, the management interface is blocked to prevent user space access
2624 * to the HBA interfering with the driver initialization.
2625 *
2626 * Return codes
2627 * 0 - successful
2628 * 1 - failed
2629 **/
dea31012005-04-17 16:05:31 -05002630int
James Smart2e0fef82007-06-17 19:56:36 -05002631lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002632{
Julia Lawall372bd282008-12-16 16:15:08 +01002633 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04002634 struct lpfc_vport **vports;
2635 int i;
James Smart16a3a202013-04-17 20:14:38 -04002636 bool vpis_cleared = false;
James Smart2e0fef82007-06-17 19:56:36 -05002637
dea31012005-04-17 16:05:31 -05002638 if (!phba)
2639 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01002640 vport = phba->pport;
dea31012005-04-17 16:05:31 -05002641
James Smart2e0fef82007-06-17 19:56:36 -05002642 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05002643 return 0;
2644
James Smarted957682007-06-17 19:56:37 -05002645 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002646 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05002647
James Smart618a5232012-06-12 13:54:36 -04002648 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05002649
James Smart46fa3112007-04-25 09:51:45 -04002650 if (!lpfc_sli_queue_setup(phba)) {
2651 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002652 return 1;
James Smart46fa3112007-04-25 09:51:45 -04002653 }
2654
James Smartda0436e2009-05-22 14:51:39 -04002655 if (phba->sli_rev == LPFC_SLI_REV4) {
2656 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
2657 lpfc_unblock_mgmt_io(phba);
2658 return 1;
2659 }
James Smart16a3a202013-04-17 20:14:38 -04002660 spin_lock_irq(&phba->hbalock);
2661 if (!phba->sli4_hba.max_cfg_param.vpi_used)
2662 vpis_cleared = true;
2663 spin_unlock_irq(&phba->hbalock);
James Smartda0436e2009-05-22 14:51:39 -04002664 } else {
2665 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
2666 lpfc_unblock_mgmt_io(phba);
2667 return 1;
2668 }
James Smart46fa3112007-04-25 09:51:45 -04002669 }
dea31012005-04-17 16:05:31 -05002670
James Smart549e55c2007-08-02 11:09:51 -04002671 vports = lpfc_create_vport_work_array(phba);
2672 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002673 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002674 struct Scsi_Host *shost;
2675 shost = lpfc_shost_from_vport(vports[i]);
2676 spin_lock_irq(shost->host_lock);
2677 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
2678 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2679 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart16a3a202013-04-17 20:14:38 -04002680 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart1c6834a2009-07-19 10:01:26 -04002681 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart16a3a202013-04-17 20:14:38 -04002682 if ((vpis_cleared) &&
2683 (vports[i]->port_type !=
2684 LPFC_PHYSICAL_PORT))
2685 vports[i]->vpi = 0;
2686 }
James Smart549e55c2007-08-02 11:09:51 -04002687 spin_unlock_irq(shost->host_lock);
2688 }
James Smart09372822008-01-11 01:52:54 -05002689 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002690
James Smart46fa3112007-04-25 09:51:45 -04002691 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002692 return 0;
2693}
2694
James Smarte59058c2008-08-24 21:49:00 -04002695/**
James Smart3621a712009-04-06 18:47:14 -04002696 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04002697 * @phba: pointer to lpfc hba data structure.
2698 *
2699 * This routine marks a HBA's management interface as not blocked. Once the
2700 * HBA's management interface is marked as not blocked, all the user space
2701 * access to the HBA, whether they are from sysfs interface or libdfc
2702 * interface will be allowed. The HBA is set to block the management interface
2703 * when the driver prepares the HBA interface for online or offline and then
2704 * set to unblock the management interface afterwards.
2705 **/
James Smart46fa3112007-04-25 09:51:45 -04002706void
James Smart46fa3112007-04-25 09:51:45 -04002707lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
2708{
2709 unsigned long iflag;
2710
James Smart2e0fef82007-06-17 19:56:36 -05002711 spin_lock_irqsave(&phba->hbalock, iflag);
2712 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
2713 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04002714}
2715
James Smarte59058c2008-08-24 21:49:00 -04002716/**
James Smart3621a712009-04-06 18:47:14 -04002717 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04002718 * @phba: pointer to lpfc hba data structure.
2719 *
2720 * This routine is invoked to prepare a HBA to be brought offline. It performs
2721 * unregistration login to all the nodes on all vports and flushes the mailbox
2722 * queue to make it ready to be brought offline.
2723 **/
James Smart46fa3112007-04-25 09:51:45 -04002724void
James Smart618a5232012-06-12 13:54:36 -04002725lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04002726{
James Smart2e0fef82007-06-17 19:56:36 -05002727 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04002728 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04002729 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05002730 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04002731 int i;
dea31012005-04-17 16:05:31 -05002732
James Smart2e0fef82007-06-17 19:56:36 -05002733 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002734 return;
dea31012005-04-17 16:05:31 -05002735
James Smart618a5232012-06-12 13:54:36 -04002736 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05002737
2738 lpfc_linkdown(phba);
2739
James Smart87af33f2007-10-27 13:37:43 -04002740 /* Issue an unreg_login to all nodes on all vports */
2741 vports = lpfc_create_vport_work_array(phba);
2742 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04002743 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04002744 if (vports[i]->load_flag & FC_UNLOADING)
2745 continue;
James Smart72100cc2010-02-12 14:43:01 -05002746 shost = lpfc_shost_from_vport(vports[i]);
2747 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05002748 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002749 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2750 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05002751 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05002752
James Smart87af33f2007-10-27 13:37:43 -04002753 shost = lpfc_shost_from_vport(vports[i]);
2754 list_for_each_entry_safe(ndlp, next_ndlp,
2755 &vports[i]->fc_nodes,
2756 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002757 if (!NLP_CHK_NODE_ACT(ndlp))
2758 continue;
James Smart87af33f2007-10-27 13:37:43 -04002759 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2760 continue;
2761 if (ndlp->nlp_type & NLP_FABRIC) {
2762 lpfc_disc_state_machine(vports[i], ndlp,
2763 NULL, NLP_EVT_DEVICE_RECOVERY);
2764 lpfc_disc_state_machine(vports[i], ndlp,
2765 NULL, NLP_EVT_DEVICE_RM);
2766 }
2767 spin_lock_irq(shost->host_lock);
2768 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart401ee0c2012-03-01 22:35:34 -05002769 spin_unlock_irq(shost->host_lock);
James Smart6b5151f2012-01-18 16:24:06 -05002770 /*
2771 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05002772 * RPI. Get a new RPI when the adapter port
2773 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05002774 */
2775 if (phba->sli_rev == LPFC_SLI_REV4)
2776 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04002777 lpfc_unreg_rpi(vports[i], ndlp);
2778 }
2779 }
2780 }
James Smart09372822008-01-11 01:52:54 -05002781 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002782
James Smart618a5232012-06-12 13:54:36 -04002783 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
James Smart46fa3112007-04-25 09:51:45 -04002784}
2785
James Smarte59058c2008-08-24 21:49:00 -04002786/**
James Smart3621a712009-04-06 18:47:14 -04002787 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04002788 * @phba: pointer to lpfc hba data structure.
2789 *
2790 * This routine actually brings a HBA offline. It stops all the timers
2791 * associated with the HBA, brings down the SLI layer, and eventually
2792 * marks the HBA as in offline state for the upper layer protocol.
2793 **/
James Smart46fa3112007-04-25 09:51:45 -04002794void
James Smart2e0fef82007-06-17 19:56:36 -05002795lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04002796{
James Smart549e55c2007-08-02 11:09:51 -04002797 struct Scsi_Host *shost;
2798 struct lpfc_vport **vports;
2799 int i;
James Smart46fa3112007-04-25 09:51:45 -04002800
James Smart549e55c2007-08-02 11:09:51 -04002801 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002802 return;
James Smart688a8862006-07-06 15:49:56 -04002803
James Smartda0436e2009-05-22 14:51:39 -04002804 /* stop port and all timers associated with this hba */
2805 lpfc_stop_port(phba);
James Smart51ef4c22007-08-02 11:10:31 -04002806 vports = lpfc_create_vport_work_array(phba);
2807 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002808 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04002809 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05002810 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05002811 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002812 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05002813 /* Bring down the SLI Layer and cleanup. The HBA is offline
2814 now. */
2815 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002816 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04002817 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05002818 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04002819 vports = lpfc_create_vport_work_array(phba);
2820 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002821 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002822 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04002823 spin_lock_irq(shost->host_lock);
2824 vports[i]->work_port_events = 0;
2825 vports[i]->fc_flag |= FC_OFFLINE_MODE;
2826 spin_unlock_irq(shost->host_lock);
2827 }
James Smart09372822008-01-11 01:52:54 -05002828 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002829}
2830
James Smarte59058c2008-08-24 21:49:00 -04002831/**
James Smart3621a712009-04-06 18:47:14 -04002832 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04002833 * @phba: pointer to lpfc hba data structure.
2834 *
2835 * This routine is to free all the SCSI buffers and IOCBs from the driver
2836 * list back to kernel. It is called from lpfc_pci_remove_one to free
2837 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04002838 **/
James Smart8a9d2e82012-05-09 21:16:12 -04002839static void
James Smart2e0fef82007-06-17 19:56:36 -05002840lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002841{
2842 struct lpfc_scsi_buf *sb, *sb_next;
2843 struct lpfc_iocbq *io, *io_next;
2844
James Smart2e0fef82007-06-17 19:56:36 -05002845 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002846 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smart1c6f4ef52009-11-18 15:40:49 -05002847 spin_lock(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05002848 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
2849 list_del(&sb->list);
2850 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05002851 sb->dma_handle);
dea31012005-04-17 16:05:31 -05002852 kfree(sb);
2853 phba->total_scsi_bufs--;
2854 }
James Smart1c6f4ef52009-11-18 15:40:49 -05002855 spin_unlock(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05002856
2857 /* Release all the lpfc_iocbq entries maintained by this host. */
2858 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
2859 list_del(&io->list);
2860 kfree(io);
2861 phba->total_iocbq_bufs--;
2862 }
James Smart6d368e52011-05-24 11:44:12 -04002863
James Smart2e0fef82007-06-17 19:56:36 -05002864 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04002865}
2866
2867/**
2868 * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping
2869 * @phba: pointer to lpfc hba data structure.
2870 *
2871 * This routine first calculates the sizes of the current els and allocated
2872 * scsi sgl lists, and then goes through all sgls to updates the physical
2873 * XRIs assigned due to port function reset. During port initialization, the
2874 * current els and allocated scsi sgl lists are 0s.
2875 *
2876 * Return codes
2877 * 0 - successful (for now, it always returns 0)
2878 **/
2879int
2880lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba)
2881{
2882 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
2883 struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL;
2884 uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt;
2885 LIST_HEAD(els_sgl_list);
2886 LIST_HEAD(scsi_sgl_list);
2887 int rc;
2888
2889 /*
2890 * update on pci function's els xri-sgl list
2891 */
2892 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
2893 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
2894 /* els xri-sgl expanded */
2895 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
2896 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2897 "3157 ELS xri-sgl count increased from "
2898 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
2899 els_xri_cnt);
2900 /* allocate the additional els sgls */
2901 for (i = 0; i < xri_cnt; i++) {
2902 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
2903 GFP_KERNEL);
2904 if (sglq_entry == NULL) {
2905 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2906 "2562 Failure to allocate an "
2907 "ELS sgl entry:%d\n", i);
2908 rc = -ENOMEM;
2909 goto out_free_mem;
2910 }
2911 sglq_entry->buff_type = GEN_BUFF_TYPE;
2912 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
2913 &sglq_entry->phys);
2914 if (sglq_entry->virt == NULL) {
2915 kfree(sglq_entry);
2916 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2917 "2563 Failure to allocate an "
2918 "ELS mbuf:%d\n", i);
2919 rc = -ENOMEM;
2920 goto out_free_mem;
2921 }
2922 sglq_entry->sgl = sglq_entry->virt;
2923 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
2924 sglq_entry->state = SGL_FREED;
2925 list_add_tail(&sglq_entry->list, &els_sgl_list);
2926 }
James Smart38c20672013-03-01 16:37:44 -05002927 spin_lock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04002928 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
James Smart38c20672013-03-01 16:37:44 -05002929 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04002930 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
2931 /* els xri-sgl shrinked */
2932 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
2933 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2934 "3158 ELS xri-sgl count decreased from "
2935 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
2936 els_xri_cnt);
2937 spin_lock_irq(&phba->hbalock);
2938 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list);
2939 spin_unlock_irq(&phba->hbalock);
2940 /* release extra els sgls from list */
2941 for (i = 0; i < xri_cnt; i++) {
2942 list_remove_head(&els_sgl_list,
2943 sglq_entry, struct lpfc_sglq, list);
2944 if (sglq_entry) {
2945 lpfc_mbuf_free(phba, sglq_entry->virt,
2946 sglq_entry->phys);
2947 kfree(sglq_entry);
2948 }
2949 }
2950 spin_lock_irq(&phba->hbalock);
2951 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
2952 spin_unlock_irq(&phba->hbalock);
2953 } else
2954 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2955 "3163 ELS xri-sgl count unchanged: %d\n",
2956 els_xri_cnt);
2957 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
2958
2959 /* update xris to els sgls on the list */
2960 sglq_entry = NULL;
2961 sglq_entry_next = NULL;
2962 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
2963 &phba->sli4_hba.lpfc_sgl_list, list) {
2964 lxri = lpfc_sli4_next_xritag(phba);
2965 if (lxri == NO_XRI) {
2966 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2967 "2400 Failed to allocate xri for "
2968 "ELS sgl\n");
2969 rc = -ENOMEM;
2970 goto out_free_mem;
2971 }
2972 sglq_entry->sli4_lxritag = lxri;
2973 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
2974 }
2975
2976 /*
2977 * update on pci function's allocated scsi xri-sgl list
2978 */
2979 phba->total_scsi_bufs = 0;
2980
2981 /* maximum number of xris available for scsi buffers */
2982 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
2983 els_xri_cnt;
2984
2985 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2986 "2401 Current allocated SCSI xri-sgl count:%d, "
2987 "maximum SCSI xri count:%d\n",
2988 phba->sli4_hba.scsi_xri_cnt,
2989 phba->sli4_hba.scsi_xri_max);
2990
2991 spin_lock_irq(&phba->scsi_buf_list_lock);
2992 list_splice_init(&phba->lpfc_scsi_buf_list, &scsi_sgl_list);
2993 spin_unlock_irq(&phba->scsi_buf_list_lock);
2994
2995 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
2996 /* max scsi xri shrinked below the allocated scsi buffers */
2997 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
2998 phba->sli4_hba.scsi_xri_max;
2999 /* release the extra allocated scsi buffers */
3000 for (i = 0; i < scsi_xri_cnt; i++) {
3001 list_remove_head(&scsi_sgl_list, psb,
3002 struct lpfc_scsi_buf, list);
3003 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, psb->data,
3004 psb->dma_handle);
3005 kfree(psb);
3006 }
3007 spin_lock_irq(&phba->scsi_buf_list_lock);
3008 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
3009 spin_unlock_irq(&phba->scsi_buf_list_lock);
3010 }
3011
3012 /* update xris associated to remaining allocated scsi buffers */
3013 psb = NULL;
3014 psb_next = NULL;
3015 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3016 lxri = lpfc_sli4_next_xritag(phba);
3017 if (lxri == NO_XRI) {
3018 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3019 "2560 Failed to allocate xri for "
3020 "scsi buffer\n");
3021 rc = -ENOMEM;
3022 goto out_free_mem;
3023 }
3024 psb->cur_iocbq.sli4_lxritag = lxri;
3025 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3026 }
James Smart38c20672013-03-01 16:37:44 -05003027 spin_lock_irq(&phba->scsi_buf_list_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003028 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list);
James Smart38c20672013-03-01 16:37:44 -05003029 spin_unlock_irq(&phba->scsi_buf_list_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003030
dea31012005-04-17 16:05:31 -05003031 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003032
3033out_free_mem:
3034 lpfc_free_els_sgl_list(phba);
3035 lpfc_scsi_free(phba);
3036 return rc;
dea31012005-04-17 16:05:31 -05003037}
3038
James Smarte59058c2008-08-24 21:49:00 -04003039/**
James Smart3621a712009-04-06 18:47:14 -04003040 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04003041 * @phba: pointer to lpfc hba data structure.
3042 * @instance: a unique integer ID to this FC port.
3043 * @dev: pointer to the device data structure.
3044 *
3045 * This routine creates a FC port for the upper layer protocol. The FC port
3046 * can be created on top of either a physical port or a virtual port provided
3047 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3048 * and associates the FC port created before adding the shost into the SCSI
3049 * layer.
3050 *
3051 * Return codes
3052 * @vport - pointer to the virtual N_Port data structure.
3053 * NULL - port create failed.
3054 **/
James Smart2e0fef82007-06-17 19:56:36 -05003055struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04003056lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04003057{
James Smart2e0fef82007-06-17 19:56:36 -05003058 struct lpfc_vport *vport;
3059 struct Scsi_Host *shost;
3060 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04003061
James Smart3de2a652007-08-02 11:09:59 -04003062 if (dev != &phba->pcidev->dev)
3063 shost = scsi_host_alloc(&lpfc_vport_template,
3064 sizeof(struct lpfc_vport));
3065 else
3066 shost = scsi_host_alloc(&lpfc_template,
3067 sizeof(struct lpfc_vport));
James Smart2e0fef82007-06-17 19:56:36 -05003068 if (!shost)
3069 goto out;
James Smart47a86172007-04-25 09:53:22 -04003070
James Smart2e0fef82007-06-17 19:56:36 -05003071 vport = (struct lpfc_vport *) shost->hostdata;
3072 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05003073 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05003074 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05003075 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04003076
James Smart3de2a652007-08-02 11:09:59 -04003077 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05003078 shost->unique_id = instance;
3079 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04003080 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05003081 shost->this_id = -1;
3082 shost->max_cmd_len = 16;
James Smartda0436e2009-05-22 14:51:39 -04003083 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05003084 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04003085 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smartda0436e2009-05-22 14:51:39 -04003086 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
3087 }
James Smart81301a92008-12-04 22:39:46 -05003088
James Smart47a86172007-04-25 09:53:22 -04003089 /*
James Smart2e0fef82007-06-17 19:56:36 -05003090 * Set initial can_queue value since 0 is no longer supported and
3091 * scsi_add_host will fail. This will be adjusted later based on the
3092 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04003093 */
James Smart2e0fef82007-06-17 19:56:36 -05003094 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04003095 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05003096 shost->transportt = lpfc_vport_transport_template;
3097 vport->port_type = LPFC_NPIV_PORT;
3098 } else {
3099 shost->transportt = lpfc_transport_template;
3100 vport->port_type = LPFC_PHYSICAL_PORT;
3101 }
James Smart47a86172007-04-25 09:53:22 -04003102
James Smart2e0fef82007-06-17 19:56:36 -05003103 /* Initialize all internally managed lists. */
3104 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04003105 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05003106 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04003107
James Smart2e0fef82007-06-17 19:56:36 -05003108 init_timer(&vport->fc_disctmo);
3109 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003110 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04003111
James Smart2e0fef82007-06-17 19:56:36 -05003112 init_timer(&vport->fc_fdmitmo);
3113 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
James Smart92d7f7b2007-06-17 19:56:38 -05003114 vport->fc_fdmitmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04003115
James Smart2e0fef82007-06-17 19:56:36 -05003116 init_timer(&vport->els_tmofunc);
3117 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003118 vport->els_tmofunc.data = (unsigned long)vport;
James Smart92494142011-02-16 12:39:44 -05003119
3120 init_timer(&vport->delayed_disc_tmo);
3121 vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
3122 vport->delayed_disc_tmo.data = (unsigned long)vport;
3123
James Bottomleyd139b9b2009-11-05 13:33:12 -06003124 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05003125 if (error)
3126 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04003127
James Smart549e55c2007-08-02 11:09:51 -04003128 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003129 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04003130 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003131 return vport;
James Smart47a86172007-04-25 09:53:22 -04003132
James Smart2e0fef82007-06-17 19:56:36 -05003133out_put_shost:
3134 scsi_host_put(shost);
3135out:
3136 return NULL;
James Smart47a86172007-04-25 09:53:22 -04003137}
3138
James Smarte59058c2008-08-24 21:49:00 -04003139/**
James Smart3621a712009-04-06 18:47:14 -04003140 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04003141 * @vport: pointer to an lpfc virtual N_Port data structure.
3142 *
3143 * This routine destroys a FC port from the upper layer protocol. All the
3144 * resources associated with the port are released.
3145 **/
James Smart2e0fef82007-06-17 19:56:36 -05003146void
3147destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04003148{
James Smart92d7f7b2007-06-17 19:56:38 -05003149 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3150 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003151
James Smart858c9f62007-06-17 19:56:39 -05003152 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05003153 fc_remove_host(shost);
3154 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04003155
James Smart92d7f7b2007-06-17 19:56:38 -05003156 spin_lock_irq(&phba->hbalock);
3157 list_del_init(&vport->listentry);
3158 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04003159
James Smart92d7f7b2007-06-17 19:56:38 -05003160 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04003161 return;
James Smart47a86172007-04-25 09:53:22 -04003162}
3163
James Smarte59058c2008-08-24 21:49:00 -04003164/**
James Smart3621a712009-04-06 18:47:14 -04003165 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04003166 *
3167 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3168 * uses the kernel idr facility to perform the task.
3169 *
3170 * Return codes:
3171 * instance - a unique integer ID allocated as the new instance.
3172 * -1 - lpfc get instance failed.
3173 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003174int
3175lpfc_get_instance(void)
3176{
Tejun Heoab516032013-02-27 17:04:44 -08003177 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003178
Tejun Heoab516032013-02-27 17:04:44 -08003179 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
3180 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003181}
3182
James Smarte59058c2008-08-24 21:49:00 -04003183/**
James Smart3621a712009-04-06 18:47:14 -04003184 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04003185 * @shost: pointer to SCSI host data structure.
3186 * @time: elapsed time of the scan in jiffies.
3187 *
3188 * This routine is called by the SCSI layer with a SCSI host to determine
3189 * whether the scan host is finished.
3190 *
3191 * Note: there is no scan_start function as adapter initialization will have
3192 * asynchronously kicked off the link initialization.
3193 *
3194 * Return codes
3195 * 0 - SCSI host scan is not over yet.
3196 * 1 - SCSI host scan is over.
3197 **/
James Smart47a86172007-04-25 09:53:22 -04003198int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
3199{
James Smart2e0fef82007-06-17 19:56:36 -05003200 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3201 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05003202 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04003203
James Smart858c9f62007-06-17 19:56:39 -05003204 spin_lock_irq(shost->host_lock);
3205
James Smart51ef4c22007-08-02 11:10:31 -04003206 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05003207 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003208 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05003209 }
James Smart2e0fef82007-06-17 19:56:36 -05003210 if (time >= 30 * HZ) {
3211 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003212 "0461 Scanning longer than 30 "
3213 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003214 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003215 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003216 }
3217 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
3218 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003219 "0465 Link down longer than 15 "
3220 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003221 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05003222 goto finished;
James Smart47a86172007-04-25 09:53:22 -04003223 }
3224
James Smart2e0fef82007-06-17 19:56:36 -05003225 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05003226 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003227 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05003228 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003229 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
James Smart858c9f62007-06-17 19:56:39 -05003230 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003231 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05003232 goto finished;
3233
3234 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003235
3236finished:
James Smart858c9f62007-06-17 19:56:39 -05003237 spin_unlock_irq(shost->host_lock);
3238 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003239}
3240
James Smarte59058c2008-08-24 21:49:00 -04003241/**
James Smart3621a712009-04-06 18:47:14 -04003242 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04003243 * @shost: pointer to SCSI host data structure.
3244 *
3245 * This routine initializes a given SCSI host attributes on a FC port. The
3246 * SCSI host can be either on top of a physical port or a virtual port.
3247 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003248void lpfc_host_attrib_init(struct Scsi_Host *shost)
3249{
3250 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3251 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003252 /*
James Smart2e0fef82007-06-17 19:56:36 -05003253 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04003254 */
3255
James Smart2e0fef82007-06-17 19:56:36 -05003256 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
3257 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04003258 fc_host_supported_classes(shost) = FC_COS_CLASS3;
3259
3260 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003261 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003262 fc_host_supported_fc4s(shost)[2] = 1;
3263 fc_host_supported_fc4s(shost)[7] = 1;
3264
James Smart92d7f7b2007-06-17 19:56:38 -05003265 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
3266 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04003267
3268 fc_host_supported_speeds(shost) = 0;
James Smart88a2cfb2011-07-22 18:36:33 -04003269 if (phba->lmt & LMT_16Gb)
3270 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
James Smart47a86172007-04-25 09:53:22 -04003271 if (phba->lmt & LMT_10Gb)
3272 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04003273 if (phba->lmt & LMT_8Gb)
3274 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04003275 if (phba->lmt & LMT_4Gb)
3276 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
3277 if (phba->lmt & LMT_2Gb)
3278 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
3279 if (phba->lmt & LMT_1Gb)
3280 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
3281
3282 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05003283 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
3284 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04003285
Mike Christie0af5d702010-09-15 16:52:31 -05003286 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
3287
James Smart47a86172007-04-25 09:53:22 -04003288 /* This value is also unchanging */
3289 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003290 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003291 fc_host_active_fc4s(shost)[2] = 1;
3292 fc_host_active_fc4s(shost)[7] = 1;
3293
James Smart92d7f7b2007-06-17 19:56:38 -05003294 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04003295 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04003296 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04003297 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04003298}
dea31012005-04-17 16:05:31 -05003299
James Smarte59058c2008-08-24 21:49:00 -04003300/**
James Smartda0436e2009-05-22 14:51:39 -04003301 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04003302 * @phba: pointer to lpfc hba data structure.
3303 *
James Smartda0436e2009-05-22 14:51:39 -04003304 * This routine is invoked to stop an SLI3 device port, it stops the device
3305 * from generating interrupts and stops the device driver's timers for the
3306 * device.
James Smarte59058c2008-08-24 21:49:00 -04003307 **/
James Smartdb2378e2008-02-08 18:49:51 -05003308static void
James Smartda0436e2009-05-22 14:51:39 -04003309lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05003310{
James Smartda0436e2009-05-22 14:51:39 -04003311 /* Clear all interrupt enable conditions */
3312 writel(0, phba->HCregaddr);
3313 readl(phba->HCregaddr); /* flush */
3314 /* Clear all pending interrupts */
3315 writel(0xffffffff, phba->HAregaddr);
3316 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04003317
James Smartda0436e2009-05-22 14:51:39 -04003318 /* Reset some HBA SLI setup states */
3319 lpfc_stop_hba_timers(phba);
3320 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05003321}
3322
James Smarte59058c2008-08-24 21:49:00 -04003323/**
James Smartda0436e2009-05-22 14:51:39 -04003324 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05003325 * @phba: pointer to lpfc hba data structure.
3326 *
James Smartda0436e2009-05-22 14:51:39 -04003327 * This routine is invoked to stop an SLI4 device port, it stops the device
3328 * from generating interrupts and stops the device driver's timers for the
3329 * device.
3330 **/
3331static void
3332lpfc_stop_port_s4(struct lpfc_hba *phba)
3333{
3334 /* Reset some HBA SLI4 setup states */
3335 lpfc_stop_hba_timers(phba);
3336 phba->pport->work_port_events = 0;
3337 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04003338}
3339
3340/**
3341 * lpfc_stop_port - Wrapper function for stopping hba port
3342 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05003343 *
James Smartda0436e2009-05-22 14:51:39 -04003344 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3345 * the API jump table function pointer from the lpfc_hba struct.
3346 **/
3347void
3348lpfc_stop_port(struct lpfc_hba *phba)
3349{
3350 phba->lpfc_stop_port(phba);
3351}
3352
3353/**
James Smartecfd03c2010-02-12 14:41:27 -05003354 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3355 * @phba: Pointer to hba for which this call is being executed.
3356 *
3357 * This routine starts the timer waiting for the FCF rediscovery to complete.
3358 **/
3359void
3360lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
3361{
3362 unsigned long fcf_redisc_wait_tmo =
3363 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
3364 /* Start fcf rediscovery wait period timer */
3365 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
3366 spin_lock_irq(&phba->hbalock);
3367 /* Allow action to new fcf asynchronous event */
3368 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
3369 /* Mark the FCF rediscovery pending state */
3370 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
3371 spin_unlock_irq(&phba->hbalock);
3372}
3373
3374/**
3375 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
3376 * @ptr: Map to lpfc_hba data structure pointer.
3377 *
3378 * This routine is invoked when waiting for FCF table rediscover has been
3379 * timed out. If new FCF record(s) has (have) been discovered during the
3380 * wait period, a new FCF event shall be added to the FCOE async event
3381 * list, and then worker thread shall be waked up for processing from the
3382 * worker thread context.
3383 **/
3384void
3385lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
3386{
3387 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
3388
3389 /* Don't send FCF rediscovery event if timer cancelled */
3390 spin_lock_irq(&phba->hbalock);
3391 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
3392 spin_unlock_irq(&phba->hbalock);
3393 return;
3394 }
3395 /* Clear FCF rediscovery timer pending flag */
3396 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
3397 /* FCF rediscovery event to worker thread */
3398 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
3399 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003400 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04003401 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05003402 /* wake up worker thread */
3403 lpfc_worker_wake_up(phba);
3404}
3405
3406/**
James Smartda0436e2009-05-22 14:51:39 -04003407 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
3408 * @phba: pointer to lpfc hba data structure.
3409 * @acqe_link: pointer to the async link completion queue entry.
3410 *
3411 * This routine is to parse the SLI4 link-attention link fault code and
3412 * translate it into the base driver's read link attention mailbox command
3413 * status.
3414 *
3415 * Return: Link-attention status in terms of base driver's coding.
3416 **/
3417static uint16_t
3418lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
3419 struct lpfc_acqe_link *acqe_link)
3420{
3421 uint16_t latt_fault;
3422
3423 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
3424 case LPFC_ASYNC_LINK_FAULT_NONE:
3425 case LPFC_ASYNC_LINK_FAULT_LOCAL:
3426 case LPFC_ASYNC_LINK_FAULT_REMOTE:
3427 latt_fault = 0;
3428 break;
3429 default:
3430 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3431 "0398 Invalid link fault code: x%x\n",
3432 bf_get(lpfc_acqe_link_fault, acqe_link));
3433 latt_fault = MBXERR_ERROR;
3434 break;
3435 }
3436 return latt_fault;
3437}
3438
3439/**
3440 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
3441 * @phba: pointer to lpfc hba data structure.
3442 * @acqe_link: pointer to the async link completion queue entry.
3443 *
3444 * This routine is to parse the SLI4 link attention type and translate it
3445 * into the base driver's link attention type coding.
3446 *
3447 * Return: Link attention type in terms of base driver's coding.
3448 **/
3449static uint8_t
3450lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
3451 struct lpfc_acqe_link *acqe_link)
3452{
3453 uint8_t att_type;
3454
3455 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
3456 case LPFC_ASYNC_LINK_STATUS_DOWN:
3457 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05003458 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04003459 break;
3460 case LPFC_ASYNC_LINK_STATUS_UP:
3461 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05003462 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003463 break;
3464 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05003465 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04003466 break;
3467 default:
3468 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3469 "0399 Invalid link attention type: x%x\n",
3470 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003471 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003472 break;
3473 }
3474 return att_type;
3475}
3476
3477/**
3478 * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
3479 * @phba: pointer to lpfc hba data structure.
3480 * @acqe_link: pointer to the async link completion queue entry.
3481 *
3482 * This routine is to parse the SLI4 link-attention link speed and translate
3483 * it into the base driver's link-attention link speed coding.
3484 *
3485 * Return: Link-attention link speed in terms of base driver's coding.
3486 **/
3487static uint8_t
3488lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba,
3489 struct lpfc_acqe_link *acqe_link)
3490{
3491 uint8_t link_speed;
3492
3493 switch (bf_get(lpfc_acqe_link_speed, acqe_link)) {
3494 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smartda0436e2009-05-22 14:51:39 -04003495 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smartda0436e2009-05-22 14:51:39 -04003496 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart76a95d72010-11-20 23:11:48 -05003497 link_speed = LPFC_LINK_SPEED_UNKNOWN;
James Smartda0436e2009-05-22 14:51:39 -04003498 break;
3499 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart76a95d72010-11-20 23:11:48 -05003500 link_speed = LPFC_LINK_SPEED_1GHZ;
James Smartda0436e2009-05-22 14:51:39 -04003501 break;
3502 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart76a95d72010-11-20 23:11:48 -05003503 link_speed = LPFC_LINK_SPEED_10GHZ;
James Smartda0436e2009-05-22 14:51:39 -04003504 break;
3505 default:
3506 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3507 "0483 Invalid link-attention link speed: x%x\n",
3508 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003509 link_speed = LPFC_LINK_SPEED_UNKNOWN;
James Smartda0436e2009-05-22 14:51:39 -04003510 break;
3511 }
3512 return link_speed;
3513}
3514
3515/**
James Smart8b68cd52012-09-29 11:32:37 -04003516 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
3517 * @phba: pointer to lpfc hba data structure.
3518 *
3519 * This routine is to get an SLI3 FC port's link speed in Mbps.
3520 *
3521 * Return: link speed in terms of Mbps.
3522 **/
3523uint32_t
3524lpfc_sli_port_speed_get(struct lpfc_hba *phba)
3525{
3526 uint32_t link_speed;
3527
3528 if (!lpfc_is_link_up(phba))
3529 return 0;
3530
3531 switch (phba->fc_linkspeed) {
3532 case LPFC_LINK_SPEED_1GHZ:
3533 link_speed = 1000;
3534 break;
3535 case LPFC_LINK_SPEED_2GHZ:
3536 link_speed = 2000;
3537 break;
3538 case LPFC_LINK_SPEED_4GHZ:
3539 link_speed = 4000;
3540 break;
3541 case LPFC_LINK_SPEED_8GHZ:
3542 link_speed = 8000;
3543 break;
3544 case LPFC_LINK_SPEED_10GHZ:
3545 link_speed = 10000;
3546 break;
3547 case LPFC_LINK_SPEED_16GHZ:
3548 link_speed = 16000;
3549 break;
3550 default:
3551 link_speed = 0;
3552 }
3553 return link_speed;
3554}
3555
3556/**
3557 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
3558 * @phba: pointer to lpfc hba data structure.
3559 * @evt_code: asynchronous event code.
3560 * @speed_code: asynchronous event link speed code.
3561 *
3562 * This routine is to parse the giving SLI4 async event link speed code into
3563 * value of Mbps for the link speed.
3564 *
3565 * Return: link speed in terms of Mbps.
3566 **/
3567static uint32_t
3568lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
3569 uint8_t speed_code)
3570{
3571 uint32_t port_speed;
3572
3573 switch (evt_code) {
3574 case LPFC_TRAILER_CODE_LINK:
3575 switch (speed_code) {
3576 case LPFC_EVT_CODE_LINK_NO_LINK:
3577 port_speed = 0;
3578 break;
3579 case LPFC_EVT_CODE_LINK_10_MBIT:
3580 port_speed = 10;
3581 break;
3582 case LPFC_EVT_CODE_LINK_100_MBIT:
3583 port_speed = 100;
3584 break;
3585 case LPFC_EVT_CODE_LINK_1_GBIT:
3586 port_speed = 1000;
3587 break;
3588 case LPFC_EVT_CODE_LINK_10_GBIT:
3589 port_speed = 10000;
3590 break;
3591 default:
3592 port_speed = 0;
3593 }
3594 break;
3595 case LPFC_TRAILER_CODE_FC:
3596 switch (speed_code) {
3597 case LPFC_EVT_CODE_FC_NO_LINK:
3598 port_speed = 0;
3599 break;
3600 case LPFC_EVT_CODE_FC_1_GBAUD:
3601 port_speed = 1000;
3602 break;
3603 case LPFC_EVT_CODE_FC_2_GBAUD:
3604 port_speed = 2000;
3605 break;
3606 case LPFC_EVT_CODE_FC_4_GBAUD:
3607 port_speed = 4000;
3608 break;
3609 case LPFC_EVT_CODE_FC_8_GBAUD:
3610 port_speed = 8000;
3611 break;
3612 case LPFC_EVT_CODE_FC_10_GBAUD:
3613 port_speed = 10000;
3614 break;
3615 case LPFC_EVT_CODE_FC_16_GBAUD:
3616 port_speed = 16000;
3617 break;
3618 default:
3619 port_speed = 0;
3620 }
3621 break;
3622 default:
3623 port_speed = 0;
3624 }
3625 return port_speed;
3626}
3627
3628/**
James Smart70f3c072010-12-15 17:57:33 -05003629 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04003630 * @phba: pointer to lpfc hba data structure.
3631 * @acqe_link: pointer to the async link completion queue entry.
3632 *
James Smart70f3c072010-12-15 17:57:33 -05003633 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04003634 **/
3635static void
3636lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
3637 struct lpfc_acqe_link *acqe_link)
3638{
3639 struct lpfc_dmabuf *mp;
3640 LPFC_MBOXQ_t *pmb;
3641 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05003642 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04003643 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05003644 int rc;
James Smartda0436e2009-05-22 14:51:39 -04003645
3646 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05003647 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04003648 return;
James Smart32b97932009-07-19 10:01:21 -04003649 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04003650 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3651 if (!pmb) {
3652 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3653 "0395 The mboxq allocation failed\n");
3654 return;
3655 }
3656 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3657 if (!mp) {
3658 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3659 "0396 The lpfc_dmabuf allocation failed\n");
3660 goto out_free_pmb;
3661 }
3662 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
3663 if (!mp->virt) {
3664 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3665 "0397 The mbuf allocation failed\n");
3666 goto out_free_dmabuf;
3667 }
3668
3669 /* Cleanup any outstanding ELS commands */
3670 lpfc_els_flush_all_cmd(phba);
3671
3672 /* Block ELS IOCBs until we have done process link event */
3673 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
3674
3675 /* Update link event statistics */
3676 phba->sli.slistat.link_event++;
3677
James Smart76a95d72010-11-20 23:11:48 -05003678 /* Create lpfc_handle_latt mailbox command from link ACQE */
3679 lpfc_read_topology(phba, pmb, mp);
3680 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04003681 pmb->vport = phba->pport;
3682
James Smartda0436e2009-05-22 14:51:39 -04003683 /* Keep the link status for extra SLI4 state machine reference */
3684 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04003685 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
3686 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04003687 phba->sli4_hba.link_state.duplex =
3688 bf_get(lpfc_acqe_link_duplex, acqe_link);
3689 phba->sli4_hba.link_state.status =
3690 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05003691 phba->sli4_hba.link_state.type =
3692 bf_get(lpfc_acqe_link_type, acqe_link);
3693 phba->sli4_hba.link_state.number =
3694 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04003695 phba->sli4_hba.link_state.fault =
3696 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05003697 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04003698 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
3699
James Smart70f3c072010-12-15 17:57:33 -05003700 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04003701 "2900 Async FC/FCoE Link event - Speed:%dGBit "
3702 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
3703 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05003704 phba->sli4_hba.link_state.speed,
3705 phba->sli4_hba.link_state.topology,
3706 phba->sli4_hba.link_state.status,
3707 phba->sli4_hba.link_state.type,
3708 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04003709 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05003710 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05003711 /*
3712 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
3713 * topology info. Note: Optional for non FC-AL ports.
3714 */
3715 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3716 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3717 if (rc == MBX_NOT_FINISHED)
3718 goto out_free_dmabuf;
3719 return;
3720 }
3721 /*
3722 * For FCoE Mode: fill in all the topology information we need and call
3723 * the READ_TOPOLOGY completion routine to continue without actually
3724 * sending the READ_TOPOLOGY mailbox command to the port.
3725 */
3726 /* Parse and translate status field */
3727 mb = &pmb->u.mb;
3728 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
3729
3730 /* Parse and translate link attention fields */
3731 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3732 la->eventTag = acqe_link->event_tag;
3733 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
3734 bf_set(lpfc_mbx_read_top_link_spd, la,
3735 lpfc_sli4_parse_latt_link_speed(phba, acqe_link));
3736
3737 /* Fake the the following irrelvant fields */
3738 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
3739 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
3740 bf_set(lpfc_mbx_read_top_il, la, 0);
3741 bf_set(lpfc_mbx_read_top_pb, la, 0);
3742 bf_set(lpfc_mbx_read_top_fa, la, 0);
3743 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04003744
3745 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05003746 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04003747
3748 return;
3749
3750out_free_dmabuf:
3751 kfree(mp);
3752out_free_pmb:
3753 mempool_free(pmb, phba->mbox_mem_pool);
3754}
3755
3756/**
James Smart70f3c072010-12-15 17:57:33 -05003757 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
3758 * @phba: pointer to lpfc hba data structure.
3759 * @acqe_fc: pointer to the async fc completion queue entry.
3760 *
3761 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
3762 * that the event was received and then issue a read_topology mailbox command so
3763 * that the rest of the driver will treat it the same as SLI3.
3764 **/
3765static void
3766lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
3767{
3768 struct lpfc_dmabuf *mp;
3769 LPFC_MBOXQ_t *pmb;
3770 int rc;
3771
3772 if (bf_get(lpfc_trailer_type, acqe_fc) !=
3773 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
3774 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3775 "2895 Non FC link Event detected.(%d)\n",
3776 bf_get(lpfc_trailer_type, acqe_fc));
3777 return;
3778 }
3779 /* Keep the link status for extra SLI4 state machine reference */
3780 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04003781 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
3782 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05003783 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
3784 phba->sli4_hba.link_state.topology =
3785 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
3786 phba->sli4_hba.link_state.status =
3787 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
3788 phba->sli4_hba.link_state.type =
3789 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
3790 phba->sli4_hba.link_state.number =
3791 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
3792 phba->sli4_hba.link_state.fault =
3793 bf_get(lpfc_acqe_link_fault, acqe_fc);
3794 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04003795 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart70f3c072010-12-15 17:57:33 -05003796 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3797 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
3798 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
3799 "%dMbps Fault:%d\n",
3800 phba->sli4_hba.link_state.speed,
3801 phba->sli4_hba.link_state.topology,
3802 phba->sli4_hba.link_state.status,
3803 phba->sli4_hba.link_state.type,
3804 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04003805 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05003806 phba->sli4_hba.link_state.fault);
3807 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3808 if (!pmb) {
3809 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3810 "2897 The mboxq allocation failed\n");
3811 return;
3812 }
3813 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3814 if (!mp) {
3815 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3816 "2898 The lpfc_dmabuf allocation failed\n");
3817 goto out_free_pmb;
3818 }
3819 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
3820 if (!mp->virt) {
3821 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3822 "2899 The mbuf allocation failed\n");
3823 goto out_free_dmabuf;
3824 }
3825
3826 /* Cleanup any outstanding ELS commands */
3827 lpfc_els_flush_all_cmd(phba);
3828
3829 /* Block ELS IOCBs until we have done process link event */
3830 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
3831
3832 /* Update link event statistics */
3833 phba->sli.slistat.link_event++;
3834
3835 /* Create lpfc_handle_latt mailbox command from link ACQE */
3836 lpfc_read_topology(phba, pmb, mp);
3837 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
3838 pmb->vport = phba->pport;
3839
3840 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3841 if (rc == MBX_NOT_FINISHED)
3842 goto out_free_dmabuf;
3843 return;
3844
3845out_free_dmabuf:
3846 kfree(mp);
3847out_free_pmb:
3848 mempool_free(pmb, phba->mbox_mem_pool);
3849}
3850
3851/**
3852 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
3853 * @phba: pointer to lpfc hba data structure.
3854 * @acqe_fc: pointer to the async SLI completion queue entry.
3855 *
3856 * This routine is to handle the SLI4 asynchronous SLI events.
3857 **/
3858static void
3859lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
3860{
James Smart4b8bae02012-06-12 13:55:07 -04003861 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04003862 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04003863 uint8_t status;
3864 struct lpfc_acqe_misconfigured_event *misconfigured;
3865
3866 /* special case misconfigured event as it contains data for all ports */
3867 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3868 LPFC_SLI_INTF_IF_TYPE_2) ||
3869 (bf_get(lpfc_trailer_type, acqe_sli) !=
3870 LPFC_SLI_EVENT_TYPE_MISCONFIGURED)) {
3871 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3872 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
3873 "x%08x SLI Event Type:%d\n",
3874 acqe_sli->event_data1, acqe_sli->event_data2,
3875 bf_get(lpfc_trailer_type, acqe_sli));
3876 return;
3877 }
3878
3879 port_name = phba->Port[0];
3880 if (port_name == 0x00)
3881 port_name = '?'; /* get port name is empty */
3882
3883 misconfigured = (struct lpfc_acqe_misconfigured_event *)
3884 &acqe_sli->event_data1;
3885
3886 /* fetch the status for this port */
3887 switch (phba->sli4_hba.lnk_info.lnk_no) {
3888 case LPFC_LINK_NUMBER_0:
3889 status = bf_get(lpfc_sli_misconfigured_port0,
3890 &misconfigured->theEvent);
3891 break;
3892 case LPFC_LINK_NUMBER_1:
3893 status = bf_get(lpfc_sli_misconfigured_port1,
3894 &misconfigured->theEvent);
3895 break;
3896 case LPFC_LINK_NUMBER_2:
3897 status = bf_get(lpfc_sli_misconfigured_port2,
3898 &misconfigured->theEvent);
3899 break;
3900 case LPFC_LINK_NUMBER_3:
3901 status = bf_get(lpfc_sli_misconfigured_port3,
3902 &misconfigured->theEvent);
3903 break;
3904 default:
3905 status = ~LPFC_SLI_EVENT_STATUS_VALID;
3906 break;
3907 }
3908
3909 switch (status) {
3910 case LPFC_SLI_EVENT_STATUS_VALID:
3911 return; /* no message if the sfp is okay */
3912 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
James Smart292098b2012-09-29 11:31:41 -04003913 sprintf(message, "Optics faulted/incorrectly installed/not " \
3914 "installed - Reseat optics, if issue not "
3915 "resolved, replace.");
James Smart4b8bae02012-06-12 13:55:07 -04003916 break;
3917 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
3918 sprintf(message,
James Smart292098b2012-09-29 11:31:41 -04003919 "Optics of two types installed - Remove one optic or " \
3920 "install matching pair of optics.");
James Smart4b8bae02012-06-12 13:55:07 -04003921 break;
3922 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
James Smart292098b2012-09-29 11:31:41 -04003923 sprintf(message, "Incompatible optics - Replace with " \
3924 "compatible optics for card to function.");
James Smart4b8bae02012-06-12 13:55:07 -04003925 break;
3926 default:
3927 /* firmware is reporting a status we don't know about */
3928 sprintf(message, "Unknown event status x%02x", status);
3929 break;
3930 }
3931
3932 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3933 "3176 Misconfigured Physical Port - "
3934 "Port Name %c %s\n", port_name, message);
James Smart70f3c072010-12-15 17:57:33 -05003935}
3936
3937/**
James Smartfc2b9892010-02-26 14:15:29 -05003938 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
3939 * @vport: pointer to vport data structure.
3940 *
3941 * This routine is to perform Clear Virtual Link (CVL) on a vport in
3942 * response to a CVL event.
3943 *
3944 * Return the pointer to the ndlp with the vport if successful, otherwise
3945 * return NULL.
3946 **/
3947static struct lpfc_nodelist *
3948lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
3949{
3950 struct lpfc_nodelist *ndlp;
3951 struct Scsi_Host *shost;
3952 struct lpfc_hba *phba;
3953
3954 if (!vport)
3955 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05003956 phba = vport->phba;
3957 if (!phba)
3958 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04003959 ndlp = lpfc_findnode_did(vport, Fabric_DID);
3960 if (!ndlp) {
3961 /* Cannot find existing Fabric ndlp, so allocate a new one */
3962 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3963 if (!ndlp)
3964 return 0;
3965 lpfc_nlp_init(vport, ndlp, Fabric_DID);
3966 /* Set the node type */
3967 ndlp->nlp_type |= NLP_FABRIC;
3968 /* Put ndlp onto node list */
3969 lpfc_enqueue_node(vport, ndlp);
3970 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3971 /* re-setup ndlp without removing from node list */
3972 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3973 if (!ndlp)
3974 return 0;
3975 }
James Smart63e801c2010-11-20 23:14:19 -05003976 if ((phba->pport->port_state < LPFC_FLOGI) &&
3977 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05003978 return NULL;
3979 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05003980 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
3981 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05003982 return NULL;
3983 shost = lpfc_shost_from_vport(vport);
3984 if (!shost)
3985 return NULL;
3986 lpfc_linkdown_port(vport);
3987 lpfc_cleanup_pending_mbox(vport);
3988 spin_lock_irq(shost->host_lock);
3989 vport->fc_flag |= FC_VPORT_CVL_RCVD;
3990 spin_unlock_irq(shost->host_lock);
3991
3992 return ndlp;
3993}
3994
3995/**
3996 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
3997 * @vport: pointer to lpfc hba data structure.
3998 *
3999 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4000 * response to a FCF dead event.
4001 **/
4002static void
4003lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
4004{
4005 struct lpfc_vport **vports;
4006 int i;
4007
4008 vports = lpfc_create_vport_work_array(phba);
4009 if (vports)
4010 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4011 lpfc_sli4_perform_vport_cvl(vports[i]);
4012 lpfc_destroy_vport_work_array(phba, vports);
4013}
4014
4015/**
James Smart25aee402013-03-01 16:36:34 -05004016 * lpfc_sli4_perform_inuse_fcf_recovery - Perform inuse fcf recovery
4017 * @vport: pointer to lpfc hba data structure.
4018 *
4019 * This routine is to perform FCF recovery when the in-use FCF either dead or
4020 * got modified.
4021 **/
4022static void
4023lpfc_sli4_perform_inuse_fcf_recovery(struct lpfc_hba *phba,
4024 struct lpfc_acqe_fip *acqe_fip)
4025{
4026 int rc;
4027
4028 spin_lock_irq(&phba->hbalock);
4029 /* Mark the fast failover process in progress */
4030 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
4031 spin_unlock_irq(&phba->hbalock);
4032
4033 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
4034 "2771 Start FCF fast failover process due to in-use "
4035 "FCF DEAD/MODIFIED event: evt_tag:x%x, index:x%x\n",
4036 acqe_fip->event_tag, acqe_fip->index);
4037 rc = lpfc_sli4_redisc_fcf_table(phba);
4038 if (rc) {
4039 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4040 "2772 Issue FCF rediscover mabilbox command "
4041 "failed, fail through to FCF dead event\n");
4042 spin_lock_irq(&phba->hbalock);
4043 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
4044 spin_unlock_irq(&phba->hbalock);
4045 /*
4046 * Last resort will fail over by treating this as a link
4047 * down to FCF registration.
4048 */
4049 lpfc_sli4_fcf_dead_failthrough(phba);
4050 } else {
4051 /* Reset FCF roundrobin bmask for new discovery */
4052 lpfc_sli4_clear_fcf_rr_bmask(phba);
4053 /*
4054 * Handling fast FCF failover to a DEAD FCF event is
4055 * considered equalivant to receiving CVL to all vports.
4056 */
4057 lpfc_sli4_perform_all_vport_cvl(phba);
4058 }
4059}
4060
4061/**
James Smart76a95d72010-11-20 23:11:48 -05004062 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04004063 * @phba: pointer to lpfc hba data structure.
4064 * @acqe_link: pointer to the async fcoe completion queue entry.
4065 *
4066 * This routine is to handle the SLI4 asynchronous fcoe event.
4067 **/
4068static void
James Smart76a95d72010-11-20 23:11:48 -05004069lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05004070 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04004071{
James Smart70f3c072010-12-15 17:57:33 -05004072 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004073 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04004074 struct lpfc_vport *vport;
4075 struct lpfc_nodelist *ndlp;
4076 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05004077 int active_vlink_present;
4078 struct lpfc_vport **vports;
4079 int i;
James Smartda0436e2009-05-22 14:51:39 -04004080
James Smart70f3c072010-12-15 17:57:33 -05004081 phba->fc_eventTag = acqe_fip->event_tag;
4082 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004083 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05004084 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
4085 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
4086 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04004087 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4088 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004089 "2546 New FCF event, evt_tag:x%x, "
4090 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004091 acqe_fip->event_tag,
4092 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04004093 else
4094 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
4095 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004096 "2788 FCF param modified event, "
4097 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004098 acqe_fip->event_tag,
4099 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04004100 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004101 /*
4102 * During period of FCF discovery, read the FCF
4103 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04004104 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05004105 */
4106 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4107 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004108 "2779 Read FCF (x%x) for updating "
4109 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05004110 acqe_fip->index);
4111 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004112 }
James Smart38b92ef2010-08-04 16:11:39 -04004113
4114 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04004115 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04004116 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04004117 spin_unlock_irq(&phba->hbalock);
4118 break;
4119 }
4120 /* If fast FCF failover rescan event is pending, do nothing */
4121 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
4122 spin_unlock_irq(&phba->hbalock);
4123 break;
4124 }
4125
James Smart25aee402013-03-01 16:36:34 -05004126 /* If FCF has been in discovered state, perform rediscovery
4127 * only if the FCF with the same index of the in-use FCF got
4128 * modified during normal operation. Otherwise, do nothing.
4129 */
4130 if (phba->pport->port_state > LPFC_FLOGI) {
James Smart3804dc82010-07-14 15:31:37 -04004131 spin_unlock_irq(&phba->hbalock);
James Smart25aee402013-03-01 16:36:34 -05004132 if (phba->fcf.current_rec.fcf_indx ==
4133 acqe_fip->index) {
4134 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
4135 "3300 In-use FCF (%d) "
4136 "modified, perform FCF "
4137 "rediscovery\n",
4138 acqe_fip->index);
4139 lpfc_sli4_perform_inuse_fcf_recovery(phba,
4140 acqe_fip);
4141 }
James Smart3804dc82010-07-14 15:31:37 -04004142 break;
4143 }
4144 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04004145
James Smart0c9ab6f2010-02-26 14:15:57 -05004146 /* Otherwise, scan the entire FCF table and re-discover SAN */
4147 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004148 "2770 Start FCF table scan per async FCF "
4149 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004150 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004151 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
4152 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04004153 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004154 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4155 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04004156 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04004157 break;
4158
James Smart70f3c072010-12-15 17:57:33 -05004159 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04004160 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04004161 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004162 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
4163 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004164 break;
4165
James Smart70f3c072010-12-15 17:57:33 -05004166 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05004167 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004168 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004169 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05004170 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04004171 /*
4172 * If we are in the middle of FCF failover process, clear
4173 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04004174 */
James Smartfc2b9892010-02-26 14:15:29 -05004175 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004176 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05004177 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004178 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05004179 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004180 break;
4181 }
James Smart38b92ef2010-08-04 16:11:39 -04004182 spin_unlock_irq(&phba->hbalock);
4183
4184 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05004185 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04004186 break;
4187
4188 /*
4189 * Otherwise, request the port to rediscover the entire FCF
4190 * table for a fast recovery from case that the current FCF
4191 * is no longer valid as we are not in the middle of FCF
4192 * failover process already.
4193 */
James Smart25aee402013-03-01 16:36:34 -05004194 lpfc_sli4_perform_inuse_fcf_recovery(phba, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004195 break;
James Smart70f3c072010-12-15 17:57:33 -05004196 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05004197 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004198 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04004199 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05004200 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04004201
James Smart6669f9b2009-10-02 15:16:45 -04004202 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04004203 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004204 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004205 if (!ndlp)
4206 break;
James Smart695a8142010-01-26 23:08:03 -05004207 active_vlink_present = 0;
4208
4209 vports = lpfc_create_vport_work_array(phba);
4210 if (vports) {
4211 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
4212 i++) {
4213 if ((!(vports[i]->fc_flag &
4214 FC_VPORT_CVL_RCVD)) &&
4215 (vports[i]->port_state > LPFC_FDISC)) {
4216 active_vlink_present = 1;
4217 break;
4218 }
4219 }
4220 lpfc_destroy_vport_work_array(phba, vports);
4221 }
4222
4223 if (active_vlink_present) {
4224 /*
4225 * If there are other active VLinks present,
4226 * re-instantiate the Vlink using FDISC.
4227 */
James Smart6669f9b2009-10-02 15:16:45 -04004228 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
James Smartfc2b9892010-02-26 14:15:29 -05004229 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004230 spin_lock_irq(shost->host_lock);
4231 ndlp->nlp_flag |= NLP_DELAY_TMO;
4232 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05004233 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
4234 vport->port_state = LPFC_FDISC;
4235 } else {
James Smartecfd03c2010-02-12 14:41:27 -05004236 /*
4237 * Otherwise, we request port to rediscover
4238 * the entire FCF table for a fast recovery
4239 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05004240 * is no longer valid if we are not already
4241 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05004242 */
James Smartfc2b9892010-02-26 14:15:29 -05004243 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004244 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05004245 spin_unlock_irq(&phba->hbalock);
4246 break;
4247 }
4248 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05004249 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004250 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004251 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4252 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004253 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05004254 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05004255 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05004256 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004257 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4258 LOG_DISCOVERY,
4259 "2774 Issue FCF rediscover "
4260 "mabilbox command failed, "
4261 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05004262 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004263 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004264 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05004265 /*
4266 * Last resort will be re-try on the
4267 * the current registered FCF entry.
4268 */
4269 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04004270 } else
4271 /*
4272 * Reset FCF roundrobin bmask for new
4273 * discovery.
4274 */
James Smart7d791df2011-07-22 18:37:52 -04004275 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04004276 }
4277 break;
James Smartda0436e2009-05-22 14:51:39 -04004278 default:
4279 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4280 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05004281 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004282 break;
4283 }
4284}
4285
4286/**
4287 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
4288 * @phba: pointer to lpfc hba data structure.
4289 * @acqe_link: pointer to the async dcbx completion queue entry.
4290 *
4291 * This routine is to handle the SLI4 asynchronous dcbx event.
4292 **/
4293static void
4294lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
4295 struct lpfc_acqe_dcbx *acqe_dcbx)
4296{
James Smart4d9ab992009-10-02 15:16:39 -04004297 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004298 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4299 "0290 The SLI4 DCBX asynchronous event is not "
4300 "handled yet\n");
4301}
4302
4303/**
James Smartb19a0612010-04-06 14:48:51 -04004304 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
4305 * @phba: pointer to lpfc hba data structure.
4306 * @acqe_link: pointer to the async grp5 completion queue entry.
4307 *
4308 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
4309 * is an asynchronous notified of a logical link speed change. The Port
4310 * reports the logical link speed in units of 10Mbps.
4311 **/
4312static void
4313lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
4314 struct lpfc_acqe_grp5 *acqe_grp5)
4315{
4316 uint16_t prev_ll_spd;
4317
4318 phba->fc_eventTag = acqe_grp5->event_tag;
4319 phba->fcoe_eventtag = acqe_grp5->event_tag;
4320 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
4321 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004322 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04004323 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4324 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04004325 "from %dMbps to %dMbps\n", prev_ll_spd,
4326 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04004327}
4328
4329/**
James Smartda0436e2009-05-22 14:51:39 -04004330 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
4331 * @phba: pointer to lpfc hba data structure.
4332 *
4333 * This routine is invoked by the worker thread to process all the pending
4334 * SLI4 asynchronous events.
4335 **/
4336void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
4337{
4338 struct lpfc_cq_event *cq_event;
4339
4340 /* First, declare the async event has been handled */
4341 spin_lock_irq(&phba->hbalock);
4342 phba->hba_flag &= ~ASYNC_EVENT;
4343 spin_unlock_irq(&phba->hbalock);
4344 /* Now, handle all the async events */
4345 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
4346 /* Get the first event from the head of the event queue */
4347 spin_lock_irq(&phba->hbalock);
4348 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
4349 cq_event, struct lpfc_cq_event, list);
4350 spin_unlock_irq(&phba->hbalock);
4351 /* Process the asynchronous event */
4352 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
4353 case LPFC_TRAILER_CODE_LINK:
4354 lpfc_sli4_async_link_evt(phba,
4355 &cq_event->cqe.acqe_link);
4356 break;
4357 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05004358 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004359 break;
4360 case LPFC_TRAILER_CODE_DCBX:
4361 lpfc_sli4_async_dcbx_evt(phba,
4362 &cq_event->cqe.acqe_dcbx);
4363 break;
James Smartb19a0612010-04-06 14:48:51 -04004364 case LPFC_TRAILER_CODE_GRP5:
4365 lpfc_sli4_async_grp5_evt(phba,
4366 &cq_event->cqe.acqe_grp5);
4367 break;
James Smart70f3c072010-12-15 17:57:33 -05004368 case LPFC_TRAILER_CODE_FC:
4369 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
4370 break;
4371 case LPFC_TRAILER_CODE_SLI:
4372 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
4373 break;
James Smartda0436e2009-05-22 14:51:39 -04004374 default:
4375 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4376 "1804 Invalid asynchrous event code: "
4377 "x%x\n", bf_get(lpfc_trailer_code,
4378 &cq_event->cqe.mcqe_cmpl));
4379 break;
4380 }
4381 /* Free the completion event processed to the free pool */
4382 lpfc_sli4_cq_event_release(phba, cq_event);
4383 }
4384}
4385
4386/**
James Smartecfd03c2010-02-12 14:41:27 -05004387 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
4388 * @phba: pointer to lpfc hba data structure.
4389 *
4390 * This routine is invoked by the worker thread to process FCF table
4391 * rediscovery pending completion event.
4392 **/
4393void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
4394{
4395 int rc;
4396
4397 spin_lock_irq(&phba->hbalock);
4398 /* Clear FCF rediscovery timeout event */
4399 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
4400 /* Clear driver fast failover FCF record flag */
4401 phba->fcf.failover_rec.flag = 0;
4402 /* Set state for FCF fast failover */
4403 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
4404 spin_unlock_irq(&phba->hbalock);
4405
4406 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05004407 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004408 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05004409 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05004410 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004411 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4412 "2747 Issue FCF scan read FCF mailbox "
4413 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05004414}
4415
4416/**
James Smartda0436e2009-05-22 14:51:39 -04004417 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
4418 * @phba: pointer to lpfc hba data structure.
4419 * @dev_grp: The HBA PCI-Device group number.
4420 *
4421 * This routine is invoked to set up the per HBA PCI-Device group function
4422 * API jump table entries.
4423 *
4424 * Return: 0 if success, otherwise -ENODEV
4425 **/
4426int
4427lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05004428{
4429 int rc;
4430
James Smartda0436e2009-05-22 14:51:39 -04004431 /* Set up lpfc PCI-device group */
4432 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05004433
James Smartda0436e2009-05-22 14:51:39 -04004434 /* The LPFC_PCI_DEV_OC uses SLI4 */
4435 if (dev_grp == LPFC_PCI_DEV_OC)
4436 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05004437
James Smartda0436e2009-05-22 14:51:39 -04004438 /* Set up device INIT API function jump table */
4439 rc = lpfc_init_api_table_setup(phba, dev_grp);
4440 if (rc)
4441 return -ENODEV;
4442 /* Set up SCSI API function jump table */
4443 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
4444 if (rc)
4445 return -ENODEV;
4446 /* Set up SLI API function jump table */
4447 rc = lpfc_sli_api_table_setup(phba, dev_grp);
4448 if (rc)
4449 return -ENODEV;
4450 /* Set up MBOX API function jump table */
4451 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
4452 if (rc)
4453 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05004454
James Smartda0436e2009-05-22 14:51:39 -04004455 return 0;
James Smart5b75da22008-12-04 22:39:35 -05004456}
4457
4458/**
James Smart3621a712009-04-06 18:47:14 -04004459 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05004460 * @phba: pointer to lpfc hba data structure.
4461 * @intr_mode: active interrupt mode adopted.
4462 *
4463 * This routine it invoked to log the currently used active interrupt mode
4464 * to the device.
James Smart3772a992009-05-22 14:50:54 -04004465 **/
4466static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05004467{
4468 switch (intr_mode) {
4469 case 0:
4470 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4471 "0470 Enable INTx interrupt mode.\n");
4472 break;
4473 case 1:
4474 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4475 "0481 Enabled MSI interrupt mode.\n");
4476 break;
4477 case 2:
4478 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4479 "0480 Enabled MSI-X interrupt mode.\n");
4480 break;
4481 default:
4482 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4483 "0482 Illegal interrupt mode.\n");
4484 break;
4485 }
4486 return;
4487}
4488
James Smart5b75da22008-12-04 22:39:35 -05004489/**
James Smart3772a992009-05-22 14:50:54 -04004490 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05004491 * @phba: pointer to lpfc hba data structure.
4492 *
James Smart3772a992009-05-22 14:50:54 -04004493 * This routine is invoked to enable the PCI device that is common to all
4494 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05004495 *
4496 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004497 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004498 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05004499 **/
James Smart3772a992009-05-22 14:50:54 -04004500static int
4501lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05004502{
James Smart3772a992009-05-22 14:50:54 -04004503 struct pci_dev *pdev;
James Smart079b5c92011-08-21 21:48:49 -04004504 int bars = 0;
James Smart5b75da22008-12-04 22:39:35 -05004505
James Smart3772a992009-05-22 14:50:54 -04004506 /* Obtain PCI device reference */
4507 if (!phba->pcidev)
4508 goto out_error;
4509 else
4510 pdev = phba->pcidev;
4511 /* Select PCI BARs */
4512 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4513 /* Enable PCI device */
4514 if (pci_enable_device_mem(pdev))
4515 goto out_error;
4516 /* Request PCI resource for the device */
4517 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
4518 goto out_disable_device;
4519 /* Set up device as PCI master and save state for EEH */
4520 pci_set_master(pdev);
4521 pci_try_set_mwi(pdev);
4522 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05004523
James Smart05580562011-05-24 11:40:48 -04004524 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
4525 if (pci_find_capability(pdev, PCI_CAP_ID_EXP))
4526 pdev->needs_freset = 1;
4527
James Smart3772a992009-05-22 14:50:54 -04004528 return 0;
James Smart5b75da22008-12-04 22:39:35 -05004529
James Smart3772a992009-05-22 14:50:54 -04004530out_disable_device:
4531 pci_disable_device(pdev);
4532out_error:
James Smart079b5c92011-08-21 21:48:49 -04004533 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4534 "1401 Failed to enable pci device, bars:x%x\n", bars);
James Smart3772a992009-05-22 14:50:54 -04004535 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05004536}
4537
4538/**
James Smart3772a992009-05-22 14:50:54 -04004539 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05004540 * @phba: pointer to lpfc hba data structure.
4541 *
James Smart3772a992009-05-22 14:50:54 -04004542 * This routine is invoked to disable the PCI device that is common to all
4543 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05004544 **/
4545static void
James Smart3772a992009-05-22 14:50:54 -04004546lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05004547{
James Smart3772a992009-05-22 14:50:54 -04004548 struct pci_dev *pdev;
4549 int bars;
James Smart5b75da22008-12-04 22:39:35 -05004550
James Smart3772a992009-05-22 14:50:54 -04004551 /* Obtain PCI device reference */
4552 if (!phba->pcidev)
4553 return;
4554 else
4555 pdev = phba->pcidev;
4556 /* Select PCI BARs */
4557 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4558 /* Release PCI resource and disable PCI device */
4559 pci_release_selected_regions(pdev, bars);
4560 pci_disable_device(pdev);
4561 /* Null out PCI private reference to driver */
4562 pci_set_drvdata(pdev, NULL);
James Smart5b75da22008-12-04 22:39:35 -05004563
4564 return;
4565}
4566
4567/**
James Smart3772a992009-05-22 14:50:54 -04004568 * lpfc_reset_hba - Reset a hba
4569 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04004570 *
James Smart3772a992009-05-22 14:50:54 -04004571 * This routine is invoked to reset a hba device. It brings the HBA
4572 * offline, performs a board restart, and then brings the board back
4573 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
4574 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04004575 **/
James Smart3772a992009-05-22 14:50:54 -04004576void
4577lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05004578{
James Smart3772a992009-05-22 14:50:54 -04004579 /* If resets are disabled then set error state and return. */
4580 if (!phba->cfg_enable_hba_reset) {
4581 phba->link_state = LPFC_HBA_ERROR;
4582 return;
4583 }
James Smart618a5232012-06-12 13:54:36 -04004584 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3772a992009-05-22 14:50:54 -04004585 lpfc_offline(phba);
4586 lpfc_sli_brdrestart(phba);
4587 lpfc_online(phba);
4588 lpfc_unblock_mgmt_io(phba);
4589}
dea31012005-04-17 16:05:31 -05004590
James Smart3772a992009-05-22 14:50:54 -04004591/**
James Smart0a96e972011-07-22 18:37:28 -04004592 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
4593 * @phba: pointer to lpfc hba data structure.
4594 *
4595 * This function enables the PCI SR-IOV virtual functions to a physical
4596 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4597 * enable the number of virtual functions to the physical function. As
4598 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4599 * API call does not considered as an error condition for most of the device.
4600 **/
4601uint16_t
4602lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
4603{
4604 struct pci_dev *pdev = phba->pcidev;
4605 uint16_t nr_virtfn;
4606 int pos;
4607
James Smart0a96e972011-07-22 18:37:28 -04004608 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4609 if (pos == 0)
4610 return 0;
4611
4612 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
4613 return nr_virtfn;
4614}
4615
4616/**
James Smart912e3ac2011-05-24 11:42:11 -04004617 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
4618 * @phba: pointer to lpfc hba data structure.
4619 * @nr_vfn: number of virtual functions to be enabled.
4620 *
4621 * This function enables the PCI SR-IOV virtual functions to a physical
4622 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4623 * enable the number of virtual functions to the physical function. As
4624 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4625 * API call does not considered as an error condition for most of the device.
4626 **/
4627int
4628lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
4629{
4630 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04004631 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04004632 int rc;
4633
James Smart0a96e972011-07-22 18:37:28 -04004634 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
4635 if (nr_vfn > max_nr_vfn) {
4636 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4637 "3057 Requested vfs (%d) greater than "
4638 "supported vfs (%d)", nr_vfn, max_nr_vfn);
4639 return -EINVAL;
4640 }
4641
James Smart912e3ac2011-05-24 11:42:11 -04004642 rc = pci_enable_sriov(pdev, nr_vfn);
4643 if (rc) {
4644 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4645 "2806 Failed to enable sriov on this device "
4646 "with vfn number nr_vf:%d, rc:%d\n",
4647 nr_vfn, rc);
4648 } else
4649 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4650 "2807 Successful enable sriov on this device "
4651 "with vfn number nr_vf:%d\n", nr_vfn);
4652 return rc;
4653}
4654
4655/**
James Smart3772a992009-05-22 14:50:54 -04004656 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
4657 * @phba: pointer to lpfc hba data structure.
4658 *
4659 * This routine is invoked to set up the driver internal resources specific to
4660 * support the SLI-3 HBA device it attached to.
4661 *
4662 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004663 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004664 * other values - error
4665 **/
4666static int
4667lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
4668{
4669 struct lpfc_sli *psli;
James Smart912e3ac2011-05-24 11:42:11 -04004670 int rc;
dea31012005-04-17 16:05:31 -05004671
James Smart3772a992009-05-22 14:50:54 -04004672 /*
4673 * Initialize timers used by driver
4674 */
dea31012005-04-17 16:05:31 -05004675
James Smart3772a992009-05-22 14:50:54 -04004676 /* Heartbeat timer */
4677 init_timer(&phba->hb_tmofunc);
4678 phba->hb_tmofunc.function = lpfc_hb_timeout;
4679 phba->hb_tmofunc.data = (unsigned long)phba;
4680
4681 psli = &phba->sli;
4682 /* MBOX heartbeat timer */
4683 init_timer(&psli->mbox_tmo);
4684 psli->mbox_tmo.function = lpfc_mbox_timeout;
4685 psli->mbox_tmo.data = (unsigned long) phba;
4686 /* FCP polling mode timer */
4687 init_timer(&phba->fcp_poll_timer);
4688 phba->fcp_poll_timer.function = lpfc_poll_timeout;
4689 phba->fcp_poll_timer.data = (unsigned long) phba;
4690 /* Fabric block timer */
4691 init_timer(&phba->fabric_block_timer);
4692 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
4693 phba->fabric_block_timer.data = (unsigned long) phba;
4694 /* EA polling mode timer */
4695 init_timer(&phba->eratt_poll);
4696 phba->eratt_poll.function = lpfc_poll_eratt;
4697 phba->eratt_poll.data = (unsigned long) phba;
4698
4699 /* Host attention work mask setup */
4700 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
4701 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
4702
4703 /* Get all the module params for configuring this host */
4704 lpfc_get_cfgparam(phba);
James Smart49198b32010-04-06 15:04:33 -04004705 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
4706 phba->menlo_flag |= HBA_MENLO_SUPPORT;
4707 /* check for menlo minimum sg count */
4708 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
4709 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
4710 }
4711
James Smart2a76a282012-08-03 12:35:54 -04004712 if (!phba->sli.ring)
4713 phba->sli.ring = (struct lpfc_sli_ring *)
4714 kzalloc(LPFC_SLI3_MAX_RING *
4715 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
4716 if (!phba->sli.ring)
4717 return -ENOMEM;
4718
James Smart3772a992009-05-22 14:50:54 -04004719 /*
4720 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
4721 * used to create the sg_dma_buf_pool must be dynamically calculated.
4722 * 2 segments are added since the IOCB needs a command and response bde.
4723 */
4724 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
4725 sizeof(struct fcp_rsp) +
4726 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
4727
4728 if (phba->cfg_enable_bg) {
4729 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT;
4730 phba->cfg_sg_dma_buf_size +=
4731 phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64);
4732 }
4733
4734 /* Also reinitialize the host templates with new values. */
4735 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4736 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4737
4738 phba->max_vpi = LPFC_MAX_VPI;
4739 /* This will be set to correct value after config_port mbox */
4740 phba->max_vports = 0;
4741
4742 /*
4743 * Initialize the SLI Layer to run with lpfc HBAs.
4744 */
4745 lpfc_sli_setup(phba);
4746 lpfc_sli_queue_setup(phba);
4747
4748 /* Allocate device driver memory */
4749 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
4750 return -ENOMEM;
4751
James Smart912e3ac2011-05-24 11:42:11 -04004752 /*
4753 * Enable sr-iov virtual functions if supported and configured
4754 * through the module parameter.
4755 */
4756 if (phba->cfg_sriov_nr_virtfn > 0) {
4757 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
4758 phba->cfg_sriov_nr_virtfn);
4759 if (rc) {
4760 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4761 "2808 Requested number of SR-IOV "
4762 "virtual functions (%d) is not "
4763 "supported\n",
4764 phba->cfg_sriov_nr_virtfn);
4765 phba->cfg_sriov_nr_virtfn = 0;
4766 }
4767 }
4768
James Smart3772a992009-05-22 14:50:54 -04004769 return 0;
4770}
4771
4772/**
4773 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
4774 * @phba: pointer to lpfc hba data structure.
4775 *
4776 * This routine is invoked to unset the driver internal resources set up
4777 * specific for supporting the SLI-3 HBA device it attached to.
4778 **/
4779static void
4780lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
4781{
4782 /* Free device driver memory allocated */
4783 lpfc_mem_free_all(phba);
4784
4785 return;
4786}
4787
4788/**
James Smartda0436e2009-05-22 14:51:39 -04004789 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
4790 * @phba: pointer to lpfc hba data structure.
4791 *
4792 * This routine is invoked to set up the driver internal resources specific to
4793 * support the SLI-4 HBA device it attached to.
4794 *
4795 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004796 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04004797 * other values - error
4798 **/
4799static int
4800lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
4801{
4802 struct lpfc_sli *psli;
James Smart28baac72010-02-12 14:42:03 -05004803 LPFC_MBOXQ_t *mboxq;
4804 int rc, i, hbq_count, buf_size, dma_buf_size, max_buf_size;
4805 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
4806 struct lpfc_mqe *mqe;
James Smart085c6472010-11-20 23:11:37 -05004807 int longs, sli_family;
James Smartacd68592012-01-18 16:25:09 -05004808 int sges_per_segment;
James Smartda0436e2009-05-22 14:51:39 -04004809
4810 /* Before proceed, wait for POST done and device ready */
4811 rc = lpfc_sli4_post_status_check(phba);
4812 if (rc)
4813 return -ENODEV;
4814
4815 /*
4816 * Initialize timers used by driver
4817 */
4818
4819 /* Heartbeat timer */
4820 init_timer(&phba->hb_tmofunc);
4821 phba->hb_tmofunc.function = lpfc_hb_timeout;
4822 phba->hb_tmofunc.data = (unsigned long)phba;
James Smart19ca7602010-11-20 23:11:55 -05004823 init_timer(&phba->rrq_tmr);
4824 phba->rrq_tmr.function = lpfc_rrq_timeout;
4825 phba->rrq_tmr.data = (unsigned long)phba;
James Smartda0436e2009-05-22 14:51:39 -04004826
4827 psli = &phba->sli;
4828 /* MBOX heartbeat timer */
4829 init_timer(&psli->mbox_tmo);
4830 psli->mbox_tmo.function = lpfc_mbox_timeout;
4831 psli->mbox_tmo.data = (unsigned long) phba;
4832 /* Fabric block timer */
4833 init_timer(&phba->fabric_block_timer);
4834 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
4835 phba->fabric_block_timer.data = (unsigned long) phba;
4836 /* EA polling mode timer */
4837 init_timer(&phba->eratt_poll);
4838 phba->eratt_poll.function = lpfc_poll_eratt;
4839 phba->eratt_poll.data = (unsigned long) phba;
James Smartecfd03c2010-02-12 14:41:27 -05004840 /* FCF rediscover timer */
4841 init_timer(&phba->fcf.redisc_wait);
4842 phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
4843 phba->fcf.redisc_wait.data = (unsigned long)phba;
4844
James Smartda0436e2009-05-22 14:51:39 -04004845 /*
James Smart7ad20aa2011-05-24 11:44:28 -04004846 * Control structure for handling external multi-buffer mailbox
4847 * command pass-through.
4848 */
4849 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
4850 sizeof(struct lpfc_mbox_ext_buf_ctx));
4851 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
4852
4853 /*
James Smartda0436e2009-05-22 14:51:39 -04004854 * We need to do a READ_CONFIG mailbox command here before
4855 * calling lpfc_get_cfgparam. For VFs this will report the
4856 * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings.
4857 * All of the resources allocated
4858 * for this Port are tied to these values.
4859 */
4860 /* Get all the module params for configuring this host */
4861 lpfc_get_cfgparam(phba);
4862 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04004863
4864 /* Eventually cfg_fcp_eq_count / cfg_fcp_wq_count will be depricated */
4865 phba->cfg_fcp_io_channel = phba->cfg_fcp_eq_count;
4866
James Smartda0436e2009-05-22 14:51:39 -04004867 /* This will be set to correct value after the read_config mbox */
4868 phba->max_vports = 0;
4869
4870 /* Program the default value of vlan_id and fc_map */
4871 phba->valid_vlan = 0;
4872 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
4873 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
4874 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
4875
James Smartacd68592012-01-18 16:25:09 -05004876 /* With BlockGuard we can have multiple SGEs per Data Segemnt */
4877 sges_per_segment = 1;
4878 if (phba->cfg_enable_bg)
4879 sges_per_segment = 2;
4880
James Smartda0436e2009-05-22 14:51:39 -04004881 /*
James Smart2a76a282012-08-03 12:35:54 -04004882 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
4883 * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple.
4884 */
4885 if (!phba->sli.ring)
4886 phba->sli.ring = kzalloc(
James Smart67d12732012-08-03 12:36:13 -04004887 (LPFC_SLI3_MAX_RING + phba->cfg_fcp_io_channel) *
James Smart2a76a282012-08-03 12:35:54 -04004888 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
4889 if (!phba->sli.ring)
4890 return -ENOMEM;
4891 /*
James Smartda0436e2009-05-22 14:51:39 -04004892 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
4893 * used to create the sg_dma_buf_pool must be dynamically calculated.
4894 * 2 segments are added since the IOCB needs a command and response bde.
4895 * To insure that the scsi sgl does not cross a 4k page boundary only
James Smart28baac72010-02-12 14:42:03 -05004896 * sgl sizes of must be a power of 2.
James Smartda0436e2009-05-22 14:51:39 -04004897 */
James Smart28baac72010-02-12 14:42:03 -05004898 buf_size = (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp) +
James Smartacd68592012-01-18 16:25:09 -05004899 (((phba->cfg_sg_seg_cnt * sges_per_segment) + 2) *
4900 sizeof(struct sli4_sge)));
James Smart085c6472010-11-20 23:11:37 -05004901
4902 sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf);
4903 max_buf_size = LPFC_SLI4_MAX_BUF_SIZE;
4904 switch (sli_family) {
4905 case LPFC_SLI_INTF_FAMILY_BE2:
4906 case LPFC_SLI_INTF_FAMILY_BE3:
4907 /* There is a single hint for BE - 2 pages per BPL. */
4908 if (bf_get(lpfc_sli_intf_sli_hint1, &phba->sli4_hba.sli_intf) ==
4909 LPFC_SLI_INTF_SLI_HINT1_1)
4910 max_buf_size = LPFC_SLI4_FL1_MAX_BUF_SIZE;
4911 break;
4912 case LPFC_SLI_INTF_FAMILY_LNCR_A0:
4913 case LPFC_SLI_INTF_FAMILY_LNCR_B0:
4914 default:
4915 break;
4916 }
James Smartacd68592012-01-18 16:25:09 -05004917
James Smart28baac72010-02-12 14:42:03 -05004918 for (dma_buf_size = LPFC_SLI4_MIN_BUF_SIZE;
4919 dma_buf_size < max_buf_size && buf_size > dma_buf_size;
4920 dma_buf_size = dma_buf_size << 1)
4921 ;
4922 if (dma_buf_size == max_buf_size)
4923 phba->cfg_sg_seg_cnt = (dma_buf_size -
4924 sizeof(struct fcp_cmnd) - sizeof(struct fcp_rsp) -
4925 (2 * sizeof(struct sli4_sge))) /
4926 sizeof(struct sli4_sge);
4927 phba->cfg_sg_dma_buf_size = dma_buf_size;
James Smartda0436e2009-05-22 14:51:39 -04004928
4929 /* Initialize buffer queue management fields */
4930 hbq_count = lpfc_sli_hbq_count();
4931 for (i = 0; i < hbq_count; ++i)
4932 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
4933 INIT_LIST_HEAD(&phba->rb_pend_list);
4934 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
4935 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
4936
4937 /*
4938 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
4939 */
4940 /* Initialize the Abort scsi buffer list used by driver */
4941 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
4942 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
4943 /* This abort list used by worker thread */
4944 spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
4945
4946 /*
James Smart6d368e52011-05-24 11:44:12 -04004947 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04004948 */
4949
4950 /* Driver internel slow-path CQ Event pool */
4951 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
4952 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04004953 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04004954 /* Asynchronous event CQ Event work queue list */
4955 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
4956 /* Fast-path XRI aborted CQ Event work queue list */
4957 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
4958 /* Slow-path XRI aborted CQ Event work queue list */
4959 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
4960 /* Receive queue CQ Event work queue list */
4961 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
4962
James Smart6d368e52011-05-24 11:44:12 -04004963 /* Initialize extent block lists. */
4964 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
4965 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
4966 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
4967 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
4968
James Smartda0436e2009-05-22 14:51:39 -04004969 /* Initialize the driver internal SLI layer lists. */
4970 lpfc_sli_setup(phba);
4971 lpfc_sli_queue_setup(phba);
4972
4973 /* Allocate device driver memory */
4974 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
4975 if (rc)
4976 return -ENOMEM;
4977
James Smart2fcee4b2010-12-15 17:57:46 -05004978 /* IF Type 2 ports get initialized now. */
4979 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
4980 LPFC_SLI_INTF_IF_TYPE_2) {
4981 rc = lpfc_pci_function_reset(phba);
4982 if (unlikely(rc))
4983 return -ENODEV;
4984 }
4985
James Smartda0436e2009-05-22 14:51:39 -04004986 /* Create the bootstrap mailbox command */
4987 rc = lpfc_create_bootstrap_mbox(phba);
4988 if (unlikely(rc))
4989 goto out_free_mem;
4990
4991 /* Set up the host's endian order with the device. */
4992 rc = lpfc_setup_endian_order(phba);
4993 if (unlikely(rc))
4994 goto out_free_bsmbx;
4995
4996 /* Set up the hba's configuration parameters. */
4997 rc = lpfc_sli4_read_config(phba);
4998 if (unlikely(rc))
4999 goto out_free_bsmbx;
5000
James Smart2fcee4b2010-12-15 17:57:46 -05005001 /* IF Type 0 ports get initialized now. */
5002 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5003 LPFC_SLI_INTF_IF_TYPE_0) {
5004 rc = lpfc_pci_function_reset(phba);
5005 if (unlikely(rc))
5006 goto out_free_bsmbx;
5007 }
James Smartda0436e2009-05-22 14:51:39 -04005008
James Smartcb5172e2010-03-15 11:25:07 -04005009 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
5010 GFP_KERNEL);
5011 if (!mboxq) {
5012 rc = -ENOMEM;
5013 goto out_free_bsmbx;
5014 }
5015
James Smartfedd3b72011-02-16 12:39:24 -05005016 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04005017 lpfc_supported_pages(mboxq);
5018 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05005019 if (!rc) {
5020 mqe = &mboxq->u.mqe;
5021 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
5022 LPFC_MAX_SUPPORTED_PAGES);
5023 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
5024 switch (pn_page[i]) {
5025 case LPFC_SLI4_PARAMETERS:
5026 phba->sli4_hba.pc_sli4_params.supported = 1;
5027 break;
5028 default:
5029 break;
5030 }
5031 }
5032 /* Read the port's SLI4 Parameters capabilities if supported. */
5033 if (phba->sli4_hba.pc_sli4_params.supported)
5034 rc = lpfc_pc_sli4_params_get(phba, mboxq);
5035 if (rc) {
5036 mempool_free(mboxq, phba->mbox_mem_pool);
5037 rc = -EIO;
5038 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04005039 }
5040 }
James Smartfedd3b72011-02-16 12:39:24 -05005041 /*
5042 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04005043 * If this call fails, it isn't critical unless the SLI4 parameters come
5044 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05005045 */
James Smart6d368e52011-05-24 11:44:12 -04005046 rc = lpfc_get_sli4_parameters(phba, mboxq);
5047 if (rc) {
5048 if (phba->sli4_hba.extents_in_use &&
5049 phba->sli4_hba.rpi_hdrs_in_use) {
5050 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5051 "2999 Unsupported SLI4 Parameters "
5052 "Extents and RPI headers enabled.\n");
5053 goto out_free_bsmbx;
5054 }
5055 }
James Smartcb5172e2010-03-15 11:25:07 -04005056 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart5350d872011-10-10 21:33:49 -04005057 /* Verify all the SLI4 queues */
5058 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04005059 if (rc)
5060 goto out_free_bsmbx;
5061
5062 /* Create driver internal CQE event pool */
5063 rc = lpfc_sli4_cq_event_pool_create(phba);
5064 if (rc)
James Smart5350d872011-10-10 21:33:49 -04005065 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005066
James Smart8a9d2e82012-05-09 21:16:12 -04005067 /* Initialize sgl lists per host */
5068 lpfc_init_sgl_list(phba);
5069
5070 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04005071 rc = lpfc_init_active_sgl_array(phba);
5072 if (rc) {
5073 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5074 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04005075 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04005076 }
James Smartda0436e2009-05-22 14:51:39 -04005077 rc = lpfc_sli4_init_rpi_hdrs(phba);
5078 if (rc) {
5079 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5080 "1432 Failed to initialize rpi headers.\n");
5081 goto out_free_active_sgl;
5082 }
5083
James Smarta93ff372010-10-22 11:06:08 -04005084 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05005085 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
5086 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
5087 GFP_KERNEL);
5088 if (!phba->fcf.fcf_rr_bmask) {
5089 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5090 "2759 Failed allocate memory for FCF round "
5091 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04005092 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05005093 goto out_remove_rpi_hdrs;
5094 }
5095
James Smart67d12732012-08-03 12:36:13 -04005096 phba->sli4_hba.fcp_eq_hdl =
5097 kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
5098 phba->cfg_fcp_io_channel), GFP_KERNEL);
5099 if (!phba->sli4_hba.fcp_eq_hdl) {
5100 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5101 "2572 Failed allocate memory for "
5102 "fast-path per-EQ handle array\n");
5103 rc = -ENOMEM;
5104 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04005105 }
5106
5107 phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
James Smart82c3e9b2012-09-29 11:29:50 -04005108 phba->cfg_fcp_io_channel), GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04005109 if (!phba->sli4_hba.msix_entries) {
5110 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5111 "2573 Failed allocate memory for msi-x "
5112 "interrupt vector entries\n");
James Smart05580562011-05-24 11:40:48 -04005113 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04005114 goto out_free_fcp_eq_hdl;
5115 }
5116
James Smart912e3ac2011-05-24 11:42:11 -04005117 /*
5118 * Enable sr-iov virtual functions if supported and configured
5119 * through the module parameter.
5120 */
5121 if (phba->cfg_sriov_nr_virtfn > 0) {
5122 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5123 phba->cfg_sriov_nr_virtfn);
5124 if (rc) {
5125 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5126 "3020 Requested number of SR-IOV "
5127 "virtual functions (%d) is not "
5128 "supported\n",
5129 phba->cfg_sriov_nr_virtfn);
5130 phba->cfg_sriov_nr_virtfn = 0;
5131 }
5132 }
5133
James Smart5248a742011-07-22 18:37:06 -04005134 return 0;
James Smartda0436e2009-05-22 14:51:39 -04005135
5136out_free_fcp_eq_hdl:
5137 kfree(phba->sli4_hba.fcp_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05005138out_free_fcf_rr_bmask:
5139 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04005140out_remove_rpi_hdrs:
5141 lpfc_sli4_remove_rpi_hdrs(phba);
5142out_free_active_sgl:
5143 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04005144out_destroy_cq_event_pool:
5145 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04005146out_free_bsmbx:
5147 lpfc_destroy_bootstrap_mbox(phba);
5148out_free_mem:
5149 lpfc_mem_free(phba);
5150 return rc;
5151}
5152
5153/**
5154 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 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-4 HBA device it attached to.
5159 **/
5160static void
5161lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
5162{
5163 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
5164
James Smartda0436e2009-05-22 14:51:39 -04005165 /* Free memory allocated for msi-x interrupt vector entries */
5166 kfree(phba->sli4_hba.msix_entries);
5167
5168 /* Free memory allocated for fast-path work queue handles */
5169 kfree(phba->sli4_hba.fcp_eq_hdl);
5170
5171 /* Free the allocated rpi headers. */
5172 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04005173 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04005174
James Smart0c9ab6f2010-02-26 14:15:57 -05005175 /* Free eligible FCF index bmask */
5176 kfree(phba->fcf.fcf_rr_bmask);
5177
James Smartda0436e2009-05-22 14:51:39 -04005178 /* Free the ELS sgl list */
5179 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04005180 lpfc_free_els_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04005181
James Smartda0436e2009-05-22 14:51:39 -04005182 /* Free the completion queue EQ event pool */
5183 lpfc_sli4_cq_event_release_all(phba);
5184 lpfc_sli4_cq_event_pool_destroy(phba);
5185
James Smart6d368e52011-05-24 11:44:12 -04005186 /* Release resource identifiers. */
5187 lpfc_sli4_dealloc_resource_identifiers(phba);
5188
James Smartda0436e2009-05-22 14:51:39 -04005189 /* Free the bsmbx region. */
5190 lpfc_destroy_bootstrap_mbox(phba);
5191
5192 /* Free the SLI Layer memory with SLI4 HBAs */
5193 lpfc_mem_free_all(phba);
5194
5195 /* Free the current connect table */
5196 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04005197 &phba->fcf_conn_rec_list, list) {
5198 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04005199 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04005200 }
James Smartda0436e2009-05-22 14:51:39 -04005201
5202 return;
5203}
5204
5205/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005206 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04005207 * @phba: The hba struct for which this call is being executed.
5208 * @dev_grp: The HBA PCI-Device group number.
5209 *
5210 * This routine sets up the device INIT interface API function jump table
5211 * in @phba struct.
5212 *
5213 * Returns: 0 - success, -ENODEV - failure.
5214 **/
5215int
5216lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5217{
James Smart84d1b002010-02-12 14:42:33 -05005218 phba->lpfc_hba_init_link = lpfc_hba_init_link;
5219 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05005220 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04005221 switch (dev_grp) {
5222 case LPFC_PCI_DEV_LP:
5223 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
5224 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
5225 phba->lpfc_stop_port = lpfc_stop_port_s3;
5226 break;
James Smartda0436e2009-05-22 14:51:39 -04005227 case LPFC_PCI_DEV_OC:
5228 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
5229 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
5230 phba->lpfc_stop_port = lpfc_stop_port_s4;
5231 break;
James Smart3772a992009-05-22 14:50:54 -04005232 default:
5233 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5234 "1431 Invalid HBA PCI-device group: 0x%x\n",
5235 dev_grp);
5236 return -ENODEV;
5237 break;
5238 }
5239 return 0;
5240}
5241
5242/**
5243 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
5244 * @phba: pointer to lpfc hba data structure.
5245 *
5246 * This routine is invoked to set up the driver internal resources before the
5247 * device specific resource setup to support the HBA device it attached to.
5248 *
5249 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005250 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005251 * other values - error
5252 **/
5253static int
5254lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
5255{
5256 /*
5257 * Driver resources common to all SLI revisions
5258 */
James Smartea2151b2008-09-07 11:52:10 -04005259 atomic_set(&phba->fast_event_count, 0);
James Smart2e0fef82007-06-17 19:56:36 -05005260 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005261
James Smarte47c9092008-02-08 18:49:26 -05005262 /* Initialize ndlp management spinlock */
5263 spin_lock_init(&phba->ndlp_lock);
5264
James Smart2e0fef82007-06-17 19:56:36 -05005265 INIT_LIST_HEAD(&phba->port_list);
James Smart3772a992009-05-22 14:50:54 -04005266 INIT_LIST_HEAD(&phba->work_list);
James Smart84774a42008-08-24 21:50:06 -04005267 init_waitqueue_head(&phba->wait_4_mlo_m_q);
dea31012005-04-17 16:05:31 -05005268
James Smart3772a992009-05-22 14:50:54 -04005269 /* Initialize the wait queue head for the kernel thread */
5270 init_waitqueue_head(&phba->work_waitq);
James Smart858c9f62007-06-17 19:56:39 -05005271
James Smart3772a992009-05-22 14:50:54 -04005272 /* Initialize the scsi buffer list used by driver for scsi IO */
5273 spin_lock_init(&phba->scsi_buf_list_lock);
5274 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
dea31012005-04-17 16:05:31 -05005275
James Smart3772a992009-05-22 14:50:54 -04005276 /* Initialize the fabric iocb list */
5277 INIT_LIST_HEAD(&phba->fabric_iocb_list);
dea31012005-04-17 16:05:31 -05005278
James Smart3772a992009-05-22 14:50:54 -04005279 /* Initialize list to save ELS buffers */
5280 INIT_LIST_HEAD(&phba->elsbuf);
dea31012005-04-17 16:05:31 -05005281
James Smart3772a992009-05-22 14:50:54 -04005282 /* Initialize FCF connection rec list */
5283 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
dea31012005-04-17 16:05:31 -05005284
James Smart3772a992009-05-22 14:50:54 -04005285 return 0;
5286}
dea31012005-04-17 16:05:31 -05005287
James Smart3772a992009-05-22 14:50:54 -04005288/**
5289 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
5290 * @phba: pointer to lpfc hba data structure.
5291 *
5292 * This routine is invoked to set up the driver internal resources after the
5293 * device specific resource setup to support the HBA device it attached to.
5294 *
5295 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005296 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005297 * other values - error
5298 **/
5299static int
5300lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
5301{
5302 int error;
5303
5304 /* Startup the kernel thread for this host adapter. */
5305 phba->worker_thread = kthread_run(lpfc_do_work, phba,
5306 "lpfc_worker_%d", phba->brd_no);
5307 if (IS_ERR(phba->worker_thread)) {
5308 error = PTR_ERR(phba->worker_thread);
5309 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005310 }
5311
James Smart3772a992009-05-22 14:50:54 -04005312 return 0;
5313}
5314
5315/**
5316 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
5317 * @phba: pointer to lpfc hba data structure.
5318 *
5319 * This routine is invoked to unset the driver internal resources set up after
5320 * the device specific resource setup for supporting the HBA device it
5321 * attached to.
5322 **/
5323static void
5324lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
5325{
5326 /* Stop kernel worker thread */
5327 kthread_stop(phba->worker_thread);
5328}
5329
5330/**
5331 * lpfc_free_iocb_list - Free iocb list.
5332 * @phba: pointer to lpfc hba data structure.
5333 *
5334 * This routine is invoked to free the driver's IOCB list and memory.
5335 **/
5336static void
5337lpfc_free_iocb_list(struct lpfc_hba *phba)
5338{
5339 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
5340
5341 spin_lock_irq(&phba->hbalock);
5342 list_for_each_entry_safe(iocbq_entry, iocbq_next,
5343 &phba->lpfc_iocb_list, list) {
5344 list_del(&iocbq_entry->list);
5345 kfree(iocbq_entry);
5346 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005347 }
James Smart3772a992009-05-22 14:50:54 -04005348 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005349
James Smart3772a992009-05-22 14:50:54 -04005350 return;
5351}
dea31012005-04-17 16:05:31 -05005352
James Smart3772a992009-05-22 14:50:54 -04005353/**
5354 * lpfc_init_iocb_list - Allocate and initialize iocb list.
5355 * @phba: pointer to lpfc hba data structure.
5356 *
5357 * This routine is invoked to allocate and initizlize the driver's IOCB
5358 * list and set up the IOCB tag array accordingly.
5359 *
5360 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005361 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005362 * other values - error
5363 **/
5364static int
5365lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
5366{
5367 struct lpfc_iocbq *iocbq_entry = NULL;
5368 uint16_t iotag;
5369 int i;
dea31012005-04-17 16:05:31 -05005370
5371 /* Initialize and populate the iocb list per host. */
5372 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04005373 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07005374 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05005375 if (iocbq_entry == NULL) {
5376 printk(KERN_ERR "%s: only allocated %d iocbs of "
5377 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07005378 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05005379 goto out_free_iocbq;
5380 }
5381
James Bottomley604a3e32005-10-29 10:28:33 -05005382 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
5383 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04005384 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05005385 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04005386 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05005387 goto out_free_iocbq;
5388 }
James Smart6d368e52011-05-24 11:44:12 -04005389 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04005390 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05005391
5392 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005393 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
5394 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05005395 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005396 }
5397
James Smart3772a992009-05-22 14:50:54 -04005398 return 0;
5399
5400out_free_iocbq:
5401 lpfc_free_iocb_list(phba);
5402
5403 return -ENOMEM;
5404}
5405
5406/**
James Smart8a9d2e82012-05-09 21:16:12 -04005407 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04005408 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04005409 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04005410 *
James Smart8a9d2e82012-05-09 21:16:12 -04005411 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04005412 **/
James Smart8a9d2e82012-05-09 21:16:12 -04005413void
5414lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04005415{
5416 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04005417
5418 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
5419 list_del(&sglq_entry->list);
5420 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
5421 kfree(sglq_entry);
5422 }
5423}
5424
5425/**
5426 * lpfc_free_els_sgl_list - Free els sgl list.
5427 * @phba: pointer to lpfc hba data structure.
5428 *
5429 * This routine is invoked to free the driver's els sgl list and memory.
5430 **/
5431static void
5432lpfc_free_els_sgl_list(struct lpfc_hba *phba)
5433{
James Smartda0436e2009-05-22 14:51:39 -04005434 LIST_HEAD(sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04005435
James Smart8a9d2e82012-05-09 21:16:12 -04005436 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04005437 spin_lock_irq(&phba->hbalock);
5438 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
5439 spin_unlock_irq(&phba->hbalock);
5440
James Smart8a9d2e82012-05-09 21:16:12 -04005441 /* Now free the sgl list */
5442 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04005443}
5444
5445/**
5446 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
5447 * @phba: pointer to lpfc hba data structure.
5448 *
5449 * This routine is invoked to allocate the driver's active sgl memory.
5450 * This array will hold the sglq_entry's for active IOs.
5451 **/
5452static int
5453lpfc_init_active_sgl_array(struct lpfc_hba *phba)
5454{
5455 int size;
5456 size = sizeof(struct lpfc_sglq *);
5457 size *= phba->sli4_hba.max_cfg_param.max_xri;
5458
5459 phba->sli4_hba.lpfc_sglq_active_list =
5460 kzalloc(size, GFP_KERNEL);
5461 if (!phba->sli4_hba.lpfc_sglq_active_list)
5462 return -ENOMEM;
5463 return 0;
5464}
5465
5466/**
5467 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
5468 * @phba: pointer to lpfc hba data structure.
5469 *
5470 * This routine is invoked to walk through the array of active sglq entries
5471 * and free all of the resources.
5472 * This is just a place holder for now.
5473 **/
5474static void
5475lpfc_free_active_sgl(struct lpfc_hba *phba)
5476{
5477 kfree(phba->sli4_hba.lpfc_sglq_active_list);
5478}
5479
5480/**
5481 * lpfc_init_sgl_list - Allocate and initialize sgl list.
5482 * @phba: pointer to lpfc hba data structure.
5483 *
5484 * This routine is invoked to allocate and initizlize the driver's sgl
5485 * list and set up the sgl xritag tag array accordingly.
5486 *
James Smartda0436e2009-05-22 14:51:39 -04005487 **/
James Smart8a9d2e82012-05-09 21:16:12 -04005488static void
James Smartda0436e2009-05-22 14:51:39 -04005489lpfc_init_sgl_list(struct lpfc_hba *phba)
5490{
James Smartda0436e2009-05-22 14:51:39 -04005491 /* Initialize and populate the sglq list per host/VF. */
5492 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
5493 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
5494
James Smart8a9d2e82012-05-09 21:16:12 -04005495 /* els xri-sgl book keeping */
5496 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04005497
James Smart8a9d2e82012-05-09 21:16:12 -04005498 /* scsi xri-buffer book keeping */
James Smartda0436e2009-05-22 14:51:39 -04005499 phba->sli4_hba.scsi_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04005500}
5501
5502/**
5503 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
5504 * @phba: pointer to lpfc hba data structure.
5505 *
5506 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04005507 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04005508 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04005509 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
5510 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04005511 *
5512 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005513 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04005514 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04005515 **/
5516int
5517lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
5518{
5519 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04005520 struct lpfc_rpi_hdr *rpi_hdr;
5521
5522 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05005523 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04005524 return rc;
James Smart6d368e52011-05-24 11:44:12 -04005525 if (phba->sli4_hba.extents_in_use)
5526 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04005527
5528 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
5529 if (!rpi_hdr) {
5530 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5531 "0391 Error during rpi post operation\n");
5532 lpfc_sli4_remove_rpis(phba);
5533 rc = -ENODEV;
5534 }
5535
5536 return rc;
5537}
5538
5539/**
5540 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
5541 * @phba: pointer to lpfc hba data structure.
5542 *
5543 * This routine is invoked to allocate a single 4KB memory region to
5544 * support rpis and stores them in the phba. This single region
5545 * provides support for up to 64 rpis. The region is used globally
5546 * by the device.
5547 *
5548 * Returns:
5549 * A valid rpi hdr on success.
5550 * A NULL pointer on any failure.
5551 **/
5552struct lpfc_rpi_hdr *
5553lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
5554{
5555 uint16_t rpi_limit, curr_rpi_range;
5556 struct lpfc_dmabuf *dmabuf;
5557 struct lpfc_rpi_hdr *rpi_hdr;
James Smart9589b0622011-04-16 11:03:17 -04005558 uint32_t rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04005559
James Smart6d368e52011-05-24 11:44:12 -04005560 /*
5561 * If the SLI4 port supports extents, posting the rpi header isn't
5562 * required. Set the expected maximum count and let the actual value
5563 * get set when extents are fully allocated.
5564 */
5565 if (!phba->sli4_hba.rpi_hdrs_in_use)
5566 return NULL;
5567 if (phba->sli4_hba.extents_in_use)
5568 return NULL;
5569
5570 /* The limit on the logical index is just the max_rpi count. */
James Smartda0436e2009-05-22 14:51:39 -04005571 rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
James Smart6d368e52011-05-24 11:44:12 -04005572 phba->sli4_hba.max_cfg_param.max_rpi - 1;
James Smartda0436e2009-05-22 14:51:39 -04005573
5574 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04005575 /*
5576 * Establish the starting RPI in this header block. The starting
5577 * rpi is normalized to a zero base because the physical rpi is
5578 * port based.
5579 */
James Smart97f2ecf2012-03-01 22:35:23 -05005580 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04005581 spin_unlock_irq(&phba->hbalock);
5582
5583 /*
5584 * The port has a limited number of rpis. The increment here
5585 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
5586 * and to allow the full max_rpi range per port.
5587 */
5588 if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
James Smart9589b0622011-04-16 11:03:17 -04005589 rpi_count = rpi_limit - curr_rpi_range;
5590 else
5591 rpi_count = LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04005592
James Smart6d368e52011-05-24 11:44:12 -04005593 if (!rpi_count)
5594 return NULL;
James Smartda0436e2009-05-22 14:51:39 -04005595 /*
5596 * First allocate the protocol header region for the port. The
5597 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
5598 */
5599 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5600 if (!dmabuf)
5601 return NULL;
5602
5603 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
5604 LPFC_HDR_TEMPLATE_SIZE,
5605 &dmabuf->phys,
5606 GFP_KERNEL);
5607 if (!dmabuf->virt) {
5608 rpi_hdr = NULL;
5609 goto err_free_dmabuf;
5610 }
5611
5612 memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE);
5613 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
5614 rpi_hdr = NULL;
5615 goto err_free_coherent;
5616 }
5617
5618 /* Save the rpi header data for cleanup later. */
5619 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
5620 if (!rpi_hdr)
5621 goto err_free_coherent;
5622
5623 rpi_hdr->dmabuf = dmabuf;
5624 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
5625 rpi_hdr->page_count = 1;
5626 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04005627
5628 /* The rpi_hdr stores the logical index only. */
5629 rpi_hdr->start_rpi = curr_rpi_range;
James Smartda0436e2009-05-22 14:51:39 -04005630 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
5631
5632 /*
James Smart6d368e52011-05-24 11:44:12 -04005633 * The next_rpi stores the next logical module-64 rpi value used
5634 * to post physical rpis in subsequent rpi postings.
James Smartda0436e2009-05-22 14:51:39 -04005635 */
James Smart9589b0622011-04-16 11:03:17 -04005636 phba->sli4_hba.next_rpi += rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04005637 spin_unlock_irq(&phba->hbalock);
5638 return rpi_hdr;
5639
5640 err_free_coherent:
5641 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
5642 dmabuf->virt, dmabuf->phys);
5643 err_free_dmabuf:
5644 kfree(dmabuf);
5645 return NULL;
5646}
5647
5648/**
5649 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
5650 * @phba: pointer to lpfc hba data structure.
5651 *
5652 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04005653 * to support rpis for SLI4 ports not supporting extents. This routine
5654 * presumes the caller has released all rpis consumed by fabric or port
5655 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04005656 **/
5657void
5658lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
5659{
5660 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
5661
James Smart6d368e52011-05-24 11:44:12 -04005662 if (!phba->sli4_hba.rpi_hdrs_in_use)
5663 goto exit;
5664
James Smartda0436e2009-05-22 14:51:39 -04005665 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
5666 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
5667 list_del(&rpi_hdr->list);
5668 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
5669 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
5670 kfree(rpi_hdr->dmabuf);
5671 kfree(rpi_hdr);
5672 }
James Smart6d368e52011-05-24 11:44:12 -04005673 exit:
5674 /* There are no rpis available to the port now. */
5675 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04005676}
5677
5678/**
James Smart3772a992009-05-22 14:50:54 -04005679 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
5680 * @pdev: pointer to pci device data structure.
5681 *
5682 * This routine is invoked to allocate the driver hba data structure for an
5683 * HBA device. If the allocation is successful, the phba reference to the
5684 * PCI device data structure is set.
5685 *
5686 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005687 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04005688 * NULL - error
5689 **/
5690static struct lpfc_hba *
5691lpfc_hba_alloc(struct pci_dev *pdev)
5692{
5693 struct lpfc_hba *phba;
5694
5695 /* Allocate memory for HBA structure */
5696 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
5697 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02005698 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04005699 return NULL;
5700 }
5701
5702 /* Set reference to PCI device in HBA structure */
5703 phba->pcidev = pdev;
5704
5705 /* Assign an unused board number */
5706 phba->brd_no = lpfc_get_instance();
5707 if (phba->brd_no < 0) {
5708 kfree(phba);
5709 return NULL;
5710 }
5711
James Smart4fede782010-01-26 23:08:55 -05005712 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04005713 INIT_LIST_HEAD(&phba->ct_ev_waiters);
5714
James Smart3772a992009-05-22 14:50:54 -04005715 return phba;
5716}
5717
5718/**
5719 * lpfc_hba_free - Free driver hba data structure with a device.
5720 * @phba: pointer to lpfc hba data structure.
5721 *
5722 * This routine is invoked to free the driver hba data structure with an
5723 * HBA device.
5724 **/
5725static void
5726lpfc_hba_free(struct lpfc_hba *phba)
5727{
5728 /* Release the driver assigned board number */
5729 idr_remove(&lpfc_hba_index, phba->brd_no);
5730
James Smart2a76a282012-08-03 12:35:54 -04005731 /* Free memory allocated with sli rings */
5732 kfree(phba->sli.ring);
5733 phba->sli.ring = NULL;
5734
James Smart3772a992009-05-22 14:50:54 -04005735 kfree(phba);
5736 return;
5737}
5738
5739/**
5740 * lpfc_create_shost - Create hba physical port with associated scsi host.
5741 * @phba: pointer to lpfc hba data structure.
5742 *
5743 * This routine is invoked to create HBA physical port and associate a SCSI
5744 * host with it.
5745 *
5746 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005747 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005748 * other values - error
5749 **/
5750static int
5751lpfc_create_shost(struct lpfc_hba *phba)
5752{
5753 struct lpfc_vport *vport;
5754 struct Scsi_Host *shost;
5755
5756 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05005757 phba->fc_edtov = FF_DEF_EDTOV;
5758 phba->fc_ratov = FF_DEF_RATOV;
5759 phba->fc_altov = FF_DEF_ALTOV;
5760 phba->fc_arbtov = FF_DEF_ARBTOV;
5761
James Smartd7c47992010-06-08 18:31:54 -04005762 atomic_set(&phba->sdev_cnt, 0);
James Smart3de2a652007-08-02 11:09:59 -04005763 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05005764 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04005765 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05005766
5767 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05005768 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05005769 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04005770 /* Put reference to SCSI host to driver's device private data */
5771 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05005772
James Smart3772a992009-05-22 14:50:54 -04005773 return 0;
5774}
dea31012005-04-17 16:05:31 -05005775
James Smart3772a992009-05-22 14:50:54 -04005776/**
5777 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
5778 * @phba: pointer to lpfc hba data structure.
5779 *
5780 * This routine is invoked to destroy HBA physical port and the associated
5781 * SCSI host.
5782 **/
5783static void
5784lpfc_destroy_shost(struct lpfc_hba *phba)
5785{
5786 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04005787
James Smart3772a992009-05-22 14:50:54 -04005788 /* Destroy physical port that associated with the SCSI host */
5789 destroy_port(vport);
5790
5791 return;
5792}
5793
5794/**
5795 * lpfc_setup_bg - Setup Block guard structures and debug areas.
5796 * @phba: pointer to lpfc hba data structure.
5797 * @shost: the shost to be used to detect Block guard settings.
5798 *
5799 * This routine sets up the local Block guard protocol settings for @shost.
5800 * This routine also allocates memory for debugging bg buffers.
5801 **/
5802static void
5803lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
5804{
James Smartbbeb79b2012-06-12 13:54:27 -04005805 uint32_t old_mask;
5806 uint32_t old_guard;
5807
James Smart3772a992009-05-22 14:50:54 -04005808 int pagecnt = 10;
5809 if (lpfc_prot_mask && lpfc_prot_guard) {
5810 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5811 "1478 Registering BlockGuard with the "
5812 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04005813
5814 old_mask = lpfc_prot_mask;
5815 old_guard = lpfc_prot_guard;
5816
5817 /* Only allow supported values */
5818 lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
5819 SHOST_DIX_TYPE0_PROTECTION |
5820 SHOST_DIX_TYPE1_PROTECTION);
5821 lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC);
5822
5823 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
5824 if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
5825 lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
5826
5827 if (lpfc_prot_mask && lpfc_prot_guard) {
5828 if ((old_mask != lpfc_prot_mask) ||
5829 (old_guard != lpfc_prot_guard))
5830 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5831 "1475 Registering BlockGuard with the "
5832 "SCSI layer: mask %d guard %d\n",
5833 lpfc_prot_mask, lpfc_prot_guard);
5834
5835 scsi_host_set_prot(shost, lpfc_prot_mask);
5836 scsi_host_set_guard(shost, lpfc_prot_guard);
5837 } else
5838 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5839 "1479 Not Registering BlockGuard with the SCSI "
5840 "layer, Bad protection parameters: %d %d\n",
5841 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04005842 }
James Smartbbeb79b2012-06-12 13:54:27 -04005843
James Smart81301a92008-12-04 22:39:46 -05005844 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05005845 while (pagecnt) {
5846 spin_lock_init(&_dump_buf_lock);
5847 _dump_buf_data =
5848 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
5849 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04005850 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5851 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04005852 "_dump_buf_data at 0x%p\n",
5853 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05005854 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04005855 memset(_dump_buf_data, 0,
5856 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05005857 break;
James Smart3772a992009-05-22 14:50:54 -04005858 } else
James Smart81301a92008-12-04 22:39:46 -05005859 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05005860 }
James Smart81301a92008-12-04 22:39:46 -05005861 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04005862 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5863 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04005864 "memory for hexdump\n");
5865 } else
James Smart6a9c52c2009-10-02 15:16:51 -04005866 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5867 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05005868 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05005869 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05005870 while (pagecnt) {
5871 _dump_buf_dif =
5872 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
5873 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04005874 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5875 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04005876 "_dump_buf_dif at 0x%p\n",
5877 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05005878 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04005879 memset(_dump_buf_dif, 0,
5880 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05005881 break;
James Smart3772a992009-05-22 14:50:54 -04005882 } else
James Smart81301a92008-12-04 22:39:46 -05005883 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05005884 }
James Smart81301a92008-12-04 22:39:46 -05005885 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04005886 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5887 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04005888 "memory for hexdump\n");
5889 } else
James Smart6a9c52c2009-10-02 15:16:51 -04005890 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5891 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04005892 _dump_buf_dif);
5893}
5894
5895/**
5896 * lpfc_post_init_setup - Perform necessary device post initialization setup.
5897 * @phba: pointer to lpfc hba data structure.
5898 *
5899 * This routine is invoked to perform all the necessary post initialization
5900 * setup for the device.
5901 **/
5902static void
5903lpfc_post_init_setup(struct lpfc_hba *phba)
5904{
5905 struct Scsi_Host *shost;
5906 struct lpfc_adapter_event_header adapter_event;
5907
5908 /* Get the default values for Model Name and Description */
5909 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
5910
5911 /*
5912 * hba setup may have changed the hba_queue_depth so we need to
5913 * adjust the value of can_queue.
5914 */
5915 shost = pci_get_drvdata(phba->pcidev);
5916 shost->can_queue = phba->cfg_hba_queue_depth - 10;
5917 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
5918 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05005919
5920 lpfc_host_attrib_init(shost);
5921
James Smart2e0fef82007-06-17 19:56:36 -05005922 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
5923 spin_lock_irq(shost->host_lock);
5924 lpfc_poll_start_timer(phba);
5925 spin_unlock_irq(shost->host_lock);
5926 }
James Smart8f6d98d2006-08-01 07:34:00 -04005927
James Smart93996272008-08-24 21:50:30 -04005928 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5929 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04005930 /* Send board arrival event to upper layer */
5931 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
5932 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
5933 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04005934 sizeof(adapter_event),
5935 (char *) &adapter_event,
5936 LPFC_NL_VENDOR_ID);
5937 return;
5938}
5939
5940/**
5941 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
5942 * @phba: pointer to lpfc hba data structure.
5943 *
5944 * This routine is invoked to set up the PCI device memory space for device
5945 * with SLI-3 interface spec.
5946 *
5947 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005948 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005949 * other values - error
5950 **/
5951static int
5952lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
5953{
5954 struct pci_dev *pdev;
5955 unsigned long bar0map_len, bar2map_len;
5956 int i, hbq_count;
5957 void *ptr;
5958 int error = -ENODEV;
5959
5960 /* Obtain PCI device reference */
5961 if (!phba->pcidev)
5962 return error;
5963 else
5964 pdev = phba->pcidev;
5965
5966 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05005967 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
5968 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
5969 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
5970 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smart3772a992009-05-22 14:50:54 -04005971 return error;
Michael Reed8e685972009-09-18 12:02:05 -05005972 }
5973 }
James Smart3772a992009-05-22 14:50:54 -04005974
5975 /* Get the bus address of Bar0 and Bar2 and the number of bytes
5976 * required by each mapping.
5977 */
5978 phba->pci_bar0_map = pci_resource_start(pdev, 0);
5979 bar0map_len = pci_resource_len(pdev, 0);
5980
5981 phba->pci_bar2_map = pci_resource_start(pdev, 2);
5982 bar2map_len = pci_resource_len(pdev, 2);
5983
5984 /* Map HBA SLIM to a kernel virtual address. */
5985 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
5986 if (!phba->slim_memmap_p) {
5987 dev_printk(KERN_ERR, &pdev->dev,
5988 "ioremap failed for SLIM memory.\n");
5989 goto out;
5990 }
5991
5992 /* Map HBA Control Registers to a kernel virtual address. */
5993 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
5994 if (!phba->ctrl_regs_memmap_p) {
5995 dev_printk(KERN_ERR, &pdev->dev,
5996 "ioremap failed for HBA control registers.\n");
5997 goto out_iounmap_slim;
5998 }
5999
6000 /* Allocate memory for SLI-2 structures */
6001 phba->slim2p.virt = dma_alloc_coherent(&pdev->dev,
6002 SLI2_SLIM_SIZE,
6003 &phba->slim2p.phys,
6004 GFP_KERNEL);
6005 if (!phba->slim2p.virt)
6006 goto out_iounmap;
6007
6008 memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
6009 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04006010 phba->mbox_ext = (phba->slim2p.virt +
6011 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04006012 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
6013 phba->IOCBs = (phba->slim2p.virt +
6014 offsetof(struct lpfc_sli2_slim, IOCBs));
6015
6016 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
6017 lpfc_sli_hbq_size(),
6018 &phba->hbqslimp.phys,
6019 GFP_KERNEL);
6020 if (!phba->hbqslimp.virt)
6021 goto out_free_slim;
6022
6023 hbq_count = lpfc_sli_hbq_count();
6024 ptr = phba->hbqslimp.virt;
6025 for (i = 0; i < hbq_count; ++i) {
6026 phba->hbqs[i].hbq_virt = ptr;
6027 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
6028 ptr += (lpfc_hbq_defs[i]->entry_count *
6029 sizeof(struct lpfc_hbq_entry));
6030 }
6031 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
6032 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
6033
6034 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
6035
6036 INIT_LIST_HEAD(&phba->rb_pend_list);
6037
6038 phba->MBslimaddr = phba->slim_memmap_p;
6039 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
6040 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
6041 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
6042 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04006043
dea31012005-04-17 16:05:31 -05006044 return 0;
6045
dea31012005-04-17 16:05:31 -05006046out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04006047 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6048 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05006049out_iounmap:
6050 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006051out_iounmap_slim:
dea31012005-04-17 16:05:31 -05006052 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05006053out:
6054 return error;
6055}
6056
James Smarte59058c2008-08-24 21:49:00 -04006057/**
James Smart3772a992009-05-22 14:50:54 -04006058 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
6059 * @phba: pointer to lpfc hba data structure.
6060 *
6061 * This routine is invoked to unset the PCI device memory space for device
6062 * with SLI-3 interface spec.
6063 **/
6064static void
6065lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
6066{
6067 struct pci_dev *pdev;
6068
6069 /* Obtain PCI device reference */
6070 if (!phba->pcidev)
6071 return;
6072 else
6073 pdev = phba->pcidev;
6074
6075 /* Free coherent DMA memory allocated */
6076 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
6077 phba->hbqslimp.virt, phba->hbqslimp.phys);
6078 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6079 phba->slim2p.virt, phba->slim2p.phys);
6080
6081 /* I/O memory unmap */
6082 iounmap(phba->ctrl_regs_memmap_p);
6083 iounmap(phba->slim_memmap_p);
6084
6085 return;
6086}
6087
6088/**
James Smartda0436e2009-05-22 14:51:39 -04006089 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
6090 * @phba: pointer to lpfc hba data structure.
6091 *
6092 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
6093 * done and check status.
6094 *
6095 * Return 0 if successful, otherwise -ENODEV.
6096 **/
6097int
6098lpfc_sli4_post_status_check(struct lpfc_hba *phba)
6099{
James Smart2fcee4b2010-12-15 17:57:46 -05006100 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
6101 struct lpfc_register reg_data;
6102 int i, port_error = 0;
6103 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04006104
James Smart9940b972011-03-11 16:06:12 -05006105 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
6106 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05006107 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04006108 return -ENODEV;
6109
James Smartda0436e2009-05-22 14:51:39 -04006110 /* Wait up to 30 seconds for the SLI Port POST done and ready */
6111 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05006112 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
6113 &portsmphr_reg.word0) ||
6114 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006115 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04006116 port_error = -ENODEV;
6117 break;
6118 }
James Smart2fcee4b2010-12-15 17:57:46 -05006119 if (LPFC_POST_STAGE_PORT_READY ==
6120 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04006121 break;
James Smartda0436e2009-05-22 14:51:39 -04006122 msleep(10);
6123 }
6124
James Smart2fcee4b2010-12-15 17:57:46 -05006125 /*
6126 * If there was a port error during POST, then don't proceed with
6127 * other register reads as the data may not be valid. Just exit.
6128 */
6129 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04006130 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006131 "1408 Port Failed POST - portsmphr=0x%x, "
6132 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
6133 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
6134 portsmphr_reg.word0,
6135 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
6136 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
6137 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
6138 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
6139 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
6140 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
6141 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
6142 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
6143 } else {
James Smart28baac72010-02-12 14:42:03 -05006144 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006145 "2534 Device Info: SLIFamily=0x%x, "
6146 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
6147 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05006148 bf_get(lpfc_sli_intf_sli_family,
6149 &phba->sli4_hba.sli_intf),
6150 bf_get(lpfc_sli_intf_slirev,
6151 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006152 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05006153 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006154 bf_get(lpfc_sli_intf_sli_hint1,
6155 &phba->sli4_hba.sli_intf),
6156 bf_get(lpfc_sli_intf_sli_hint2,
6157 &phba->sli4_hba.sli_intf),
6158 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05006159 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05006160 /*
6161 * Check for other Port errors during the initialization
6162 * process. Fail the load if the port did not come up
6163 * correctly.
6164 */
6165 if_type = bf_get(lpfc_sli_intf_if_type,
6166 &phba->sli4_hba.sli_intf);
6167 switch (if_type) {
6168 case LPFC_SLI_INTF_IF_TYPE_0:
6169 phba->sli4_hba.ue_mask_lo =
6170 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
6171 phba->sli4_hba.ue_mask_hi =
6172 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
6173 uerrlo_reg.word0 =
6174 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
6175 uerrhi_reg.word0 =
6176 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
6177 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
6178 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
6179 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6180 "1422 Unrecoverable Error "
6181 "Detected during POST "
6182 "uerr_lo_reg=0x%x, "
6183 "uerr_hi_reg=0x%x, "
6184 "ue_mask_lo_reg=0x%x, "
6185 "ue_mask_hi_reg=0x%x\n",
6186 uerrlo_reg.word0,
6187 uerrhi_reg.word0,
6188 phba->sli4_hba.ue_mask_lo,
6189 phba->sli4_hba.ue_mask_hi);
6190 port_error = -ENODEV;
6191 }
6192 break;
6193 case LPFC_SLI_INTF_IF_TYPE_2:
6194 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05006195 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
6196 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04006197 (bf_get(lpfc_sliport_status_err, &reg_data) &&
6198 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006199 phba->work_status[0] =
6200 readl(phba->sli4_hba.u.if_type2.
6201 ERR1regaddr);
6202 phba->work_status[1] =
6203 readl(phba->sli4_hba.u.if_type2.
6204 ERR2regaddr);
6205 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05006206 "2888 Unrecoverable port error "
6207 "following POST: port status reg "
6208 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05006209 "error 1=0x%x, error 2=0x%x\n",
6210 reg_data.word0,
6211 portsmphr_reg.word0,
6212 phba->work_status[0],
6213 phba->work_status[1]);
6214 port_error = -ENODEV;
6215 }
6216 break;
6217 case LPFC_SLI_INTF_IF_TYPE_1:
6218 default:
6219 break;
6220 }
James Smart28baac72010-02-12 14:42:03 -05006221 }
James Smartda0436e2009-05-22 14:51:39 -04006222 return port_error;
6223}
6224
6225/**
6226 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
6227 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05006228 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04006229 *
6230 * This routine is invoked to set up SLI4 BAR0 PCI config space register
6231 * memory map.
6232 **/
6233static void
James Smart2fcee4b2010-12-15 17:57:46 -05006234lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04006235{
James Smart2fcee4b2010-12-15 17:57:46 -05006236 switch (if_type) {
6237 case LPFC_SLI_INTF_IF_TYPE_0:
6238 phba->sli4_hba.u.if_type0.UERRLOregaddr =
6239 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
6240 phba->sli4_hba.u.if_type0.UERRHIregaddr =
6241 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
6242 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
6243 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
6244 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
6245 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
6246 phba->sli4_hba.SLIINTFregaddr =
6247 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6248 break;
6249 case LPFC_SLI_INTF_IF_TYPE_2:
6250 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006251 phba->sli4_hba.conf_regs_memmap_p +
6252 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006253 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006254 phba->sli4_hba.conf_regs_memmap_p +
6255 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006256 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006257 phba->sli4_hba.conf_regs_memmap_p +
6258 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006259 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006260 phba->sli4_hba.conf_regs_memmap_p +
6261 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006262 phba->sli4_hba.SLIINTFregaddr =
6263 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6264 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006265 phba->sli4_hba.conf_regs_memmap_p +
6266 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006267 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006268 phba->sli4_hba.conf_regs_memmap_p +
6269 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006270 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006271 phba->sli4_hba.conf_regs_memmap_p +
6272 LPFC_ULP0_WQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006273 phba->sli4_hba.EQCQDBregaddr =
6274 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
6275 phba->sli4_hba.MQDBregaddr =
6276 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
6277 phba->sli4_hba.BMBXregaddr =
6278 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
6279 break;
6280 case LPFC_SLI_INTF_IF_TYPE_1:
6281 default:
6282 dev_printk(KERN_ERR, &phba->pcidev->dev,
6283 "FATAL - unsupported SLI4 interface type - %d\n",
6284 if_type);
6285 break;
6286 }
James Smartda0436e2009-05-22 14:51:39 -04006287}
6288
6289/**
6290 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
6291 * @phba: pointer to lpfc hba data structure.
6292 *
6293 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
6294 * memory map.
6295 **/
6296static void
6297lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
6298{
James Smart2fcee4b2010-12-15 17:57:46 -05006299 phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
6300 LPFC_SLIPORT_IF0_SMPHR;
James Smartda0436e2009-05-22 14:51:39 -04006301 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006302 LPFC_HST_ISR0;
James Smartda0436e2009-05-22 14:51:39 -04006303 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006304 LPFC_HST_IMR0;
James Smartda0436e2009-05-22 14:51:39 -04006305 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006306 LPFC_HST_ISCR0;
James Smartda0436e2009-05-22 14:51:39 -04006307}
6308
6309/**
6310 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
6311 * @phba: pointer to lpfc hba data structure.
6312 * @vf: virtual function number
6313 *
6314 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
6315 * based on the given viftual function number, @vf.
6316 *
6317 * Return 0 if successful, otherwise -ENODEV.
6318 **/
6319static int
6320lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
6321{
6322 if (vf > LPFC_VIR_FUNC_MAX)
6323 return -ENODEV;
6324
6325 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05006326 vf * LPFC_VFR_PAGE_SIZE +
6327 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04006328 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05006329 vf * LPFC_VFR_PAGE_SIZE +
6330 LPFC_ULP0_WQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04006331 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6332 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
6333 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6334 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
6335 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6336 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
6337 return 0;
6338}
6339
6340/**
6341 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
6342 * @phba: pointer to lpfc hba data structure.
6343 *
6344 * This routine is invoked to create the bootstrap mailbox
6345 * region consistent with the SLI-4 interface spec. This
6346 * routine allocates all memory necessary to communicate
6347 * mailbox commands to the port and sets up all alignment
6348 * needs. No locks are expected to be held when calling
6349 * this routine.
6350 *
6351 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006352 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04006353 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04006354 **/
6355static int
6356lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
6357{
6358 uint32_t bmbx_size;
6359 struct lpfc_dmabuf *dmabuf;
6360 struct dma_address *dma_address;
6361 uint32_t pa_addr;
6362 uint64_t phys_addr;
6363
6364 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6365 if (!dmabuf)
6366 return -ENOMEM;
6367
6368 /*
6369 * The bootstrap mailbox region is comprised of 2 parts
6370 * plus an alignment restriction of 16 bytes.
6371 */
6372 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
6373 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
6374 bmbx_size,
6375 &dmabuf->phys,
6376 GFP_KERNEL);
6377 if (!dmabuf->virt) {
6378 kfree(dmabuf);
6379 return -ENOMEM;
6380 }
6381 memset(dmabuf->virt, 0, bmbx_size);
6382
6383 /*
6384 * Initialize the bootstrap mailbox pointers now so that the register
6385 * operations are simple later. The mailbox dma address is required
6386 * to be 16-byte aligned. Also align the virtual memory as each
6387 * maibox is copied into the bmbx mailbox region before issuing the
6388 * command to the port.
6389 */
6390 phba->sli4_hba.bmbx.dmabuf = dmabuf;
6391 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
6392
6393 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
6394 LPFC_ALIGN_16_BYTE);
6395 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
6396 LPFC_ALIGN_16_BYTE);
6397
6398 /*
6399 * Set the high and low physical addresses now. The SLI4 alignment
6400 * requirement is 16 bytes and the mailbox is posted to the port
6401 * as two 30-bit addresses. The other data is a bit marking whether
6402 * the 30-bit address is the high or low address.
6403 * Upcast bmbx aphys to 64bits so shift instruction compiles
6404 * clean on 32 bit machines.
6405 */
6406 dma_address = &phba->sli4_hba.bmbx.dma_address;
6407 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
6408 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
6409 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
6410 LPFC_BMBX_BIT1_ADDR_HI);
6411
6412 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
6413 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
6414 LPFC_BMBX_BIT1_ADDR_LO);
6415 return 0;
6416}
6417
6418/**
6419 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
6420 * @phba: pointer to lpfc hba data structure.
6421 *
6422 * This routine is invoked to teardown the bootstrap mailbox
6423 * region and release all host resources. This routine requires
6424 * the caller to ensure all mailbox commands recovered, no
6425 * additional mailbox comands are sent, and interrupts are disabled
6426 * before calling this routine.
6427 *
6428 **/
6429static void
6430lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
6431{
6432 dma_free_coherent(&phba->pcidev->dev,
6433 phba->sli4_hba.bmbx.bmbx_size,
6434 phba->sli4_hba.bmbx.dmabuf->virt,
6435 phba->sli4_hba.bmbx.dmabuf->phys);
6436
6437 kfree(phba->sli4_hba.bmbx.dmabuf);
6438 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
6439}
6440
6441/**
6442 * lpfc_sli4_read_config - Get the config parameters.
6443 * @phba: pointer to lpfc hba data structure.
6444 *
6445 * This routine is invoked to read the configuration parameters from the HBA.
6446 * The configuration parameters are used to set the base and maximum values
6447 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
6448 * allocation for the port.
6449 *
6450 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006451 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006452 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006453 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006454 **/
James Smartff78d8f2011-12-13 13:21:35 -05006455int
James Smartda0436e2009-05-22 14:51:39 -04006456lpfc_sli4_read_config(struct lpfc_hba *phba)
6457{
6458 LPFC_MBOXQ_t *pmb;
6459 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04006460 union lpfc_sli4_cfg_shdr *shdr;
6461 uint32_t shdr_status, shdr_add_status;
6462 struct lpfc_mbx_get_func_cfg *get_func_cfg;
6463 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04006464 char *pdesc_0;
James Smart912e3ac2011-05-24 11:42:11 -04006465 uint32_t desc_count;
James Smart8aa134a2012-08-14 14:25:29 -04006466 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04006467
6468 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6469 if (!pmb) {
6470 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6471 "2011 Unable to allocate memory for issuing "
6472 "SLI_CONFIG_SPECIAL mailbox command\n");
6473 return -ENOMEM;
6474 }
6475
6476 lpfc_read_config(phba, pmb);
6477
6478 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
6479 if (rc != MBX_SUCCESS) {
6480 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6481 "2012 Mailbox failed , mbxCmd x%x "
6482 "READ_CONFIG, mbxStatus x%x\n",
6483 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6484 bf_get(lpfc_mqe_status, &pmb->u.mqe));
6485 rc = -EIO;
6486 } else {
6487 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05006488 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
6489 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
6490 phba->sli4_hba.lnk_info.lnk_tp =
6491 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
6492 phba->sli4_hba.lnk_info.lnk_no =
6493 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
6494 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6495 "3081 lnk_type:%d, lnk_numb:%d\n",
6496 phba->sli4_hba.lnk_info.lnk_tp,
6497 phba->sli4_hba.lnk_info.lnk_no);
6498 } else
6499 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6500 "3082 Mailbox (x%x) returned ldv:x0\n",
6501 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart6d368e52011-05-24 11:44:12 -04006502 phba->sli4_hba.extents_in_use =
6503 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04006504 phba->sli4_hba.max_cfg_param.max_xri =
6505 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
6506 phba->sli4_hba.max_cfg_param.xri_base =
6507 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
6508 phba->sli4_hba.max_cfg_param.max_vpi =
6509 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
6510 phba->sli4_hba.max_cfg_param.vpi_base =
6511 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
6512 phba->sli4_hba.max_cfg_param.max_rpi =
6513 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
6514 phba->sli4_hba.max_cfg_param.rpi_base =
6515 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
6516 phba->sli4_hba.max_cfg_param.max_vfi =
6517 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
6518 phba->sli4_hba.max_cfg_param.vfi_base =
6519 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
6520 phba->sli4_hba.max_cfg_param.max_fcfi =
6521 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04006522 phba->sli4_hba.max_cfg_param.max_eq =
6523 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
6524 phba->sli4_hba.max_cfg_param.max_rq =
6525 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
6526 phba->sli4_hba.max_cfg_param.max_wq =
6527 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
6528 phba->sli4_hba.max_cfg_param.max_cq =
6529 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
6530 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
6531 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
6532 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
6533 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05006534 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
6535 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04006536 phba->max_vports = phba->max_vpi;
6537 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04006538 "2003 cfg params Extents? %d "
6539 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04006540 "VPI(B:%d M:%d) "
6541 "VFI(B:%d M:%d) "
6542 "RPI(B:%d M:%d) "
James Smart6d368e52011-05-24 11:44:12 -04006543 "FCFI(Count:%d)\n",
6544 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04006545 phba->sli4_hba.max_cfg_param.xri_base,
6546 phba->sli4_hba.max_cfg_param.max_xri,
6547 phba->sli4_hba.max_cfg_param.vpi_base,
6548 phba->sli4_hba.max_cfg_param.max_vpi,
6549 phba->sli4_hba.max_cfg_param.vfi_base,
6550 phba->sli4_hba.max_cfg_param.max_vfi,
6551 phba->sli4_hba.max_cfg_param.rpi_base,
6552 phba->sli4_hba.max_cfg_param.max_rpi,
James Smartda0436e2009-05-22 14:51:39 -04006553 phba->sli4_hba.max_cfg_param.max_fcfi);
6554 }
James Smart912e3ac2011-05-24 11:42:11 -04006555
6556 if (rc)
6557 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04006558
6559 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smartb92938b2010-06-07 15:24:12 -04006560 if (phba->cfg_hba_queue_depth >
6561 (phba->sli4_hba.max_cfg_param.max_xri -
6562 lpfc_sli4_get_els_iocb_cnt(phba)))
James Smartda0436e2009-05-22 14:51:39 -04006563 phba->cfg_hba_queue_depth =
James Smartb92938b2010-06-07 15:24:12 -04006564 phba->sli4_hba.max_cfg_param.max_xri -
6565 lpfc_sli4_get_els_iocb_cnt(phba);
James Smart912e3ac2011-05-24 11:42:11 -04006566
6567 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
6568 LPFC_SLI_INTF_IF_TYPE_2)
6569 goto read_cfg_out;
6570
6571 /* get the pf# and vf# for SLI4 if_type 2 port */
6572 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
6573 sizeof(struct lpfc_sli4_cfg_mhdr));
6574 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
6575 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
6576 length, LPFC_SLI4_MBX_EMBED);
6577
James Smart8aa134a2012-08-14 14:25:29 -04006578 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04006579 shdr = (union lpfc_sli4_cfg_shdr *)
6580 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
6581 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6582 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04006583 if (rc2 || shdr_status || shdr_add_status) {
James Smart912e3ac2011-05-24 11:42:11 -04006584 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6585 "3026 Mailbox failed , mbxCmd x%x "
6586 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
6587 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6588 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04006589 goto read_cfg_out;
6590 }
6591
6592 /* search for fc_fcoe resrouce descriptor */
6593 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
6594 desc_count = get_func_cfg->func_cfg.rsrc_desc_count;
6595
James Smart8aa134a2012-08-14 14:25:29 -04006596 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
6597 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
6598 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
6599 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
6600 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
6601 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
6602 goto read_cfg_out;
6603
James Smart912e3ac2011-05-24 11:42:11 -04006604 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04006605 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04006606 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04006607 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04006608 phba->sli4_hba.iov.pf_number =
6609 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
6610 phba->sli4_hba.iov.vf_number =
6611 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
6612 break;
6613 }
6614 }
6615
6616 if (i < LPFC_RSRC_DESC_MAX_NUM)
6617 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6618 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
6619 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
6620 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04006621 else
James Smart912e3ac2011-05-24 11:42:11 -04006622 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6623 "3028 GET_FUNCTION_CONFIG: failed to find "
6624 "Resrouce Descriptor:x%x\n",
6625 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04006626
6627read_cfg_out:
6628 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04006629 return rc;
6630}
6631
6632/**
James Smart2fcee4b2010-12-15 17:57:46 -05006633 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04006634 * @phba: pointer to lpfc hba data structure.
6635 *
James Smart2fcee4b2010-12-15 17:57:46 -05006636 * This routine is invoked to setup the port-side endian order when
6637 * the port if_type is 0. This routine has no function for other
6638 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04006639 *
6640 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006641 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006642 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006643 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006644 **/
6645static int
6646lpfc_setup_endian_order(struct lpfc_hba *phba)
6647{
6648 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05006649 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04006650 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
6651 HOST_ENDIAN_HIGH_WORD1};
6652
James Smart2fcee4b2010-12-15 17:57:46 -05006653 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
6654 switch (if_type) {
6655 case LPFC_SLI_INTF_IF_TYPE_0:
6656 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
6657 GFP_KERNEL);
6658 if (!mboxq) {
6659 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6660 "0492 Unable to allocate memory for "
6661 "issuing SLI_CONFIG_SPECIAL mailbox "
6662 "command\n");
6663 return -ENOMEM;
6664 }
James Smartda0436e2009-05-22 14:51:39 -04006665
James Smart2fcee4b2010-12-15 17:57:46 -05006666 /*
6667 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
6668 * two words to contain special data values and no other data.
6669 */
6670 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
6671 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
6672 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6673 if (rc != MBX_SUCCESS) {
6674 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6675 "0493 SLI_CONFIG_SPECIAL mailbox "
6676 "failed with status x%x\n",
6677 rc);
6678 rc = -EIO;
6679 }
6680 mempool_free(mboxq, phba->mbox_mem_pool);
6681 break;
6682 case LPFC_SLI_INTF_IF_TYPE_2:
6683 case LPFC_SLI_INTF_IF_TYPE_1:
6684 default:
6685 break;
James Smartda0436e2009-05-22 14:51:39 -04006686 }
James Smartda0436e2009-05-22 14:51:39 -04006687 return rc;
6688}
6689
6690/**
James Smart5350d872011-10-10 21:33:49 -04006691 * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts
James Smartda0436e2009-05-22 14:51:39 -04006692 * @phba: pointer to lpfc hba data structure.
6693 *
James Smart5350d872011-10-10 21:33:49 -04006694 * This routine is invoked to check the user settable queue counts for EQs and
6695 * CQs. after this routine is called the counts will be set to valid values that
6696 * adhere to the constraints of the system's interrupt vectors and the port's
6697 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04006698 *
6699 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006700 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006701 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04006702 **/
6703static int
James Smart5350d872011-10-10 21:33:49 -04006704lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04006705{
James Smart67d12732012-08-03 12:36:13 -04006706 int cfg_fcp_io_channel;
James Smart90695ee2012-08-14 14:25:36 -04006707 uint32_t cpu;
6708 uint32_t i = 0;
6709
James Smartda0436e2009-05-22 14:51:39 -04006710
6711 /*
James Smart67d12732012-08-03 12:36:13 -04006712 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04006713 * device parameters
6714 */
6715
James Smart67d12732012-08-03 12:36:13 -04006716 /* Sanity check on HBA EQ parameters */
6717 cfg_fcp_io_channel = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04006718
James Smart90695ee2012-08-14 14:25:36 -04006719 /* It doesn't make sense to have more io channels then CPUs */
6720 for_each_online_cpu(cpu) {
6721 i++;
6722 }
6723 if (i < cfg_fcp_io_channel) {
James Smart82c3e9b2012-09-29 11:29:50 -04006724 lpfc_printf_log(phba,
6725 KERN_ERR, LOG_INIT,
James Smart90695ee2012-08-14 14:25:36 -04006726 "3188 Reducing IO channels to match number of "
6727 "CPUs: from %d to %d\n", cfg_fcp_io_channel, i);
6728 cfg_fcp_io_channel = i;
6729 }
6730
James Smart67d12732012-08-03 12:36:13 -04006731 if (cfg_fcp_io_channel >
6732 phba->sli4_hba.max_cfg_param.max_eq) {
James Smart82c3e9b2012-09-29 11:29:50 -04006733 if (phba->sli4_hba.max_cfg_param.max_eq <
6734 LPFC_FCP_IO_CHAN_MIN) {
James Smartda0436e2009-05-22 14:51:39 -04006735 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6736 "2574 Not enough EQs (%d) from the "
6737 "pci function for supporting FCP "
6738 "EQs (%d)\n",
6739 phba->sli4_hba.max_cfg_param.max_eq,
James Smart67d12732012-08-03 12:36:13 -04006740 phba->cfg_fcp_io_channel);
James Smartda0436e2009-05-22 14:51:39 -04006741 goto out_error;
6742 }
James Smart82c3e9b2012-09-29 11:29:50 -04006743 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6744 "2575 Reducing IO channels to match number of "
6745 "available EQs: from %d to %d\n",
6746 cfg_fcp_io_channel,
6747 phba->sli4_hba.max_cfg_param.max_eq);
6748 cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq;
James Smartda0436e2009-05-22 14:51:39 -04006749 }
James Smart67d12732012-08-03 12:36:13 -04006750
6751 /* Eventually cfg_fcp_eq_count / cfg_fcp_wq_count will be depricated */
6752
James Smartda0436e2009-05-22 14:51:39 -04006753 /* The actual number of FCP event queues adopted */
James Smart67d12732012-08-03 12:36:13 -04006754 phba->cfg_fcp_eq_count = cfg_fcp_io_channel;
6755 phba->cfg_fcp_wq_count = cfg_fcp_io_channel;
6756 phba->cfg_fcp_io_channel = cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04006757
James Smartda0436e2009-05-22 14:51:39 -04006758 /* Get EQ depth from module parameter, fake the default for now */
6759 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
6760 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
6761
James Smart5350d872011-10-10 21:33:49 -04006762 /* Get CQ depth from module parameter, fake the default for now */
6763 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
6764 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
6765
6766 return 0;
6767out_error:
6768 return -ENOMEM;
6769}
6770
6771/**
6772 * lpfc_sli4_queue_create - Create all the SLI4 queues
6773 * @phba: pointer to lpfc hba data structure.
6774 *
6775 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
6776 * operation. For each SLI4 queue type, the parameters such as queue entry
6777 * count (queue depth) shall be taken from the module parameter. For now,
6778 * we just use some constant number as place holder.
6779 *
6780 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07006781 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04006782 * -ENOMEM - No availble memory
6783 * -EIO - The mailbox failed to complete successfully.
6784 **/
6785int
6786lpfc_sli4_queue_create(struct lpfc_hba *phba)
6787{
6788 struct lpfc_queue *qdesc;
James Smart67d12732012-08-03 12:36:13 -04006789 int idx;
James Smart5350d872011-10-10 21:33:49 -04006790
6791 /*
James Smart67d12732012-08-03 12:36:13 -04006792 * Create HBA Record arrays.
James Smart5350d872011-10-10 21:33:49 -04006793 */
James Smart67d12732012-08-03 12:36:13 -04006794 if (!phba->cfg_fcp_io_channel)
6795 return -ERANGE;
James Smart5350d872011-10-10 21:33:49 -04006796
James Smart67d12732012-08-03 12:36:13 -04006797 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
6798 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
6799 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
6800 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
6801 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
6802 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
6803
6804 phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) *
6805 phba->cfg_fcp_io_channel), GFP_KERNEL);
6806 if (!phba->sli4_hba.hba_eq) {
James Smartda0436e2009-05-22 14:51:39 -04006807 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04006808 "2576 Failed allocate memory for "
6809 "fast-path EQ record array\n");
James Smartda0436e2009-05-22 14:51:39 -04006810 goto out_error;
6811 }
James Smart67d12732012-08-03 12:36:13 -04006812
6813 phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
6814 phba->cfg_fcp_io_channel), GFP_KERNEL);
6815 if (!phba->sli4_hba.fcp_cq) {
6816 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6817 "2577 Failed allocate memory for fast-path "
6818 "CQ record array\n");
6819 goto out_error;
6820 }
6821
6822 phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
6823 phba->cfg_fcp_io_channel), GFP_KERNEL);
6824 if (!phba->sli4_hba.fcp_wq) {
6825 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6826 "2578 Failed allocate memory for fast-path "
6827 "WQ record array\n");
6828 goto out_error;
6829 }
James Smartda0436e2009-05-22 14:51:39 -04006830
James Smart5350d872011-10-10 21:33:49 -04006831 /*
James Smart67d12732012-08-03 12:36:13 -04006832 * Since the first EQ can have multiple CQs associated with it,
6833 * this array is used to quickly see if we have a FCP fast-path
6834 * CQ match.
James Smart5350d872011-10-10 21:33:49 -04006835 */
James Smart67d12732012-08-03 12:36:13 -04006836 phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) *
6837 phba->cfg_fcp_io_channel), GFP_KERNEL);
6838 if (!phba->sli4_hba.fcp_cq_map) {
6839 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6840 "2545 Failed allocate memory for fast-path "
6841 "CQ map\n");
6842 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04006843 }
James Smart67d12732012-08-03 12:36:13 -04006844
6845 /*
6846 * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies
6847 * how many EQs to create.
6848 */
6849 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
6850
6851 /* Create EQs */
James Smartda0436e2009-05-22 14:51:39 -04006852 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
6853 phba->sli4_hba.eq_ecount);
6854 if (!qdesc) {
6855 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04006856 "0497 Failed allocate EQ (%d)\n", idx);
6857 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04006858 }
James Smart67d12732012-08-03 12:36:13 -04006859 phba->sli4_hba.hba_eq[idx] = qdesc;
6860
6861 /* Create Fast Path FCP CQs */
6862 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
6863 phba->sli4_hba.cq_ecount);
6864 if (!qdesc) {
6865 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6866 "0499 Failed allocate fast-path FCP "
6867 "CQ (%d)\n", idx);
6868 goto out_error;
6869 }
6870 phba->sli4_hba.fcp_cq[idx] = qdesc;
6871
6872 /* Create Fast Path FCP WQs */
6873 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
6874 phba->sli4_hba.wq_ecount);
6875 if (!qdesc) {
6876 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6877 "0503 Failed allocate fast-path FCP "
6878 "WQ (%d)\n", idx);
6879 goto out_error;
6880 }
6881 phba->sli4_hba.fcp_wq[idx] = qdesc;
James Smartda0436e2009-05-22 14:51:39 -04006882 }
6883
James Smart67d12732012-08-03 12:36:13 -04006884
James Smartda0436e2009-05-22 14:51:39 -04006885 /*
James Smart67d12732012-08-03 12:36:13 -04006886 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04006887 */
6888
James Smartda0436e2009-05-22 14:51:39 -04006889 /* Create slow-path Mailbox Command Complete Queue */
6890 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
6891 phba->sli4_hba.cq_ecount);
6892 if (!qdesc) {
6893 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6894 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04006895 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04006896 }
6897 phba->sli4_hba.mbx_cq = qdesc;
6898
6899 /* Create slow-path ELS Complete Queue */
6900 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
6901 phba->sli4_hba.cq_ecount);
6902 if (!qdesc) {
6903 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6904 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -04006905 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04006906 }
6907 phba->sli4_hba.els_cq = qdesc;
6908
James Smartda0436e2009-05-22 14:51:39 -04006909
James Smart5350d872011-10-10 21:33:49 -04006910 /*
James Smart67d12732012-08-03 12:36:13 -04006911 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04006912 */
James Smartda0436e2009-05-22 14:51:39 -04006913
6914 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04006915
6916 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
6917 phba->sli4_hba.mq_ecount);
6918 if (!qdesc) {
6919 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6920 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04006921 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04006922 }
6923 phba->sli4_hba.mbx_wq = qdesc;
6924
6925 /*
James Smart67d12732012-08-03 12:36:13 -04006926 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04006927 */
James Smartda0436e2009-05-22 14:51:39 -04006928
6929 /* Create slow-path ELS Work Queue */
6930 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
6931 phba->sli4_hba.wq_ecount);
6932 if (!qdesc) {
6933 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6934 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04006935 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04006936 }
6937 phba->sli4_hba.els_wq = qdesc;
6938
James Smartda0436e2009-05-22 14:51:39 -04006939 /*
6940 * Create Receive Queue (RQ)
6941 */
James Smartda0436e2009-05-22 14:51:39 -04006942
6943 /* Create Receive Queue for header */
6944 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
6945 phba->sli4_hba.rq_ecount);
6946 if (!qdesc) {
6947 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6948 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04006949 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04006950 }
6951 phba->sli4_hba.hdr_rq = qdesc;
6952
6953 /* Create Receive Queue for data */
6954 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
6955 phba->sli4_hba.rq_ecount);
6956 if (!qdesc) {
6957 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6958 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04006959 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04006960 }
6961 phba->sli4_hba.dat_rq = qdesc;
6962
6963 return 0;
6964
James Smartda0436e2009-05-22 14:51:39 -04006965out_error:
James Smart67d12732012-08-03 12:36:13 -04006966 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04006967 return -ENOMEM;
6968}
6969
6970/**
6971 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
6972 * @phba: pointer to lpfc hba data structure.
6973 *
6974 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
6975 * operation.
6976 *
6977 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006978 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006979 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006980 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006981 **/
James Smart5350d872011-10-10 21:33:49 -04006982void
James Smartda0436e2009-05-22 14:51:39 -04006983lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
6984{
James Smart67d12732012-08-03 12:36:13 -04006985 int idx;
6986
6987 if (phba->sli4_hba.hba_eq != NULL) {
6988 /* Release HBA event queue */
6989 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
6990 if (phba->sli4_hba.hba_eq[idx] != NULL) {
6991 lpfc_sli4_queue_free(
6992 phba->sli4_hba.hba_eq[idx]);
6993 phba->sli4_hba.hba_eq[idx] = NULL;
6994 }
6995 }
6996 kfree(phba->sli4_hba.hba_eq);
6997 phba->sli4_hba.hba_eq = NULL;
6998 }
6999
7000 if (phba->sli4_hba.fcp_cq != NULL) {
7001 /* Release FCP completion queue */
7002 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7003 if (phba->sli4_hba.fcp_cq[idx] != NULL) {
7004 lpfc_sli4_queue_free(
7005 phba->sli4_hba.fcp_cq[idx]);
7006 phba->sli4_hba.fcp_cq[idx] = NULL;
7007 }
7008 }
7009 kfree(phba->sli4_hba.fcp_cq);
7010 phba->sli4_hba.fcp_cq = NULL;
7011 }
7012
7013 if (phba->sli4_hba.fcp_wq != NULL) {
7014 /* Release FCP work queue */
7015 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7016 if (phba->sli4_hba.fcp_wq[idx] != NULL) {
7017 lpfc_sli4_queue_free(
7018 phba->sli4_hba.fcp_wq[idx]);
7019 phba->sli4_hba.fcp_wq[idx] = NULL;
7020 }
7021 }
7022 kfree(phba->sli4_hba.fcp_wq);
7023 phba->sli4_hba.fcp_wq = NULL;
7024 }
7025
James Smart962bc512013-01-03 15:44:00 -05007026 if (phba->pci_bar0_memmap_p) {
7027 iounmap(phba->pci_bar0_memmap_p);
7028 phba->pci_bar0_memmap_p = NULL;
7029 }
7030 if (phba->pci_bar2_memmap_p) {
7031 iounmap(phba->pci_bar2_memmap_p);
7032 phba->pci_bar2_memmap_p = NULL;
7033 }
7034 if (phba->pci_bar4_memmap_p) {
7035 iounmap(phba->pci_bar4_memmap_p);
7036 phba->pci_bar4_memmap_p = NULL;
7037 }
7038
James Smart67d12732012-08-03 12:36:13 -04007039 /* Release FCP CQ mapping array */
7040 if (phba->sli4_hba.fcp_cq_map != NULL) {
7041 kfree(phba->sli4_hba.fcp_cq_map);
7042 phba->sli4_hba.fcp_cq_map = NULL;
7043 }
James Smartda0436e2009-05-22 14:51:39 -04007044
7045 /* Release mailbox command work queue */
James Smart67d12732012-08-03 12:36:13 -04007046 if (phba->sli4_hba.mbx_wq != NULL) {
7047 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
7048 phba->sli4_hba.mbx_wq = NULL;
7049 }
James Smartda0436e2009-05-22 14:51:39 -04007050
7051 /* Release ELS work queue */
James Smart67d12732012-08-03 12:36:13 -04007052 if (phba->sli4_hba.els_wq != NULL) {
7053 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
7054 phba->sli4_hba.els_wq = NULL;
7055 }
James Smartda0436e2009-05-22 14:51:39 -04007056
7057 /* Release unsolicited receive queue */
James Smart67d12732012-08-03 12:36:13 -04007058 if (phba->sli4_hba.hdr_rq != NULL) {
7059 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
7060 phba->sli4_hba.hdr_rq = NULL;
7061 }
7062 if (phba->sli4_hba.dat_rq != NULL) {
7063 lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
7064 phba->sli4_hba.dat_rq = NULL;
7065 }
James Smartda0436e2009-05-22 14:51:39 -04007066
James Smartda0436e2009-05-22 14:51:39 -04007067 /* Release ELS complete queue */
James Smart67d12732012-08-03 12:36:13 -04007068 if (phba->sli4_hba.els_cq != NULL) {
7069 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
7070 phba->sli4_hba.els_cq = NULL;
7071 }
James Smartda0436e2009-05-22 14:51:39 -04007072
7073 /* Release mailbox command complete queue */
James Smart67d12732012-08-03 12:36:13 -04007074 if (phba->sli4_hba.mbx_cq != NULL) {
7075 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
7076 phba->sli4_hba.mbx_cq = NULL;
7077 }
James Smartda0436e2009-05-22 14:51:39 -04007078
7079 return;
7080}
7081
7082/**
7083 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
7084 * @phba: pointer to lpfc hba data structure.
7085 *
7086 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
7087 * operation.
7088 *
7089 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007090 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007091 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007092 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007093 **/
7094int
7095lpfc_sli4_queue_setup(struct lpfc_hba *phba)
7096{
James Smart2a76a282012-08-03 12:35:54 -04007097 struct lpfc_sli *psli = &phba->sli;
7098 struct lpfc_sli_ring *pring;
James Smartda0436e2009-05-22 14:51:39 -04007099 int rc = -ENOMEM;
7100 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
7101 int fcp_cq_index = 0;
James Smart962bc512013-01-03 15:44:00 -05007102 uint32_t shdr_status, shdr_add_status;
7103 union lpfc_sli4_cfg_shdr *shdr;
7104 LPFC_MBOXQ_t *mboxq;
7105 uint32_t length;
7106
7107 /* Check for dual-ULP support */
7108 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7109 if (!mboxq) {
7110 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7111 "3249 Unable to allocate memory for "
7112 "QUERY_FW_CFG mailbox command\n");
7113 return -ENOMEM;
7114 }
7115 length = (sizeof(struct lpfc_mbx_query_fw_config) -
7116 sizeof(struct lpfc_sli4_cfg_mhdr));
7117 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
7118 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
7119 length, LPFC_SLI4_MBX_EMBED);
7120
7121 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7122
7123 shdr = (union lpfc_sli4_cfg_shdr *)
7124 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
7125 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7126 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7127 if (shdr_status || shdr_add_status || rc) {
7128 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7129 "3250 QUERY_FW_CFG mailbox failed with status "
7130 "x%x add_status x%x, mbx status x%x\n",
7131 shdr_status, shdr_add_status, rc);
7132 if (rc != MBX_TIMEOUT)
7133 mempool_free(mboxq, phba->mbox_mem_pool);
7134 rc = -ENXIO;
7135 goto out_error;
7136 }
7137
7138 phba->sli4_hba.fw_func_mode =
7139 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
7140 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
7141 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
7142 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7143 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
7144 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
7145 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
7146
7147 if (rc != MBX_TIMEOUT)
7148 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04007149
7150 /*
James Smart67d12732012-08-03 12:36:13 -04007151 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04007152 */
7153
James Smart67d12732012-08-03 12:36:13 -04007154 /* Set up HBA event queue */
7155 if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) {
James Smart2e90f4b2011-12-13 13:22:37 -05007156 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7157 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007158 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007159 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05007160 }
James Smart67d12732012-08-03 12:36:13 -04007161 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
7162 if (!phba->sli4_hba.hba_eq[fcp_eqidx]) {
James Smartda0436e2009-05-22 14:51:39 -04007163 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7164 "0522 Fast-path EQ (%d) not "
7165 "allocated\n", fcp_eqidx);
James Smart1b511972011-12-13 13:23:09 -05007166 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007167 goto out_destroy_hba_eq;
James Smartda0436e2009-05-22 14:51:39 -04007168 }
James Smart67d12732012-08-03 12:36:13 -04007169 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx],
James Smartbf8dae82012-08-03 12:36:24 -04007170 (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel));
James Smartda0436e2009-05-22 14:51:39 -04007171 if (rc) {
7172 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7173 "0523 Failed setup of fast-path EQ "
7174 "(%d), rc = 0x%x\n", fcp_eqidx, rc);
James Smart67d12732012-08-03 12:36:13 -04007175 goto out_destroy_hba_eq;
James Smartda0436e2009-05-22 14:51:39 -04007176 }
7177 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007178 "2584 HBA EQ setup: "
James Smartda0436e2009-05-22 14:51:39 -04007179 "queue[%d]-id=%d\n", fcp_eqidx,
James Smart67d12732012-08-03 12:36:13 -04007180 phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007181 }
7182
James Smart67d12732012-08-03 12:36:13 -04007183 /* Set up fast-path FCP Response Complete Queue */
7184 if (!phba->sli4_hba.fcp_cq) {
7185 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7186 "3148 Fast-path FCP CQ array not "
7187 "allocated\n");
7188 rc = -ENOMEM;
7189 goto out_destroy_hba_eq;
7190 }
7191
7192 for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) {
7193 if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
7194 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7195 "0526 Fast-path FCP CQ (%d) not "
7196 "allocated\n", fcp_cqidx);
7197 rc = -ENOMEM;
7198 goto out_destroy_fcp_cq;
7199 }
7200 rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
7201 phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP);
7202 if (rc) {
7203 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7204 "0527 Failed setup of fast-path FCP "
7205 "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc);
7206 goto out_destroy_fcp_cq;
7207 }
7208
7209 /* Setup fcp_cq_map for fast lookup */
7210 phba->sli4_hba.fcp_cq_map[fcp_cqidx] =
7211 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id;
7212
7213 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7214 "2588 FCP CQ setup: cq[%d]-id=%d, "
7215 "parent seq[%d]-id=%d\n",
7216 fcp_cqidx,
7217 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
7218 fcp_cqidx,
7219 phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id);
7220 }
7221
7222 /* Set up fast-path FCP Work Queue */
7223 if (!phba->sli4_hba.fcp_wq) {
7224 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7225 "3149 Fast-path FCP WQ array not "
7226 "allocated\n");
7227 rc = -ENOMEM;
7228 goto out_destroy_fcp_cq;
7229 }
7230
7231 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) {
7232 if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
7233 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7234 "0534 Fast-path FCP WQ (%d) not "
7235 "allocated\n", fcp_wqidx);
7236 rc = -ENOMEM;
7237 goto out_destroy_fcp_wq;
7238 }
7239 rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
7240 phba->sli4_hba.fcp_cq[fcp_wqidx],
7241 LPFC_FCP);
7242 if (rc) {
7243 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7244 "0535 Failed setup of fast-path FCP "
7245 "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc);
7246 goto out_destroy_fcp_wq;
7247 }
7248
7249 /* Bind this WQ to the next FCP ring */
7250 pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx];
7251 pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx];
7252 phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring;
7253
7254 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7255 "2591 FCP WQ setup: wq[%d]-id=%d, "
7256 "parent cq[%d]-id=%d\n",
7257 fcp_wqidx,
7258 phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
7259 fcp_cq_index,
7260 phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id);
7261 }
James Smartda0436e2009-05-22 14:51:39 -04007262 /*
7263 * Set up Complete Queues (CQs)
7264 */
7265
7266 /* Set up slow-path MBOX Complete Queue as the first CQ */
7267 if (!phba->sli4_hba.mbx_cq) {
7268 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7269 "0528 Mailbox CQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007270 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007271 goto out_destroy_fcp_wq;
James Smartda0436e2009-05-22 14:51:39 -04007272 }
James Smart67d12732012-08-03 12:36:13 -04007273 rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq,
7274 phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04007275 if (rc) {
7276 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7277 "0529 Failed setup of slow-path mailbox CQ: "
7278 "rc = 0x%x\n", rc);
James Smart67d12732012-08-03 12:36:13 -04007279 goto out_destroy_fcp_wq;
James Smartda0436e2009-05-22 14:51:39 -04007280 }
7281 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7282 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
7283 phba->sli4_hba.mbx_cq->queue_id,
James Smart67d12732012-08-03 12:36:13 -04007284 phba->sli4_hba.hba_eq[0]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007285
7286 /* Set up slow-path ELS Complete Queue */
7287 if (!phba->sli4_hba.els_cq) {
7288 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7289 "0530 ELS CQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007290 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007291 goto out_destroy_mbx_cq;
7292 }
James Smart67d12732012-08-03 12:36:13 -04007293 rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq,
7294 phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04007295 if (rc) {
7296 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7297 "0531 Failed setup of slow-path ELS CQ: "
7298 "rc = 0x%x\n", rc);
7299 goto out_destroy_mbx_cq;
7300 }
7301 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7302 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
7303 phba->sli4_hba.els_cq->queue_id,
James Smart67d12732012-08-03 12:36:13 -04007304 phba->sli4_hba.hba_eq[0]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007305
7306 /*
7307 * Set up all the Work Queues (WQs)
7308 */
7309
7310 /* Set up Mailbox Command Queue */
7311 if (!phba->sli4_hba.mbx_wq) {
7312 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7313 "0538 Slow-path MQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007314 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007315 goto out_destroy_els_cq;
James Smartda0436e2009-05-22 14:51:39 -04007316 }
7317 rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
7318 phba->sli4_hba.mbx_cq, LPFC_MBOX);
7319 if (rc) {
7320 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7321 "0539 Failed setup of slow-path MQ: "
7322 "rc = 0x%x\n", rc);
James Smart67d12732012-08-03 12:36:13 -04007323 goto out_destroy_els_cq;
James Smartda0436e2009-05-22 14:51:39 -04007324 }
7325 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7326 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
7327 phba->sli4_hba.mbx_wq->queue_id,
7328 phba->sli4_hba.mbx_cq->queue_id);
7329
7330 /* Set up slow-path ELS Work Queue */
7331 if (!phba->sli4_hba.els_wq) {
7332 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7333 "0536 Slow-path ELS WQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007334 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007335 goto out_destroy_mbx_wq;
7336 }
7337 rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
7338 phba->sli4_hba.els_cq, LPFC_ELS);
7339 if (rc) {
7340 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7341 "0537 Failed setup of slow-path ELS WQ: "
7342 "rc = 0x%x\n", rc);
7343 goto out_destroy_mbx_wq;
7344 }
James Smart2a76a282012-08-03 12:35:54 -04007345
7346 /* Bind this WQ to the ELS ring */
7347 pring = &psli->ring[LPFC_ELS_RING];
7348 pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq;
7349 phba->sli4_hba.els_cq->pring = pring;
7350
James Smartda0436e2009-05-22 14:51:39 -04007351 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7352 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
7353 phba->sli4_hba.els_wq->queue_id,
7354 phba->sli4_hba.els_cq->queue_id);
7355
James Smartda0436e2009-05-22 14:51:39 -04007356 /*
7357 * Create Receive Queue (RQ)
7358 */
7359 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
7360 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7361 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007362 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007363 goto out_destroy_els_wq;
James Smartda0436e2009-05-22 14:51:39 -04007364 }
James Smart73d91e52011-10-10 21:32:10 -04007365
7366 lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
7367 lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
7368
James Smartda0436e2009-05-22 14:51:39 -04007369 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04007370 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04007371 if (rc) {
7372 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7373 "0541 Failed setup of Receive Queue: "
7374 "rc = 0x%x\n", rc);
7375 goto out_destroy_fcp_wq;
7376 }
James Smart73d91e52011-10-10 21:32:10 -04007377
James Smartda0436e2009-05-22 14:51:39 -04007378 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7379 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
7380 "parent cq-id=%d\n",
7381 phba->sli4_hba.hdr_rq->queue_id,
7382 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04007383 phba->sli4_hba.els_cq->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007384 return 0;
7385
James Smart2e90f4b2011-12-13 13:22:37 -05007386out_destroy_els_wq:
James Smartda0436e2009-05-22 14:51:39 -04007387 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7388out_destroy_mbx_wq:
7389 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
James Smart2e90f4b2011-12-13 13:22:37 -05007390out_destroy_els_cq:
James Smartda0436e2009-05-22 14:51:39 -04007391 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
7392out_destroy_mbx_cq:
7393 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
James Smart67d12732012-08-03 12:36:13 -04007394out_destroy_fcp_wq:
7395 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
7396 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
7397out_destroy_fcp_cq:
7398 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
7399 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
7400out_destroy_hba_eq:
James Smartda0436e2009-05-22 14:51:39 -04007401 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
James Smart67d12732012-08-03 12:36:13 -04007402 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]);
James Smartda0436e2009-05-22 14:51:39 -04007403out_error:
7404 return rc;
7405}
7406
7407/**
7408 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
7409 * @phba: pointer to lpfc hba data structure.
7410 *
7411 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
7412 * operation.
7413 *
7414 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007415 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007416 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007417 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007418 **/
7419void
7420lpfc_sli4_queue_unset(struct lpfc_hba *phba)
7421{
7422 int fcp_qidx;
7423
7424 /* Unset mailbox command work queue */
7425 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
7426 /* Unset ELS work queue */
7427 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7428 /* Unset unsolicited receive queue */
7429 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
7430 /* Unset FCP work queue */
James Smart67d12732012-08-03 12:36:13 -04007431 if (phba->sli4_hba.fcp_wq) {
7432 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
7433 fcp_qidx++)
7434 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
7435 }
James Smartda0436e2009-05-22 14:51:39 -04007436 /* Unset mailbox command complete queue */
7437 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
7438 /* Unset ELS complete queue */
7439 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
James Smartda0436e2009-05-22 14:51:39 -04007440 /* Unset FCP response complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05007441 if (phba->sli4_hba.fcp_cq) {
James Smart67d12732012-08-03 12:36:13 -04007442 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
7443 fcp_qidx++)
James Smart2e90f4b2011-12-13 13:22:37 -05007444 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
James Smart2e90f4b2011-12-13 13:22:37 -05007445 }
James Smartda0436e2009-05-22 14:51:39 -04007446 /* Unset fast-path event queue */
James Smart67d12732012-08-03 12:36:13 -04007447 if (phba->sli4_hba.hba_eq) {
7448 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
James Smart2e90f4b2011-12-13 13:22:37 -05007449 fcp_qidx++)
James Smart67d12732012-08-03 12:36:13 -04007450 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_qidx]);
James Smart2e90f4b2011-12-13 13:22:37 -05007451 }
James Smartda0436e2009-05-22 14:51:39 -04007452}
7453
7454/**
7455 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
7456 * @phba: pointer to lpfc hba data structure.
7457 *
7458 * This routine is invoked to allocate and set up a pool of completion queue
7459 * events. The body of the completion queue event is a completion queue entry
7460 * CQE. For now, this pool is used for the interrupt service routine to queue
7461 * the following HBA completion queue events for the worker thread to process:
7462 * - Mailbox asynchronous events
7463 * - Receive queue completion unsolicited events
7464 * Later, this can be used for all the slow-path events.
7465 *
7466 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007467 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007468 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007469 **/
7470static int
7471lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
7472{
7473 struct lpfc_cq_event *cq_event;
7474 int i;
7475
7476 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
7477 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
7478 if (!cq_event)
7479 goto out_pool_create_fail;
7480 list_add_tail(&cq_event->list,
7481 &phba->sli4_hba.sp_cqe_event_pool);
7482 }
7483 return 0;
7484
7485out_pool_create_fail:
7486 lpfc_sli4_cq_event_pool_destroy(phba);
7487 return -ENOMEM;
7488}
7489
7490/**
7491 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
7492 * @phba: pointer to lpfc hba data structure.
7493 *
7494 * This routine is invoked to free the pool of completion queue events at
7495 * driver unload time. Note that, it is the responsibility of the driver
7496 * cleanup routine to free all the outstanding completion-queue events
7497 * allocated from this pool back into the pool before invoking this routine
7498 * to destroy the pool.
7499 **/
7500static void
7501lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
7502{
7503 struct lpfc_cq_event *cq_event, *next_cq_event;
7504
7505 list_for_each_entry_safe(cq_event, next_cq_event,
7506 &phba->sli4_hba.sp_cqe_event_pool, list) {
7507 list_del(&cq_event->list);
7508 kfree(cq_event);
7509 }
7510}
7511
7512/**
7513 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7514 * @phba: pointer to lpfc hba data structure.
7515 *
7516 * This routine is the lock free version of the API invoked to allocate a
7517 * completion-queue event from the free pool.
7518 *
7519 * Return: Pointer to the newly allocated completion-queue event if successful
7520 * NULL otherwise.
7521 **/
7522struct lpfc_cq_event *
7523__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
7524{
7525 struct lpfc_cq_event *cq_event = NULL;
7526
7527 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
7528 struct lpfc_cq_event, list);
7529 return cq_event;
7530}
7531
7532/**
7533 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7534 * @phba: pointer to lpfc hba data structure.
7535 *
7536 * This routine is the lock version of the API invoked to allocate a
7537 * completion-queue event from the free pool.
7538 *
7539 * Return: Pointer to the newly allocated completion-queue event if successful
7540 * NULL otherwise.
7541 **/
7542struct lpfc_cq_event *
7543lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
7544{
7545 struct lpfc_cq_event *cq_event;
7546 unsigned long iflags;
7547
7548 spin_lock_irqsave(&phba->hbalock, iflags);
7549 cq_event = __lpfc_sli4_cq_event_alloc(phba);
7550 spin_unlock_irqrestore(&phba->hbalock, iflags);
7551 return cq_event;
7552}
7553
7554/**
7555 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7556 * @phba: pointer to lpfc hba data structure.
7557 * @cq_event: pointer to the completion queue event to be freed.
7558 *
7559 * This routine is the lock free version of the API invoked to release a
7560 * completion-queue event back into the free pool.
7561 **/
7562void
7563__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
7564 struct lpfc_cq_event *cq_event)
7565{
7566 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
7567}
7568
7569/**
7570 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7571 * @phba: pointer to lpfc hba data structure.
7572 * @cq_event: pointer to the completion queue event to be freed.
7573 *
7574 * This routine is the lock version of the API invoked to release a
7575 * completion-queue event back into the free pool.
7576 **/
7577void
7578lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
7579 struct lpfc_cq_event *cq_event)
7580{
7581 unsigned long iflags;
7582 spin_lock_irqsave(&phba->hbalock, iflags);
7583 __lpfc_sli4_cq_event_release(phba, cq_event);
7584 spin_unlock_irqrestore(&phba->hbalock, iflags);
7585}
7586
7587/**
7588 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
7589 * @phba: pointer to lpfc hba data structure.
7590 *
7591 * This routine is to free all the pending completion-queue events to the
7592 * back into the free pool for device reset.
7593 **/
7594static void
7595lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
7596{
7597 LIST_HEAD(cqelist);
7598 struct lpfc_cq_event *cqe;
7599 unsigned long iflags;
7600
7601 /* Retrieve all the pending WCQEs from pending WCQE lists */
7602 spin_lock_irqsave(&phba->hbalock, iflags);
7603 /* Pending FCP XRI abort events */
7604 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
7605 &cqelist);
7606 /* Pending ELS XRI abort events */
7607 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
7608 &cqelist);
7609 /* Pending asynnc events */
7610 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
7611 &cqelist);
7612 spin_unlock_irqrestore(&phba->hbalock, iflags);
7613
7614 while (!list_empty(&cqelist)) {
7615 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
7616 lpfc_sli4_cq_event_release(phba, cqe);
7617 }
7618}
7619
7620/**
7621 * lpfc_pci_function_reset - Reset pci function.
7622 * @phba: pointer to lpfc hba data structure.
7623 *
7624 * This routine is invoked to request a PCI function reset. It will destroys
7625 * all resources assigned to the PCI function which originates this request.
7626 *
7627 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007628 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007629 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007630 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007631 **/
7632int
7633lpfc_pci_function_reset(struct lpfc_hba *phba)
7634{
7635 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05007636 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04007637 uint32_t shdr_status, shdr_add_status;
James Smart2fcee4b2010-12-15 17:57:46 -05007638 uint32_t rdy_chk, num_resets = 0, reset_again = 0;
James Smartda0436e2009-05-22 14:51:39 -04007639 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05007640 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -05007641 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -04007642
James Smart2fcee4b2010-12-15 17:57:46 -05007643 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7644 switch (if_type) {
7645 case LPFC_SLI_INTF_IF_TYPE_0:
7646 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7647 GFP_KERNEL);
7648 if (!mboxq) {
7649 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7650 "0494 Unable to allocate memory for "
7651 "issuing SLI_FUNCTION_RESET mailbox "
7652 "command\n");
7653 return -ENOMEM;
7654 }
7655
7656 /* Setup PCI function reset mailbox-ioctl command */
7657 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
7658 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
7659 LPFC_SLI4_MBX_EMBED);
7660 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7661 shdr = (union lpfc_sli4_cfg_shdr *)
7662 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
7663 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7664 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
7665 &shdr->response);
7666 if (rc != MBX_TIMEOUT)
7667 mempool_free(mboxq, phba->mbox_mem_pool);
7668 if (shdr_status || shdr_add_status || rc) {
7669 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7670 "0495 SLI_FUNCTION_RESET mailbox "
7671 "failed with status x%x add_status x%x,"
7672 " mbx status x%x\n",
7673 shdr_status, shdr_add_status, rc);
7674 rc = -ENXIO;
7675 }
7676 break;
7677 case LPFC_SLI_INTF_IF_TYPE_2:
7678 for (num_resets = 0;
7679 num_resets < MAX_IF_TYPE_2_RESETS;
7680 num_resets++) {
7681 reg_data.word0 = 0;
7682 bf_set(lpfc_sliport_ctrl_end, &reg_data,
7683 LPFC_SLIPORT_LITTLE_ENDIAN);
7684 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
7685 LPFC_SLIPORT_INIT_PORT);
7686 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
7687 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -05007688 /* flush */
James Smart2b81f942012-03-01 22:37:18 -05007689 pci_read_config_word(phba->pcidev,
7690 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -05007691 /*
7692 * Poll the Port Status Register and wait for RDY for
7693 * up to 10 seconds. If the port doesn't respond, treat
7694 * it as an error. If the port responds with RN, start
7695 * the loop again.
7696 */
7697 for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) {
James Smart73d91e52011-10-10 21:32:10 -04007698 msleep(10);
James Smart9940b972011-03-11 16:06:12 -05007699 if (lpfc_readl(phba->sli4_hba.u.if_type2.
7700 STATUSregaddr, &reg_data.word0)) {
7701 rc = -ENODEV;
James Smart73d91e52011-10-10 21:32:10 -04007702 goto out;
James Smart9940b972011-03-11 16:06:12 -05007703 }
James Smart6b5151f2012-01-18 16:24:06 -05007704 if (bf_get(lpfc_sliport_status_rn, &reg_data))
7705 reset_again++;
James Smart2fcee4b2010-12-15 17:57:46 -05007706 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
7707 break;
James Smart2fcee4b2010-12-15 17:57:46 -05007708 }
7709
7710 /*
7711 * If the port responds to the init request with
7712 * reset needed, delay for a bit and restart the loop.
7713 */
James Smart6b5151f2012-01-18 16:24:06 -05007714 if (reset_again && (rdy_chk < 1000)) {
James Smart2fcee4b2010-12-15 17:57:46 -05007715 msleep(10);
7716 reset_again = 0;
7717 continue;
7718 }
7719
7720 /* Detect any port errors. */
James Smart2fcee4b2010-12-15 17:57:46 -05007721 if ((bf_get(lpfc_sliport_status_err, &reg_data)) ||
7722 (rdy_chk >= 1000)) {
7723 phba->work_status[0] = readl(
7724 phba->sli4_hba.u.if_type2.ERR1regaddr);
7725 phba->work_status[1] = readl(
7726 phba->sli4_hba.u.if_type2.ERR2regaddr);
7727 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05007728 "2890 Port error detected during port "
James Smart8a9d2e82012-05-09 21:16:12 -04007729 "reset(%d): wait_tmo:%d ms, "
7730 "port status reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05007731 "error 1=0x%x, error 2=0x%x\n",
James Smart8a9d2e82012-05-09 21:16:12 -04007732 num_resets, rdy_chk*10,
7733 reg_data.word0,
James Smart2fcee4b2010-12-15 17:57:46 -05007734 phba->work_status[0],
7735 phba->work_status[1]);
7736 rc = -ENODEV;
7737 }
7738
7739 /*
7740 * Terminate the outer loop provided the Port indicated
7741 * ready within 10 seconds.
7742 */
7743 if (rdy_chk < 1000)
7744 break;
7745 }
James Smart05580562011-05-24 11:40:48 -04007746 /* delay driver action following IF_TYPE_2 function reset */
7747 msleep(100);
James Smart2fcee4b2010-12-15 17:57:46 -05007748 break;
7749 case LPFC_SLI_INTF_IF_TYPE_1:
7750 default:
7751 break;
James Smartda0436e2009-05-22 14:51:39 -04007752 }
7753
James Smart73d91e52011-10-10 21:32:10 -04007754out:
James Smart2fcee4b2010-12-15 17:57:46 -05007755 /* Catch the not-ready port failure after a port reset. */
7756 if (num_resets >= MAX_IF_TYPE_2_RESETS)
7757 rc = -ENODEV;
7758
James Smartda0436e2009-05-22 14:51:39 -04007759 return rc;
7760}
7761
7762/**
James Smartda0436e2009-05-22 14:51:39 -04007763 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
7764 * @phba: pointer to lpfc hba data structure.
7765 *
7766 * This routine is invoked to set up the PCI device memory space for device
7767 * with SLI-4 interface spec.
7768 *
7769 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007770 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04007771 * other values - error
7772 **/
7773static int
7774lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
7775{
7776 struct pci_dev *pdev;
7777 unsigned long bar0map_len, bar1map_len, bar2map_len;
7778 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05007779 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04007780
7781 /* Obtain PCI device reference */
7782 if (!phba->pcidev)
7783 return error;
7784 else
7785 pdev = phba->pcidev;
7786
7787 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05007788 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
7789 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
7790 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
7791 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smartda0436e2009-05-22 14:51:39 -04007792 return error;
Michael Reed8e685972009-09-18 12:02:05 -05007793 }
7794 }
James Smartda0436e2009-05-22 14:51:39 -04007795
James Smart2fcee4b2010-12-15 17:57:46 -05007796 /*
7797 * The BARs and register set definitions and offset locations are
7798 * dependent on the if_type.
7799 */
7800 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
7801 &phba->sli4_hba.sli_intf.word0)) {
7802 return error;
7803 }
7804
7805 /* There is no SLI3 failback for SLI4 devices. */
7806 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
7807 LPFC_SLI_INTF_VALID) {
7808 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7809 "2894 SLI_INTF reg contents invalid "
7810 "sli_intf reg 0x%x\n",
7811 phba->sli4_hba.sli_intf.word0);
7812 return error;
7813 }
7814
7815 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7816 /*
7817 * Get the bus address of SLI4 device Bar regions and the
7818 * number of bytes required by each mapping. The mapping of the
7819 * particular PCI BARs regions is dependent on the type of
7820 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04007821 */
James Smart1dfb5a42010-02-12 14:40:50 -05007822 if (pci_resource_start(pdev, 0)) {
7823 phba->pci_bar0_map = pci_resource_start(pdev, 0);
7824 bar0map_len = pci_resource_len(pdev, 0);
James Smart2fcee4b2010-12-15 17:57:46 -05007825
7826 /*
7827 * Map SLI4 PCI Config Space Register base to a kernel virtual
7828 * addr
7829 */
7830 phba->sli4_hba.conf_regs_memmap_p =
7831 ioremap(phba->pci_bar0_map, bar0map_len);
7832 if (!phba->sli4_hba.conf_regs_memmap_p) {
7833 dev_printk(KERN_ERR, &pdev->dev,
7834 "ioremap failed for SLI4 PCI config "
7835 "registers.\n");
7836 goto out;
7837 }
7838 /* Set up BAR0 PCI config space register memory map */
7839 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05007840 } else {
7841 phba->pci_bar0_map = pci_resource_start(pdev, 1);
7842 bar0map_len = pci_resource_len(pdev, 1);
James Smart2fcee4b2010-12-15 17:57:46 -05007843 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
7844 dev_printk(KERN_ERR, &pdev->dev,
7845 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
7846 goto out;
7847 }
7848 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04007849 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05007850 if (!phba->sli4_hba.conf_regs_memmap_p) {
7851 dev_printk(KERN_ERR, &pdev->dev,
7852 "ioremap failed for SLI4 PCI config "
7853 "registers.\n");
7854 goto out;
7855 }
7856 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04007857 }
7858
James Smartc31098c2011-04-16 11:03:33 -04007859 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
7860 (pci_resource_start(pdev, 2))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007861 /*
7862 * Map SLI4 if type 0 HBA Control Register base to a kernel
7863 * virtual address and setup the registers.
7864 */
7865 phba->pci_bar1_map = pci_resource_start(pdev, 2);
7866 bar1map_len = pci_resource_len(pdev, 2);
7867 phba->sli4_hba.ctrl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04007868 ioremap(phba->pci_bar1_map, bar1map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05007869 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
7870 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04007871 "ioremap failed for SLI4 HBA control registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05007872 goto out_iounmap_conf;
7873 }
7874 lpfc_sli4_bar1_register_memmap(phba);
James Smartda0436e2009-05-22 14:51:39 -04007875 }
7876
James Smartc31098c2011-04-16 11:03:33 -04007877 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
7878 (pci_resource_start(pdev, 4))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007879 /*
7880 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
7881 * virtual address and setup the registers.
7882 */
7883 phba->pci_bar2_map = pci_resource_start(pdev, 4);
7884 bar2map_len = pci_resource_len(pdev, 4);
7885 phba->sli4_hba.drbl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04007886 ioremap(phba->pci_bar2_map, bar2map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05007887 if (!phba->sli4_hba.drbl_regs_memmap_p) {
7888 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04007889 "ioremap failed for SLI4 HBA doorbell registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05007890 goto out_iounmap_ctrl;
7891 }
7892 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
7893 if (error)
7894 goto out_iounmap_all;
James Smartda0436e2009-05-22 14:51:39 -04007895 }
7896
James Smartda0436e2009-05-22 14:51:39 -04007897 return 0;
7898
7899out_iounmap_all:
7900 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
7901out_iounmap_ctrl:
7902 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
7903out_iounmap_conf:
7904 iounmap(phba->sli4_hba.conf_regs_memmap_p);
7905out:
7906 return error;
7907}
7908
7909/**
7910 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
7911 * @phba: pointer to lpfc hba data structure.
7912 *
7913 * This routine is invoked to unset the PCI device memory space for device
7914 * with SLI-4 interface spec.
7915 **/
7916static void
7917lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
7918{
James Smart2e90f4b2011-12-13 13:22:37 -05007919 uint32_t if_type;
7920 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -04007921
James Smart2e90f4b2011-12-13 13:22:37 -05007922 switch (if_type) {
7923 case LPFC_SLI_INTF_IF_TYPE_0:
7924 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
7925 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
7926 iounmap(phba->sli4_hba.conf_regs_memmap_p);
7927 break;
7928 case LPFC_SLI_INTF_IF_TYPE_2:
7929 iounmap(phba->sli4_hba.conf_regs_memmap_p);
7930 break;
7931 case LPFC_SLI_INTF_IF_TYPE_1:
7932 default:
7933 dev_printk(KERN_ERR, &phba->pcidev->dev,
7934 "FATAL - unsupported SLI4 interface type - %d\n",
7935 if_type);
7936 break;
7937 }
James Smartda0436e2009-05-22 14:51:39 -04007938}
7939
7940/**
James Smart3772a992009-05-22 14:50:54 -04007941 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
7942 * @phba: pointer to lpfc hba data structure.
7943 *
7944 * This routine is invoked to enable the MSI-X interrupt vectors to device
7945 * with SLI-3 interface specs. The kernel function pci_enable_msix() is
7946 * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
7947 * invoked, enables either all or nothing, depending on the current
7948 * availability of PCI vector resources. The device driver is responsible
7949 * for calling the individual request_irq() to register each MSI-X vector
7950 * with a interrupt handler, which is done in this function. Note that
7951 * later when device is unloading, the driver should always call free_irq()
7952 * on all MSI-X vectors it has done request_irq() on before calling
7953 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
7954 * will be left with MSI-X enabled and leaks its vectors.
7955 *
7956 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007957 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007958 * other values - error
7959 **/
7960static int
7961lpfc_sli_enable_msix(struct lpfc_hba *phba)
7962{
7963 int rc, i;
7964 LPFC_MBOXQ_t *pmb;
7965
7966 /* Set up MSI-X multi-message vectors */
7967 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
7968 phba->msix_entries[i].entry = i;
7969
7970 /* Configure MSI-X capability structure */
7971 rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
7972 ARRAY_SIZE(phba->msix_entries));
7973 if (rc) {
7974 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7975 "0420 PCI enable MSI-X failed (%d)\n", rc);
7976 goto msi_fail_out;
7977 }
7978 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
7979 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7980 "0477 MSI-X entry[%d]: vector=x%x "
7981 "message=%d\n", i,
7982 phba->msix_entries[i].vector,
7983 phba->msix_entries[i].entry);
7984 /*
7985 * Assign MSI-X vectors to interrupt handlers
7986 */
7987
7988 /* vector-0 is associated to slow-path handler */
7989 rc = request_irq(phba->msix_entries[0].vector,
7990 &lpfc_sli_sp_intr_handler, IRQF_SHARED,
7991 LPFC_SP_DRIVER_HANDLER_NAME, phba);
7992 if (rc) {
7993 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7994 "0421 MSI-X slow-path request_irq failed "
7995 "(%d)\n", rc);
7996 goto msi_fail_out;
7997 }
7998
7999 /* vector-1 is associated to fast-path handler */
8000 rc = request_irq(phba->msix_entries[1].vector,
8001 &lpfc_sli_fp_intr_handler, IRQF_SHARED,
8002 LPFC_FP_DRIVER_HANDLER_NAME, phba);
8003
8004 if (rc) {
8005 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8006 "0429 MSI-X fast-path request_irq failed "
8007 "(%d)\n", rc);
8008 goto irq_fail_out;
8009 }
8010
8011 /*
8012 * Configure HBA MSI-X attention conditions to messages
8013 */
8014 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8015
8016 if (!pmb) {
8017 rc = -ENOMEM;
8018 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8019 "0474 Unable to allocate memory for issuing "
8020 "MBOX_CONFIG_MSI command\n");
8021 goto mem_fail_out;
8022 }
8023 rc = lpfc_config_msi(phba, pmb);
8024 if (rc)
8025 goto mbx_fail_out;
8026 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
8027 if (rc != MBX_SUCCESS) {
8028 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
8029 "0351 Config MSI mailbox command failed, "
8030 "mbxCmd x%x, mbxStatus x%x\n",
8031 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
8032 goto mbx_fail_out;
8033 }
8034
8035 /* Free memory allocated for mailbox command */
8036 mempool_free(pmb, phba->mbox_mem_pool);
8037 return rc;
8038
8039mbx_fail_out:
8040 /* Free memory allocated for mailbox command */
8041 mempool_free(pmb, phba->mbox_mem_pool);
8042
8043mem_fail_out:
8044 /* free the irq already requested */
8045 free_irq(phba->msix_entries[1].vector, phba);
8046
8047irq_fail_out:
8048 /* free the irq already requested */
8049 free_irq(phba->msix_entries[0].vector, phba);
8050
8051msi_fail_out:
8052 /* Unconfigure MSI-X capability structure */
8053 pci_disable_msix(phba->pcidev);
8054 return rc;
8055}
8056
8057/**
8058 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
8059 * @phba: pointer to lpfc hba data structure.
8060 *
8061 * This routine is invoked to release the MSI-X vectors and then disable the
8062 * MSI-X interrupt mode to device with SLI-3 interface spec.
8063 **/
8064static void
8065lpfc_sli_disable_msix(struct lpfc_hba *phba)
8066{
8067 int i;
8068
8069 /* Free up MSI-X multi-message vectors */
8070 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8071 free_irq(phba->msix_entries[i].vector, phba);
8072 /* Disable MSI-X */
8073 pci_disable_msix(phba->pcidev);
8074
8075 return;
8076}
8077
8078/**
8079 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
8080 * @phba: pointer to lpfc hba data structure.
8081 *
8082 * This routine is invoked to enable the MSI interrupt mode to device with
8083 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
8084 * enable the MSI vector. The device driver is responsible for calling the
8085 * request_irq() to register MSI vector with a interrupt the handler, which
8086 * is done in this function.
8087 *
8088 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008089 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008090 * other values - error
8091 */
8092static int
8093lpfc_sli_enable_msi(struct lpfc_hba *phba)
8094{
8095 int rc;
8096
8097 rc = pci_enable_msi(phba->pcidev);
8098 if (!rc)
8099 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8100 "0462 PCI enable MSI mode success.\n");
8101 else {
8102 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8103 "0471 PCI enable MSI mode failed (%d)\n", rc);
8104 return rc;
8105 }
8106
8107 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
8108 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8109 if (rc) {
8110 pci_disable_msi(phba->pcidev);
8111 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8112 "0478 MSI request_irq failed (%d)\n", rc);
8113 }
8114 return rc;
8115}
8116
8117/**
8118 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
8119 * @phba: pointer to lpfc hba data structure.
8120 *
8121 * This routine is invoked to disable the MSI interrupt mode to device with
8122 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
8123 * done request_irq() on before calling pci_disable_msi(). Failure to do so
8124 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
8125 * its vector.
8126 */
8127static void
8128lpfc_sli_disable_msi(struct lpfc_hba *phba)
8129{
8130 free_irq(phba->pcidev->irq, phba);
8131 pci_disable_msi(phba->pcidev);
8132 return;
8133}
8134
8135/**
8136 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
8137 * @phba: pointer to lpfc hba data structure.
8138 *
8139 * This routine is invoked to enable device interrupt and associate driver's
8140 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
8141 * spec. Depends on the interrupt mode configured to the driver, the driver
8142 * will try to fallback from the configured interrupt mode to an interrupt
8143 * mode which is supported by the platform, kernel, and device in the order
8144 * of:
8145 * MSI-X -> MSI -> IRQ.
8146 *
8147 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008148 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008149 * other values - error
8150 **/
8151static uint32_t
8152lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
8153{
8154 uint32_t intr_mode = LPFC_INTR_ERROR;
8155 int retval;
8156
8157 if (cfg_mode == 2) {
8158 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
8159 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
8160 if (!retval) {
8161 /* Now, try to enable MSI-X interrupt mode */
8162 retval = lpfc_sli_enable_msix(phba);
8163 if (!retval) {
8164 /* Indicate initialization to MSI-X mode */
8165 phba->intr_type = MSIX;
8166 intr_mode = 2;
8167 }
8168 }
8169 }
8170
8171 /* Fallback to MSI if MSI-X initialization failed */
8172 if (cfg_mode >= 1 && phba->intr_type == NONE) {
8173 retval = lpfc_sli_enable_msi(phba);
8174 if (!retval) {
8175 /* Indicate initialization to MSI mode */
8176 phba->intr_type = MSI;
8177 intr_mode = 1;
8178 }
8179 }
8180
8181 /* Fallback to INTx if both MSI-X/MSI initalization failed */
8182 if (phba->intr_type == NONE) {
8183 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
8184 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8185 if (!retval) {
8186 /* Indicate initialization to INTx mode */
8187 phba->intr_type = INTx;
8188 intr_mode = 0;
8189 }
8190 }
8191 return intr_mode;
8192}
8193
8194/**
8195 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
8196 * @phba: pointer to lpfc hba data structure.
8197 *
8198 * This routine is invoked to disable device interrupt and disassociate the
8199 * driver's interrupt handler(s) from interrupt vector(s) to device with
8200 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
8201 * release the interrupt vector(s) for the message signaled interrupt.
8202 **/
8203static void
8204lpfc_sli_disable_intr(struct lpfc_hba *phba)
8205{
8206 /* Disable the currently initialized interrupt mode */
8207 if (phba->intr_type == MSIX)
8208 lpfc_sli_disable_msix(phba);
8209 else if (phba->intr_type == MSI)
8210 lpfc_sli_disable_msi(phba);
8211 else if (phba->intr_type == INTx)
8212 free_irq(phba->pcidev->irq, phba);
8213
8214 /* Reset interrupt management states */
8215 phba->intr_type = NONE;
8216 phba->sli.slistat.sli_intr = 0;
8217
8218 return;
8219}
8220
8221/**
James Smartda0436e2009-05-22 14:51:39 -04008222 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
8223 * @phba: pointer to lpfc hba data structure.
8224 *
8225 * This routine is invoked to enable the MSI-X interrupt vectors to device
8226 * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
8227 * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
8228 * enables either all or nothing, depending on the current availability of
8229 * PCI vector resources. The device driver is responsible for calling the
8230 * individual request_irq() to register each MSI-X vector with a interrupt
8231 * handler, which is done in this function. Note that later when device is
8232 * unloading, the driver should always call free_irq() on all MSI-X vectors
8233 * it has done request_irq() on before calling pci_disable_msix(). Failure
8234 * to do so results in a BUG_ON() and a device will be left with MSI-X
8235 * enabled and leaks its vectors.
8236 *
8237 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008238 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008239 * other values - error
8240 **/
8241static int
8242lpfc_sli4_enable_msix(struct lpfc_hba *phba)
8243{
James Smart75baf692010-06-08 18:31:21 -04008244 int vectors, rc, index;
James Smartda0436e2009-05-22 14:51:39 -04008245
8246 /* Set up MSI-X multi-message vectors */
James Smart82c3e9b2012-09-29 11:29:50 -04008247 for (index = 0; index < phba->cfg_fcp_io_channel; index++)
James Smartda0436e2009-05-22 14:51:39 -04008248 phba->sli4_hba.msix_entries[index].entry = index;
8249
8250 /* Configure MSI-X capability structure */
James Smart82c3e9b2012-09-29 11:29:50 -04008251 vectors = phba->cfg_fcp_io_channel;
James Smart75baf692010-06-08 18:31:21 -04008252enable_msix_vectors:
James Smartda0436e2009-05-22 14:51:39 -04008253 rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries,
James Smart75baf692010-06-08 18:31:21 -04008254 vectors);
8255 if (rc > 1) {
8256 vectors = rc;
8257 goto enable_msix_vectors;
8258 } else if (rc) {
James Smartda0436e2009-05-22 14:51:39 -04008259 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8260 "0484 PCI enable MSI-X failed (%d)\n", rc);
8261 goto msi_fail_out;
8262 }
James Smart75baf692010-06-08 18:31:21 -04008263
James Smartda0436e2009-05-22 14:51:39 -04008264 /* Log MSI-X vector assignment */
James Smart75baf692010-06-08 18:31:21 -04008265 for (index = 0; index < vectors; index++)
James Smartda0436e2009-05-22 14:51:39 -04008266 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8267 "0489 MSI-X entry[%d]: vector=x%x "
8268 "message=%d\n", index,
8269 phba->sli4_hba.msix_entries[index].vector,
8270 phba->sli4_hba.msix_entries[index].entry);
James Smart67d12732012-08-03 12:36:13 -04008271
James Smartda0436e2009-05-22 14:51:39 -04008272 /*
8273 * Assign MSI-X vectors to interrupt handlers
8274 */
James Smart67d12732012-08-03 12:36:13 -04008275 for (index = 0; index < vectors; index++) {
James Smart4305f182012-08-03 12:36:33 -04008276 memset(&phba->sli4_hba.handler_name[index], 0, 16);
8277 sprintf((char *)&phba->sli4_hba.handler_name[index],
8278 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -04008279
James Smart67d12732012-08-03 12:36:13 -04008280 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
8281 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
James Smartba20c852012-08-03 12:36:52 -04008282 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].fcp_eq_in_use, 1);
James Smartda0436e2009-05-22 14:51:39 -04008283 rc = request_irq(phba->sli4_hba.msix_entries[index].vector,
James Smart67d12732012-08-03 12:36:13 -04008284 &lpfc_sli4_hba_intr_handler, IRQF_SHARED,
James Smart4305f182012-08-03 12:36:33 -04008285 (char *)&phba->sli4_hba.handler_name[index],
James Smart67d12732012-08-03 12:36:13 -04008286 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -04008287 if (rc) {
8288 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8289 "0486 MSI-X fast-path (%d) "
8290 "request_irq failed (%d)\n", index, rc);
8291 goto cfg_fail_out;
8292 }
8293 }
8294
James Smart82c3e9b2012-09-29 11:29:50 -04008295 if (vectors != phba->cfg_fcp_io_channel) {
8296 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8297 "3238 Reducing IO channels to match number of "
8298 "MSI-X vectors, requested %d got %d\n",
8299 phba->cfg_fcp_io_channel, vectors);
8300 phba->cfg_fcp_io_channel = vectors;
8301 }
James Smartda0436e2009-05-22 14:51:39 -04008302 return rc;
8303
8304cfg_fail_out:
8305 /* free the irq already requested */
James Smart67d12732012-08-03 12:36:13 -04008306 for (--index; index >= 0; index--)
8307 free_irq(phba->sli4_hba.msix_entries[index].vector,
8308 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -04008309
8310msi_fail_out:
8311 /* Unconfigure MSI-X capability structure */
8312 pci_disable_msix(phba->pcidev);
8313 return rc;
8314}
8315
8316/**
8317 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
8318 * @phba: pointer to lpfc hba data structure.
8319 *
8320 * This routine is invoked to release the MSI-X vectors and then disable the
8321 * MSI-X interrupt mode to device with SLI-4 interface spec.
8322 **/
8323static void
8324lpfc_sli4_disable_msix(struct lpfc_hba *phba)
8325{
8326 int index;
8327
8328 /* Free up MSI-X multi-message vectors */
James Smart82c3e9b2012-09-29 11:29:50 -04008329 for (index = 0; index < phba->cfg_fcp_io_channel; index++)
James Smartda0436e2009-05-22 14:51:39 -04008330 free_irq(phba->sli4_hba.msix_entries[index].vector,
James Smart67d12732012-08-03 12:36:13 -04008331 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smart75baf692010-06-08 18:31:21 -04008332
James Smartda0436e2009-05-22 14:51:39 -04008333 /* Disable MSI-X */
8334 pci_disable_msix(phba->pcidev);
8335
8336 return;
8337}
8338
8339/**
8340 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
8341 * @phba: pointer to lpfc hba data structure.
8342 *
8343 * This routine is invoked to enable the MSI interrupt mode to device with
8344 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
8345 * to enable the MSI vector. The device driver is responsible for calling
8346 * the request_irq() to register MSI vector with a interrupt the handler,
8347 * which is done in this function.
8348 *
8349 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008350 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008351 * other values - error
8352 **/
8353static int
8354lpfc_sli4_enable_msi(struct lpfc_hba *phba)
8355{
8356 int rc, index;
8357
8358 rc = pci_enable_msi(phba->pcidev);
8359 if (!rc)
8360 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8361 "0487 PCI enable MSI mode success.\n");
8362 else {
8363 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8364 "0488 PCI enable MSI mode failed (%d)\n", rc);
8365 return rc;
8366 }
8367
8368 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
8369 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8370 if (rc) {
8371 pci_disable_msi(phba->pcidev);
8372 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8373 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -04008374 return rc;
James Smartda0436e2009-05-22 14:51:39 -04008375 }
8376
James Smart67d12732012-08-03 12:36:13 -04008377 for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
James Smartda0436e2009-05-22 14:51:39 -04008378 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
8379 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
8380 }
8381
James Smart75baf692010-06-08 18:31:21 -04008382 return 0;
James Smartda0436e2009-05-22 14:51:39 -04008383}
8384
8385/**
8386 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
8387 * @phba: pointer to lpfc hba data structure.
8388 *
8389 * This routine is invoked to disable the MSI interrupt mode to device with
8390 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
8391 * done request_irq() on before calling pci_disable_msi(). Failure to do so
8392 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
8393 * its vector.
8394 **/
8395static void
8396lpfc_sli4_disable_msi(struct lpfc_hba *phba)
8397{
8398 free_irq(phba->pcidev->irq, phba);
8399 pci_disable_msi(phba->pcidev);
8400 return;
8401}
8402
8403/**
8404 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
8405 * @phba: pointer to lpfc hba data structure.
8406 *
8407 * This routine is invoked to enable device interrupt and associate driver's
8408 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
8409 * interface spec. Depends on the interrupt mode configured to the driver,
8410 * the driver will try to fallback from the configured interrupt mode to an
8411 * interrupt mode which is supported by the platform, kernel, and device in
8412 * the order of:
8413 * MSI-X -> MSI -> IRQ.
8414 *
8415 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008416 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008417 * other values - error
8418 **/
8419static uint32_t
8420lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
8421{
8422 uint32_t intr_mode = LPFC_INTR_ERROR;
8423 int retval, index;
8424
8425 if (cfg_mode == 2) {
8426 /* Preparation before conf_msi mbox cmd */
8427 retval = 0;
8428 if (!retval) {
8429 /* Now, try to enable MSI-X interrupt mode */
8430 retval = lpfc_sli4_enable_msix(phba);
8431 if (!retval) {
8432 /* Indicate initialization to MSI-X mode */
8433 phba->intr_type = MSIX;
8434 intr_mode = 2;
8435 }
8436 }
8437 }
8438
8439 /* Fallback to MSI if MSI-X initialization failed */
8440 if (cfg_mode >= 1 && phba->intr_type == NONE) {
8441 retval = lpfc_sli4_enable_msi(phba);
8442 if (!retval) {
8443 /* Indicate initialization to MSI mode */
8444 phba->intr_type = MSI;
8445 intr_mode = 1;
8446 }
8447 }
8448
8449 /* Fallback to INTx if both MSI-X/MSI initalization failed */
8450 if (phba->intr_type == NONE) {
8451 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
8452 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8453 if (!retval) {
8454 /* Indicate initialization to INTx mode */
8455 phba->intr_type = INTx;
8456 intr_mode = 0;
James Smart67d12732012-08-03 12:36:13 -04008457 for (index = 0; index < phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04008458 index++) {
8459 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
8460 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
James Smartba20c852012-08-03 12:36:52 -04008461 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
8462 fcp_eq_in_use, 1);
James Smartda0436e2009-05-22 14:51:39 -04008463 }
8464 }
8465 }
8466 return intr_mode;
8467}
8468
8469/**
8470 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
8471 * @phba: pointer to lpfc hba data structure.
8472 *
8473 * This routine is invoked to disable device interrupt and disassociate
8474 * the driver's interrupt handler(s) from interrupt vector(s) to device
8475 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
8476 * will release the interrupt vector(s) for the message signaled interrupt.
8477 **/
8478static void
8479lpfc_sli4_disable_intr(struct lpfc_hba *phba)
8480{
8481 /* Disable the currently initialized interrupt mode */
8482 if (phba->intr_type == MSIX)
8483 lpfc_sli4_disable_msix(phba);
8484 else if (phba->intr_type == MSI)
8485 lpfc_sli4_disable_msi(phba);
8486 else if (phba->intr_type == INTx)
8487 free_irq(phba->pcidev->irq, phba);
8488
8489 /* Reset interrupt management states */
8490 phba->intr_type = NONE;
8491 phba->sli.slistat.sli_intr = 0;
8492
8493 return;
8494}
8495
8496/**
James Smart3772a992009-05-22 14:50:54 -04008497 * lpfc_unset_hba - Unset SLI3 hba device initialization
8498 * @phba: pointer to lpfc hba data structure.
8499 *
8500 * This routine is invoked to unset the HBA device initialization steps to
8501 * a device with SLI-3 interface spec.
8502 **/
8503static void
8504lpfc_unset_hba(struct lpfc_hba *phba)
8505{
8506 struct lpfc_vport *vport = phba->pport;
8507 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8508
8509 spin_lock_irq(shost->host_lock);
8510 vport->load_flag |= FC_UNLOADING;
8511 spin_unlock_irq(shost->host_lock);
8512
James Smart72859902012-01-18 16:25:38 -05008513 kfree(phba->vpi_bmask);
8514 kfree(phba->vpi_ids);
8515
James Smart3772a992009-05-22 14:50:54 -04008516 lpfc_stop_hba_timers(phba);
8517
8518 phba->pport->work_port_events = 0;
8519
8520 lpfc_sli_hba_down(phba);
8521
8522 lpfc_sli_brdrestart(phba);
8523
8524 lpfc_sli_disable_intr(phba);
8525
8526 return;
8527}
8528
8529/**
James Smart5af5eee2010-10-22 11:06:38 -04008530 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
8531 * @phba: Pointer to HBA context object.
8532 *
8533 * This function is called in the SLI4 code path to wait for completion
8534 * of device's XRIs exchange busy. It will check the XRI exchange busy
8535 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
8536 * that, it will check the XRI exchange busy on outstanding FCP and ELS
8537 * I/Os every 30 seconds, log error message, and wait forever. Only when
8538 * all XRI exchange busy complete, the driver unload shall proceed with
8539 * invoking the function reset ioctl mailbox command to the CNA and the
8540 * the rest of the driver unload resource release.
8541 **/
8542static void
8543lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
8544{
8545 int wait_time = 0;
8546 int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
8547 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
8548
8549 while (!fcp_xri_cmpl || !els_xri_cmpl) {
8550 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
8551 if (!fcp_xri_cmpl)
8552 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8553 "2877 FCP XRI exchange busy "
8554 "wait time: %d seconds.\n",
8555 wait_time/1000);
8556 if (!els_xri_cmpl)
8557 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8558 "2878 ELS XRI exchange busy "
8559 "wait time: %d seconds.\n",
8560 wait_time/1000);
8561 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
8562 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
8563 } else {
8564 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
8565 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
8566 }
8567 fcp_xri_cmpl =
8568 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
8569 els_xri_cmpl =
8570 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
8571 }
8572}
8573
8574/**
James Smartda0436e2009-05-22 14:51:39 -04008575 * lpfc_sli4_hba_unset - Unset the fcoe hba
8576 * @phba: Pointer to HBA context object.
8577 *
8578 * This function is called in the SLI4 code path to reset the HBA's FCoE
8579 * function. The caller is not required to hold any lock. This routine
8580 * issues PCI function reset mailbox command to reset the FCoE function.
8581 * At the end of the function, it calls lpfc_hba_down_post function to
8582 * free any pending commands.
8583 **/
8584static void
8585lpfc_sli4_hba_unset(struct lpfc_hba *phba)
8586{
8587 int wait_cnt = 0;
8588 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -04008589 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -04008590
8591 lpfc_stop_hba_timers(phba);
8592 phba->sli4_hba.intr_enable = 0;
8593
8594 /*
8595 * Gracefully wait out the potential current outstanding asynchronous
8596 * mailbox command.
8597 */
8598
8599 /* First, block any pending async mailbox command from posted */
8600 spin_lock_irq(&phba->hbalock);
8601 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
8602 spin_unlock_irq(&phba->hbalock);
8603 /* Now, trying to wait it out if we can */
8604 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
8605 msleep(10);
8606 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
8607 break;
8608 }
8609 /* Forcefully release the outstanding mailbox command if timed out */
8610 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
8611 spin_lock_irq(&phba->hbalock);
8612 mboxq = phba->sli.mbox_active;
8613 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
8614 __lpfc_mbox_cmpl_put(phba, mboxq);
8615 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8616 phba->sli.mbox_active = NULL;
8617 spin_unlock_irq(&phba->hbalock);
8618 }
8619
James Smart5af5eee2010-10-22 11:06:38 -04008620 /* Abort all iocbs associated with the hba */
8621 lpfc_sli_hba_iocb_abort(phba);
8622
8623 /* Wait for completion of device XRI exchange busy */
8624 lpfc_sli4_xri_exchange_busy_wait(phba);
8625
James Smartda0436e2009-05-22 14:51:39 -04008626 /* Disable PCI subsystem interrupt */
8627 lpfc_sli4_disable_intr(phba);
8628
James Smart912e3ac2011-05-24 11:42:11 -04008629 /* Disable SR-IOV if enabled */
8630 if (phba->cfg_sriov_nr_virtfn)
8631 pci_disable_sriov(pdev);
8632
James Smartda0436e2009-05-22 14:51:39 -04008633 /* Stop kthread signal shall trigger work_done one more time */
8634 kthread_stop(phba->worker_thread);
8635
James Smart3677a3a2010-09-29 11:19:14 -04008636 /* Reset SLI4 HBA FCoE function */
8637 lpfc_pci_function_reset(phba);
James Smart5350d872011-10-10 21:33:49 -04008638 lpfc_sli4_queue_destroy(phba);
James Smart3677a3a2010-09-29 11:19:14 -04008639
James Smartda0436e2009-05-22 14:51:39 -04008640 /* Stop the SLI4 device port */
8641 phba->pport->work_port_events = 0;
8642}
8643
James Smart28baac72010-02-12 14:42:03 -05008644 /**
8645 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
8646 * @phba: Pointer to HBA context object.
8647 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
8648 *
8649 * This function is called in the SLI4 code path to read the port's
8650 * sli4 capabilities.
8651 *
8652 * This function may be be called from any context that can block-wait
8653 * for the completion. The expectation is that this routine is called
8654 * typically from probe_one or from the online routine.
8655 **/
8656int
8657lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
8658{
8659 int rc;
8660 struct lpfc_mqe *mqe;
8661 struct lpfc_pc_sli4_params *sli4_params;
8662 uint32_t mbox_tmo;
8663
8664 rc = 0;
8665 mqe = &mboxq->u.mqe;
8666
8667 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -05008668 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -05008669 if (!phba->sli4_hba.intr_enable)
8670 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8671 else {
James Smarta183a152011-10-10 21:32:43 -04008672 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -05008673 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
8674 }
8675
8676 if (unlikely(rc))
8677 return 1;
8678
8679 sli4_params = &phba->sli4_hba.pc_sli4_params;
8680 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
8681 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
8682 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
8683 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
8684 &mqe->un.sli4_params);
8685 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
8686 &mqe->un.sli4_params);
8687 sli4_params->proto_types = mqe->un.sli4_params.word3;
8688 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
8689 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
8690 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
8691 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
8692 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
8693 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
8694 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
8695 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
8696 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
8697 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
8698 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
8699 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
8700 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
8701 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
8702 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
8703 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
8704 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
8705 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
8706 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
8707 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -04008708
8709 /* Make sure that sge_supp_len can be handled by the driver */
8710 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
8711 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
8712
James Smart28baac72010-02-12 14:42:03 -05008713 return rc;
8714}
8715
James Smartda0436e2009-05-22 14:51:39 -04008716/**
James Smartfedd3b72011-02-16 12:39:24 -05008717 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
8718 * @phba: Pointer to HBA context object.
8719 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
8720 *
8721 * This function is called in the SLI4 code path to read the port's
8722 * sli4 capabilities.
8723 *
8724 * This function may be be called from any context that can block-wait
8725 * for the completion. The expectation is that this routine is called
8726 * typically from probe_one or from the online routine.
8727 **/
8728int
8729lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
8730{
8731 int rc;
8732 struct lpfc_mqe *mqe = &mboxq->u.mqe;
8733 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -04008734 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -05008735 int length;
8736 struct lpfc_sli4_parameters *mbx_sli4_parameters;
8737
James Smart6d368e52011-05-24 11:44:12 -04008738 /*
8739 * By default, the driver assumes the SLI4 port requires RPI
8740 * header postings. The SLI4_PARAM response will correct this
8741 * assumption.
8742 */
8743 phba->sli4_hba.rpi_hdrs_in_use = 1;
8744
James Smartfedd3b72011-02-16 12:39:24 -05008745 /* Read the port's SLI4 Config Parameters */
8746 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
8747 sizeof(struct lpfc_sli4_cfg_mhdr));
8748 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8749 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
8750 length, LPFC_SLI4_MBX_EMBED);
8751 if (!phba->sli4_hba.intr_enable)
8752 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -04008753 else {
8754 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
8755 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
8756 }
James Smartfedd3b72011-02-16 12:39:24 -05008757 if (unlikely(rc))
8758 return rc;
8759 sli4_params = &phba->sli4_hba.pc_sli4_params;
8760 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
8761 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
8762 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
8763 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
8764 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
8765 mbx_sli4_parameters);
8766 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
8767 mbx_sli4_parameters);
8768 if (bf_get(cfg_phwq, mbx_sli4_parameters))
8769 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
8770 else
8771 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
8772 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
8773 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
8774 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
8775 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
8776 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
8777 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
8778 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
8779 mbx_sli4_parameters);
8780 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
8781 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -04008782 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
8783 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart05580562011-05-24 11:40:48 -04008784
8785 /* Make sure that sge_supp_len can be handled by the driver */
8786 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
8787 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
8788
James Smartfedd3b72011-02-16 12:39:24 -05008789 return 0;
8790}
8791
8792/**
James Smart3772a992009-05-22 14:50:54 -04008793 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
8794 * @pdev: pointer to PCI device
8795 * @pid: pointer to PCI device identifier
8796 *
8797 * This routine is to be called to attach a device with SLI-3 interface spec
8798 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
8799 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
8800 * information of the device and driver to see if the driver state that it can
8801 * support this kind of device. If the match is successful, the driver core
8802 * invokes this routine. If this routine determines it can claim the HBA, it
8803 * does all the initialization that it needs to do to handle the HBA properly.
8804 *
8805 * Return code
8806 * 0 - driver can claim the device
8807 * negative value - driver can not claim the device
8808 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008809static int
James Smart3772a992009-05-22 14:50:54 -04008810lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
8811{
8812 struct lpfc_hba *phba;
8813 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -04008814 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -04008815 int error;
8816 uint32_t cfg_mode, intr_mode;
8817
8818 /* Allocate memory for HBA structure */
8819 phba = lpfc_hba_alloc(pdev);
8820 if (!phba)
8821 return -ENOMEM;
8822
8823 /* Perform generic PCI device enabling operation */
8824 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -04008825 if (error)
James Smart3772a992009-05-22 14:50:54 -04008826 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -04008827
8828 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
8829 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
8830 if (error)
8831 goto out_disable_pci_dev;
8832
8833 /* Set up SLI-3 specific device PCI memory space */
8834 error = lpfc_sli_pci_mem_setup(phba);
8835 if (error) {
8836 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8837 "1402 Failed to set up pci memory space.\n");
8838 goto out_disable_pci_dev;
8839 }
8840
8841 /* Set up phase-1 common device driver resources */
8842 error = lpfc_setup_driver_resource_phase1(phba);
8843 if (error) {
8844 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8845 "1403 Failed to set up driver resource.\n");
8846 goto out_unset_pci_mem_s3;
8847 }
8848
8849 /* Set up SLI-3 specific device driver resources */
8850 error = lpfc_sli_driver_resource_setup(phba);
8851 if (error) {
8852 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8853 "1404 Failed to set up driver resource.\n");
8854 goto out_unset_pci_mem_s3;
8855 }
8856
8857 /* Initialize and populate the iocb list per host */
8858 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
8859 if (error) {
8860 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8861 "1405 Failed to initialize iocb list.\n");
8862 goto out_unset_driver_resource_s3;
8863 }
8864
8865 /* Set up common device driver resources */
8866 error = lpfc_setup_driver_resource_phase2(phba);
8867 if (error) {
8868 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8869 "1406 Failed to set up driver resource.\n");
8870 goto out_free_iocb_list;
8871 }
8872
James Smart079b5c92011-08-21 21:48:49 -04008873 /* Get the default values for Model Name and Description */
8874 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
8875
James Smart3772a992009-05-22 14:50:54 -04008876 /* Create SCSI host to the physical port */
8877 error = lpfc_create_shost(phba);
8878 if (error) {
8879 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8880 "1407 Failed to create scsi host.\n");
8881 goto out_unset_driver_resource;
8882 }
8883
8884 /* Configure sysfs attributes */
8885 vport = phba->pport;
8886 error = lpfc_alloc_sysfs_attr(vport);
8887 if (error) {
8888 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8889 "1476 Failed to allocate sysfs attr\n");
8890 goto out_destroy_shost;
8891 }
8892
James Smart6669f9b2009-10-02 15:16:45 -04008893 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -04008894 /* Now, trying to enable interrupt and bring up the device */
8895 cfg_mode = phba->cfg_use_msi;
8896 while (true) {
8897 /* Put device to a known state before enabling interrupt */
8898 lpfc_stop_port(phba);
8899 /* Configure and enable interrupt */
8900 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
8901 if (intr_mode == LPFC_INTR_ERROR) {
8902 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8903 "0431 Failed to enable interrupt.\n");
8904 error = -ENODEV;
8905 goto out_free_sysfs_attr;
8906 }
8907 /* SLI-3 HBA setup */
8908 if (lpfc_sli_hba_setup(phba)) {
8909 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8910 "1477 Failed to set up hba\n");
8911 error = -ENODEV;
8912 goto out_remove_device;
8913 }
8914
8915 /* Wait 50ms for the interrupts of previous mailbox commands */
8916 msleep(50);
8917 /* Check active interrupts on message signaled interrupts */
8918 if (intr_mode == 0 ||
8919 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
8920 /* Log the current active interrupt mode */
8921 phba->intr_mode = intr_mode;
8922 lpfc_log_intr_mode(phba, intr_mode);
8923 break;
8924 } else {
8925 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8926 "0447 Configure interrupt mode (%d) "
8927 "failed active interrupt test.\n",
8928 intr_mode);
8929 /* Disable the current interrupt mode */
8930 lpfc_sli_disable_intr(phba);
8931 /* Try next level of interrupt mode */
8932 cfg_mode = --intr_mode;
8933 }
8934 }
8935
8936 /* Perform post initialization setup */
8937 lpfc_post_init_setup(phba);
8938
8939 /* Check if there are static vports to be created. */
8940 lpfc_create_static_vport(phba);
8941
8942 return 0;
8943
8944out_remove_device:
8945 lpfc_unset_hba(phba);
8946out_free_sysfs_attr:
8947 lpfc_free_sysfs_attr(vport);
8948out_destroy_shost:
8949 lpfc_destroy_shost(phba);
8950out_unset_driver_resource:
8951 lpfc_unset_driver_resource_phase2(phba);
8952out_free_iocb_list:
8953 lpfc_free_iocb_list(phba);
8954out_unset_driver_resource_s3:
8955 lpfc_sli_driver_resource_unset(phba);
8956out_unset_pci_mem_s3:
8957 lpfc_sli_pci_mem_unset(phba);
8958out_disable_pci_dev:
8959 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -04008960 if (shost)
8961 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -04008962out_free_phba:
8963 lpfc_hba_free(phba);
8964 return error;
8965}
8966
8967/**
8968 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -04008969 * @pdev: pointer to PCI device
8970 *
James Smart3772a992009-05-22 14:50:54 -04008971 * This routine is to be called to disattach a device with SLI-3 interface
8972 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
8973 * removed from PCI bus, it performs all the necessary cleanup for the HBA
8974 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -04008975 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008976static void
James Smart3772a992009-05-22 14:50:54 -04008977lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -05008978{
James Smart2e0fef82007-06-17 19:56:36 -05008979 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8980 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -05008981 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -05008982 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -05008983 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05008984 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
8985
James Smart549e55c2007-08-02 11:09:51 -04008986 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04008987 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04008988 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05008989
James Smart858c9f62007-06-17 19:56:39 -05008990 lpfc_free_sysfs_attr(vport);
8991
James Smarteada2722008-12-04 22:39:13 -05008992 /* Release all the vports against this physical port */
8993 vports = lpfc_create_vport_work_array(phba);
8994 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -04008995 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
8996 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
8997 continue;
James Smarteada2722008-12-04 22:39:13 -05008998 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -04008999 }
James Smarteada2722008-12-04 22:39:13 -05009000 lpfc_destroy_vport_work_array(phba, vports);
9001
9002 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -05009003 fc_remove_host(shost);
9004 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04009005 lpfc_cleanup(vport);
9006
James Smart2e0fef82007-06-17 19:56:36 -05009007 /*
9008 * Bring down the SLI Layer. This step disable all interrupts,
9009 * clears the rings, discards all mailbox commands, and resets
9010 * the HBA.
9011 */
James Smarta257bf92009-04-06 18:48:10 -04009012
Justin P. Mattock48e34d02010-12-30 15:07:58 -08009013 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -05009014 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -04009015 /* Stop kthread signal shall trigger work_done one more time */
9016 kthread_stop(phba->worker_thread);
9017 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -05009018 lpfc_sli_brdrestart(phba);
9019
James Smart72859902012-01-18 16:25:38 -05009020 kfree(phba->vpi_bmask);
9021 kfree(phba->vpi_ids);
9022
James Smart3772a992009-05-22 14:50:54 -04009023 lpfc_stop_hba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05009024 spin_lock_irq(&phba->hbalock);
9025 list_del_init(&vport->listentry);
9026 spin_unlock_irq(&phba->hbalock);
9027
James Smart858c9f62007-06-17 19:56:39 -05009028 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05009029
James Smart912e3ac2011-05-24 11:42:11 -04009030 /* Disable SR-IOV if enabled */
9031 if (phba->cfg_sriov_nr_virtfn)
9032 pci_disable_sriov(pdev);
9033
James Smart5b75da22008-12-04 22:39:35 -05009034 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009035 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -05009036
9037 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05009038 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05009039
9040 /*
9041 * Call scsi_free before mem_free since scsi bufs are released to their
9042 * corresponding pools here.
9043 */
9044 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -04009045 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -05009046
James Smart34b02dc2008-08-24 21:49:55 -04009047 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
9048 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -05009049
James Smart2e0fef82007-06-17 19:56:36 -05009050 /* Free resources associated with SLI2 interface */
9051 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -04009052 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -05009053
9054 /* unmap adapter SLIM and Control Registers */
9055 iounmap(phba->ctrl_regs_memmap_p);
9056 iounmap(phba->slim_memmap_p);
9057
James Smart3772a992009-05-22 14:50:54 -04009058 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -05009059
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05009060 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05009061 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05009062}
9063
Linas Vepstas8d63f372007-02-14 14:28:36 -06009064/**
James Smart3772a992009-05-22 14:50:54 -04009065 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05009066 * @pdev: pointer to PCI device
9067 * @msg: power management message
9068 *
James Smart3772a992009-05-22 14:50:54 -04009069 * This routine is to be called from the kernel's PCI subsystem to support
9070 * system Power Management (PM) to device with SLI-3 interface spec. When
9071 * PM invokes this method, it quiesces the device by stopping the driver's
9072 * worker thread for the device, turning off device's interrupt and DMA,
9073 * and bring the device offline. Note that as the driver implements the
9074 * minimum PM requirements to a power-aware driver's PM support for the
9075 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
9076 * to the suspend() method call will be treated as SUSPEND and the driver will
9077 * fully reinitialize its device during resume() method call, the driver will
9078 * set device to PCI_D3hot state in PCI config space instead of setting it
9079 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -05009080 *
9081 * Return code
James Smart3772a992009-05-22 14:50:54 -04009082 * 0 - driver suspended the device
9083 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05009084 **/
9085static int
James Smart3772a992009-05-22 14:50:54 -04009086lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -05009087{
9088 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9089 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9090
9091 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9092 "0473 PCI device Power Management suspend.\n");
9093
9094 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -04009095 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -05009096 lpfc_offline(phba);
9097 kthread_stop(phba->worker_thread);
9098
9099 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -04009100 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -05009101
9102 /* Save device state to PCI config space */
9103 pci_save_state(pdev);
9104 pci_set_power_state(pdev, PCI_D3hot);
9105
9106 return 0;
9107}
9108
9109/**
James Smart3772a992009-05-22 14:50:54 -04009110 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05009111 * @pdev: pointer to PCI device
9112 *
James Smart3772a992009-05-22 14:50:54 -04009113 * This routine is to be called from the kernel's PCI subsystem to support
9114 * system Power Management (PM) to device with SLI-3 interface spec. When PM
9115 * invokes this method, it restores the device's PCI config space state and
9116 * fully reinitializes the device and brings it online. Note that as the
9117 * driver implements the minimum PM requirements to a power-aware driver's
9118 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
9119 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
9120 * driver will fully reinitialize its device during resume() method call,
9121 * the device will be set to PCI_D0 directly in PCI config space before
9122 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -05009123 *
9124 * Return code
James Smart3772a992009-05-22 14:50:54 -04009125 * 0 - driver suspended the device
9126 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05009127 **/
9128static int
James Smart3772a992009-05-22 14:50:54 -04009129lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -05009130{
9131 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9132 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -05009133 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05009134 int error;
9135
9136 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9137 "0452 PCI device Power Management resume.\n");
9138
9139 /* Restore device state from PCI config space */
9140 pci_set_power_state(pdev, PCI_D0);
9141 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -04009142
James Smart1dfb5a42010-02-12 14:40:50 -05009143 /*
9144 * As the new kernel behavior of pci_restore_state() API call clears
9145 * device saved_state flag, need to save the restored state again.
9146 */
9147 pci_save_state(pdev);
9148
James Smart3a55b532008-12-04 22:38:54 -05009149 if (pdev->is_busmaster)
9150 pci_set_master(pdev);
9151
9152 /* Startup the kernel thread for this host adapter. */
9153 phba->worker_thread = kthread_run(lpfc_do_work, phba,
9154 "lpfc_worker_%d", phba->brd_no);
9155 if (IS_ERR(phba->worker_thread)) {
9156 error = PTR_ERR(phba->worker_thread);
9157 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9158 "0434 PM resume failed to start worker "
9159 "thread: error=x%x.\n", error);
9160 return error;
9161 }
9162
James Smart5b75da22008-12-04 22:39:35 -05009163 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009164 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05009165 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -05009166 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -05009167 "0430 PM resume Failed to enable interrupt\n");
9168 return -EIO;
9169 } else
9170 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05009171
9172 /* Restart HBA and bring it online */
9173 lpfc_sli_brdrestart(phba);
9174 lpfc_online(phba);
9175
James Smart5b75da22008-12-04 22:39:35 -05009176 /* Log the current active interrupt mode */
9177 lpfc_log_intr_mode(phba, phba->intr_mode);
9178
James Smart3a55b532008-12-04 22:38:54 -05009179 return 0;
9180}
9181
9182/**
James Smart891478a2009-11-18 15:40:23 -05009183 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
9184 * @phba: pointer to lpfc hba data structure.
9185 *
9186 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -04009187 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -05009188 **/
9189static void
9190lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
9191{
James Smarte2af0d22010-03-15 11:25:32 -04009192 struct lpfc_sli *psli = &phba->sli;
9193 struct lpfc_sli_ring *pring;
9194
James Smart891478a2009-11-18 15:40:23 -05009195 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9196 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -04009197
9198 /*
9199 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
9200 * and let the SCSI mid-layer to retry them to recover.
9201 */
9202 pring = &psli->ring[psli->fcp_ring];
9203 lpfc_sli_abort_iocb_ring(phba, pring);
James Smart891478a2009-11-18 15:40:23 -05009204}
9205
9206/**
James Smart0d878412009-10-02 15:16:56 -04009207 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
9208 * @phba: pointer to lpfc hba data structure.
9209 *
9210 * This routine is called to prepare the SLI3 device for PCI slot reset. It
9211 * disables the device interrupt and pci device, and aborts the internal FCP
9212 * pending I/Os.
9213 **/
9214static void
9215lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
9216{
James Smart0d878412009-10-02 15:16:56 -04009217 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -05009218 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -04009219
James Smart75baf692010-06-08 18:31:21 -04009220 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -04009221 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -04009222
James Smarte2af0d22010-03-15 11:25:32 -04009223 /* Block all SCSI devices' I/Os on the host */
9224 lpfc_scsi_dev_block(phba);
9225
9226 /* stop all timers */
9227 lpfc_stop_hba_timers(phba);
9228
James Smart0d878412009-10-02 15:16:56 -04009229 /* Disable interrupt and pci device */
9230 lpfc_sli_disable_intr(phba);
9231 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -04009232
James Smarte2af0d22010-03-15 11:25:32 -04009233 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9234 lpfc_sli_flush_fcp_rings(phba);
James Smart0d878412009-10-02 15:16:56 -04009235}
9236
9237/**
9238 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
9239 * @phba: pointer to lpfc hba data structure.
9240 *
9241 * This routine is called to prepare the SLI3 device for PCI slot permanently
9242 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
9243 * pending I/Os.
9244 **/
9245static void
James Smart75baf692010-06-08 18:31:21 -04009246lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -04009247{
9248 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -05009249 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -04009250 /* Block all SCSI devices' I/Os on the host */
9251 lpfc_scsi_dev_block(phba);
9252
9253 /* stop all timers */
9254 lpfc_stop_hba_timers(phba);
9255
James Smart0d878412009-10-02 15:16:56 -04009256 /* Clean up all driver's outstanding SCSI I/Os */
9257 lpfc_sli_flush_fcp_rings(phba);
9258}
9259
9260/**
James Smart3772a992009-05-22 14:50:54 -04009261 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -04009262 * @pdev: pointer to PCI device.
9263 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -06009264 *
James Smart3772a992009-05-22 14:50:54 -04009265 * This routine is called from the PCI subsystem for I/O error handling to
9266 * device with SLI-3 interface spec. This function is called by the PCI
9267 * subsystem after a PCI bus error affecting this device has been detected.
9268 * When this function is invoked, it will need to stop all the I/Os and
9269 * interrupt(s) to the device. Once that is done, it will return
9270 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
9271 * as desired.
James Smarte59058c2008-08-24 21:49:00 -04009272 *
9273 * Return codes
James Smart0d878412009-10-02 15:16:56 -04009274 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -04009275 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
9276 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -04009277 **/
James Smart3772a992009-05-22 14:50:54 -04009278static pci_ers_result_t
9279lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -06009280{
James Smart51ef4c22007-08-02 11:10:31 -04009281 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9282 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009283
James Smart0d878412009-10-02 15:16:56 -04009284 switch (state) {
9285 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -05009286 /* Non-fatal error, prepare for recovery */
9287 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -04009288 return PCI_ERS_RESULT_CAN_RECOVER;
9289 case pci_channel_io_frozen:
9290 /* Fatal error, prepare for slot reset */
9291 lpfc_sli_prep_dev_for_reset(phba);
9292 return PCI_ERS_RESULT_NEED_RESET;
9293 case pci_channel_io_perm_failure:
9294 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -04009295 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06009296 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -04009297 default:
9298 /* Unknown state, prepare and request slot reset */
9299 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9300 "0472 Unknown PCI error state: x%x\n", state);
9301 lpfc_sli_prep_dev_for_reset(phba);
9302 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -04009303 }
Linas Vepstas8d63f372007-02-14 14:28:36 -06009304}
9305
9306/**
James Smart3772a992009-05-22 14:50:54 -04009307 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -04009308 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -06009309 *
James Smart3772a992009-05-22 14:50:54 -04009310 * This routine is called from the PCI subsystem for error handling to
9311 * device with SLI-3 interface spec. This is called after PCI bus has been
9312 * reset to restart the PCI card from scratch, as if from a cold-boot.
9313 * During the PCI subsystem error recovery, after driver returns
9314 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
9315 * recovery and then call this routine before calling the .resume method
9316 * to recover the device. This function will initialize the HBA device,
9317 * enable the interrupt, but it will just put the HBA to offline state
9318 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -04009319 *
9320 * Return codes
James Smart3772a992009-05-22 14:50:54 -04009321 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
9322 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -06009323 */
James Smart3772a992009-05-22 14:50:54 -04009324static pci_ers_result_t
9325lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -06009326{
James Smart51ef4c22007-08-02 11:10:31 -04009327 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9328 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009329 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -05009330 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009331
9332 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11009333 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -06009334 printk(KERN_ERR "lpfc: Cannot re-enable "
9335 "PCI device after reset.\n");
9336 return PCI_ERS_RESULT_DISCONNECT;
9337 }
9338
James Smart97207482008-12-04 22:39:19 -05009339 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -05009340
9341 /*
9342 * As the new kernel behavior of pci_restore_state() API call clears
9343 * device saved_state flag, need to save the restored state again.
9344 */
9345 pci_save_state(pdev);
9346
James Smart97207482008-12-04 22:39:19 -05009347 if (pdev->is_busmaster)
9348 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -06009349
James Smart92d7f7b2007-06-17 19:56:38 -05009350 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -04009351 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05009352 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06009353
James Smart5b75da22008-12-04 22:39:35 -05009354 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009355 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05009356 if (intr_mode == LPFC_INTR_ERROR) {
9357 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9358 "0427 Cannot re-enable interrupt after "
9359 "slot reset.\n");
9360 return PCI_ERS_RESULT_DISCONNECT;
9361 } else
9362 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009363
James Smart75baf692010-06-08 18:31:21 -04009364 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -04009365 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -06009366 lpfc_offline(phba);
9367 lpfc_sli_brdrestart(phba);
9368
James Smart5b75da22008-12-04 22:39:35 -05009369 /* Log the current active interrupt mode */
9370 lpfc_log_intr_mode(phba, phba->intr_mode);
9371
Linas Vepstas8d63f372007-02-14 14:28:36 -06009372 return PCI_ERS_RESULT_RECOVERED;
9373}
9374
9375/**
James Smart3772a992009-05-22 14:50:54 -04009376 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -04009377 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -06009378 *
James Smart3772a992009-05-22 14:50:54 -04009379 * This routine is called from the PCI subsystem for error handling to device
9380 * with SLI-3 interface spec. It is called when kernel error recovery tells
9381 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
9382 * error recovery. After this call, traffic can start to flow from this device
9383 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -06009384 */
James Smart3772a992009-05-22 14:50:54 -04009385static void
9386lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -06009387{
James Smart51ef4c22007-08-02 11:10:31 -04009388 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9389 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009390
James Smarte2af0d22010-03-15 11:25:32 -04009391 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -04009392 lpfc_online(phba);
James Smart0d878412009-10-02 15:16:56 -04009393
9394 /* Clean up Advanced Error Reporting (AER) if needed */
9395 if (phba->hba_flag & HBA_AER_ENABLED)
9396 pci_cleanup_aer_uncorrect_error_status(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -06009397}
9398
James Smart3772a992009-05-22 14:50:54 -04009399/**
James Smartda0436e2009-05-22 14:51:39 -04009400 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
9401 * @phba: pointer to lpfc hba data structure.
9402 *
9403 * returns the number of ELS/CT IOCBs to reserve
9404 **/
9405int
9406lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
9407{
9408 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
9409
James Smartf1126682009-06-10 17:22:44 -04009410 if (phba->sli_rev == LPFC_SLI_REV4) {
9411 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -04009412 return 10;
James Smartf1126682009-06-10 17:22:44 -04009413 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -04009414 return 25;
James Smartf1126682009-06-10 17:22:44 -04009415 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -04009416 return 50;
James Smartf1126682009-06-10 17:22:44 -04009417 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -04009418 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -04009419 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -04009420 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -04009421 else if (max_xri <= 2048)
9422 return 200;
9423 else
9424 return 250;
James Smartf1126682009-06-10 17:22:44 -04009425 } else
9426 return 0;
James Smartda0436e2009-05-22 14:51:39 -04009427}
9428
9429/**
James Smart52d52442011-05-24 11:42:45 -04009430 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -04009431 * @fw: pointer to firmware image returned from request_firmware.
James Smartce396282012-09-29 11:30:56 -04009432 * @phba: pointer to lpfc hba data structure.
James Smart52d52442011-05-24 11:42:45 -04009433 *
James Smart52d52442011-05-24 11:42:45 -04009434 **/
James Smartce396282012-09-29 11:30:56 -04009435static void
9436lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -04009437{
James Smartce396282012-09-29 11:30:56 -04009438 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -05009439 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -04009440 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -04009441 struct list_head dma_buffer_list;
9442 int i, rc = 0;
9443 struct lpfc_dmabuf *dmabuf, *next;
9444 uint32_t offset = 0, temp_offset = 0;
9445
James Smartc71ab862012-10-31 14:44:33 -04009446 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -04009447 if (!fw) {
9448 rc = -ENXIO;
9449 goto out;
9450 }
9451 image = (struct lpfc_grp_hdr *)fw->data;
9452
James Smart52d52442011-05-24 11:42:45 -04009453 INIT_LIST_HEAD(&dma_buffer_list);
James Smart079b5c92011-08-21 21:48:49 -04009454 if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) ||
9455 (bf_get_be32(lpfc_grp_hdr_file_type, image) !=
9456 LPFC_FILE_TYPE_GROUP) ||
9457 (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) ||
9458 (be32_to_cpu(image->size) != fw->size)) {
James Smart52d52442011-05-24 11:42:45 -04009459 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9460 "3022 Invalid FW image found. "
James Smart079b5c92011-08-21 21:48:49 -04009461 "Magic:%x Type:%x ID:%x\n",
9462 be32_to_cpu(image->magic_number),
9463 bf_get_be32(lpfc_grp_hdr_file_type, image),
9464 bf_get_be32(lpfc_grp_hdr_id, image));
James Smartce396282012-09-29 11:30:56 -04009465 rc = -EINVAL;
9466 goto release_out;
James Smart52d52442011-05-24 11:42:45 -04009467 }
9468 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -04009469 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -04009470 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartce396282012-09-29 11:30:56 -04009471 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -04009472 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -04009473 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -04009474 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
9475 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
9476 GFP_KERNEL);
9477 if (!dmabuf) {
9478 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -04009479 goto release_out;
James Smart52d52442011-05-24 11:42:45 -04009480 }
9481 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
9482 SLI4_PAGE_SIZE,
9483 &dmabuf->phys,
9484 GFP_KERNEL);
9485 if (!dmabuf->virt) {
9486 kfree(dmabuf);
9487 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -04009488 goto release_out;
James Smart52d52442011-05-24 11:42:45 -04009489 }
9490 list_add_tail(&dmabuf->list, &dma_buffer_list);
9491 }
9492 while (offset < fw->size) {
9493 temp_offset = offset;
9494 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -04009495 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -04009496 memcpy(dmabuf->virt,
9497 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -04009498 fw->size - temp_offset);
9499 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -04009500 break;
9501 }
James Smart52d52442011-05-24 11:42:45 -04009502 memcpy(dmabuf->virt, fw->data + temp_offset,
9503 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -04009504 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -04009505 }
9506 rc = lpfc_wr_object(phba, &dma_buffer_list,
9507 (fw->size - offset), &offset);
James Smartce396282012-09-29 11:30:56 -04009508 if (rc)
9509 goto release_out;
James Smart52d52442011-05-24 11:42:45 -04009510 }
9511 rc = offset;
9512 }
James Smartce396282012-09-29 11:30:56 -04009513
9514release_out:
James Smart52d52442011-05-24 11:42:45 -04009515 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
9516 list_del(&dmabuf->list);
9517 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
9518 dmabuf->virt, dmabuf->phys);
9519 kfree(dmabuf);
9520 }
James Smartce396282012-09-29 11:30:56 -04009521 release_firmware(fw);
9522out:
9523 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc71ab862012-10-31 14:44:33 -04009524 "3024 Firmware update done: %d.\n", rc);
James Smartce396282012-09-29 11:30:56 -04009525 return;
James Smart52d52442011-05-24 11:42:45 -04009526}
9527
9528/**
James Smartc71ab862012-10-31 14:44:33 -04009529 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
9530 * @phba: pointer to lpfc hba data structure.
9531 *
9532 * This routine is called to perform Linux generic firmware upgrade on device
9533 * that supports such feature.
9534 **/
9535int
9536lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
9537{
9538 uint8_t file_name[ELX_MODEL_NAME_SIZE];
9539 int ret;
9540 const struct firmware *fw;
9541
9542 /* Only supported on SLI4 interface type 2 for now */
9543 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
9544 LPFC_SLI_INTF_IF_TYPE_2)
9545 return -EPERM;
9546
9547 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
9548
9549 if (fw_upgrade == INT_FW_UPGRADE) {
9550 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
9551 file_name, &phba->pcidev->dev,
9552 GFP_KERNEL, (void *)phba,
9553 lpfc_write_firmware);
9554 } else if (fw_upgrade == RUN_FW_UPGRADE) {
9555 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
9556 if (!ret)
9557 lpfc_write_firmware(fw, (void *)phba);
9558 } else {
9559 ret = -EINVAL;
9560 }
9561
9562 return ret;
9563}
9564
9565/**
James Smartda0436e2009-05-22 14:51:39 -04009566 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
9567 * @pdev: pointer to PCI device
9568 * @pid: pointer to PCI device identifier
9569 *
9570 * This routine is called from the kernel's PCI subsystem to device with
9571 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
9572 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
9573 * information of the device and driver to see if the driver state that it
9574 * can support this kind of device. If the match is successful, the driver
9575 * core invokes this routine. If this routine determines it can claim the HBA,
9576 * it does all the initialization that it needs to do to handle the HBA
9577 * properly.
9578 *
9579 * Return code
9580 * 0 - driver can claim the device
9581 * negative value - driver can not claim the device
9582 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009583static int
James Smartda0436e2009-05-22 14:51:39 -04009584lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
9585{
9586 struct lpfc_hba *phba;
9587 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -04009588 struct Scsi_Host *shost = NULL;
James Smartce396282012-09-29 11:30:56 -04009589 int error, ret;
James Smartda0436e2009-05-22 14:51:39 -04009590 uint32_t cfg_mode, intr_mode;
James Smart67d12732012-08-03 12:36:13 -04009591 int adjusted_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04009592
9593 /* Allocate memory for HBA structure */
9594 phba = lpfc_hba_alloc(pdev);
9595 if (!phba)
9596 return -ENOMEM;
9597
9598 /* Perform generic PCI device enabling operation */
9599 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -04009600 if (error)
James Smartda0436e2009-05-22 14:51:39 -04009601 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -04009602
9603 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
9604 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
9605 if (error)
9606 goto out_disable_pci_dev;
9607
9608 /* Set up SLI-4 specific device PCI memory space */
9609 error = lpfc_sli4_pci_mem_setup(phba);
9610 if (error) {
9611 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9612 "1410 Failed to set up pci memory space.\n");
9613 goto out_disable_pci_dev;
9614 }
9615
9616 /* Set up phase-1 common device driver resources */
9617 error = lpfc_setup_driver_resource_phase1(phba);
9618 if (error) {
9619 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9620 "1411 Failed to set up driver resource.\n");
9621 goto out_unset_pci_mem_s4;
9622 }
9623
9624 /* Set up SLI-4 Specific device driver resources */
9625 error = lpfc_sli4_driver_resource_setup(phba);
9626 if (error) {
9627 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9628 "1412 Failed to set up driver resource.\n");
9629 goto out_unset_pci_mem_s4;
9630 }
9631
9632 /* Initialize and populate the iocb list per host */
James Smart2a9bf3d2010-06-07 15:24:45 -04009633
9634 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9635 "2821 initialize iocb list %d.\n",
9636 phba->cfg_iocb_cnt*1024);
9637 error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
9638
James Smartda0436e2009-05-22 14:51:39 -04009639 if (error) {
9640 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9641 "1413 Failed to initialize iocb list.\n");
9642 goto out_unset_driver_resource_s4;
9643 }
9644
James Smart19ca7602010-11-20 23:11:55 -05009645 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -04009646 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -05009647
James Smartda0436e2009-05-22 14:51:39 -04009648 /* Set up common device driver resources */
9649 error = lpfc_setup_driver_resource_phase2(phba);
9650 if (error) {
9651 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9652 "1414 Failed to set up driver resource.\n");
9653 goto out_free_iocb_list;
9654 }
9655
James Smart079b5c92011-08-21 21:48:49 -04009656 /* Get the default values for Model Name and Description */
9657 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
9658
James Smartda0436e2009-05-22 14:51:39 -04009659 /* Create SCSI host to the physical port */
9660 error = lpfc_create_shost(phba);
9661 if (error) {
9662 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9663 "1415 Failed to create scsi host.\n");
9664 goto out_unset_driver_resource;
9665 }
9666
9667 /* Configure sysfs attributes */
9668 vport = phba->pport;
9669 error = lpfc_alloc_sysfs_attr(vport);
9670 if (error) {
9671 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9672 "1416 Failed to allocate sysfs attr\n");
9673 goto out_destroy_shost;
9674 }
9675
James Smart6669f9b2009-10-02 15:16:45 -04009676 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -04009677 /* Now, trying to enable interrupt and bring up the device */
9678 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -04009679
James Smart7b15db32013-01-03 15:43:29 -05009680 /* Put device to a known state before enabling interrupt */
9681 lpfc_stop_port(phba);
9682 /* Configure and enable interrupt */
9683 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
9684 if (intr_mode == LPFC_INTR_ERROR) {
9685 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9686 "0426 Failed to enable interrupt.\n");
9687 error = -ENODEV;
9688 goto out_free_sysfs_attr;
James Smartda0436e2009-05-22 14:51:39 -04009689 }
James Smart7b15db32013-01-03 15:43:29 -05009690 /* Default to single EQ for non-MSI-X */
9691 if (phba->intr_type != MSIX)
9692 adjusted_fcp_io_channel = 1;
9693 else
9694 adjusted_fcp_io_channel = phba->cfg_fcp_io_channel;
9695 phba->cfg_fcp_io_channel = adjusted_fcp_io_channel;
9696 /* Set up SLI-4 HBA */
9697 if (lpfc_sli4_hba_setup(phba)) {
9698 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9699 "1421 Failed to set up hba\n");
9700 error = -ENODEV;
9701 goto out_disable_intr;
9702 }
9703
9704 /* Log the current active interrupt mode */
9705 phba->intr_mode = intr_mode;
9706 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -04009707
9708 /* Perform post initialization setup */
9709 lpfc_post_init_setup(phba);
9710
James Smartc71ab862012-10-31 14:44:33 -04009711 /* check for firmware upgrade or downgrade */
9712 if (phba->cfg_request_firmware_upgrade)
9713 ret = lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -04009714
James Smart1c6834a2009-07-19 10:01:26 -04009715 /* Check if there are static vports to be created. */
9716 lpfc_create_static_vport(phba);
James Smartda0436e2009-05-22 14:51:39 -04009717 return 0;
9718
9719out_disable_intr:
9720 lpfc_sli4_disable_intr(phba);
9721out_free_sysfs_attr:
9722 lpfc_free_sysfs_attr(vport);
9723out_destroy_shost:
9724 lpfc_destroy_shost(phba);
9725out_unset_driver_resource:
9726 lpfc_unset_driver_resource_phase2(phba);
9727out_free_iocb_list:
9728 lpfc_free_iocb_list(phba);
9729out_unset_driver_resource_s4:
9730 lpfc_sli4_driver_resource_unset(phba);
9731out_unset_pci_mem_s4:
9732 lpfc_sli4_pci_mem_unset(phba);
9733out_disable_pci_dev:
9734 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -04009735 if (shost)
9736 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -04009737out_free_phba:
9738 lpfc_hba_free(phba);
9739 return error;
9740}
9741
9742/**
9743 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
9744 * @pdev: pointer to PCI device
9745 *
9746 * This routine is called from the kernel's PCI subsystem to device with
9747 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
9748 * removed from PCI bus, it performs all the necessary cleanup for the HBA
9749 * device to be removed from the PCI subsystem properly.
9750 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009751static void
James Smartda0436e2009-05-22 14:51:39 -04009752lpfc_pci_remove_one_s4(struct pci_dev *pdev)
9753{
9754 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9755 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
9756 struct lpfc_vport **vports;
9757 struct lpfc_hba *phba = vport->phba;
9758 int i;
9759
9760 /* Mark the device unloading flag */
9761 spin_lock_irq(&phba->hbalock);
9762 vport->load_flag |= FC_UNLOADING;
9763 spin_unlock_irq(&phba->hbalock);
9764
9765 /* Free the HBA sysfs attributes */
9766 lpfc_free_sysfs_attr(vport);
9767
9768 /* Release all the vports against this physical port */
9769 vports = lpfc_create_vport_work_array(phba);
9770 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -04009771 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9772 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
9773 continue;
James Smartda0436e2009-05-22 14:51:39 -04009774 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -04009775 }
James Smartda0436e2009-05-22 14:51:39 -04009776 lpfc_destroy_vport_work_array(phba, vports);
9777
9778 /* Remove FC host and then SCSI host with the physical port */
9779 fc_remove_host(shost);
9780 scsi_remove_host(shost);
9781
9782 /* Perform cleanup on the physical port */
9783 lpfc_cleanup(vport);
9784
9785 /*
9786 * Bring down the SLI Layer. This step disables all interrupts,
9787 * clears the rings, discards all mailbox commands, and resets
9788 * the HBA FCoE function.
9789 */
9790 lpfc_debugfs_terminate(vport);
9791 lpfc_sli4_hba_unset(phba);
9792
9793 spin_lock_irq(&phba->hbalock);
9794 list_del_init(&vport->listentry);
9795 spin_unlock_irq(&phba->hbalock);
9796
James Smart3677a3a2010-09-29 11:19:14 -04009797 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -04009798 * buffers are released to their corresponding pools here.
9799 */
9800 lpfc_scsi_free(phba);
James Smart67d12732012-08-03 12:36:13 -04009801
James Smartda0436e2009-05-22 14:51:39 -04009802 lpfc_sli4_driver_resource_unset(phba);
9803
9804 /* Unmap adapter Control and Doorbell registers */
9805 lpfc_sli4_pci_mem_unset(phba);
9806
9807 /* Release PCI resources and disable device's PCI function */
9808 scsi_host_put(shost);
9809 lpfc_disable_pci_dev(phba);
9810
9811 /* Finally, free the driver's device data structure */
9812 lpfc_hba_free(phba);
9813
9814 return;
9815}
9816
9817/**
9818 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
9819 * @pdev: pointer to PCI device
9820 * @msg: power management message
9821 *
9822 * This routine is called from the kernel's PCI subsystem to support system
9823 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
9824 * this method, it quiesces the device by stopping the driver's worker
9825 * thread for the device, turning off device's interrupt and DMA, and bring
9826 * the device offline. Note that as the driver implements the minimum PM
9827 * requirements to a power-aware driver's PM support for suspend/resume -- all
9828 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
9829 * method call will be treated as SUSPEND and the driver will fully
9830 * reinitialize its device during resume() method call, the driver will set
9831 * device to PCI_D3hot state in PCI config space instead of setting it
9832 * according to the @msg provided by the PM.
9833 *
9834 * Return code
9835 * 0 - driver suspended the device
9836 * Error otherwise
9837 **/
9838static int
9839lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
9840{
9841 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9842 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9843
9844 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -04009845 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -04009846
9847 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -04009848 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -04009849 lpfc_offline(phba);
9850 kthread_stop(phba->worker_thread);
9851
9852 /* Disable interrupt from device */
9853 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -04009854 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04009855
9856 /* Save device state to PCI config space */
9857 pci_save_state(pdev);
9858 pci_set_power_state(pdev, PCI_D3hot);
9859
9860 return 0;
9861}
9862
9863/**
9864 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
9865 * @pdev: pointer to PCI device
9866 *
9867 * This routine is called from the kernel's PCI subsystem to support system
9868 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
9869 * this method, it restores the device's PCI config space state and fully
9870 * reinitializes the device and brings it online. Note that as the driver
9871 * implements the minimum PM requirements to a power-aware driver's PM for
9872 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
9873 * to the suspend() method call will be treated as SUSPEND and the driver
9874 * will fully reinitialize its device during resume() method call, the device
9875 * will be set to PCI_D0 directly in PCI config space before restoring the
9876 * state.
9877 *
9878 * Return code
9879 * 0 - driver suspended the device
9880 * Error otherwise
9881 **/
9882static int
9883lpfc_pci_resume_one_s4(struct pci_dev *pdev)
9884{
9885 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9886 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9887 uint32_t intr_mode;
9888 int error;
9889
9890 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9891 "0292 PCI device Power Management resume.\n");
9892
9893 /* Restore device state from PCI config space */
9894 pci_set_power_state(pdev, PCI_D0);
9895 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -05009896
9897 /*
9898 * As the new kernel behavior of pci_restore_state() API call clears
9899 * device saved_state flag, need to save the restored state again.
9900 */
9901 pci_save_state(pdev);
9902
James Smartda0436e2009-05-22 14:51:39 -04009903 if (pdev->is_busmaster)
9904 pci_set_master(pdev);
9905
9906 /* Startup the kernel thread for this host adapter. */
9907 phba->worker_thread = kthread_run(lpfc_do_work, phba,
9908 "lpfc_worker_%d", phba->brd_no);
9909 if (IS_ERR(phba->worker_thread)) {
9910 error = PTR_ERR(phba->worker_thread);
9911 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9912 "0293 PM resume failed to start worker "
9913 "thread: error=x%x.\n", error);
9914 return error;
9915 }
9916
9917 /* Configure and enable interrupt */
9918 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
9919 if (intr_mode == LPFC_INTR_ERROR) {
9920 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9921 "0294 PM resume Failed to enable interrupt\n");
9922 return -EIO;
9923 } else
9924 phba->intr_mode = intr_mode;
9925
9926 /* Restart HBA and bring it online */
9927 lpfc_sli_brdrestart(phba);
9928 lpfc_online(phba);
9929
9930 /* Log the current active interrupt mode */
9931 lpfc_log_intr_mode(phba, phba->intr_mode);
9932
9933 return 0;
9934}
9935
9936/**
James Smart75baf692010-06-08 18:31:21 -04009937 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
9938 * @phba: pointer to lpfc hba data structure.
9939 *
9940 * This routine is called to prepare the SLI4 device for PCI slot recover. It
9941 * aborts all the outstanding SCSI I/Os to the pci device.
9942 **/
9943static void
9944lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
9945{
9946 struct lpfc_sli *psli = &phba->sli;
9947 struct lpfc_sli_ring *pring;
9948
9949 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9950 "2828 PCI channel I/O abort preparing for recovery\n");
9951 /*
9952 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
9953 * and let the SCSI mid-layer to retry them to recover.
9954 */
9955 pring = &psli->ring[psli->fcp_ring];
9956 lpfc_sli_abort_iocb_ring(phba, pring);
9957}
9958
9959/**
9960 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
9961 * @phba: pointer to lpfc hba data structure.
9962 *
9963 * This routine is called to prepare the SLI4 device for PCI slot reset. It
9964 * disables the device interrupt and pci device, and aborts the internal FCP
9965 * pending I/Os.
9966 **/
9967static void
9968lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
9969{
9970 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9971 "2826 PCI channel disable preparing for reset\n");
9972
9973 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -04009974 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -04009975
9976 /* Block all SCSI devices' I/Os on the host */
9977 lpfc_scsi_dev_block(phba);
9978
9979 /* stop all timers */
9980 lpfc_stop_hba_timers(phba);
9981
9982 /* Disable interrupt and pci device */
9983 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -04009984 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -04009985 pci_disable_device(phba->pcidev);
9986
9987 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9988 lpfc_sli_flush_fcp_rings(phba);
9989}
9990
9991/**
9992 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
9993 * @phba: pointer to lpfc hba data structure.
9994 *
9995 * This routine is called to prepare the SLI4 device for PCI slot permanently
9996 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
9997 * pending I/Os.
9998 **/
9999static void
10000lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
10001{
10002 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10003 "2827 PCI channel permanent disable for failure\n");
10004
10005 /* Block all SCSI devices' I/Os on the host */
10006 lpfc_scsi_dev_block(phba);
10007
10008 /* stop all timers */
10009 lpfc_stop_hba_timers(phba);
10010
10011 /* Clean up all driver's outstanding SCSI I/Os */
10012 lpfc_sli_flush_fcp_rings(phba);
10013}
10014
10015/**
James Smartda0436e2009-05-22 14:51:39 -040010016 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
10017 * @pdev: pointer to PCI device.
10018 * @state: the current PCI connection state.
10019 *
10020 * This routine is called from the PCI subsystem for error handling to device
10021 * with SLI-4 interface spec. This function is called by the PCI subsystem
10022 * after a PCI bus error affecting this device has been detected. When this
10023 * function is invoked, it will need to stop all the I/Os and interrupt(s)
10024 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
10025 * for the PCI subsystem to perform proper recovery as desired.
10026 *
10027 * Return codes
10028 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10029 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10030 **/
10031static pci_ers_result_t
10032lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
10033{
James Smart75baf692010-06-08 18:31:21 -040010034 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10035 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10036
10037 switch (state) {
10038 case pci_channel_io_normal:
10039 /* Non-fatal error, prepare for recovery */
10040 lpfc_sli4_prep_dev_for_recover(phba);
10041 return PCI_ERS_RESULT_CAN_RECOVER;
10042 case pci_channel_io_frozen:
10043 /* Fatal error, prepare for slot reset */
10044 lpfc_sli4_prep_dev_for_reset(phba);
10045 return PCI_ERS_RESULT_NEED_RESET;
10046 case pci_channel_io_perm_failure:
10047 /* Permanent failure, prepare for device down */
10048 lpfc_sli4_prep_dev_for_perm_failure(phba);
10049 return PCI_ERS_RESULT_DISCONNECT;
10050 default:
10051 /* Unknown state, prepare and request slot reset */
10052 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10053 "2825 Unknown PCI error state: x%x\n", state);
10054 lpfc_sli4_prep_dev_for_reset(phba);
10055 return PCI_ERS_RESULT_NEED_RESET;
10056 }
James Smartda0436e2009-05-22 14:51:39 -040010057}
10058
10059/**
10060 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
10061 * @pdev: pointer to PCI device.
10062 *
10063 * This routine is called from the PCI subsystem for error handling to device
10064 * with SLI-4 interface spec. It is called after PCI bus has been reset to
10065 * restart the PCI card from scratch, as if from a cold-boot. During the
10066 * PCI subsystem error recovery, after the driver returns
10067 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10068 * recovery and then call this routine before calling the .resume method to
10069 * recover the device. This function will initialize the HBA device, enable
10070 * the interrupt, but it will just put the HBA to offline state without
10071 * passing any I/O traffic.
10072 *
10073 * Return codes
10074 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10075 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10076 */
10077static pci_ers_result_t
10078lpfc_io_slot_reset_s4(struct pci_dev *pdev)
10079{
James Smart75baf692010-06-08 18:31:21 -040010080 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10081 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10082 struct lpfc_sli *psli = &phba->sli;
10083 uint32_t intr_mode;
10084
10085 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
10086 if (pci_enable_device_mem(pdev)) {
10087 printk(KERN_ERR "lpfc: Cannot re-enable "
10088 "PCI device after reset.\n");
10089 return PCI_ERS_RESULT_DISCONNECT;
10090 }
10091
10092 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040010093
10094 /*
10095 * As the new kernel behavior of pci_restore_state() API call clears
10096 * device saved_state flag, need to save the restored state again.
10097 */
10098 pci_save_state(pdev);
10099
James Smart75baf692010-06-08 18:31:21 -040010100 if (pdev->is_busmaster)
10101 pci_set_master(pdev);
10102
10103 spin_lock_irq(&phba->hbalock);
10104 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
10105 spin_unlock_irq(&phba->hbalock);
10106
10107 /* Configure and enable interrupt */
10108 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
10109 if (intr_mode == LPFC_INTR_ERROR) {
10110 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10111 "2824 Cannot re-enable interrupt after "
10112 "slot reset.\n");
10113 return PCI_ERS_RESULT_DISCONNECT;
10114 } else
10115 phba->intr_mode = intr_mode;
10116
10117 /* Log the current active interrupt mode */
10118 lpfc_log_intr_mode(phba, phba->intr_mode);
10119
James Smartda0436e2009-05-22 14:51:39 -040010120 return PCI_ERS_RESULT_RECOVERED;
10121}
10122
10123/**
10124 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
10125 * @pdev: pointer to PCI device
10126 *
10127 * This routine is called from the PCI subsystem for error handling to device
10128 * with SLI-4 interface spec. It is called when kernel error recovery tells
10129 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10130 * error recovery. After this call, traffic can start to flow from this device
10131 * again.
10132 **/
10133static void
10134lpfc_io_resume_s4(struct pci_dev *pdev)
10135{
James Smart75baf692010-06-08 18:31:21 -040010136 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10137 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10138
10139 /*
10140 * In case of slot reset, as function reset is performed through
10141 * mailbox command which needs DMA to be enabled, this operation
10142 * has to be moved to the io resume phase. Taking device offline
10143 * will perform the necessary cleanup.
10144 */
10145 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
10146 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040010147 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010148 lpfc_offline(phba);
10149 lpfc_sli_brdrestart(phba);
10150 /* Bring the device back online */
10151 lpfc_online(phba);
10152 }
10153
10154 /* Clean up Advanced Error Reporting (AER) if needed */
10155 if (phba->hba_flag & HBA_AER_ENABLED)
10156 pci_cleanup_aer_uncorrect_error_status(pdev);
James Smartda0436e2009-05-22 14:51:39 -040010157}
10158
10159/**
James Smart3772a992009-05-22 14:50:54 -040010160 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
10161 * @pdev: pointer to PCI device
10162 * @pid: pointer to PCI device identifier
10163 *
10164 * This routine is to be registered to the kernel's PCI subsystem. When an
10165 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
10166 * at PCI device-specific information of the device and driver to see if the
10167 * driver state that it can support this kind of device. If the match is
10168 * successful, the driver core invokes this routine. This routine dispatches
10169 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
10170 * do all the initialization that it needs to do to handle the HBA device
10171 * properly.
10172 *
10173 * Return code
10174 * 0 - driver can claim the device
10175 * negative value - driver can not claim the device
10176 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010177static int
James Smart3772a992009-05-22 14:50:54 -040010178lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
10179{
10180 int rc;
James Smart8fa38512009-07-19 10:01:03 -040010181 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040010182
James Smart28baac72010-02-12 14:42:03 -050010183 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040010184 return -ENODEV;
10185
James Smart8fa38512009-07-19 10:01:03 -040010186 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050010187 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040010188 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040010189 else
James Smart3772a992009-05-22 14:50:54 -040010190 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040010191
James Smart3772a992009-05-22 14:50:54 -040010192 return rc;
10193}
10194
10195/**
10196 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
10197 * @pdev: pointer to PCI device
10198 *
10199 * This routine is to be registered to the kernel's PCI subsystem. When an
10200 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
10201 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
10202 * remove routine, which will perform all the necessary cleanup for the
10203 * device to be removed from the PCI subsystem properly.
10204 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010205static void
James Smart3772a992009-05-22 14:50:54 -040010206lpfc_pci_remove_one(struct pci_dev *pdev)
10207{
10208 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10209 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10210
10211 switch (phba->pci_dev_grp) {
10212 case LPFC_PCI_DEV_LP:
10213 lpfc_pci_remove_one_s3(pdev);
10214 break;
James Smartda0436e2009-05-22 14:51:39 -040010215 case LPFC_PCI_DEV_OC:
10216 lpfc_pci_remove_one_s4(pdev);
10217 break;
James Smart3772a992009-05-22 14:50:54 -040010218 default:
10219 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10220 "1424 Invalid PCI device group: 0x%x\n",
10221 phba->pci_dev_grp);
10222 break;
10223 }
10224 return;
10225}
10226
10227/**
10228 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
10229 * @pdev: pointer to PCI device
10230 * @msg: power management message
10231 *
10232 * This routine is to be registered to the kernel's PCI subsystem to support
10233 * system Power Management (PM). When PM invokes this method, it dispatches
10234 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
10235 * suspend the device.
10236 *
10237 * Return code
10238 * 0 - driver suspended the device
10239 * Error otherwise
10240 **/
10241static int
10242lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
10243{
10244 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10245 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10246 int rc = -ENODEV;
10247
10248 switch (phba->pci_dev_grp) {
10249 case LPFC_PCI_DEV_LP:
10250 rc = lpfc_pci_suspend_one_s3(pdev, msg);
10251 break;
James Smartda0436e2009-05-22 14:51:39 -040010252 case LPFC_PCI_DEV_OC:
10253 rc = lpfc_pci_suspend_one_s4(pdev, msg);
10254 break;
James Smart3772a992009-05-22 14:50:54 -040010255 default:
10256 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10257 "1425 Invalid PCI device group: 0x%x\n",
10258 phba->pci_dev_grp);
10259 break;
10260 }
10261 return rc;
10262}
10263
10264/**
10265 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
10266 * @pdev: pointer to PCI device
10267 *
10268 * This routine is to be registered to the kernel's PCI subsystem to support
10269 * system Power Management (PM). When PM invokes this method, it dispatches
10270 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
10271 * resume the device.
10272 *
10273 * Return code
10274 * 0 - driver suspended the device
10275 * Error otherwise
10276 **/
10277static int
10278lpfc_pci_resume_one(struct pci_dev *pdev)
10279{
10280 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10281 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10282 int rc = -ENODEV;
10283
10284 switch (phba->pci_dev_grp) {
10285 case LPFC_PCI_DEV_LP:
10286 rc = lpfc_pci_resume_one_s3(pdev);
10287 break;
James Smartda0436e2009-05-22 14:51:39 -040010288 case LPFC_PCI_DEV_OC:
10289 rc = lpfc_pci_resume_one_s4(pdev);
10290 break;
James Smart3772a992009-05-22 14:50:54 -040010291 default:
10292 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10293 "1426 Invalid PCI device group: 0x%x\n",
10294 phba->pci_dev_grp);
10295 break;
10296 }
10297 return rc;
10298}
10299
10300/**
10301 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
10302 * @pdev: pointer to PCI device.
10303 * @state: the current PCI connection state.
10304 *
10305 * This routine is registered to the PCI subsystem for error handling. This
10306 * function is called by the PCI subsystem after a PCI bus error affecting
10307 * this device has been detected. When this routine is invoked, it dispatches
10308 * the action to the proper SLI-3 or SLI-4 device error detected handling
10309 * routine, which will perform the proper error detected operation.
10310 *
10311 * Return codes
10312 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10313 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10314 **/
10315static pci_ers_result_t
10316lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
10317{
10318 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10319 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10320 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
10321
10322 switch (phba->pci_dev_grp) {
10323 case LPFC_PCI_DEV_LP:
10324 rc = lpfc_io_error_detected_s3(pdev, state);
10325 break;
James Smartda0436e2009-05-22 14:51:39 -040010326 case LPFC_PCI_DEV_OC:
10327 rc = lpfc_io_error_detected_s4(pdev, state);
10328 break;
James Smart3772a992009-05-22 14:50:54 -040010329 default:
10330 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10331 "1427 Invalid PCI device group: 0x%x\n",
10332 phba->pci_dev_grp);
10333 break;
10334 }
10335 return rc;
10336}
10337
10338/**
10339 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
10340 * @pdev: pointer to PCI device.
10341 *
10342 * This routine is registered to the PCI subsystem for error handling. This
10343 * function is called after PCI bus has been reset to restart the PCI card
10344 * from scratch, as if from a cold-boot. When this routine is invoked, it
10345 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
10346 * routine, which will perform the proper device reset.
10347 *
10348 * Return codes
10349 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10350 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10351 **/
10352static pci_ers_result_t
10353lpfc_io_slot_reset(struct pci_dev *pdev)
10354{
10355 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10356 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10357 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
10358
10359 switch (phba->pci_dev_grp) {
10360 case LPFC_PCI_DEV_LP:
10361 rc = lpfc_io_slot_reset_s3(pdev);
10362 break;
James Smartda0436e2009-05-22 14:51:39 -040010363 case LPFC_PCI_DEV_OC:
10364 rc = lpfc_io_slot_reset_s4(pdev);
10365 break;
James Smart3772a992009-05-22 14:50:54 -040010366 default:
10367 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10368 "1428 Invalid PCI device group: 0x%x\n",
10369 phba->pci_dev_grp);
10370 break;
10371 }
10372 return rc;
10373}
10374
10375/**
10376 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
10377 * @pdev: pointer to PCI device
10378 *
10379 * This routine is registered to the PCI subsystem for error handling. It
10380 * is called when kernel error recovery tells the lpfc driver that it is
10381 * OK to resume normal PCI operation after PCI bus error recovery. When
10382 * this routine is invoked, it dispatches the action to the proper SLI-3
10383 * or SLI-4 device io_resume routine, which will resume the device operation.
10384 **/
10385static void
10386lpfc_io_resume(struct pci_dev *pdev)
10387{
10388 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10389 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10390
10391 switch (phba->pci_dev_grp) {
10392 case LPFC_PCI_DEV_LP:
10393 lpfc_io_resume_s3(pdev);
10394 break;
James Smartda0436e2009-05-22 14:51:39 -040010395 case LPFC_PCI_DEV_OC:
10396 lpfc_io_resume_s4(pdev);
10397 break;
James Smart3772a992009-05-22 14:50:54 -040010398 default:
10399 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10400 "1429 Invalid PCI device group: 0x%x\n",
10401 phba->pci_dev_grp);
10402 break;
10403 }
10404 return;
10405}
10406
James Smart3ef6d242012-01-18 16:23:48 -050010407/**
10408 * lpfc_mgmt_open - method called when 'lpfcmgmt' is opened from userspace
10409 * @inode: pointer to the inode representing the lpfcmgmt device
10410 * @filep: pointer to the file representing the open lpfcmgmt device
10411 *
10412 * This routine puts a reference count on the lpfc module whenever the
10413 * character device is opened
10414 **/
10415static int
10416lpfc_mgmt_open(struct inode *inode, struct file *filep)
10417{
10418 try_module_get(THIS_MODULE);
10419 return 0;
10420}
10421
10422/**
10423 * lpfc_mgmt_release - method called when 'lpfcmgmt' is closed in userspace
10424 * @inode: pointer to the inode representing the lpfcmgmt device
10425 * @filep: pointer to the file representing the open lpfcmgmt device
10426 *
10427 * This routine removes a reference count from the lpfc module when the
10428 * character device is closed
10429 **/
10430static int
10431lpfc_mgmt_release(struct inode *inode, struct file *filep)
10432{
10433 module_put(THIS_MODULE);
10434 return 0;
10435}
10436
dea31012005-04-17 16:05:31 -050010437static struct pci_device_id lpfc_id_table[] = {
10438 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
10439 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -040010440 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
10441 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050010442 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
10443 PCI_ANY_ID, PCI_ANY_ID, },
10444 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
10445 PCI_ANY_ID, PCI_ANY_ID, },
10446 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
10447 PCI_ANY_ID, PCI_ANY_ID, },
10448 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
10449 PCI_ANY_ID, PCI_ANY_ID, },
10450 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
10451 PCI_ANY_ID, PCI_ANY_ID, },
10452 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
10453 PCI_ANY_ID, PCI_ANY_ID, },
10454 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
10455 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050010456 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
10457 PCI_ANY_ID, PCI_ANY_ID, },
10458 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
10459 PCI_ANY_ID, PCI_ANY_ID, },
10460 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
10461 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050010462 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
10463 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050010464 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
10465 PCI_ANY_ID, PCI_ANY_ID, },
10466 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
10467 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050010468 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
10469 PCI_ANY_ID, PCI_ANY_ID, },
10470 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
10471 PCI_ANY_ID, PCI_ANY_ID, },
10472 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
10473 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -040010474 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
10475 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050010476 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
10477 PCI_ANY_ID, PCI_ANY_ID, },
10478 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
10479 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050010480 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
10481 PCI_ANY_ID, PCI_ANY_ID, },
10482 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
10483 PCI_ANY_ID, PCI_ANY_ID, },
10484 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
10485 PCI_ANY_ID, PCI_ANY_ID, },
10486 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
10487 PCI_ANY_ID, PCI_ANY_ID, },
10488 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
10489 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050010490 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
10491 PCI_ANY_ID, PCI_ANY_ID, },
10492 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
10493 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -040010494 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
10495 PCI_ANY_ID, PCI_ANY_ID, },
10496 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
10497 PCI_ANY_ID, PCI_ANY_ID, },
10498 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
10499 PCI_ANY_ID, PCI_ANY_ID, },
10500 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
10501 PCI_ANY_ID, PCI_ANY_ID, },
10502 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
10503 PCI_ANY_ID, PCI_ANY_ID, },
10504 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
10505 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -040010506 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
10507 PCI_ANY_ID, PCI_ANY_ID, },
10508 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
10509 PCI_ANY_ID, PCI_ANY_ID, },
10510 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
10511 PCI_ANY_ID, PCI_ANY_ID, },
James Smart3772a992009-05-22 14:50:54 -040010512 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
10513 PCI_ANY_ID, PCI_ANY_ID, },
James Smarta747c9c2009-11-18 15:41:10 -050010514 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT,
10515 PCI_ANY_ID, PCI_ANY_ID, },
10516 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON,
James Smart6669f9b2009-10-02 15:16:45 -040010517 PCI_ANY_ID, PCI_ANY_ID, },
James Smart98fc5dd2010-06-07 15:24:29 -040010518 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS,
10519 PCI_ANY_ID, PCI_ANY_ID, },
James Smart085c6472010-11-20 23:11:37 -050010520 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC,
10521 PCI_ANY_ID, PCI_ANY_ID, },
10522 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE,
10523 PCI_ANY_ID, PCI_ANY_ID, },
James Smartc0c11512011-05-24 11:41:34 -040010524 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF,
10525 PCI_ANY_ID, PCI_ANY_ID, },
10526 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF,
10527 PCI_ANY_ID, PCI_ANY_ID, },
James Smartf8cafd32012-08-03 12:42:51 -040010528 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK,
10529 PCI_ANY_ID, PCI_ANY_ID, },
10530 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF,
10531 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050010532 { 0 }
10533};
10534
10535MODULE_DEVICE_TABLE(pci, lpfc_id_table);
10536
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070010537static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060010538 .error_detected = lpfc_io_error_detected,
10539 .slot_reset = lpfc_io_slot_reset,
10540 .resume = lpfc_io_resume,
10541};
10542
dea31012005-04-17 16:05:31 -050010543static struct pci_driver lpfc_driver = {
10544 .name = LPFC_DRIVER_NAME,
10545 .id_table = lpfc_id_table,
10546 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010547 .remove = lpfc_pci_remove_one,
James Smart3a55b532008-12-04 22:38:54 -050010548 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040010549 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050010550 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050010551};
10552
James Smart3ef6d242012-01-18 16:23:48 -050010553static const struct file_operations lpfc_mgmt_fop = {
10554 .open = lpfc_mgmt_open,
10555 .release = lpfc_mgmt_release,
10556};
10557
10558static struct miscdevice lpfc_mgmt_dev = {
10559 .minor = MISC_DYNAMIC_MINOR,
10560 .name = "lpfcmgmt",
10561 .fops = &lpfc_mgmt_fop,
10562};
10563
James Smarte59058c2008-08-24 21:49:00 -040010564/**
James Smart3621a712009-04-06 18:47:14 -040010565 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040010566 *
10567 * This routine is to be invoked when the lpfc module is loaded into the
10568 * kernel. The special kernel macro module_init() is used to indicate the
10569 * role of this routine to the kernel as lpfc module entry point.
10570 *
10571 * Return codes
10572 * 0 - successful
10573 * -ENOMEM - FC attach transport failed
10574 * all others - failed
10575 */
dea31012005-04-17 16:05:31 -050010576static int __init
10577lpfc_init(void)
10578{
10579 int error = 0;
10580
10581 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010582 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050010583
James Smart3ef6d242012-01-18 16:23:48 -050010584 error = misc_register(&lpfc_mgmt_dev);
10585 if (error)
10586 printk(KERN_ERR "Could not register lpfcmgmt device, "
10587 "misc_register returned with status %d", error);
10588
James Smart7ee5d432007-10-27 13:37:17 -040010589 if (lpfc_enable_npiv) {
10590 lpfc_transport_functions.vport_create = lpfc_vport_create;
10591 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
10592 }
dea31012005-04-17 16:05:31 -050010593 lpfc_transport_template =
10594 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040010595 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050010596 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040010597 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -040010598 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -040010599 fc_attach_transport(&lpfc_vport_transport_functions);
10600 if (lpfc_vport_transport_template == NULL) {
10601 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040010602 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -040010603 }
James Smart7ee5d432007-10-27 13:37:17 -040010604 }
dea31012005-04-17 16:05:31 -050010605 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050010606 if (error) {
dea31012005-04-17 16:05:31 -050010607 fc_release_transport(lpfc_transport_template);
James Smartd7c255b2008-08-24 21:50:00 -040010608 if (lpfc_enable_npiv)
10609 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050010610 }
dea31012005-04-17 16:05:31 -050010611
10612 return error;
10613}
10614
James Smarte59058c2008-08-24 21:49:00 -040010615/**
James Smart3621a712009-04-06 18:47:14 -040010616 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040010617 *
10618 * This routine is invoked when the lpfc module is removed from the kernel.
10619 * The special kernel macro module_exit() is used to indicate the role of
10620 * this routine to the kernel as lpfc module exit point.
10621 */
dea31012005-04-17 16:05:31 -050010622static void __exit
10623lpfc_exit(void)
10624{
James Smart3ef6d242012-01-18 16:23:48 -050010625 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050010626 pci_unregister_driver(&lpfc_driver);
10627 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040010628 if (lpfc_enable_npiv)
10629 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050010630 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040010631 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
10632 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050010633 (1L << _dump_buf_data_order), _dump_buf_data);
10634 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
10635 }
10636
10637 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040010638 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
10639 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050010640 (1L << _dump_buf_dif_order), _dump_buf_dif);
10641 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
10642 }
dea31012005-04-17 16:05:31 -050010643}
10644
10645module_init(lpfc_init);
10646module_exit(lpfc_exit);
10647MODULE_LICENSE("GPL");
10648MODULE_DESCRIPTION(LPFC_MODULE_DESC);
10649MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
10650MODULE_VERSION("0:" LPFC_DRIVER_VERSION);