blob: 5da297290262c82754e92cd5014820304ca64fde [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 Smart2e0fef82007-06-17 19:56:36 -05002636
dea31012005-04-17 16:05:31 -05002637 if (!phba)
2638 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01002639 vport = phba->pport;
dea31012005-04-17 16:05:31 -05002640
James Smart2e0fef82007-06-17 19:56:36 -05002641 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05002642 return 0;
2643
James Smarted957682007-06-17 19:56:37 -05002644 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002645 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05002646
James Smart618a5232012-06-12 13:54:36 -04002647 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05002648
James Smart46fa3112007-04-25 09:51:45 -04002649 if (!lpfc_sli_queue_setup(phba)) {
2650 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002651 return 1;
James Smart46fa3112007-04-25 09:51:45 -04002652 }
2653
James Smartda0436e2009-05-22 14:51:39 -04002654 if (phba->sli_rev == LPFC_SLI_REV4) {
2655 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
2656 lpfc_unblock_mgmt_io(phba);
2657 return 1;
2658 }
2659 } else {
2660 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
2661 lpfc_unblock_mgmt_io(phba);
2662 return 1;
2663 }
James Smart46fa3112007-04-25 09:51:45 -04002664 }
dea31012005-04-17 16:05:31 -05002665
James Smart549e55c2007-08-02 11:09:51 -04002666 vports = lpfc_create_vport_work_array(phba);
2667 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002668 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002669 struct Scsi_Host *shost;
2670 shost = lpfc_shost_from_vport(vports[i]);
2671 spin_lock_irq(shost->host_lock);
2672 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
2673 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2674 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart1c6834a2009-07-19 10:01:26 -04002675 if (phba->sli_rev == LPFC_SLI_REV4)
2676 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart549e55c2007-08-02 11:09:51 -04002677 spin_unlock_irq(shost->host_lock);
2678 }
James Smart09372822008-01-11 01:52:54 -05002679 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002680
James Smart46fa3112007-04-25 09:51:45 -04002681 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002682 return 0;
2683}
2684
James Smarte59058c2008-08-24 21:49:00 -04002685/**
James Smart3621a712009-04-06 18:47:14 -04002686 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04002687 * @phba: pointer to lpfc hba data structure.
2688 *
2689 * This routine marks a HBA's management interface as not blocked. Once the
2690 * HBA's management interface is marked as not blocked, all the user space
2691 * access to the HBA, whether they are from sysfs interface or libdfc
2692 * interface will be allowed. The HBA is set to block the management interface
2693 * when the driver prepares the HBA interface for online or offline and then
2694 * set to unblock the management interface afterwards.
2695 **/
James Smart46fa3112007-04-25 09:51:45 -04002696void
James Smart46fa3112007-04-25 09:51:45 -04002697lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
2698{
2699 unsigned long iflag;
2700
James Smart2e0fef82007-06-17 19:56:36 -05002701 spin_lock_irqsave(&phba->hbalock, iflag);
2702 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
2703 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04002704}
2705
James Smarte59058c2008-08-24 21:49:00 -04002706/**
James Smart3621a712009-04-06 18:47:14 -04002707 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04002708 * @phba: pointer to lpfc hba data structure.
2709 *
2710 * This routine is invoked to prepare a HBA to be brought offline. It performs
2711 * unregistration login to all the nodes on all vports and flushes the mailbox
2712 * queue to make it ready to be brought offline.
2713 **/
James Smart46fa3112007-04-25 09:51:45 -04002714void
James Smart618a5232012-06-12 13:54:36 -04002715lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04002716{
James Smart2e0fef82007-06-17 19:56:36 -05002717 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04002718 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04002719 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05002720 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04002721 int i;
dea31012005-04-17 16:05:31 -05002722
James Smart2e0fef82007-06-17 19:56:36 -05002723 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002724 return;
dea31012005-04-17 16:05:31 -05002725
James Smart618a5232012-06-12 13:54:36 -04002726 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05002727
2728 lpfc_linkdown(phba);
2729
James Smart87af33f2007-10-27 13:37:43 -04002730 /* Issue an unreg_login to all nodes on all vports */
2731 vports = lpfc_create_vport_work_array(phba);
2732 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04002733 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04002734 if (vports[i]->load_flag & FC_UNLOADING)
2735 continue;
James Smart72100cc2010-02-12 14:43:01 -05002736 shost = lpfc_shost_from_vport(vports[i]);
2737 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05002738 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002739 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2740 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05002741 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05002742
James Smart87af33f2007-10-27 13:37:43 -04002743 shost = lpfc_shost_from_vport(vports[i]);
2744 list_for_each_entry_safe(ndlp, next_ndlp,
2745 &vports[i]->fc_nodes,
2746 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002747 if (!NLP_CHK_NODE_ACT(ndlp))
2748 continue;
James Smart87af33f2007-10-27 13:37:43 -04002749 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2750 continue;
2751 if (ndlp->nlp_type & NLP_FABRIC) {
2752 lpfc_disc_state_machine(vports[i], ndlp,
2753 NULL, NLP_EVT_DEVICE_RECOVERY);
2754 lpfc_disc_state_machine(vports[i], ndlp,
2755 NULL, NLP_EVT_DEVICE_RM);
2756 }
2757 spin_lock_irq(shost->host_lock);
2758 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart401ee0c2012-03-01 22:35:34 -05002759 spin_unlock_irq(shost->host_lock);
James Smart6b5151f2012-01-18 16:24:06 -05002760 /*
2761 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05002762 * RPI. Get a new RPI when the adapter port
2763 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05002764 */
2765 if (phba->sli_rev == LPFC_SLI_REV4)
2766 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04002767 lpfc_unreg_rpi(vports[i], ndlp);
2768 }
2769 }
2770 }
James Smart09372822008-01-11 01:52:54 -05002771 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002772
James Smart618a5232012-06-12 13:54:36 -04002773 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
James Smart46fa3112007-04-25 09:51:45 -04002774}
2775
James Smarte59058c2008-08-24 21:49:00 -04002776/**
James Smart3621a712009-04-06 18:47:14 -04002777 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04002778 * @phba: pointer to lpfc hba data structure.
2779 *
2780 * This routine actually brings a HBA offline. It stops all the timers
2781 * associated with the HBA, brings down the SLI layer, and eventually
2782 * marks the HBA as in offline state for the upper layer protocol.
2783 **/
James Smart46fa3112007-04-25 09:51:45 -04002784void
James Smart2e0fef82007-06-17 19:56:36 -05002785lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04002786{
James Smart549e55c2007-08-02 11:09:51 -04002787 struct Scsi_Host *shost;
2788 struct lpfc_vport **vports;
2789 int i;
James Smart46fa3112007-04-25 09:51:45 -04002790
James Smart549e55c2007-08-02 11:09:51 -04002791 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002792 return;
James Smart688a8862006-07-06 15:49:56 -04002793
James Smartda0436e2009-05-22 14:51:39 -04002794 /* stop port and all timers associated with this hba */
2795 lpfc_stop_port(phba);
James Smart51ef4c22007-08-02 11:10:31 -04002796 vports = lpfc_create_vport_work_array(phba);
2797 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002798 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04002799 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05002800 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05002801 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002802 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05002803 /* Bring down the SLI Layer and cleanup. The HBA is offline
2804 now. */
2805 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002806 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04002807 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05002808 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04002809 vports = lpfc_create_vport_work_array(phba);
2810 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002811 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002812 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04002813 spin_lock_irq(shost->host_lock);
2814 vports[i]->work_port_events = 0;
2815 vports[i]->fc_flag |= FC_OFFLINE_MODE;
2816 spin_unlock_irq(shost->host_lock);
2817 }
James Smart09372822008-01-11 01:52:54 -05002818 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002819}
2820
James Smarte59058c2008-08-24 21:49:00 -04002821/**
James Smart3621a712009-04-06 18:47:14 -04002822 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04002823 * @phba: pointer to lpfc hba data structure.
2824 *
2825 * This routine is to free all the SCSI buffers and IOCBs from the driver
2826 * list back to kernel. It is called from lpfc_pci_remove_one to free
2827 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04002828 **/
James Smart8a9d2e82012-05-09 21:16:12 -04002829static void
James Smart2e0fef82007-06-17 19:56:36 -05002830lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002831{
2832 struct lpfc_scsi_buf *sb, *sb_next;
2833 struct lpfc_iocbq *io, *io_next;
2834
James Smart2e0fef82007-06-17 19:56:36 -05002835 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002836 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smart1c6f4ef52009-11-18 15:40:49 -05002837 spin_lock(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05002838 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
2839 list_del(&sb->list);
2840 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05002841 sb->dma_handle);
dea31012005-04-17 16:05:31 -05002842 kfree(sb);
2843 phba->total_scsi_bufs--;
2844 }
James Smart1c6f4ef52009-11-18 15:40:49 -05002845 spin_unlock(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05002846
2847 /* Release all the lpfc_iocbq entries maintained by this host. */
2848 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
2849 list_del(&io->list);
2850 kfree(io);
2851 phba->total_iocbq_bufs--;
2852 }
James Smart6d368e52011-05-24 11:44:12 -04002853
James Smart2e0fef82007-06-17 19:56:36 -05002854 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04002855}
2856
2857/**
2858 * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping
2859 * @phba: pointer to lpfc hba data structure.
2860 *
2861 * This routine first calculates the sizes of the current els and allocated
2862 * scsi sgl lists, and then goes through all sgls to updates the physical
2863 * XRIs assigned due to port function reset. During port initialization, the
2864 * current els and allocated scsi sgl lists are 0s.
2865 *
2866 * Return codes
2867 * 0 - successful (for now, it always returns 0)
2868 **/
2869int
2870lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba)
2871{
2872 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
2873 struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL;
2874 uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt;
2875 LIST_HEAD(els_sgl_list);
2876 LIST_HEAD(scsi_sgl_list);
2877 int rc;
2878
2879 /*
2880 * update on pci function's els xri-sgl list
2881 */
2882 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
2883 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
2884 /* els xri-sgl expanded */
2885 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
2886 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2887 "3157 ELS xri-sgl count increased from "
2888 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
2889 els_xri_cnt);
2890 /* allocate the additional els sgls */
2891 for (i = 0; i < xri_cnt; i++) {
2892 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
2893 GFP_KERNEL);
2894 if (sglq_entry == NULL) {
2895 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2896 "2562 Failure to allocate an "
2897 "ELS sgl entry:%d\n", i);
2898 rc = -ENOMEM;
2899 goto out_free_mem;
2900 }
2901 sglq_entry->buff_type = GEN_BUFF_TYPE;
2902 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
2903 &sglq_entry->phys);
2904 if (sglq_entry->virt == NULL) {
2905 kfree(sglq_entry);
2906 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2907 "2563 Failure to allocate an "
2908 "ELS mbuf:%d\n", i);
2909 rc = -ENOMEM;
2910 goto out_free_mem;
2911 }
2912 sglq_entry->sgl = sglq_entry->virt;
2913 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
2914 sglq_entry->state = SGL_FREED;
2915 list_add_tail(&sglq_entry->list, &els_sgl_list);
2916 }
James Smart38c20672013-03-01 16:37:44 -05002917 spin_lock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04002918 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
James Smart38c20672013-03-01 16:37:44 -05002919 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04002920 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
2921 /* els xri-sgl shrinked */
2922 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
2923 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2924 "3158 ELS xri-sgl count decreased from "
2925 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
2926 els_xri_cnt);
2927 spin_lock_irq(&phba->hbalock);
2928 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list);
2929 spin_unlock_irq(&phba->hbalock);
2930 /* release extra els sgls from list */
2931 for (i = 0; i < xri_cnt; i++) {
2932 list_remove_head(&els_sgl_list,
2933 sglq_entry, struct lpfc_sglq, list);
2934 if (sglq_entry) {
2935 lpfc_mbuf_free(phba, sglq_entry->virt,
2936 sglq_entry->phys);
2937 kfree(sglq_entry);
2938 }
2939 }
2940 spin_lock_irq(&phba->hbalock);
2941 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
2942 spin_unlock_irq(&phba->hbalock);
2943 } else
2944 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2945 "3163 ELS xri-sgl count unchanged: %d\n",
2946 els_xri_cnt);
2947 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
2948
2949 /* update xris to els sgls on the list */
2950 sglq_entry = NULL;
2951 sglq_entry_next = NULL;
2952 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
2953 &phba->sli4_hba.lpfc_sgl_list, list) {
2954 lxri = lpfc_sli4_next_xritag(phba);
2955 if (lxri == NO_XRI) {
2956 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2957 "2400 Failed to allocate xri for "
2958 "ELS sgl\n");
2959 rc = -ENOMEM;
2960 goto out_free_mem;
2961 }
2962 sglq_entry->sli4_lxritag = lxri;
2963 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
2964 }
2965
2966 /*
2967 * update on pci function's allocated scsi xri-sgl list
2968 */
2969 phba->total_scsi_bufs = 0;
2970
2971 /* maximum number of xris available for scsi buffers */
2972 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
2973 els_xri_cnt;
2974
2975 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2976 "2401 Current allocated SCSI xri-sgl count:%d, "
2977 "maximum SCSI xri count:%d\n",
2978 phba->sli4_hba.scsi_xri_cnt,
2979 phba->sli4_hba.scsi_xri_max);
2980
2981 spin_lock_irq(&phba->scsi_buf_list_lock);
2982 list_splice_init(&phba->lpfc_scsi_buf_list, &scsi_sgl_list);
2983 spin_unlock_irq(&phba->scsi_buf_list_lock);
2984
2985 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
2986 /* max scsi xri shrinked below the allocated scsi buffers */
2987 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
2988 phba->sli4_hba.scsi_xri_max;
2989 /* release the extra allocated scsi buffers */
2990 for (i = 0; i < scsi_xri_cnt; i++) {
2991 list_remove_head(&scsi_sgl_list, psb,
2992 struct lpfc_scsi_buf, list);
2993 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, psb->data,
2994 psb->dma_handle);
2995 kfree(psb);
2996 }
2997 spin_lock_irq(&phba->scsi_buf_list_lock);
2998 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
2999 spin_unlock_irq(&phba->scsi_buf_list_lock);
3000 }
3001
3002 /* update xris associated to remaining allocated scsi buffers */
3003 psb = NULL;
3004 psb_next = NULL;
3005 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3006 lxri = lpfc_sli4_next_xritag(phba);
3007 if (lxri == NO_XRI) {
3008 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3009 "2560 Failed to allocate xri for "
3010 "scsi buffer\n");
3011 rc = -ENOMEM;
3012 goto out_free_mem;
3013 }
3014 psb->cur_iocbq.sli4_lxritag = lxri;
3015 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3016 }
James Smart38c20672013-03-01 16:37:44 -05003017 spin_lock_irq(&phba->scsi_buf_list_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003018 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list);
James Smart38c20672013-03-01 16:37:44 -05003019 spin_unlock_irq(&phba->scsi_buf_list_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003020
dea31012005-04-17 16:05:31 -05003021 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003022
3023out_free_mem:
3024 lpfc_free_els_sgl_list(phba);
3025 lpfc_scsi_free(phba);
3026 return rc;
dea31012005-04-17 16:05:31 -05003027}
3028
James Smarte59058c2008-08-24 21:49:00 -04003029/**
James Smart3621a712009-04-06 18:47:14 -04003030 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04003031 * @phba: pointer to lpfc hba data structure.
3032 * @instance: a unique integer ID to this FC port.
3033 * @dev: pointer to the device data structure.
3034 *
3035 * This routine creates a FC port for the upper layer protocol. The FC port
3036 * can be created on top of either a physical port or a virtual port provided
3037 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3038 * and associates the FC port created before adding the shost into the SCSI
3039 * layer.
3040 *
3041 * Return codes
3042 * @vport - pointer to the virtual N_Port data structure.
3043 * NULL - port create failed.
3044 **/
James Smart2e0fef82007-06-17 19:56:36 -05003045struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04003046lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04003047{
James Smart2e0fef82007-06-17 19:56:36 -05003048 struct lpfc_vport *vport;
3049 struct Scsi_Host *shost;
3050 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04003051
James Smart3de2a652007-08-02 11:09:59 -04003052 if (dev != &phba->pcidev->dev)
3053 shost = scsi_host_alloc(&lpfc_vport_template,
3054 sizeof(struct lpfc_vport));
3055 else
3056 shost = scsi_host_alloc(&lpfc_template,
3057 sizeof(struct lpfc_vport));
James Smart2e0fef82007-06-17 19:56:36 -05003058 if (!shost)
3059 goto out;
James Smart47a86172007-04-25 09:53:22 -04003060
James Smart2e0fef82007-06-17 19:56:36 -05003061 vport = (struct lpfc_vport *) shost->hostdata;
3062 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05003063 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05003064 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05003065 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04003066
James Smart3de2a652007-08-02 11:09:59 -04003067 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05003068 shost->unique_id = instance;
3069 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04003070 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05003071 shost->this_id = -1;
3072 shost->max_cmd_len = 16;
James Smartda0436e2009-05-22 14:51:39 -04003073 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05003074 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04003075 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smartda0436e2009-05-22 14:51:39 -04003076 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
3077 }
James Smart81301a92008-12-04 22:39:46 -05003078
James Smart47a86172007-04-25 09:53:22 -04003079 /*
James Smart2e0fef82007-06-17 19:56:36 -05003080 * Set initial can_queue value since 0 is no longer supported and
3081 * scsi_add_host will fail. This will be adjusted later based on the
3082 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04003083 */
James Smart2e0fef82007-06-17 19:56:36 -05003084 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04003085 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05003086 shost->transportt = lpfc_vport_transport_template;
3087 vport->port_type = LPFC_NPIV_PORT;
3088 } else {
3089 shost->transportt = lpfc_transport_template;
3090 vport->port_type = LPFC_PHYSICAL_PORT;
3091 }
James Smart47a86172007-04-25 09:53:22 -04003092
James Smart2e0fef82007-06-17 19:56:36 -05003093 /* Initialize all internally managed lists. */
3094 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04003095 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05003096 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04003097
James Smart2e0fef82007-06-17 19:56:36 -05003098 init_timer(&vport->fc_disctmo);
3099 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003100 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04003101
James Smart2e0fef82007-06-17 19:56:36 -05003102 init_timer(&vport->fc_fdmitmo);
3103 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
James Smart92d7f7b2007-06-17 19:56:38 -05003104 vport->fc_fdmitmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04003105
James Smart2e0fef82007-06-17 19:56:36 -05003106 init_timer(&vport->els_tmofunc);
3107 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003108 vport->els_tmofunc.data = (unsigned long)vport;
James Smart92494142011-02-16 12:39:44 -05003109
3110 init_timer(&vport->delayed_disc_tmo);
3111 vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
3112 vport->delayed_disc_tmo.data = (unsigned long)vport;
3113
James Bottomleyd139b9b2009-11-05 13:33:12 -06003114 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05003115 if (error)
3116 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04003117
James Smart549e55c2007-08-02 11:09:51 -04003118 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003119 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04003120 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003121 return vport;
James Smart47a86172007-04-25 09:53:22 -04003122
James Smart2e0fef82007-06-17 19:56:36 -05003123out_put_shost:
3124 scsi_host_put(shost);
3125out:
3126 return NULL;
James Smart47a86172007-04-25 09:53:22 -04003127}
3128
James Smarte59058c2008-08-24 21:49:00 -04003129/**
James Smart3621a712009-04-06 18:47:14 -04003130 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04003131 * @vport: pointer to an lpfc virtual N_Port data structure.
3132 *
3133 * This routine destroys a FC port from the upper layer protocol. All the
3134 * resources associated with the port are released.
3135 **/
James Smart2e0fef82007-06-17 19:56:36 -05003136void
3137destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04003138{
James Smart92d7f7b2007-06-17 19:56:38 -05003139 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3140 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003141
James Smart858c9f62007-06-17 19:56:39 -05003142 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05003143 fc_remove_host(shost);
3144 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04003145
James Smart92d7f7b2007-06-17 19:56:38 -05003146 spin_lock_irq(&phba->hbalock);
3147 list_del_init(&vport->listentry);
3148 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04003149
James Smart92d7f7b2007-06-17 19:56:38 -05003150 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04003151 return;
James Smart47a86172007-04-25 09:53:22 -04003152}
3153
James Smarte59058c2008-08-24 21:49:00 -04003154/**
James Smart3621a712009-04-06 18:47:14 -04003155 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04003156 *
3157 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3158 * uses the kernel idr facility to perform the task.
3159 *
3160 * Return codes:
3161 * instance - a unique integer ID allocated as the new instance.
3162 * -1 - lpfc get instance failed.
3163 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003164int
3165lpfc_get_instance(void)
3166{
Tejun Heoab516032013-02-27 17:04:44 -08003167 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003168
Tejun Heoab516032013-02-27 17:04:44 -08003169 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
3170 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003171}
3172
James Smarte59058c2008-08-24 21:49:00 -04003173/**
James Smart3621a712009-04-06 18:47:14 -04003174 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04003175 * @shost: pointer to SCSI host data structure.
3176 * @time: elapsed time of the scan in jiffies.
3177 *
3178 * This routine is called by the SCSI layer with a SCSI host to determine
3179 * whether the scan host is finished.
3180 *
3181 * Note: there is no scan_start function as adapter initialization will have
3182 * asynchronously kicked off the link initialization.
3183 *
3184 * Return codes
3185 * 0 - SCSI host scan is not over yet.
3186 * 1 - SCSI host scan is over.
3187 **/
James Smart47a86172007-04-25 09:53:22 -04003188int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
3189{
James Smart2e0fef82007-06-17 19:56:36 -05003190 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3191 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05003192 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04003193
James Smart858c9f62007-06-17 19:56:39 -05003194 spin_lock_irq(shost->host_lock);
3195
James Smart51ef4c22007-08-02 11:10:31 -04003196 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05003197 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003198 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05003199 }
James Smart2e0fef82007-06-17 19:56:36 -05003200 if (time >= 30 * HZ) {
3201 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003202 "0461 Scanning longer than 30 "
3203 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003204 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003205 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003206 }
3207 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
3208 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003209 "0465 Link down longer than 15 "
3210 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003211 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05003212 goto finished;
James Smart47a86172007-04-25 09:53:22 -04003213 }
3214
James Smart2e0fef82007-06-17 19:56:36 -05003215 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05003216 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003217 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05003218 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003219 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
James Smart858c9f62007-06-17 19:56:39 -05003220 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003221 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05003222 goto finished;
3223
3224 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003225
3226finished:
James Smart858c9f62007-06-17 19:56:39 -05003227 spin_unlock_irq(shost->host_lock);
3228 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003229}
3230
James Smarte59058c2008-08-24 21:49:00 -04003231/**
James Smart3621a712009-04-06 18:47:14 -04003232 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04003233 * @shost: pointer to SCSI host data structure.
3234 *
3235 * This routine initializes a given SCSI host attributes on a FC port. The
3236 * SCSI host can be either on top of a physical port or a virtual port.
3237 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003238void lpfc_host_attrib_init(struct Scsi_Host *shost)
3239{
3240 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3241 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003242 /*
James Smart2e0fef82007-06-17 19:56:36 -05003243 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04003244 */
3245
James Smart2e0fef82007-06-17 19:56:36 -05003246 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
3247 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04003248 fc_host_supported_classes(shost) = FC_COS_CLASS3;
3249
3250 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003251 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003252 fc_host_supported_fc4s(shost)[2] = 1;
3253 fc_host_supported_fc4s(shost)[7] = 1;
3254
James Smart92d7f7b2007-06-17 19:56:38 -05003255 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
3256 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04003257
3258 fc_host_supported_speeds(shost) = 0;
James Smart88a2cfb2011-07-22 18:36:33 -04003259 if (phba->lmt & LMT_16Gb)
3260 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
James Smart47a86172007-04-25 09:53:22 -04003261 if (phba->lmt & LMT_10Gb)
3262 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04003263 if (phba->lmt & LMT_8Gb)
3264 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04003265 if (phba->lmt & LMT_4Gb)
3266 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
3267 if (phba->lmt & LMT_2Gb)
3268 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
3269 if (phba->lmt & LMT_1Gb)
3270 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
3271
3272 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05003273 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
3274 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04003275
Mike Christie0af5d702010-09-15 16:52:31 -05003276 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
3277
James Smart47a86172007-04-25 09:53:22 -04003278 /* This value is also unchanging */
3279 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003280 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003281 fc_host_active_fc4s(shost)[2] = 1;
3282 fc_host_active_fc4s(shost)[7] = 1;
3283
James Smart92d7f7b2007-06-17 19:56:38 -05003284 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04003285 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04003286 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04003287 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04003288}
dea31012005-04-17 16:05:31 -05003289
James Smarte59058c2008-08-24 21:49:00 -04003290/**
James Smartda0436e2009-05-22 14:51:39 -04003291 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04003292 * @phba: pointer to lpfc hba data structure.
3293 *
James Smartda0436e2009-05-22 14:51:39 -04003294 * This routine is invoked to stop an SLI3 device port, it stops the device
3295 * from generating interrupts and stops the device driver's timers for the
3296 * device.
James Smarte59058c2008-08-24 21:49:00 -04003297 **/
James Smartdb2378e2008-02-08 18:49:51 -05003298static void
James Smartda0436e2009-05-22 14:51:39 -04003299lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05003300{
James Smartda0436e2009-05-22 14:51:39 -04003301 /* Clear all interrupt enable conditions */
3302 writel(0, phba->HCregaddr);
3303 readl(phba->HCregaddr); /* flush */
3304 /* Clear all pending interrupts */
3305 writel(0xffffffff, phba->HAregaddr);
3306 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04003307
James Smartda0436e2009-05-22 14:51:39 -04003308 /* Reset some HBA SLI setup states */
3309 lpfc_stop_hba_timers(phba);
3310 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05003311}
3312
James Smarte59058c2008-08-24 21:49:00 -04003313/**
James Smartda0436e2009-05-22 14:51:39 -04003314 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05003315 * @phba: pointer to lpfc hba data structure.
3316 *
James Smartda0436e2009-05-22 14:51:39 -04003317 * This routine is invoked to stop an SLI4 device port, it stops the device
3318 * from generating interrupts and stops the device driver's timers for the
3319 * device.
3320 **/
3321static void
3322lpfc_stop_port_s4(struct lpfc_hba *phba)
3323{
3324 /* Reset some HBA SLI4 setup states */
3325 lpfc_stop_hba_timers(phba);
3326 phba->pport->work_port_events = 0;
3327 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04003328}
3329
3330/**
3331 * lpfc_stop_port - Wrapper function for stopping hba port
3332 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05003333 *
James Smartda0436e2009-05-22 14:51:39 -04003334 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3335 * the API jump table function pointer from the lpfc_hba struct.
3336 **/
3337void
3338lpfc_stop_port(struct lpfc_hba *phba)
3339{
3340 phba->lpfc_stop_port(phba);
3341}
3342
3343/**
James Smartecfd03c2010-02-12 14:41:27 -05003344 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3345 * @phba: Pointer to hba for which this call is being executed.
3346 *
3347 * This routine starts the timer waiting for the FCF rediscovery to complete.
3348 **/
3349void
3350lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
3351{
3352 unsigned long fcf_redisc_wait_tmo =
3353 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
3354 /* Start fcf rediscovery wait period timer */
3355 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
3356 spin_lock_irq(&phba->hbalock);
3357 /* Allow action to new fcf asynchronous event */
3358 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
3359 /* Mark the FCF rediscovery pending state */
3360 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
3361 spin_unlock_irq(&phba->hbalock);
3362}
3363
3364/**
3365 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
3366 * @ptr: Map to lpfc_hba data structure pointer.
3367 *
3368 * This routine is invoked when waiting for FCF table rediscover has been
3369 * timed out. If new FCF record(s) has (have) been discovered during the
3370 * wait period, a new FCF event shall be added to the FCOE async event
3371 * list, and then worker thread shall be waked up for processing from the
3372 * worker thread context.
3373 **/
3374void
3375lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
3376{
3377 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
3378
3379 /* Don't send FCF rediscovery event if timer cancelled */
3380 spin_lock_irq(&phba->hbalock);
3381 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
3382 spin_unlock_irq(&phba->hbalock);
3383 return;
3384 }
3385 /* Clear FCF rediscovery timer pending flag */
3386 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
3387 /* FCF rediscovery event to worker thread */
3388 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
3389 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003390 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04003391 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05003392 /* wake up worker thread */
3393 lpfc_worker_wake_up(phba);
3394}
3395
3396/**
James Smartda0436e2009-05-22 14:51:39 -04003397 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
3398 * @phba: pointer to lpfc hba data structure.
3399 * @acqe_link: pointer to the async link completion queue entry.
3400 *
3401 * This routine is to parse the SLI4 link-attention link fault code and
3402 * translate it into the base driver's read link attention mailbox command
3403 * status.
3404 *
3405 * Return: Link-attention status in terms of base driver's coding.
3406 **/
3407static uint16_t
3408lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
3409 struct lpfc_acqe_link *acqe_link)
3410{
3411 uint16_t latt_fault;
3412
3413 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
3414 case LPFC_ASYNC_LINK_FAULT_NONE:
3415 case LPFC_ASYNC_LINK_FAULT_LOCAL:
3416 case LPFC_ASYNC_LINK_FAULT_REMOTE:
3417 latt_fault = 0;
3418 break;
3419 default:
3420 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3421 "0398 Invalid link fault code: x%x\n",
3422 bf_get(lpfc_acqe_link_fault, acqe_link));
3423 latt_fault = MBXERR_ERROR;
3424 break;
3425 }
3426 return latt_fault;
3427}
3428
3429/**
3430 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
3431 * @phba: pointer to lpfc hba data structure.
3432 * @acqe_link: pointer to the async link completion queue entry.
3433 *
3434 * This routine is to parse the SLI4 link attention type and translate it
3435 * into the base driver's link attention type coding.
3436 *
3437 * Return: Link attention type in terms of base driver's coding.
3438 **/
3439static uint8_t
3440lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
3441 struct lpfc_acqe_link *acqe_link)
3442{
3443 uint8_t att_type;
3444
3445 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
3446 case LPFC_ASYNC_LINK_STATUS_DOWN:
3447 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05003448 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04003449 break;
3450 case LPFC_ASYNC_LINK_STATUS_UP:
3451 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05003452 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003453 break;
3454 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05003455 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04003456 break;
3457 default:
3458 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3459 "0399 Invalid link attention type: x%x\n",
3460 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003461 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003462 break;
3463 }
3464 return att_type;
3465}
3466
3467/**
3468 * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
3469 * @phba: pointer to lpfc hba data structure.
3470 * @acqe_link: pointer to the async link completion queue entry.
3471 *
3472 * This routine is to parse the SLI4 link-attention link speed and translate
3473 * it into the base driver's link-attention link speed coding.
3474 *
3475 * Return: Link-attention link speed in terms of base driver's coding.
3476 **/
3477static uint8_t
3478lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba,
3479 struct lpfc_acqe_link *acqe_link)
3480{
3481 uint8_t link_speed;
3482
3483 switch (bf_get(lpfc_acqe_link_speed, acqe_link)) {
3484 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smartda0436e2009-05-22 14:51:39 -04003485 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smartda0436e2009-05-22 14:51:39 -04003486 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart76a95d72010-11-20 23:11:48 -05003487 link_speed = LPFC_LINK_SPEED_UNKNOWN;
James Smartda0436e2009-05-22 14:51:39 -04003488 break;
3489 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart76a95d72010-11-20 23:11:48 -05003490 link_speed = LPFC_LINK_SPEED_1GHZ;
James Smartda0436e2009-05-22 14:51:39 -04003491 break;
3492 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart76a95d72010-11-20 23:11:48 -05003493 link_speed = LPFC_LINK_SPEED_10GHZ;
James Smartda0436e2009-05-22 14:51:39 -04003494 break;
3495 default:
3496 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3497 "0483 Invalid link-attention link speed: x%x\n",
3498 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003499 link_speed = LPFC_LINK_SPEED_UNKNOWN;
James Smartda0436e2009-05-22 14:51:39 -04003500 break;
3501 }
3502 return link_speed;
3503}
3504
3505/**
James Smart8b68cd52012-09-29 11:32:37 -04003506 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
3507 * @phba: pointer to lpfc hba data structure.
3508 *
3509 * This routine is to get an SLI3 FC port's link speed in Mbps.
3510 *
3511 * Return: link speed in terms of Mbps.
3512 **/
3513uint32_t
3514lpfc_sli_port_speed_get(struct lpfc_hba *phba)
3515{
3516 uint32_t link_speed;
3517
3518 if (!lpfc_is_link_up(phba))
3519 return 0;
3520
3521 switch (phba->fc_linkspeed) {
3522 case LPFC_LINK_SPEED_1GHZ:
3523 link_speed = 1000;
3524 break;
3525 case LPFC_LINK_SPEED_2GHZ:
3526 link_speed = 2000;
3527 break;
3528 case LPFC_LINK_SPEED_4GHZ:
3529 link_speed = 4000;
3530 break;
3531 case LPFC_LINK_SPEED_8GHZ:
3532 link_speed = 8000;
3533 break;
3534 case LPFC_LINK_SPEED_10GHZ:
3535 link_speed = 10000;
3536 break;
3537 case LPFC_LINK_SPEED_16GHZ:
3538 link_speed = 16000;
3539 break;
3540 default:
3541 link_speed = 0;
3542 }
3543 return link_speed;
3544}
3545
3546/**
3547 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
3548 * @phba: pointer to lpfc hba data structure.
3549 * @evt_code: asynchronous event code.
3550 * @speed_code: asynchronous event link speed code.
3551 *
3552 * This routine is to parse the giving SLI4 async event link speed code into
3553 * value of Mbps for the link speed.
3554 *
3555 * Return: link speed in terms of Mbps.
3556 **/
3557static uint32_t
3558lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
3559 uint8_t speed_code)
3560{
3561 uint32_t port_speed;
3562
3563 switch (evt_code) {
3564 case LPFC_TRAILER_CODE_LINK:
3565 switch (speed_code) {
3566 case LPFC_EVT_CODE_LINK_NO_LINK:
3567 port_speed = 0;
3568 break;
3569 case LPFC_EVT_CODE_LINK_10_MBIT:
3570 port_speed = 10;
3571 break;
3572 case LPFC_EVT_CODE_LINK_100_MBIT:
3573 port_speed = 100;
3574 break;
3575 case LPFC_EVT_CODE_LINK_1_GBIT:
3576 port_speed = 1000;
3577 break;
3578 case LPFC_EVT_CODE_LINK_10_GBIT:
3579 port_speed = 10000;
3580 break;
3581 default:
3582 port_speed = 0;
3583 }
3584 break;
3585 case LPFC_TRAILER_CODE_FC:
3586 switch (speed_code) {
3587 case LPFC_EVT_CODE_FC_NO_LINK:
3588 port_speed = 0;
3589 break;
3590 case LPFC_EVT_CODE_FC_1_GBAUD:
3591 port_speed = 1000;
3592 break;
3593 case LPFC_EVT_CODE_FC_2_GBAUD:
3594 port_speed = 2000;
3595 break;
3596 case LPFC_EVT_CODE_FC_4_GBAUD:
3597 port_speed = 4000;
3598 break;
3599 case LPFC_EVT_CODE_FC_8_GBAUD:
3600 port_speed = 8000;
3601 break;
3602 case LPFC_EVT_CODE_FC_10_GBAUD:
3603 port_speed = 10000;
3604 break;
3605 case LPFC_EVT_CODE_FC_16_GBAUD:
3606 port_speed = 16000;
3607 break;
3608 default:
3609 port_speed = 0;
3610 }
3611 break;
3612 default:
3613 port_speed = 0;
3614 }
3615 return port_speed;
3616}
3617
3618/**
James Smart70f3c072010-12-15 17:57:33 -05003619 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04003620 * @phba: pointer to lpfc hba data structure.
3621 * @acqe_link: pointer to the async link completion queue entry.
3622 *
James Smart70f3c072010-12-15 17:57:33 -05003623 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04003624 **/
3625static void
3626lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
3627 struct lpfc_acqe_link *acqe_link)
3628{
3629 struct lpfc_dmabuf *mp;
3630 LPFC_MBOXQ_t *pmb;
3631 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05003632 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04003633 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05003634 int rc;
James Smartda0436e2009-05-22 14:51:39 -04003635
3636 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05003637 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04003638 return;
James Smart32b97932009-07-19 10:01:21 -04003639 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04003640 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3641 if (!pmb) {
3642 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3643 "0395 The mboxq allocation failed\n");
3644 return;
3645 }
3646 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3647 if (!mp) {
3648 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3649 "0396 The lpfc_dmabuf allocation failed\n");
3650 goto out_free_pmb;
3651 }
3652 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
3653 if (!mp->virt) {
3654 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3655 "0397 The mbuf allocation failed\n");
3656 goto out_free_dmabuf;
3657 }
3658
3659 /* Cleanup any outstanding ELS commands */
3660 lpfc_els_flush_all_cmd(phba);
3661
3662 /* Block ELS IOCBs until we have done process link event */
3663 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
3664
3665 /* Update link event statistics */
3666 phba->sli.slistat.link_event++;
3667
James Smart76a95d72010-11-20 23:11:48 -05003668 /* Create lpfc_handle_latt mailbox command from link ACQE */
3669 lpfc_read_topology(phba, pmb, mp);
3670 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04003671 pmb->vport = phba->pport;
3672
James Smartda0436e2009-05-22 14:51:39 -04003673 /* Keep the link status for extra SLI4 state machine reference */
3674 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04003675 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
3676 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04003677 phba->sli4_hba.link_state.duplex =
3678 bf_get(lpfc_acqe_link_duplex, acqe_link);
3679 phba->sli4_hba.link_state.status =
3680 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05003681 phba->sli4_hba.link_state.type =
3682 bf_get(lpfc_acqe_link_type, acqe_link);
3683 phba->sli4_hba.link_state.number =
3684 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04003685 phba->sli4_hba.link_state.fault =
3686 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05003687 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04003688 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
3689
James Smart70f3c072010-12-15 17:57:33 -05003690 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04003691 "2900 Async FC/FCoE Link event - Speed:%dGBit "
3692 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
3693 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05003694 phba->sli4_hba.link_state.speed,
3695 phba->sli4_hba.link_state.topology,
3696 phba->sli4_hba.link_state.status,
3697 phba->sli4_hba.link_state.type,
3698 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04003699 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05003700 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05003701 /*
3702 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
3703 * topology info. Note: Optional for non FC-AL ports.
3704 */
3705 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3706 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3707 if (rc == MBX_NOT_FINISHED)
3708 goto out_free_dmabuf;
3709 return;
3710 }
3711 /*
3712 * For FCoE Mode: fill in all the topology information we need and call
3713 * the READ_TOPOLOGY completion routine to continue without actually
3714 * sending the READ_TOPOLOGY mailbox command to the port.
3715 */
3716 /* Parse and translate status field */
3717 mb = &pmb->u.mb;
3718 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
3719
3720 /* Parse and translate link attention fields */
3721 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3722 la->eventTag = acqe_link->event_tag;
3723 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
3724 bf_set(lpfc_mbx_read_top_link_spd, la,
3725 lpfc_sli4_parse_latt_link_speed(phba, acqe_link));
3726
3727 /* Fake the the following irrelvant fields */
3728 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
3729 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
3730 bf_set(lpfc_mbx_read_top_il, la, 0);
3731 bf_set(lpfc_mbx_read_top_pb, la, 0);
3732 bf_set(lpfc_mbx_read_top_fa, la, 0);
3733 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04003734
3735 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05003736 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04003737
3738 return;
3739
3740out_free_dmabuf:
3741 kfree(mp);
3742out_free_pmb:
3743 mempool_free(pmb, phba->mbox_mem_pool);
3744}
3745
3746/**
James Smart70f3c072010-12-15 17:57:33 -05003747 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
3748 * @phba: pointer to lpfc hba data structure.
3749 * @acqe_fc: pointer to the async fc completion queue entry.
3750 *
3751 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
3752 * that the event was received and then issue a read_topology mailbox command so
3753 * that the rest of the driver will treat it the same as SLI3.
3754 **/
3755static void
3756lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
3757{
3758 struct lpfc_dmabuf *mp;
3759 LPFC_MBOXQ_t *pmb;
3760 int rc;
3761
3762 if (bf_get(lpfc_trailer_type, acqe_fc) !=
3763 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
3764 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3765 "2895 Non FC link Event detected.(%d)\n",
3766 bf_get(lpfc_trailer_type, acqe_fc));
3767 return;
3768 }
3769 /* Keep the link status for extra SLI4 state machine reference */
3770 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04003771 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
3772 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05003773 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
3774 phba->sli4_hba.link_state.topology =
3775 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
3776 phba->sli4_hba.link_state.status =
3777 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
3778 phba->sli4_hba.link_state.type =
3779 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
3780 phba->sli4_hba.link_state.number =
3781 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
3782 phba->sli4_hba.link_state.fault =
3783 bf_get(lpfc_acqe_link_fault, acqe_fc);
3784 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04003785 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart70f3c072010-12-15 17:57:33 -05003786 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3787 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
3788 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
3789 "%dMbps Fault:%d\n",
3790 phba->sli4_hba.link_state.speed,
3791 phba->sli4_hba.link_state.topology,
3792 phba->sli4_hba.link_state.status,
3793 phba->sli4_hba.link_state.type,
3794 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04003795 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05003796 phba->sli4_hba.link_state.fault);
3797 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3798 if (!pmb) {
3799 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3800 "2897 The mboxq allocation failed\n");
3801 return;
3802 }
3803 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3804 if (!mp) {
3805 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3806 "2898 The lpfc_dmabuf allocation failed\n");
3807 goto out_free_pmb;
3808 }
3809 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
3810 if (!mp->virt) {
3811 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3812 "2899 The mbuf allocation failed\n");
3813 goto out_free_dmabuf;
3814 }
3815
3816 /* Cleanup any outstanding ELS commands */
3817 lpfc_els_flush_all_cmd(phba);
3818
3819 /* Block ELS IOCBs until we have done process link event */
3820 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
3821
3822 /* Update link event statistics */
3823 phba->sli.slistat.link_event++;
3824
3825 /* Create lpfc_handle_latt mailbox command from link ACQE */
3826 lpfc_read_topology(phba, pmb, mp);
3827 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
3828 pmb->vport = phba->pport;
3829
3830 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3831 if (rc == MBX_NOT_FINISHED)
3832 goto out_free_dmabuf;
3833 return;
3834
3835out_free_dmabuf:
3836 kfree(mp);
3837out_free_pmb:
3838 mempool_free(pmb, phba->mbox_mem_pool);
3839}
3840
3841/**
3842 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
3843 * @phba: pointer to lpfc hba data structure.
3844 * @acqe_fc: pointer to the async SLI completion queue entry.
3845 *
3846 * This routine is to handle the SLI4 asynchronous SLI events.
3847 **/
3848static void
3849lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
3850{
James Smart4b8bae02012-06-12 13:55:07 -04003851 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04003852 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04003853 uint8_t status;
3854 struct lpfc_acqe_misconfigured_event *misconfigured;
3855
3856 /* special case misconfigured event as it contains data for all ports */
3857 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3858 LPFC_SLI_INTF_IF_TYPE_2) ||
3859 (bf_get(lpfc_trailer_type, acqe_sli) !=
3860 LPFC_SLI_EVENT_TYPE_MISCONFIGURED)) {
3861 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3862 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
3863 "x%08x SLI Event Type:%d\n",
3864 acqe_sli->event_data1, acqe_sli->event_data2,
3865 bf_get(lpfc_trailer_type, acqe_sli));
3866 return;
3867 }
3868
3869 port_name = phba->Port[0];
3870 if (port_name == 0x00)
3871 port_name = '?'; /* get port name is empty */
3872
3873 misconfigured = (struct lpfc_acqe_misconfigured_event *)
3874 &acqe_sli->event_data1;
3875
3876 /* fetch the status for this port */
3877 switch (phba->sli4_hba.lnk_info.lnk_no) {
3878 case LPFC_LINK_NUMBER_0:
3879 status = bf_get(lpfc_sli_misconfigured_port0,
3880 &misconfigured->theEvent);
3881 break;
3882 case LPFC_LINK_NUMBER_1:
3883 status = bf_get(lpfc_sli_misconfigured_port1,
3884 &misconfigured->theEvent);
3885 break;
3886 case LPFC_LINK_NUMBER_2:
3887 status = bf_get(lpfc_sli_misconfigured_port2,
3888 &misconfigured->theEvent);
3889 break;
3890 case LPFC_LINK_NUMBER_3:
3891 status = bf_get(lpfc_sli_misconfigured_port3,
3892 &misconfigured->theEvent);
3893 break;
3894 default:
3895 status = ~LPFC_SLI_EVENT_STATUS_VALID;
3896 break;
3897 }
3898
3899 switch (status) {
3900 case LPFC_SLI_EVENT_STATUS_VALID:
3901 return; /* no message if the sfp is okay */
3902 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
James Smart292098b2012-09-29 11:31:41 -04003903 sprintf(message, "Optics faulted/incorrectly installed/not " \
3904 "installed - Reseat optics, if issue not "
3905 "resolved, replace.");
James Smart4b8bae02012-06-12 13:55:07 -04003906 break;
3907 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
3908 sprintf(message,
James Smart292098b2012-09-29 11:31:41 -04003909 "Optics of two types installed - Remove one optic or " \
3910 "install matching pair of optics.");
James Smart4b8bae02012-06-12 13:55:07 -04003911 break;
3912 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
James Smart292098b2012-09-29 11:31:41 -04003913 sprintf(message, "Incompatible optics - Replace with " \
3914 "compatible optics for card to function.");
James Smart4b8bae02012-06-12 13:55:07 -04003915 break;
3916 default:
3917 /* firmware is reporting a status we don't know about */
3918 sprintf(message, "Unknown event status x%02x", status);
3919 break;
3920 }
3921
3922 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3923 "3176 Misconfigured Physical Port - "
3924 "Port Name %c %s\n", port_name, message);
James Smart70f3c072010-12-15 17:57:33 -05003925}
3926
3927/**
James Smartfc2b9892010-02-26 14:15:29 -05003928 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
3929 * @vport: pointer to vport data structure.
3930 *
3931 * This routine is to perform Clear Virtual Link (CVL) on a vport in
3932 * response to a CVL event.
3933 *
3934 * Return the pointer to the ndlp with the vport if successful, otherwise
3935 * return NULL.
3936 **/
3937static struct lpfc_nodelist *
3938lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
3939{
3940 struct lpfc_nodelist *ndlp;
3941 struct Scsi_Host *shost;
3942 struct lpfc_hba *phba;
3943
3944 if (!vport)
3945 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05003946 phba = vport->phba;
3947 if (!phba)
3948 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04003949 ndlp = lpfc_findnode_did(vport, Fabric_DID);
3950 if (!ndlp) {
3951 /* Cannot find existing Fabric ndlp, so allocate a new one */
3952 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3953 if (!ndlp)
3954 return 0;
3955 lpfc_nlp_init(vport, ndlp, Fabric_DID);
3956 /* Set the node type */
3957 ndlp->nlp_type |= NLP_FABRIC;
3958 /* Put ndlp onto node list */
3959 lpfc_enqueue_node(vport, ndlp);
3960 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3961 /* re-setup ndlp without removing from node list */
3962 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3963 if (!ndlp)
3964 return 0;
3965 }
James Smart63e801c2010-11-20 23:14:19 -05003966 if ((phba->pport->port_state < LPFC_FLOGI) &&
3967 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05003968 return NULL;
3969 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05003970 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
3971 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05003972 return NULL;
3973 shost = lpfc_shost_from_vport(vport);
3974 if (!shost)
3975 return NULL;
3976 lpfc_linkdown_port(vport);
3977 lpfc_cleanup_pending_mbox(vport);
3978 spin_lock_irq(shost->host_lock);
3979 vport->fc_flag |= FC_VPORT_CVL_RCVD;
3980 spin_unlock_irq(shost->host_lock);
3981
3982 return ndlp;
3983}
3984
3985/**
3986 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
3987 * @vport: pointer to lpfc hba data structure.
3988 *
3989 * This routine is to perform Clear Virtual Link (CVL) on all vports in
3990 * response to a FCF dead event.
3991 **/
3992static void
3993lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
3994{
3995 struct lpfc_vport **vports;
3996 int i;
3997
3998 vports = lpfc_create_vport_work_array(phba);
3999 if (vports)
4000 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4001 lpfc_sli4_perform_vport_cvl(vports[i]);
4002 lpfc_destroy_vport_work_array(phba, vports);
4003}
4004
4005/**
James Smart25aee402013-03-01 16:36:34 -05004006 * lpfc_sli4_perform_inuse_fcf_recovery - Perform inuse fcf recovery
4007 * @vport: pointer to lpfc hba data structure.
4008 *
4009 * This routine is to perform FCF recovery when the in-use FCF either dead or
4010 * got modified.
4011 **/
4012static void
4013lpfc_sli4_perform_inuse_fcf_recovery(struct lpfc_hba *phba,
4014 struct lpfc_acqe_fip *acqe_fip)
4015{
4016 int rc;
4017
4018 spin_lock_irq(&phba->hbalock);
4019 /* Mark the fast failover process in progress */
4020 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
4021 spin_unlock_irq(&phba->hbalock);
4022
4023 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
4024 "2771 Start FCF fast failover process due to in-use "
4025 "FCF DEAD/MODIFIED event: evt_tag:x%x, index:x%x\n",
4026 acqe_fip->event_tag, acqe_fip->index);
4027 rc = lpfc_sli4_redisc_fcf_table(phba);
4028 if (rc) {
4029 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4030 "2772 Issue FCF rediscover mabilbox command "
4031 "failed, fail through to FCF dead event\n");
4032 spin_lock_irq(&phba->hbalock);
4033 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
4034 spin_unlock_irq(&phba->hbalock);
4035 /*
4036 * Last resort will fail over by treating this as a link
4037 * down to FCF registration.
4038 */
4039 lpfc_sli4_fcf_dead_failthrough(phba);
4040 } else {
4041 /* Reset FCF roundrobin bmask for new discovery */
4042 lpfc_sli4_clear_fcf_rr_bmask(phba);
4043 /*
4044 * Handling fast FCF failover to a DEAD FCF event is
4045 * considered equalivant to receiving CVL to all vports.
4046 */
4047 lpfc_sli4_perform_all_vport_cvl(phba);
4048 }
4049}
4050
4051/**
James Smart76a95d72010-11-20 23:11:48 -05004052 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04004053 * @phba: pointer to lpfc hba data structure.
4054 * @acqe_link: pointer to the async fcoe completion queue entry.
4055 *
4056 * This routine is to handle the SLI4 asynchronous fcoe event.
4057 **/
4058static void
James Smart76a95d72010-11-20 23:11:48 -05004059lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05004060 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04004061{
James Smart70f3c072010-12-15 17:57:33 -05004062 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004063 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04004064 struct lpfc_vport *vport;
4065 struct lpfc_nodelist *ndlp;
4066 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05004067 int active_vlink_present;
4068 struct lpfc_vport **vports;
4069 int i;
James Smartda0436e2009-05-22 14:51:39 -04004070
James Smart70f3c072010-12-15 17:57:33 -05004071 phba->fc_eventTag = acqe_fip->event_tag;
4072 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004073 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05004074 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
4075 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
4076 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04004077 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4078 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004079 "2546 New FCF event, evt_tag:x%x, "
4080 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004081 acqe_fip->event_tag,
4082 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04004083 else
4084 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
4085 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004086 "2788 FCF param modified event, "
4087 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004088 acqe_fip->event_tag,
4089 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04004090 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004091 /*
4092 * During period of FCF discovery, read the FCF
4093 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04004094 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05004095 */
4096 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4097 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004098 "2779 Read FCF (x%x) for updating "
4099 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05004100 acqe_fip->index);
4101 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004102 }
James Smart38b92ef2010-08-04 16:11:39 -04004103
4104 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04004105 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04004106 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04004107 spin_unlock_irq(&phba->hbalock);
4108 break;
4109 }
4110 /* If fast FCF failover rescan event is pending, do nothing */
4111 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
4112 spin_unlock_irq(&phba->hbalock);
4113 break;
4114 }
4115
James Smart25aee402013-03-01 16:36:34 -05004116 /* If FCF has been in discovered state, perform rediscovery
4117 * only if the FCF with the same index of the in-use FCF got
4118 * modified during normal operation. Otherwise, do nothing.
4119 */
4120 if (phba->pport->port_state > LPFC_FLOGI) {
James Smart3804dc82010-07-14 15:31:37 -04004121 spin_unlock_irq(&phba->hbalock);
James Smart25aee402013-03-01 16:36:34 -05004122 if (phba->fcf.current_rec.fcf_indx ==
4123 acqe_fip->index) {
4124 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
4125 "3300 In-use FCF (%d) "
4126 "modified, perform FCF "
4127 "rediscovery\n",
4128 acqe_fip->index);
4129 lpfc_sli4_perform_inuse_fcf_recovery(phba,
4130 acqe_fip);
4131 }
James Smart3804dc82010-07-14 15:31:37 -04004132 break;
4133 }
4134 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04004135
James Smart0c9ab6f2010-02-26 14:15:57 -05004136 /* Otherwise, scan the entire FCF table and re-discover SAN */
4137 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004138 "2770 Start FCF table scan per async FCF "
4139 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004140 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004141 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
4142 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04004143 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004144 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4145 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04004146 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04004147 break;
4148
James Smart70f3c072010-12-15 17:57:33 -05004149 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04004150 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04004151 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004152 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
4153 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004154 break;
4155
James Smart70f3c072010-12-15 17:57:33 -05004156 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05004157 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004158 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004159 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05004160 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04004161 /*
4162 * If we are in the middle of FCF failover process, clear
4163 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04004164 */
James Smartfc2b9892010-02-26 14:15:29 -05004165 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004166 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05004167 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004168 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05004169 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004170 break;
4171 }
James Smart38b92ef2010-08-04 16:11:39 -04004172 spin_unlock_irq(&phba->hbalock);
4173
4174 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05004175 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04004176 break;
4177
4178 /*
4179 * Otherwise, request the port to rediscover the entire FCF
4180 * table for a fast recovery from case that the current FCF
4181 * is no longer valid as we are not in the middle of FCF
4182 * failover process already.
4183 */
James Smart25aee402013-03-01 16:36:34 -05004184 lpfc_sli4_perform_inuse_fcf_recovery(phba, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004185 break;
James Smart70f3c072010-12-15 17:57:33 -05004186 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05004187 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004188 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04004189 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05004190 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04004191
James Smart6669f9b2009-10-02 15:16:45 -04004192 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04004193 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004194 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004195 if (!ndlp)
4196 break;
James Smart695a8142010-01-26 23:08:03 -05004197 active_vlink_present = 0;
4198
4199 vports = lpfc_create_vport_work_array(phba);
4200 if (vports) {
4201 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
4202 i++) {
4203 if ((!(vports[i]->fc_flag &
4204 FC_VPORT_CVL_RCVD)) &&
4205 (vports[i]->port_state > LPFC_FDISC)) {
4206 active_vlink_present = 1;
4207 break;
4208 }
4209 }
4210 lpfc_destroy_vport_work_array(phba, vports);
4211 }
4212
4213 if (active_vlink_present) {
4214 /*
4215 * If there are other active VLinks present,
4216 * re-instantiate the Vlink using FDISC.
4217 */
James Smart6669f9b2009-10-02 15:16:45 -04004218 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
James Smartfc2b9892010-02-26 14:15:29 -05004219 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004220 spin_lock_irq(shost->host_lock);
4221 ndlp->nlp_flag |= NLP_DELAY_TMO;
4222 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05004223 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
4224 vport->port_state = LPFC_FDISC;
4225 } else {
James Smartecfd03c2010-02-12 14:41:27 -05004226 /*
4227 * Otherwise, we request port to rediscover
4228 * the entire FCF table for a fast recovery
4229 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05004230 * is no longer valid if we are not already
4231 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05004232 */
James Smartfc2b9892010-02-26 14:15:29 -05004233 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004234 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05004235 spin_unlock_irq(&phba->hbalock);
4236 break;
4237 }
4238 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05004239 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004240 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004241 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4242 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004243 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05004244 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05004245 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05004246 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004247 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4248 LOG_DISCOVERY,
4249 "2774 Issue FCF rediscover "
4250 "mabilbox command failed, "
4251 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05004252 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004253 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004254 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05004255 /*
4256 * Last resort will be re-try on the
4257 * the current registered FCF entry.
4258 */
4259 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04004260 } else
4261 /*
4262 * Reset FCF roundrobin bmask for new
4263 * discovery.
4264 */
James Smart7d791df2011-07-22 18:37:52 -04004265 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04004266 }
4267 break;
James Smartda0436e2009-05-22 14:51:39 -04004268 default:
4269 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4270 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05004271 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004272 break;
4273 }
4274}
4275
4276/**
4277 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
4278 * @phba: pointer to lpfc hba data structure.
4279 * @acqe_link: pointer to the async dcbx completion queue entry.
4280 *
4281 * This routine is to handle the SLI4 asynchronous dcbx event.
4282 **/
4283static void
4284lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
4285 struct lpfc_acqe_dcbx *acqe_dcbx)
4286{
James Smart4d9ab992009-10-02 15:16:39 -04004287 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004288 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4289 "0290 The SLI4 DCBX asynchronous event is not "
4290 "handled yet\n");
4291}
4292
4293/**
James Smartb19a0612010-04-06 14:48:51 -04004294 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
4295 * @phba: pointer to lpfc hba data structure.
4296 * @acqe_link: pointer to the async grp5 completion queue entry.
4297 *
4298 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
4299 * is an asynchronous notified of a logical link speed change. The Port
4300 * reports the logical link speed in units of 10Mbps.
4301 **/
4302static void
4303lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
4304 struct lpfc_acqe_grp5 *acqe_grp5)
4305{
4306 uint16_t prev_ll_spd;
4307
4308 phba->fc_eventTag = acqe_grp5->event_tag;
4309 phba->fcoe_eventtag = acqe_grp5->event_tag;
4310 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
4311 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004312 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04004313 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4314 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04004315 "from %dMbps to %dMbps\n", prev_ll_spd,
4316 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04004317}
4318
4319/**
James Smartda0436e2009-05-22 14:51:39 -04004320 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
4321 * @phba: pointer to lpfc hba data structure.
4322 *
4323 * This routine is invoked by the worker thread to process all the pending
4324 * SLI4 asynchronous events.
4325 **/
4326void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
4327{
4328 struct lpfc_cq_event *cq_event;
4329
4330 /* First, declare the async event has been handled */
4331 spin_lock_irq(&phba->hbalock);
4332 phba->hba_flag &= ~ASYNC_EVENT;
4333 spin_unlock_irq(&phba->hbalock);
4334 /* Now, handle all the async events */
4335 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
4336 /* Get the first event from the head of the event queue */
4337 spin_lock_irq(&phba->hbalock);
4338 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
4339 cq_event, struct lpfc_cq_event, list);
4340 spin_unlock_irq(&phba->hbalock);
4341 /* Process the asynchronous event */
4342 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
4343 case LPFC_TRAILER_CODE_LINK:
4344 lpfc_sli4_async_link_evt(phba,
4345 &cq_event->cqe.acqe_link);
4346 break;
4347 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05004348 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004349 break;
4350 case LPFC_TRAILER_CODE_DCBX:
4351 lpfc_sli4_async_dcbx_evt(phba,
4352 &cq_event->cqe.acqe_dcbx);
4353 break;
James Smartb19a0612010-04-06 14:48:51 -04004354 case LPFC_TRAILER_CODE_GRP5:
4355 lpfc_sli4_async_grp5_evt(phba,
4356 &cq_event->cqe.acqe_grp5);
4357 break;
James Smart70f3c072010-12-15 17:57:33 -05004358 case LPFC_TRAILER_CODE_FC:
4359 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
4360 break;
4361 case LPFC_TRAILER_CODE_SLI:
4362 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
4363 break;
James Smartda0436e2009-05-22 14:51:39 -04004364 default:
4365 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4366 "1804 Invalid asynchrous event code: "
4367 "x%x\n", bf_get(lpfc_trailer_code,
4368 &cq_event->cqe.mcqe_cmpl));
4369 break;
4370 }
4371 /* Free the completion event processed to the free pool */
4372 lpfc_sli4_cq_event_release(phba, cq_event);
4373 }
4374}
4375
4376/**
James Smartecfd03c2010-02-12 14:41:27 -05004377 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
4378 * @phba: pointer to lpfc hba data structure.
4379 *
4380 * This routine is invoked by the worker thread to process FCF table
4381 * rediscovery pending completion event.
4382 **/
4383void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
4384{
4385 int rc;
4386
4387 spin_lock_irq(&phba->hbalock);
4388 /* Clear FCF rediscovery timeout event */
4389 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
4390 /* Clear driver fast failover FCF record flag */
4391 phba->fcf.failover_rec.flag = 0;
4392 /* Set state for FCF fast failover */
4393 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
4394 spin_unlock_irq(&phba->hbalock);
4395
4396 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05004397 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004398 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05004399 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05004400 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004401 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4402 "2747 Issue FCF scan read FCF mailbox "
4403 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05004404}
4405
4406/**
James Smartda0436e2009-05-22 14:51:39 -04004407 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
4408 * @phba: pointer to lpfc hba data structure.
4409 * @dev_grp: The HBA PCI-Device group number.
4410 *
4411 * This routine is invoked to set up the per HBA PCI-Device group function
4412 * API jump table entries.
4413 *
4414 * Return: 0 if success, otherwise -ENODEV
4415 **/
4416int
4417lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05004418{
4419 int rc;
4420
James Smartda0436e2009-05-22 14:51:39 -04004421 /* Set up lpfc PCI-device group */
4422 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05004423
James Smartda0436e2009-05-22 14:51:39 -04004424 /* The LPFC_PCI_DEV_OC uses SLI4 */
4425 if (dev_grp == LPFC_PCI_DEV_OC)
4426 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05004427
James Smartda0436e2009-05-22 14:51:39 -04004428 /* Set up device INIT API function jump table */
4429 rc = lpfc_init_api_table_setup(phba, dev_grp);
4430 if (rc)
4431 return -ENODEV;
4432 /* Set up SCSI API function jump table */
4433 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
4434 if (rc)
4435 return -ENODEV;
4436 /* Set up SLI API function jump table */
4437 rc = lpfc_sli_api_table_setup(phba, dev_grp);
4438 if (rc)
4439 return -ENODEV;
4440 /* Set up MBOX API function jump table */
4441 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
4442 if (rc)
4443 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05004444
James Smartda0436e2009-05-22 14:51:39 -04004445 return 0;
James Smart5b75da22008-12-04 22:39:35 -05004446}
4447
4448/**
James Smart3621a712009-04-06 18:47:14 -04004449 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05004450 * @phba: pointer to lpfc hba data structure.
4451 * @intr_mode: active interrupt mode adopted.
4452 *
4453 * This routine it invoked to log the currently used active interrupt mode
4454 * to the device.
James Smart3772a992009-05-22 14:50:54 -04004455 **/
4456static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05004457{
4458 switch (intr_mode) {
4459 case 0:
4460 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4461 "0470 Enable INTx interrupt mode.\n");
4462 break;
4463 case 1:
4464 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4465 "0481 Enabled MSI interrupt mode.\n");
4466 break;
4467 case 2:
4468 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4469 "0480 Enabled MSI-X interrupt mode.\n");
4470 break;
4471 default:
4472 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4473 "0482 Illegal interrupt mode.\n");
4474 break;
4475 }
4476 return;
4477}
4478
James Smart5b75da22008-12-04 22:39:35 -05004479/**
James Smart3772a992009-05-22 14:50:54 -04004480 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05004481 * @phba: pointer to lpfc hba data structure.
4482 *
James Smart3772a992009-05-22 14:50:54 -04004483 * This routine is invoked to enable the PCI device that is common to all
4484 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05004485 *
4486 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004487 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004488 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05004489 **/
James Smart3772a992009-05-22 14:50:54 -04004490static int
4491lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05004492{
James Smart3772a992009-05-22 14:50:54 -04004493 struct pci_dev *pdev;
James Smart079b5c92011-08-21 21:48:49 -04004494 int bars = 0;
James Smart5b75da22008-12-04 22:39:35 -05004495
James Smart3772a992009-05-22 14:50:54 -04004496 /* Obtain PCI device reference */
4497 if (!phba->pcidev)
4498 goto out_error;
4499 else
4500 pdev = phba->pcidev;
4501 /* Select PCI BARs */
4502 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4503 /* Enable PCI device */
4504 if (pci_enable_device_mem(pdev))
4505 goto out_error;
4506 /* Request PCI resource for the device */
4507 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
4508 goto out_disable_device;
4509 /* Set up device as PCI master and save state for EEH */
4510 pci_set_master(pdev);
4511 pci_try_set_mwi(pdev);
4512 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05004513
James Smart05580562011-05-24 11:40:48 -04004514 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
4515 if (pci_find_capability(pdev, PCI_CAP_ID_EXP))
4516 pdev->needs_freset = 1;
4517
James Smart3772a992009-05-22 14:50:54 -04004518 return 0;
James Smart5b75da22008-12-04 22:39:35 -05004519
James Smart3772a992009-05-22 14:50:54 -04004520out_disable_device:
4521 pci_disable_device(pdev);
4522out_error:
James Smart079b5c92011-08-21 21:48:49 -04004523 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4524 "1401 Failed to enable pci device, bars:x%x\n", bars);
James Smart3772a992009-05-22 14:50:54 -04004525 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05004526}
4527
4528/**
James Smart3772a992009-05-22 14:50:54 -04004529 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05004530 * @phba: pointer to lpfc hba data structure.
4531 *
James Smart3772a992009-05-22 14:50:54 -04004532 * This routine is invoked to disable the PCI device that is common to all
4533 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05004534 **/
4535static void
James Smart3772a992009-05-22 14:50:54 -04004536lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05004537{
James Smart3772a992009-05-22 14:50:54 -04004538 struct pci_dev *pdev;
4539 int bars;
James Smart5b75da22008-12-04 22:39:35 -05004540
James Smart3772a992009-05-22 14:50:54 -04004541 /* Obtain PCI device reference */
4542 if (!phba->pcidev)
4543 return;
4544 else
4545 pdev = phba->pcidev;
4546 /* Select PCI BARs */
4547 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4548 /* Release PCI resource and disable PCI device */
4549 pci_release_selected_regions(pdev, bars);
4550 pci_disable_device(pdev);
4551 /* Null out PCI private reference to driver */
4552 pci_set_drvdata(pdev, NULL);
James Smart5b75da22008-12-04 22:39:35 -05004553
4554 return;
4555}
4556
4557/**
James Smart3772a992009-05-22 14:50:54 -04004558 * lpfc_reset_hba - Reset a hba
4559 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04004560 *
James Smart3772a992009-05-22 14:50:54 -04004561 * This routine is invoked to reset a hba device. It brings the HBA
4562 * offline, performs a board restart, and then brings the board back
4563 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
4564 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04004565 **/
James Smart3772a992009-05-22 14:50:54 -04004566void
4567lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05004568{
James Smart3772a992009-05-22 14:50:54 -04004569 /* If resets are disabled then set error state and return. */
4570 if (!phba->cfg_enable_hba_reset) {
4571 phba->link_state = LPFC_HBA_ERROR;
4572 return;
4573 }
James Smart618a5232012-06-12 13:54:36 -04004574 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3772a992009-05-22 14:50:54 -04004575 lpfc_offline(phba);
4576 lpfc_sli_brdrestart(phba);
4577 lpfc_online(phba);
4578 lpfc_unblock_mgmt_io(phba);
4579}
dea31012005-04-17 16:05:31 -05004580
James Smart3772a992009-05-22 14:50:54 -04004581/**
James Smart0a96e972011-07-22 18:37:28 -04004582 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
4583 * @phba: pointer to lpfc hba data structure.
4584 *
4585 * This function enables the PCI SR-IOV virtual functions to a physical
4586 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4587 * enable the number of virtual functions to the physical function. As
4588 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4589 * API call does not considered as an error condition for most of the device.
4590 **/
4591uint16_t
4592lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
4593{
4594 struct pci_dev *pdev = phba->pcidev;
4595 uint16_t nr_virtfn;
4596 int pos;
4597
James Smart0a96e972011-07-22 18:37:28 -04004598 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4599 if (pos == 0)
4600 return 0;
4601
4602 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
4603 return nr_virtfn;
4604}
4605
4606/**
James Smart912e3ac2011-05-24 11:42:11 -04004607 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
4608 * @phba: pointer to lpfc hba data structure.
4609 * @nr_vfn: number of virtual functions to be enabled.
4610 *
4611 * This function enables the PCI SR-IOV virtual functions to a physical
4612 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4613 * enable the number of virtual functions to the physical function. As
4614 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4615 * API call does not considered as an error condition for most of the device.
4616 **/
4617int
4618lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
4619{
4620 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04004621 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04004622 int rc;
4623
James Smart0a96e972011-07-22 18:37:28 -04004624 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
4625 if (nr_vfn > max_nr_vfn) {
4626 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4627 "3057 Requested vfs (%d) greater than "
4628 "supported vfs (%d)", nr_vfn, max_nr_vfn);
4629 return -EINVAL;
4630 }
4631
James Smart912e3ac2011-05-24 11:42:11 -04004632 rc = pci_enable_sriov(pdev, nr_vfn);
4633 if (rc) {
4634 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4635 "2806 Failed to enable sriov on this device "
4636 "with vfn number nr_vf:%d, rc:%d\n",
4637 nr_vfn, rc);
4638 } else
4639 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4640 "2807 Successful enable sriov on this device "
4641 "with vfn number nr_vf:%d\n", nr_vfn);
4642 return rc;
4643}
4644
4645/**
James Smart3772a992009-05-22 14:50:54 -04004646 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
4647 * @phba: pointer to lpfc hba data structure.
4648 *
4649 * This routine is invoked to set up the driver internal resources specific to
4650 * support the SLI-3 HBA device it attached to.
4651 *
4652 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004653 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004654 * other values - error
4655 **/
4656static int
4657lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
4658{
4659 struct lpfc_sli *psli;
James Smart912e3ac2011-05-24 11:42:11 -04004660 int rc;
dea31012005-04-17 16:05:31 -05004661
James Smart3772a992009-05-22 14:50:54 -04004662 /*
4663 * Initialize timers used by driver
4664 */
dea31012005-04-17 16:05:31 -05004665
James Smart3772a992009-05-22 14:50:54 -04004666 /* Heartbeat timer */
4667 init_timer(&phba->hb_tmofunc);
4668 phba->hb_tmofunc.function = lpfc_hb_timeout;
4669 phba->hb_tmofunc.data = (unsigned long)phba;
4670
4671 psli = &phba->sli;
4672 /* MBOX heartbeat timer */
4673 init_timer(&psli->mbox_tmo);
4674 psli->mbox_tmo.function = lpfc_mbox_timeout;
4675 psli->mbox_tmo.data = (unsigned long) phba;
4676 /* FCP polling mode timer */
4677 init_timer(&phba->fcp_poll_timer);
4678 phba->fcp_poll_timer.function = lpfc_poll_timeout;
4679 phba->fcp_poll_timer.data = (unsigned long) phba;
4680 /* Fabric block timer */
4681 init_timer(&phba->fabric_block_timer);
4682 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
4683 phba->fabric_block_timer.data = (unsigned long) phba;
4684 /* EA polling mode timer */
4685 init_timer(&phba->eratt_poll);
4686 phba->eratt_poll.function = lpfc_poll_eratt;
4687 phba->eratt_poll.data = (unsigned long) phba;
4688
4689 /* Host attention work mask setup */
4690 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
4691 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
4692
4693 /* Get all the module params for configuring this host */
4694 lpfc_get_cfgparam(phba);
James Smart49198b32010-04-06 15:04:33 -04004695 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
4696 phba->menlo_flag |= HBA_MENLO_SUPPORT;
4697 /* check for menlo minimum sg count */
4698 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
4699 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
4700 }
4701
James Smart2a76a282012-08-03 12:35:54 -04004702 if (!phba->sli.ring)
4703 phba->sli.ring = (struct lpfc_sli_ring *)
4704 kzalloc(LPFC_SLI3_MAX_RING *
4705 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
4706 if (!phba->sli.ring)
4707 return -ENOMEM;
4708
James Smart3772a992009-05-22 14:50:54 -04004709 /*
4710 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
4711 * used to create the sg_dma_buf_pool must be dynamically calculated.
4712 * 2 segments are added since the IOCB needs a command and response bde.
4713 */
4714 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
4715 sizeof(struct fcp_rsp) +
4716 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
4717
4718 if (phba->cfg_enable_bg) {
4719 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT;
4720 phba->cfg_sg_dma_buf_size +=
4721 phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64);
4722 }
4723
4724 /* Also reinitialize the host templates with new values. */
4725 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4726 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4727
4728 phba->max_vpi = LPFC_MAX_VPI;
4729 /* This will be set to correct value after config_port mbox */
4730 phba->max_vports = 0;
4731
4732 /*
4733 * Initialize the SLI Layer to run with lpfc HBAs.
4734 */
4735 lpfc_sli_setup(phba);
4736 lpfc_sli_queue_setup(phba);
4737
4738 /* Allocate device driver memory */
4739 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
4740 return -ENOMEM;
4741
James Smart912e3ac2011-05-24 11:42:11 -04004742 /*
4743 * Enable sr-iov virtual functions if supported and configured
4744 * through the module parameter.
4745 */
4746 if (phba->cfg_sriov_nr_virtfn > 0) {
4747 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
4748 phba->cfg_sriov_nr_virtfn);
4749 if (rc) {
4750 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4751 "2808 Requested number of SR-IOV "
4752 "virtual functions (%d) is not "
4753 "supported\n",
4754 phba->cfg_sriov_nr_virtfn);
4755 phba->cfg_sriov_nr_virtfn = 0;
4756 }
4757 }
4758
James Smart3772a992009-05-22 14:50:54 -04004759 return 0;
4760}
4761
4762/**
4763 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
4764 * @phba: pointer to lpfc hba data structure.
4765 *
4766 * This routine is invoked to unset the driver internal resources set up
4767 * specific for supporting the SLI-3 HBA device it attached to.
4768 **/
4769static void
4770lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
4771{
4772 /* Free device driver memory allocated */
4773 lpfc_mem_free_all(phba);
4774
4775 return;
4776}
4777
4778/**
James Smartda0436e2009-05-22 14:51:39 -04004779 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
4780 * @phba: pointer to lpfc hba data structure.
4781 *
4782 * This routine is invoked to set up the driver internal resources specific to
4783 * support the SLI-4 HBA device it attached to.
4784 *
4785 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004786 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04004787 * other values - error
4788 **/
4789static int
4790lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
4791{
4792 struct lpfc_sli *psli;
James Smart28baac72010-02-12 14:42:03 -05004793 LPFC_MBOXQ_t *mboxq;
4794 int rc, i, hbq_count, buf_size, dma_buf_size, max_buf_size;
4795 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
4796 struct lpfc_mqe *mqe;
James Smart085c6472010-11-20 23:11:37 -05004797 int longs, sli_family;
James Smartacd68592012-01-18 16:25:09 -05004798 int sges_per_segment;
James Smartda0436e2009-05-22 14:51:39 -04004799
4800 /* Before proceed, wait for POST done and device ready */
4801 rc = lpfc_sli4_post_status_check(phba);
4802 if (rc)
4803 return -ENODEV;
4804
4805 /*
4806 * Initialize timers used by driver
4807 */
4808
4809 /* Heartbeat timer */
4810 init_timer(&phba->hb_tmofunc);
4811 phba->hb_tmofunc.function = lpfc_hb_timeout;
4812 phba->hb_tmofunc.data = (unsigned long)phba;
James Smart19ca7602010-11-20 23:11:55 -05004813 init_timer(&phba->rrq_tmr);
4814 phba->rrq_tmr.function = lpfc_rrq_timeout;
4815 phba->rrq_tmr.data = (unsigned long)phba;
James Smartda0436e2009-05-22 14:51:39 -04004816
4817 psli = &phba->sli;
4818 /* MBOX heartbeat timer */
4819 init_timer(&psli->mbox_tmo);
4820 psli->mbox_tmo.function = lpfc_mbox_timeout;
4821 psli->mbox_tmo.data = (unsigned long) phba;
4822 /* Fabric block timer */
4823 init_timer(&phba->fabric_block_timer);
4824 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
4825 phba->fabric_block_timer.data = (unsigned long) phba;
4826 /* EA polling mode timer */
4827 init_timer(&phba->eratt_poll);
4828 phba->eratt_poll.function = lpfc_poll_eratt;
4829 phba->eratt_poll.data = (unsigned long) phba;
James Smartecfd03c2010-02-12 14:41:27 -05004830 /* FCF rediscover timer */
4831 init_timer(&phba->fcf.redisc_wait);
4832 phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
4833 phba->fcf.redisc_wait.data = (unsigned long)phba;
4834
James Smartda0436e2009-05-22 14:51:39 -04004835 /*
James Smart7ad20aa2011-05-24 11:44:28 -04004836 * Control structure for handling external multi-buffer mailbox
4837 * command pass-through.
4838 */
4839 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
4840 sizeof(struct lpfc_mbox_ext_buf_ctx));
4841 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
4842
4843 /*
James Smartda0436e2009-05-22 14:51:39 -04004844 * We need to do a READ_CONFIG mailbox command here before
4845 * calling lpfc_get_cfgparam. For VFs this will report the
4846 * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings.
4847 * All of the resources allocated
4848 * for this Port are tied to these values.
4849 */
4850 /* Get all the module params for configuring this host */
4851 lpfc_get_cfgparam(phba);
4852 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04004853
4854 /* Eventually cfg_fcp_eq_count / cfg_fcp_wq_count will be depricated */
4855 phba->cfg_fcp_io_channel = phba->cfg_fcp_eq_count;
4856
James Smartda0436e2009-05-22 14:51:39 -04004857 /* This will be set to correct value after the read_config mbox */
4858 phba->max_vports = 0;
4859
4860 /* Program the default value of vlan_id and fc_map */
4861 phba->valid_vlan = 0;
4862 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
4863 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
4864 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
4865
James Smartacd68592012-01-18 16:25:09 -05004866 /* With BlockGuard we can have multiple SGEs per Data Segemnt */
4867 sges_per_segment = 1;
4868 if (phba->cfg_enable_bg)
4869 sges_per_segment = 2;
4870
James Smartda0436e2009-05-22 14:51:39 -04004871 /*
James Smart2a76a282012-08-03 12:35:54 -04004872 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
4873 * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple.
4874 */
4875 if (!phba->sli.ring)
4876 phba->sli.ring = kzalloc(
James Smart67d12732012-08-03 12:36:13 -04004877 (LPFC_SLI3_MAX_RING + phba->cfg_fcp_io_channel) *
James Smart2a76a282012-08-03 12:35:54 -04004878 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
4879 if (!phba->sli.ring)
4880 return -ENOMEM;
4881 /*
James Smartda0436e2009-05-22 14:51:39 -04004882 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
4883 * used to create the sg_dma_buf_pool must be dynamically calculated.
4884 * 2 segments are added since the IOCB needs a command and response bde.
4885 * To insure that the scsi sgl does not cross a 4k page boundary only
James Smart28baac72010-02-12 14:42:03 -05004886 * sgl sizes of must be a power of 2.
James Smartda0436e2009-05-22 14:51:39 -04004887 */
James Smart28baac72010-02-12 14:42:03 -05004888 buf_size = (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp) +
James Smartacd68592012-01-18 16:25:09 -05004889 (((phba->cfg_sg_seg_cnt * sges_per_segment) + 2) *
4890 sizeof(struct sli4_sge)));
James Smart085c6472010-11-20 23:11:37 -05004891
4892 sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf);
4893 max_buf_size = LPFC_SLI4_MAX_BUF_SIZE;
4894 switch (sli_family) {
4895 case LPFC_SLI_INTF_FAMILY_BE2:
4896 case LPFC_SLI_INTF_FAMILY_BE3:
4897 /* There is a single hint for BE - 2 pages per BPL. */
4898 if (bf_get(lpfc_sli_intf_sli_hint1, &phba->sli4_hba.sli_intf) ==
4899 LPFC_SLI_INTF_SLI_HINT1_1)
4900 max_buf_size = LPFC_SLI4_FL1_MAX_BUF_SIZE;
4901 break;
4902 case LPFC_SLI_INTF_FAMILY_LNCR_A0:
4903 case LPFC_SLI_INTF_FAMILY_LNCR_B0:
4904 default:
4905 break;
4906 }
James Smartacd68592012-01-18 16:25:09 -05004907
James Smart28baac72010-02-12 14:42:03 -05004908 for (dma_buf_size = LPFC_SLI4_MIN_BUF_SIZE;
4909 dma_buf_size < max_buf_size && buf_size > dma_buf_size;
4910 dma_buf_size = dma_buf_size << 1)
4911 ;
4912 if (dma_buf_size == max_buf_size)
4913 phba->cfg_sg_seg_cnt = (dma_buf_size -
4914 sizeof(struct fcp_cmnd) - sizeof(struct fcp_rsp) -
4915 (2 * sizeof(struct sli4_sge))) /
4916 sizeof(struct sli4_sge);
4917 phba->cfg_sg_dma_buf_size = dma_buf_size;
James Smartda0436e2009-05-22 14:51:39 -04004918
4919 /* Initialize buffer queue management fields */
4920 hbq_count = lpfc_sli_hbq_count();
4921 for (i = 0; i < hbq_count; ++i)
4922 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
4923 INIT_LIST_HEAD(&phba->rb_pend_list);
4924 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
4925 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
4926
4927 /*
4928 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
4929 */
4930 /* Initialize the Abort scsi buffer list used by driver */
4931 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
4932 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
4933 /* This abort list used by worker thread */
4934 spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
4935
4936 /*
James Smart6d368e52011-05-24 11:44:12 -04004937 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04004938 */
4939
4940 /* Driver internel slow-path CQ Event pool */
4941 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
4942 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04004943 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04004944 /* Asynchronous event CQ Event work queue list */
4945 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
4946 /* Fast-path XRI aborted CQ Event work queue list */
4947 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
4948 /* Slow-path XRI aborted CQ Event work queue list */
4949 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
4950 /* Receive queue CQ Event work queue list */
4951 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
4952
James Smart6d368e52011-05-24 11:44:12 -04004953 /* Initialize extent block lists. */
4954 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
4955 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
4956 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
4957 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
4958
James Smartda0436e2009-05-22 14:51:39 -04004959 /* Initialize the driver internal SLI layer lists. */
4960 lpfc_sli_setup(phba);
4961 lpfc_sli_queue_setup(phba);
4962
4963 /* Allocate device driver memory */
4964 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
4965 if (rc)
4966 return -ENOMEM;
4967
James Smart2fcee4b2010-12-15 17:57:46 -05004968 /* IF Type 2 ports get initialized now. */
4969 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
4970 LPFC_SLI_INTF_IF_TYPE_2) {
4971 rc = lpfc_pci_function_reset(phba);
4972 if (unlikely(rc))
4973 return -ENODEV;
4974 }
4975
James Smartda0436e2009-05-22 14:51:39 -04004976 /* Create the bootstrap mailbox command */
4977 rc = lpfc_create_bootstrap_mbox(phba);
4978 if (unlikely(rc))
4979 goto out_free_mem;
4980
4981 /* Set up the host's endian order with the device. */
4982 rc = lpfc_setup_endian_order(phba);
4983 if (unlikely(rc))
4984 goto out_free_bsmbx;
4985
4986 /* Set up the hba's configuration parameters. */
4987 rc = lpfc_sli4_read_config(phba);
4988 if (unlikely(rc))
4989 goto out_free_bsmbx;
4990
James Smart2fcee4b2010-12-15 17:57:46 -05004991 /* IF Type 0 ports get initialized now. */
4992 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
4993 LPFC_SLI_INTF_IF_TYPE_0) {
4994 rc = lpfc_pci_function_reset(phba);
4995 if (unlikely(rc))
4996 goto out_free_bsmbx;
4997 }
James Smartda0436e2009-05-22 14:51:39 -04004998
James Smartcb5172e2010-03-15 11:25:07 -04004999 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
5000 GFP_KERNEL);
5001 if (!mboxq) {
5002 rc = -ENOMEM;
5003 goto out_free_bsmbx;
5004 }
5005
James Smartfedd3b72011-02-16 12:39:24 -05005006 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04005007 lpfc_supported_pages(mboxq);
5008 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05005009 if (!rc) {
5010 mqe = &mboxq->u.mqe;
5011 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
5012 LPFC_MAX_SUPPORTED_PAGES);
5013 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
5014 switch (pn_page[i]) {
5015 case LPFC_SLI4_PARAMETERS:
5016 phba->sli4_hba.pc_sli4_params.supported = 1;
5017 break;
5018 default:
5019 break;
5020 }
5021 }
5022 /* Read the port's SLI4 Parameters capabilities if supported. */
5023 if (phba->sli4_hba.pc_sli4_params.supported)
5024 rc = lpfc_pc_sli4_params_get(phba, mboxq);
5025 if (rc) {
5026 mempool_free(mboxq, phba->mbox_mem_pool);
5027 rc = -EIO;
5028 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04005029 }
5030 }
James Smartfedd3b72011-02-16 12:39:24 -05005031 /*
5032 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04005033 * If this call fails, it isn't critical unless the SLI4 parameters come
5034 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05005035 */
James Smart6d368e52011-05-24 11:44:12 -04005036 rc = lpfc_get_sli4_parameters(phba, mboxq);
5037 if (rc) {
5038 if (phba->sli4_hba.extents_in_use &&
5039 phba->sli4_hba.rpi_hdrs_in_use) {
5040 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5041 "2999 Unsupported SLI4 Parameters "
5042 "Extents and RPI headers enabled.\n");
5043 goto out_free_bsmbx;
5044 }
5045 }
James Smartcb5172e2010-03-15 11:25:07 -04005046 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart5350d872011-10-10 21:33:49 -04005047 /* Verify all the SLI4 queues */
5048 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04005049 if (rc)
5050 goto out_free_bsmbx;
5051
5052 /* Create driver internal CQE event pool */
5053 rc = lpfc_sli4_cq_event_pool_create(phba);
5054 if (rc)
James Smart5350d872011-10-10 21:33:49 -04005055 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005056
James Smart8a9d2e82012-05-09 21:16:12 -04005057 /* Initialize sgl lists per host */
5058 lpfc_init_sgl_list(phba);
5059
5060 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04005061 rc = lpfc_init_active_sgl_array(phba);
5062 if (rc) {
5063 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5064 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04005065 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04005066 }
James Smartda0436e2009-05-22 14:51:39 -04005067 rc = lpfc_sli4_init_rpi_hdrs(phba);
5068 if (rc) {
5069 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5070 "1432 Failed to initialize rpi headers.\n");
5071 goto out_free_active_sgl;
5072 }
5073
James Smarta93ff372010-10-22 11:06:08 -04005074 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05005075 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
5076 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
5077 GFP_KERNEL);
5078 if (!phba->fcf.fcf_rr_bmask) {
5079 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5080 "2759 Failed allocate memory for FCF round "
5081 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04005082 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05005083 goto out_remove_rpi_hdrs;
5084 }
5085
James Smart67d12732012-08-03 12:36:13 -04005086 phba->sli4_hba.fcp_eq_hdl =
5087 kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
5088 phba->cfg_fcp_io_channel), GFP_KERNEL);
5089 if (!phba->sli4_hba.fcp_eq_hdl) {
5090 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5091 "2572 Failed allocate memory for "
5092 "fast-path per-EQ handle array\n");
5093 rc = -ENOMEM;
5094 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04005095 }
5096
5097 phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
James Smart82c3e9b2012-09-29 11:29:50 -04005098 phba->cfg_fcp_io_channel), GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04005099 if (!phba->sli4_hba.msix_entries) {
5100 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5101 "2573 Failed allocate memory for msi-x "
5102 "interrupt vector entries\n");
James Smart05580562011-05-24 11:40:48 -04005103 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04005104 goto out_free_fcp_eq_hdl;
5105 }
5106
James Smart912e3ac2011-05-24 11:42:11 -04005107 /*
5108 * Enable sr-iov virtual functions if supported and configured
5109 * through the module parameter.
5110 */
5111 if (phba->cfg_sriov_nr_virtfn > 0) {
5112 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5113 phba->cfg_sriov_nr_virtfn);
5114 if (rc) {
5115 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5116 "3020 Requested number of SR-IOV "
5117 "virtual functions (%d) is not "
5118 "supported\n",
5119 phba->cfg_sriov_nr_virtfn);
5120 phba->cfg_sriov_nr_virtfn = 0;
5121 }
5122 }
5123
James Smart5248a742011-07-22 18:37:06 -04005124 return 0;
James Smartda0436e2009-05-22 14:51:39 -04005125
5126out_free_fcp_eq_hdl:
5127 kfree(phba->sli4_hba.fcp_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05005128out_free_fcf_rr_bmask:
5129 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04005130out_remove_rpi_hdrs:
5131 lpfc_sli4_remove_rpi_hdrs(phba);
5132out_free_active_sgl:
5133 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04005134out_destroy_cq_event_pool:
5135 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04005136out_free_bsmbx:
5137 lpfc_destroy_bootstrap_mbox(phba);
5138out_free_mem:
5139 lpfc_mem_free(phba);
5140 return rc;
5141}
5142
5143/**
5144 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
5145 * @phba: pointer to lpfc hba data structure.
5146 *
5147 * This routine is invoked to unset the driver internal resources set up
5148 * specific for supporting the SLI-4 HBA device it attached to.
5149 **/
5150static void
5151lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
5152{
5153 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
5154
James Smartda0436e2009-05-22 14:51:39 -04005155 /* Free memory allocated for msi-x interrupt vector entries */
5156 kfree(phba->sli4_hba.msix_entries);
5157
5158 /* Free memory allocated for fast-path work queue handles */
5159 kfree(phba->sli4_hba.fcp_eq_hdl);
5160
5161 /* Free the allocated rpi headers. */
5162 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04005163 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04005164
James Smart0c9ab6f2010-02-26 14:15:57 -05005165 /* Free eligible FCF index bmask */
5166 kfree(phba->fcf.fcf_rr_bmask);
5167
James Smartda0436e2009-05-22 14:51:39 -04005168 /* Free the ELS sgl list */
5169 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04005170 lpfc_free_els_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04005171
James Smartda0436e2009-05-22 14:51:39 -04005172 /* Free the completion queue EQ event pool */
5173 lpfc_sli4_cq_event_release_all(phba);
5174 lpfc_sli4_cq_event_pool_destroy(phba);
5175
James Smart6d368e52011-05-24 11:44:12 -04005176 /* Release resource identifiers. */
5177 lpfc_sli4_dealloc_resource_identifiers(phba);
5178
James Smartda0436e2009-05-22 14:51:39 -04005179 /* Free the bsmbx region. */
5180 lpfc_destroy_bootstrap_mbox(phba);
5181
5182 /* Free the SLI Layer memory with SLI4 HBAs */
5183 lpfc_mem_free_all(phba);
5184
5185 /* Free the current connect table */
5186 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04005187 &phba->fcf_conn_rec_list, list) {
5188 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04005189 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04005190 }
James Smartda0436e2009-05-22 14:51:39 -04005191
5192 return;
5193}
5194
5195/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005196 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04005197 * @phba: The hba struct for which this call is being executed.
5198 * @dev_grp: The HBA PCI-Device group number.
5199 *
5200 * This routine sets up the device INIT interface API function jump table
5201 * in @phba struct.
5202 *
5203 * Returns: 0 - success, -ENODEV - failure.
5204 **/
5205int
5206lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5207{
James Smart84d1b002010-02-12 14:42:33 -05005208 phba->lpfc_hba_init_link = lpfc_hba_init_link;
5209 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05005210 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04005211 switch (dev_grp) {
5212 case LPFC_PCI_DEV_LP:
5213 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
5214 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
5215 phba->lpfc_stop_port = lpfc_stop_port_s3;
5216 break;
James Smartda0436e2009-05-22 14:51:39 -04005217 case LPFC_PCI_DEV_OC:
5218 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
5219 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
5220 phba->lpfc_stop_port = lpfc_stop_port_s4;
5221 break;
James Smart3772a992009-05-22 14:50:54 -04005222 default:
5223 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5224 "1431 Invalid HBA PCI-device group: 0x%x\n",
5225 dev_grp);
5226 return -ENODEV;
5227 break;
5228 }
5229 return 0;
5230}
5231
5232/**
5233 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
5234 * @phba: pointer to lpfc hba data structure.
5235 *
5236 * This routine is invoked to set up the driver internal resources before the
5237 * device specific resource setup to support the HBA device it attached to.
5238 *
5239 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005240 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005241 * other values - error
5242 **/
5243static int
5244lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
5245{
5246 /*
5247 * Driver resources common to all SLI revisions
5248 */
James Smartea2151b2008-09-07 11:52:10 -04005249 atomic_set(&phba->fast_event_count, 0);
James Smart2e0fef82007-06-17 19:56:36 -05005250 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005251
James Smarte47c9092008-02-08 18:49:26 -05005252 /* Initialize ndlp management spinlock */
5253 spin_lock_init(&phba->ndlp_lock);
5254
James Smart2e0fef82007-06-17 19:56:36 -05005255 INIT_LIST_HEAD(&phba->port_list);
James Smart3772a992009-05-22 14:50:54 -04005256 INIT_LIST_HEAD(&phba->work_list);
James Smart84774a42008-08-24 21:50:06 -04005257 init_waitqueue_head(&phba->wait_4_mlo_m_q);
dea31012005-04-17 16:05:31 -05005258
James Smart3772a992009-05-22 14:50:54 -04005259 /* Initialize the wait queue head for the kernel thread */
5260 init_waitqueue_head(&phba->work_waitq);
James Smart858c9f62007-06-17 19:56:39 -05005261
James Smart3772a992009-05-22 14:50:54 -04005262 /* Initialize the scsi buffer list used by driver for scsi IO */
5263 spin_lock_init(&phba->scsi_buf_list_lock);
5264 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
dea31012005-04-17 16:05:31 -05005265
James Smart3772a992009-05-22 14:50:54 -04005266 /* Initialize the fabric iocb list */
5267 INIT_LIST_HEAD(&phba->fabric_iocb_list);
dea31012005-04-17 16:05:31 -05005268
James Smart3772a992009-05-22 14:50:54 -04005269 /* Initialize list to save ELS buffers */
5270 INIT_LIST_HEAD(&phba->elsbuf);
dea31012005-04-17 16:05:31 -05005271
James Smart3772a992009-05-22 14:50:54 -04005272 /* Initialize FCF connection rec list */
5273 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
dea31012005-04-17 16:05:31 -05005274
James Smart3772a992009-05-22 14:50:54 -04005275 return 0;
5276}
dea31012005-04-17 16:05:31 -05005277
James Smart3772a992009-05-22 14:50:54 -04005278/**
5279 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
5280 * @phba: pointer to lpfc hba data structure.
5281 *
5282 * This routine is invoked to set up the driver internal resources after the
5283 * device specific resource setup to support the HBA device it attached to.
5284 *
5285 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005286 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005287 * other values - error
5288 **/
5289static int
5290lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
5291{
5292 int error;
5293
5294 /* Startup the kernel thread for this host adapter. */
5295 phba->worker_thread = kthread_run(lpfc_do_work, phba,
5296 "lpfc_worker_%d", phba->brd_no);
5297 if (IS_ERR(phba->worker_thread)) {
5298 error = PTR_ERR(phba->worker_thread);
5299 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005300 }
5301
James Smart3772a992009-05-22 14:50:54 -04005302 return 0;
5303}
5304
5305/**
5306 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
5307 * @phba: pointer to lpfc hba data structure.
5308 *
5309 * This routine is invoked to unset the driver internal resources set up after
5310 * the device specific resource setup for supporting the HBA device it
5311 * attached to.
5312 **/
5313static void
5314lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
5315{
5316 /* Stop kernel worker thread */
5317 kthread_stop(phba->worker_thread);
5318}
5319
5320/**
5321 * lpfc_free_iocb_list - Free iocb list.
5322 * @phba: pointer to lpfc hba data structure.
5323 *
5324 * This routine is invoked to free the driver's IOCB list and memory.
5325 **/
5326static void
5327lpfc_free_iocb_list(struct lpfc_hba *phba)
5328{
5329 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
5330
5331 spin_lock_irq(&phba->hbalock);
5332 list_for_each_entry_safe(iocbq_entry, iocbq_next,
5333 &phba->lpfc_iocb_list, list) {
5334 list_del(&iocbq_entry->list);
5335 kfree(iocbq_entry);
5336 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005337 }
James Smart3772a992009-05-22 14:50:54 -04005338 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005339
James Smart3772a992009-05-22 14:50:54 -04005340 return;
5341}
dea31012005-04-17 16:05:31 -05005342
James Smart3772a992009-05-22 14:50:54 -04005343/**
5344 * lpfc_init_iocb_list - Allocate and initialize iocb list.
5345 * @phba: pointer to lpfc hba data structure.
5346 *
5347 * This routine is invoked to allocate and initizlize the driver's IOCB
5348 * list and set up the IOCB tag array accordingly.
5349 *
5350 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005351 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005352 * other values - error
5353 **/
5354static int
5355lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
5356{
5357 struct lpfc_iocbq *iocbq_entry = NULL;
5358 uint16_t iotag;
5359 int i;
dea31012005-04-17 16:05:31 -05005360
5361 /* Initialize and populate the iocb list per host. */
5362 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04005363 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07005364 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05005365 if (iocbq_entry == NULL) {
5366 printk(KERN_ERR "%s: only allocated %d iocbs of "
5367 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07005368 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05005369 goto out_free_iocbq;
5370 }
5371
James Bottomley604a3e32005-10-29 10:28:33 -05005372 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
5373 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04005374 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05005375 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04005376 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05005377 goto out_free_iocbq;
5378 }
James Smart6d368e52011-05-24 11:44:12 -04005379 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04005380 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05005381
5382 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005383 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
5384 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05005385 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005386 }
5387
James Smart3772a992009-05-22 14:50:54 -04005388 return 0;
5389
5390out_free_iocbq:
5391 lpfc_free_iocb_list(phba);
5392
5393 return -ENOMEM;
5394}
5395
5396/**
James Smart8a9d2e82012-05-09 21:16:12 -04005397 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04005398 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04005399 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04005400 *
James Smart8a9d2e82012-05-09 21:16:12 -04005401 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04005402 **/
James Smart8a9d2e82012-05-09 21:16:12 -04005403void
5404lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04005405{
5406 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04005407
5408 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
5409 list_del(&sglq_entry->list);
5410 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
5411 kfree(sglq_entry);
5412 }
5413}
5414
5415/**
5416 * lpfc_free_els_sgl_list - Free els sgl list.
5417 * @phba: pointer to lpfc hba data structure.
5418 *
5419 * This routine is invoked to free the driver's els sgl list and memory.
5420 **/
5421static void
5422lpfc_free_els_sgl_list(struct lpfc_hba *phba)
5423{
James Smartda0436e2009-05-22 14:51:39 -04005424 LIST_HEAD(sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04005425
James Smart8a9d2e82012-05-09 21:16:12 -04005426 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04005427 spin_lock_irq(&phba->hbalock);
5428 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
5429 spin_unlock_irq(&phba->hbalock);
5430
James Smart8a9d2e82012-05-09 21:16:12 -04005431 /* Now free the sgl list */
5432 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04005433}
5434
5435/**
5436 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
5437 * @phba: pointer to lpfc hba data structure.
5438 *
5439 * This routine is invoked to allocate the driver's active sgl memory.
5440 * This array will hold the sglq_entry's for active IOs.
5441 **/
5442static int
5443lpfc_init_active_sgl_array(struct lpfc_hba *phba)
5444{
5445 int size;
5446 size = sizeof(struct lpfc_sglq *);
5447 size *= phba->sli4_hba.max_cfg_param.max_xri;
5448
5449 phba->sli4_hba.lpfc_sglq_active_list =
5450 kzalloc(size, GFP_KERNEL);
5451 if (!phba->sli4_hba.lpfc_sglq_active_list)
5452 return -ENOMEM;
5453 return 0;
5454}
5455
5456/**
5457 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
5458 * @phba: pointer to lpfc hba data structure.
5459 *
5460 * This routine is invoked to walk through the array of active sglq entries
5461 * and free all of the resources.
5462 * This is just a place holder for now.
5463 **/
5464static void
5465lpfc_free_active_sgl(struct lpfc_hba *phba)
5466{
5467 kfree(phba->sli4_hba.lpfc_sglq_active_list);
5468}
5469
5470/**
5471 * lpfc_init_sgl_list - Allocate and initialize sgl list.
5472 * @phba: pointer to lpfc hba data structure.
5473 *
5474 * This routine is invoked to allocate and initizlize the driver's sgl
5475 * list and set up the sgl xritag tag array accordingly.
5476 *
James Smartda0436e2009-05-22 14:51:39 -04005477 **/
James Smart8a9d2e82012-05-09 21:16:12 -04005478static void
James Smartda0436e2009-05-22 14:51:39 -04005479lpfc_init_sgl_list(struct lpfc_hba *phba)
5480{
James Smartda0436e2009-05-22 14:51:39 -04005481 /* Initialize and populate the sglq list per host/VF. */
5482 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
5483 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
5484
James Smart8a9d2e82012-05-09 21:16:12 -04005485 /* els xri-sgl book keeping */
5486 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04005487
James Smart8a9d2e82012-05-09 21:16:12 -04005488 /* scsi xri-buffer book keeping */
James Smartda0436e2009-05-22 14:51:39 -04005489 phba->sli4_hba.scsi_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04005490}
5491
5492/**
5493 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
5494 * @phba: pointer to lpfc hba data structure.
5495 *
5496 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04005497 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04005498 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04005499 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
5500 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04005501 *
5502 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005503 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04005504 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04005505 **/
5506int
5507lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
5508{
5509 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04005510 struct lpfc_rpi_hdr *rpi_hdr;
5511
5512 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05005513 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04005514 return rc;
James Smart6d368e52011-05-24 11:44:12 -04005515 if (phba->sli4_hba.extents_in_use)
5516 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04005517
5518 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
5519 if (!rpi_hdr) {
5520 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5521 "0391 Error during rpi post operation\n");
5522 lpfc_sli4_remove_rpis(phba);
5523 rc = -ENODEV;
5524 }
5525
5526 return rc;
5527}
5528
5529/**
5530 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
5531 * @phba: pointer to lpfc hba data structure.
5532 *
5533 * This routine is invoked to allocate a single 4KB memory region to
5534 * support rpis and stores them in the phba. This single region
5535 * provides support for up to 64 rpis. The region is used globally
5536 * by the device.
5537 *
5538 * Returns:
5539 * A valid rpi hdr on success.
5540 * A NULL pointer on any failure.
5541 **/
5542struct lpfc_rpi_hdr *
5543lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
5544{
5545 uint16_t rpi_limit, curr_rpi_range;
5546 struct lpfc_dmabuf *dmabuf;
5547 struct lpfc_rpi_hdr *rpi_hdr;
James Smart9589b0622011-04-16 11:03:17 -04005548 uint32_t rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04005549
James Smart6d368e52011-05-24 11:44:12 -04005550 /*
5551 * If the SLI4 port supports extents, posting the rpi header isn't
5552 * required. Set the expected maximum count and let the actual value
5553 * get set when extents are fully allocated.
5554 */
5555 if (!phba->sli4_hba.rpi_hdrs_in_use)
5556 return NULL;
5557 if (phba->sli4_hba.extents_in_use)
5558 return NULL;
5559
5560 /* The limit on the logical index is just the max_rpi count. */
James Smartda0436e2009-05-22 14:51:39 -04005561 rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
James Smart6d368e52011-05-24 11:44:12 -04005562 phba->sli4_hba.max_cfg_param.max_rpi - 1;
James Smartda0436e2009-05-22 14:51:39 -04005563
5564 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04005565 /*
5566 * Establish the starting RPI in this header block. The starting
5567 * rpi is normalized to a zero base because the physical rpi is
5568 * port based.
5569 */
James Smart97f2ecf2012-03-01 22:35:23 -05005570 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04005571 spin_unlock_irq(&phba->hbalock);
5572
5573 /*
5574 * The port has a limited number of rpis. The increment here
5575 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
5576 * and to allow the full max_rpi range per port.
5577 */
5578 if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
James Smart9589b0622011-04-16 11:03:17 -04005579 rpi_count = rpi_limit - curr_rpi_range;
5580 else
5581 rpi_count = LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04005582
James Smart6d368e52011-05-24 11:44:12 -04005583 if (!rpi_count)
5584 return NULL;
James Smartda0436e2009-05-22 14:51:39 -04005585 /*
5586 * First allocate the protocol header region for the port. The
5587 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
5588 */
5589 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5590 if (!dmabuf)
5591 return NULL;
5592
5593 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
5594 LPFC_HDR_TEMPLATE_SIZE,
5595 &dmabuf->phys,
5596 GFP_KERNEL);
5597 if (!dmabuf->virt) {
5598 rpi_hdr = NULL;
5599 goto err_free_dmabuf;
5600 }
5601
5602 memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE);
5603 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
5604 rpi_hdr = NULL;
5605 goto err_free_coherent;
5606 }
5607
5608 /* Save the rpi header data for cleanup later. */
5609 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
5610 if (!rpi_hdr)
5611 goto err_free_coherent;
5612
5613 rpi_hdr->dmabuf = dmabuf;
5614 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
5615 rpi_hdr->page_count = 1;
5616 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04005617
5618 /* The rpi_hdr stores the logical index only. */
5619 rpi_hdr->start_rpi = curr_rpi_range;
James Smartda0436e2009-05-22 14:51:39 -04005620 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
5621
5622 /*
James Smart6d368e52011-05-24 11:44:12 -04005623 * The next_rpi stores the next logical module-64 rpi value used
5624 * to post physical rpis in subsequent rpi postings.
James Smartda0436e2009-05-22 14:51:39 -04005625 */
James Smart9589b0622011-04-16 11:03:17 -04005626 phba->sli4_hba.next_rpi += rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04005627 spin_unlock_irq(&phba->hbalock);
5628 return rpi_hdr;
5629
5630 err_free_coherent:
5631 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
5632 dmabuf->virt, dmabuf->phys);
5633 err_free_dmabuf:
5634 kfree(dmabuf);
5635 return NULL;
5636}
5637
5638/**
5639 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
5640 * @phba: pointer to lpfc hba data structure.
5641 *
5642 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04005643 * to support rpis for SLI4 ports not supporting extents. This routine
5644 * presumes the caller has released all rpis consumed by fabric or port
5645 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04005646 **/
5647void
5648lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
5649{
5650 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
5651
James Smart6d368e52011-05-24 11:44:12 -04005652 if (!phba->sli4_hba.rpi_hdrs_in_use)
5653 goto exit;
5654
James Smartda0436e2009-05-22 14:51:39 -04005655 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
5656 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
5657 list_del(&rpi_hdr->list);
5658 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
5659 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
5660 kfree(rpi_hdr->dmabuf);
5661 kfree(rpi_hdr);
5662 }
James Smart6d368e52011-05-24 11:44:12 -04005663 exit:
5664 /* There are no rpis available to the port now. */
5665 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04005666}
5667
5668/**
James Smart3772a992009-05-22 14:50:54 -04005669 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
5670 * @pdev: pointer to pci device data structure.
5671 *
5672 * This routine is invoked to allocate the driver hba data structure for an
5673 * HBA device. If the allocation is successful, the phba reference to the
5674 * PCI device data structure is set.
5675 *
5676 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005677 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04005678 * NULL - error
5679 **/
5680static struct lpfc_hba *
5681lpfc_hba_alloc(struct pci_dev *pdev)
5682{
5683 struct lpfc_hba *phba;
5684
5685 /* Allocate memory for HBA structure */
5686 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
5687 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02005688 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04005689 return NULL;
5690 }
5691
5692 /* Set reference to PCI device in HBA structure */
5693 phba->pcidev = pdev;
5694
5695 /* Assign an unused board number */
5696 phba->brd_no = lpfc_get_instance();
5697 if (phba->brd_no < 0) {
5698 kfree(phba);
5699 return NULL;
5700 }
5701
James Smart4fede782010-01-26 23:08:55 -05005702 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04005703 INIT_LIST_HEAD(&phba->ct_ev_waiters);
5704
James Smart3772a992009-05-22 14:50:54 -04005705 return phba;
5706}
5707
5708/**
5709 * lpfc_hba_free - Free driver hba data structure with a device.
5710 * @phba: pointer to lpfc hba data structure.
5711 *
5712 * This routine is invoked to free the driver hba data structure with an
5713 * HBA device.
5714 **/
5715static void
5716lpfc_hba_free(struct lpfc_hba *phba)
5717{
5718 /* Release the driver assigned board number */
5719 idr_remove(&lpfc_hba_index, phba->brd_no);
5720
James Smart2a76a282012-08-03 12:35:54 -04005721 /* Free memory allocated with sli rings */
5722 kfree(phba->sli.ring);
5723 phba->sli.ring = NULL;
5724
James Smart3772a992009-05-22 14:50:54 -04005725 kfree(phba);
5726 return;
5727}
5728
5729/**
5730 * lpfc_create_shost - Create hba physical port with associated scsi host.
5731 * @phba: pointer to lpfc hba data structure.
5732 *
5733 * This routine is invoked to create HBA physical port and associate a SCSI
5734 * host with it.
5735 *
5736 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005737 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005738 * other values - error
5739 **/
5740static int
5741lpfc_create_shost(struct lpfc_hba *phba)
5742{
5743 struct lpfc_vport *vport;
5744 struct Scsi_Host *shost;
5745
5746 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05005747 phba->fc_edtov = FF_DEF_EDTOV;
5748 phba->fc_ratov = FF_DEF_RATOV;
5749 phba->fc_altov = FF_DEF_ALTOV;
5750 phba->fc_arbtov = FF_DEF_ARBTOV;
5751
James Smartd7c47992010-06-08 18:31:54 -04005752 atomic_set(&phba->sdev_cnt, 0);
James Smart3de2a652007-08-02 11:09:59 -04005753 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05005754 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04005755 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05005756
5757 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05005758 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05005759 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04005760 /* Put reference to SCSI host to driver's device private data */
5761 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05005762
James Smart3772a992009-05-22 14:50:54 -04005763 return 0;
5764}
dea31012005-04-17 16:05:31 -05005765
James Smart3772a992009-05-22 14:50:54 -04005766/**
5767 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
5768 * @phba: pointer to lpfc hba data structure.
5769 *
5770 * This routine is invoked to destroy HBA physical port and the associated
5771 * SCSI host.
5772 **/
5773static void
5774lpfc_destroy_shost(struct lpfc_hba *phba)
5775{
5776 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04005777
James Smart3772a992009-05-22 14:50:54 -04005778 /* Destroy physical port that associated with the SCSI host */
5779 destroy_port(vport);
5780
5781 return;
5782}
5783
5784/**
5785 * lpfc_setup_bg - Setup Block guard structures and debug areas.
5786 * @phba: pointer to lpfc hba data structure.
5787 * @shost: the shost to be used to detect Block guard settings.
5788 *
5789 * This routine sets up the local Block guard protocol settings for @shost.
5790 * This routine also allocates memory for debugging bg buffers.
5791 **/
5792static void
5793lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
5794{
James Smartbbeb79b2012-06-12 13:54:27 -04005795 uint32_t old_mask;
5796 uint32_t old_guard;
5797
James Smart3772a992009-05-22 14:50:54 -04005798 int pagecnt = 10;
5799 if (lpfc_prot_mask && lpfc_prot_guard) {
5800 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5801 "1478 Registering BlockGuard with the "
5802 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04005803
5804 old_mask = lpfc_prot_mask;
5805 old_guard = lpfc_prot_guard;
5806
5807 /* Only allow supported values */
5808 lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
5809 SHOST_DIX_TYPE0_PROTECTION |
5810 SHOST_DIX_TYPE1_PROTECTION);
5811 lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC);
5812
5813 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
5814 if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
5815 lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
5816
5817 if (lpfc_prot_mask && lpfc_prot_guard) {
5818 if ((old_mask != lpfc_prot_mask) ||
5819 (old_guard != lpfc_prot_guard))
5820 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5821 "1475 Registering BlockGuard with the "
5822 "SCSI layer: mask %d guard %d\n",
5823 lpfc_prot_mask, lpfc_prot_guard);
5824
5825 scsi_host_set_prot(shost, lpfc_prot_mask);
5826 scsi_host_set_guard(shost, lpfc_prot_guard);
5827 } else
5828 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5829 "1479 Not Registering BlockGuard with the SCSI "
5830 "layer, Bad protection parameters: %d %d\n",
5831 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04005832 }
James Smartbbeb79b2012-06-12 13:54:27 -04005833
James Smart81301a92008-12-04 22:39:46 -05005834 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05005835 while (pagecnt) {
5836 spin_lock_init(&_dump_buf_lock);
5837 _dump_buf_data =
5838 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
5839 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04005840 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5841 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04005842 "_dump_buf_data at 0x%p\n",
5843 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05005844 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04005845 memset(_dump_buf_data, 0,
5846 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05005847 break;
James Smart3772a992009-05-22 14:50:54 -04005848 } else
James Smart81301a92008-12-04 22:39:46 -05005849 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05005850 }
James Smart81301a92008-12-04 22:39:46 -05005851 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04005852 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5853 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04005854 "memory for hexdump\n");
5855 } else
James Smart6a9c52c2009-10-02 15:16:51 -04005856 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5857 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05005858 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05005859 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05005860 while (pagecnt) {
5861 _dump_buf_dif =
5862 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
5863 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04005864 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5865 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04005866 "_dump_buf_dif at 0x%p\n",
5867 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05005868 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04005869 memset(_dump_buf_dif, 0,
5870 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05005871 break;
James Smart3772a992009-05-22 14:50:54 -04005872 } else
James Smart81301a92008-12-04 22:39:46 -05005873 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05005874 }
James Smart81301a92008-12-04 22:39:46 -05005875 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04005876 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5877 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04005878 "memory for hexdump\n");
5879 } else
James Smart6a9c52c2009-10-02 15:16:51 -04005880 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5881 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04005882 _dump_buf_dif);
5883}
5884
5885/**
5886 * lpfc_post_init_setup - Perform necessary device post initialization setup.
5887 * @phba: pointer to lpfc hba data structure.
5888 *
5889 * This routine is invoked to perform all the necessary post initialization
5890 * setup for the device.
5891 **/
5892static void
5893lpfc_post_init_setup(struct lpfc_hba *phba)
5894{
5895 struct Scsi_Host *shost;
5896 struct lpfc_adapter_event_header adapter_event;
5897
5898 /* Get the default values for Model Name and Description */
5899 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
5900
5901 /*
5902 * hba setup may have changed the hba_queue_depth so we need to
5903 * adjust the value of can_queue.
5904 */
5905 shost = pci_get_drvdata(phba->pcidev);
5906 shost->can_queue = phba->cfg_hba_queue_depth - 10;
5907 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
5908 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05005909
5910 lpfc_host_attrib_init(shost);
5911
James Smart2e0fef82007-06-17 19:56:36 -05005912 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
5913 spin_lock_irq(shost->host_lock);
5914 lpfc_poll_start_timer(phba);
5915 spin_unlock_irq(shost->host_lock);
5916 }
James Smart8f6d98d2006-08-01 07:34:00 -04005917
James Smart93996272008-08-24 21:50:30 -04005918 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5919 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04005920 /* Send board arrival event to upper layer */
5921 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
5922 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
5923 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04005924 sizeof(adapter_event),
5925 (char *) &adapter_event,
5926 LPFC_NL_VENDOR_ID);
5927 return;
5928}
5929
5930/**
5931 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
5932 * @phba: pointer to lpfc hba data structure.
5933 *
5934 * This routine is invoked to set up the PCI device memory space for device
5935 * with SLI-3 interface spec.
5936 *
5937 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005938 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005939 * other values - error
5940 **/
5941static int
5942lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
5943{
5944 struct pci_dev *pdev;
5945 unsigned long bar0map_len, bar2map_len;
5946 int i, hbq_count;
5947 void *ptr;
5948 int error = -ENODEV;
5949
5950 /* Obtain PCI device reference */
5951 if (!phba->pcidev)
5952 return error;
5953 else
5954 pdev = phba->pcidev;
5955
5956 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05005957 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
5958 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
5959 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
5960 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smart3772a992009-05-22 14:50:54 -04005961 return error;
Michael Reed8e685972009-09-18 12:02:05 -05005962 }
5963 }
James Smart3772a992009-05-22 14:50:54 -04005964
5965 /* Get the bus address of Bar0 and Bar2 and the number of bytes
5966 * required by each mapping.
5967 */
5968 phba->pci_bar0_map = pci_resource_start(pdev, 0);
5969 bar0map_len = pci_resource_len(pdev, 0);
5970
5971 phba->pci_bar2_map = pci_resource_start(pdev, 2);
5972 bar2map_len = pci_resource_len(pdev, 2);
5973
5974 /* Map HBA SLIM to a kernel virtual address. */
5975 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
5976 if (!phba->slim_memmap_p) {
5977 dev_printk(KERN_ERR, &pdev->dev,
5978 "ioremap failed for SLIM memory.\n");
5979 goto out;
5980 }
5981
5982 /* Map HBA Control Registers to a kernel virtual address. */
5983 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
5984 if (!phba->ctrl_regs_memmap_p) {
5985 dev_printk(KERN_ERR, &pdev->dev,
5986 "ioremap failed for HBA control registers.\n");
5987 goto out_iounmap_slim;
5988 }
5989
5990 /* Allocate memory for SLI-2 structures */
5991 phba->slim2p.virt = dma_alloc_coherent(&pdev->dev,
5992 SLI2_SLIM_SIZE,
5993 &phba->slim2p.phys,
5994 GFP_KERNEL);
5995 if (!phba->slim2p.virt)
5996 goto out_iounmap;
5997
5998 memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
5999 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04006000 phba->mbox_ext = (phba->slim2p.virt +
6001 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04006002 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
6003 phba->IOCBs = (phba->slim2p.virt +
6004 offsetof(struct lpfc_sli2_slim, IOCBs));
6005
6006 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
6007 lpfc_sli_hbq_size(),
6008 &phba->hbqslimp.phys,
6009 GFP_KERNEL);
6010 if (!phba->hbqslimp.virt)
6011 goto out_free_slim;
6012
6013 hbq_count = lpfc_sli_hbq_count();
6014 ptr = phba->hbqslimp.virt;
6015 for (i = 0; i < hbq_count; ++i) {
6016 phba->hbqs[i].hbq_virt = ptr;
6017 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
6018 ptr += (lpfc_hbq_defs[i]->entry_count *
6019 sizeof(struct lpfc_hbq_entry));
6020 }
6021 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
6022 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
6023
6024 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
6025
6026 INIT_LIST_HEAD(&phba->rb_pend_list);
6027
6028 phba->MBslimaddr = phba->slim_memmap_p;
6029 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
6030 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
6031 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
6032 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04006033
dea31012005-04-17 16:05:31 -05006034 return 0;
6035
dea31012005-04-17 16:05:31 -05006036out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04006037 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6038 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05006039out_iounmap:
6040 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006041out_iounmap_slim:
dea31012005-04-17 16:05:31 -05006042 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05006043out:
6044 return error;
6045}
6046
James Smarte59058c2008-08-24 21:49:00 -04006047/**
James Smart3772a992009-05-22 14:50:54 -04006048 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
6049 * @phba: pointer to lpfc hba data structure.
6050 *
6051 * This routine is invoked to unset the PCI device memory space for device
6052 * with SLI-3 interface spec.
6053 **/
6054static void
6055lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
6056{
6057 struct pci_dev *pdev;
6058
6059 /* Obtain PCI device reference */
6060 if (!phba->pcidev)
6061 return;
6062 else
6063 pdev = phba->pcidev;
6064
6065 /* Free coherent DMA memory allocated */
6066 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
6067 phba->hbqslimp.virt, phba->hbqslimp.phys);
6068 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6069 phba->slim2p.virt, phba->slim2p.phys);
6070
6071 /* I/O memory unmap */
6072 iounmap(phba->ctrl_regs_memmap_p);
6073 iounmap(phba->slim_memmap_p);
6074
6075 return;
6076}
6077
6078/**
James Smartda0436e2009-05-22 14:51:39 -04006079 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
6080 * @phba: pointer to lpfc hba data structure.
6081 *
6082 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
6083 * done and check status.
6084 *
6085 * Return 0 if successful, otherwise -ENODEV.
6086 **/
6087int
6088lpfc_sli4_post_status_check(struct lpfc_hba *phba)
6089{
James Smart2fcee4b2010-12-15 17:57:46 -05006090 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
6091 struct lpfc_register reg_data;
6092 int i, port_error = 0;
6093 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04006094
James Smart9940b972011-03-11 16:06:12 -05006095 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
6096 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05006097 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04006098 return -ENODEV;
6099
James Smartda0436e2009-05-22 14:51:39 -04006100 /* Wait up to 30 seconds for the SLI Port POST done and ready */
6101 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05006102 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
6103 &portsmphr_reg.word0) ||
6104 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006105 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04006106 port_error = -ENODEV;
6107 break;
6108 }
James Smart2fcee4b2010-12-15 17:57:46 -05006109 if (LPFC_POST_STAGE_PORT_READY ==
6110 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04006111 break;
James Smartda0436e2009-05-22 14:51:39 -04006112 msleep(10);
6113 }
6114
James Smart2fcee4b2010-12-15 17:57:46 -05006115 /*
6116 * If there was a port error during POST, then don't proceed with
6117 * other register reads as the data may not be valid. Just exit.
6118 */
6119 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04006120 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006121 "1408 Port Failed POST - portsmphr=0x%x, "
6122 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
6123 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
6124 portsmphr_reg.word0,
6125 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
6126 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
6127 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
6128 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
6129 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
6130 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
6131 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
6132 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
6133 } else {
James Smart28baac72010-02-12 14:42:03 -05006134 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006135 "2534 Device Info: SLIFamily=0x%x, "
6136 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
6137 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05006138 bf_get(lpfc_sli_intf_sli_family,
6139 &phba->sli4_hba.sli_intf),
6140 bf_get(lpfc_sli_intf_slirev,
6141 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006142 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05006143 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006144 bf_get(lpfc_sli_intf_sli_hint1,
6145 &phba->sli4_hba.sli_intf),
6146 bf_get(lpfc_sli_intf_sli_hint2,
6147 &phba->sli4_hba.sli_intf),
6148 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05006149 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05006150 /*
6151 * Check for other Port errors during the initialization
6152 * process. Fail the load if the port did not come up
6153 * correctly.
6154 */
6155 if_type = bf_get(lpfc_sli_intf_if_type,
6156 &phba->sli4_hba.sli_intf);
6157 switch (if_type) {
6158 case LPFC_SLI_INTF_IF_TYPE_0:
6159 phba->sli4_hba.ue_mask_lo =
6160 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
6161 phba->sli4_hba.ue_mask_hi =
6162 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
6163 uerrlo_reg.word0 =
6164 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
6165 uerrhi_reg.word0 =
6166 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
6167 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
6168 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
6169 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6170 "1422 Unrecoverable Error "
6171 "Detected during POST "
6172 "uerr_lo_reg=0x%x, "
6173 "uerr_hi_reg=0x%x, "
6174 "ue_mask_lo_reg=0x%x, "
6175 "ue_mask_hi_reg=0x%x\n",
6176 uerrlo_reg.word0,
6177 uerrhi_reg.word0,
6178 phba->sli4_hba.ue_mask_lo,
6179 phba->sli4_hba.ue_mask_hi);
6180 port_error = -ENODEV;
6181 }
6182 break;
6183 case LPFC_SLI_INTF_IF_TYPE_2:
6184 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05006185 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
6186 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04006187 (bf_get(lpfc_sliport_status_err, &reg_data) &&
6188 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006189 phba->work_status[0] =
6190 readl(phba->sli4_hba.u.if_type2.
6191 ERR1regaddr);
6192 phba->work_status[1] =
6193 readl(phba->sli4_hba.u.if_type2.
6194 ERR2regaddr);
6195 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05006196 "2888 Unrecoverable port error "
6197 "following POST: port status reg "
6198 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05006199 "error 1=0x%x, error 2=0x%x\n",
6200 reg_data.word0,
6201 portsmphr_reg.word0,
6202 phba->work_status[0],
6203 phba->work_status[1]);
6204 port_error = -ENODEV;
6205 }
6206 break;
6207 case LPFC_SLI_INTF_IF_TYPE_1:
6208 default:
6209 break;
6210 }
James Smart28baac72010-02-12 14:42:03 -05006211 }
James Smartda0436e2009-05-22 14:51:39 -04006212 return port_error;
6213}
6214
6215/**
6216 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
6217 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05006218 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04006219 *
6220 * This routine is invoked to set up SLI4 BAR0 PCI config space register
6221 * memory map.
6222 **/
6223static void
James Smart2fcee4b2010-12-15 17:57:46 -05006224lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04006225{
James Smart2fcee4b2010-12-15 17:57:46 -05006226 switch (if_type) {
6227 case LPFC_SLI_INTF_IF_TYPE_0:
6228 phba->sli4_hba.u.if_type0.UERRLOregaddr =
6229 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
6230 phba->sli4_hba.u.if_type0.UERRHIregaddr =
6231 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
6232 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
6233 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
6234 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
6235 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
6236 phba->sli4_hba.SLIINTFregaddr =
6237 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6238 break;
6239 case LPFC_SLI_INTF_IF_TYPE_2:
6240 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006241 phba->sli4_hba.conf_regs_memmap_p +
6242 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006243 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006244 phba->sli4_hba.conf_regs_memmap_p +
6245 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006246 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006247 phba->sli4_hba.conf_regs_memmap_p +
6248 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006249 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006250 phba->sli4_hba.conf_regs_memmap_p +
6251 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006252 phba->sli4_hba.SLIINTFregaddr =
6253 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6254 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006255 phba->sli4_hba.conf_regs_memmap_p +
6256 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006257 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006258 phba->sli4_hba.conf_regs_memmap_p +
6259 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006260 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006261 phba->sli4_hba.conf_regs_memmap_p +
6262 LPFC_ULP0_WQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006263 phba->sli4_hba.EQCQDBregaddr =
6264 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
6265 phba->sli4_hba.MQDBregaddr =
6266 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
6267 phba->sli4_hba.BMBXregaddr =
6268 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
6269 break;
6270 case LPFC_SLI_INTF_IF_TYPE_1:
6271 default:
6272 dev_printk(KERN_ERR, &phba->pcidev->dev,
6273 "FATAL - unsupported SLI4 interface type - %d\n",
6274 if_type);
6275 break;
6276 }
James Smartda0436e2009-05-22 14:51:39 -04006277}
6278
6279/**
6280 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
6281 * @phba: pointer to lpfc hba data structure.
6282 *
6283 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
6284 * memory map.
6285 **/
6286static void
6287lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
6288{
James Smart2fcee4b2010-12-15 17:57:46 -05006289 phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
6290 LPFC_SLIPORT_IF0_SMPHR;
James Smartda0436e2009-05-22 14:51:39 -04006291 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006292 LPFC_HST_ISR0;
James Smartda0436e2009-05-22 14:51:39 -04006293 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006294 LPFC_HST_IMR0;
James Smartda0436e2009-05-22 14:51:39 -04006295 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006296 LPFC_HST_ISCR0;
James Smartda0436e2009-05-22 14:51:39 -04006297}
6298
6299/**
6300 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
6301 * @phba: pointer to lpfc hba data structure.
6302 * @vf: virtual function number
6303 *
6304 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
6305 * based on the given viftual function number, @vf.
6306 *
6307 * Return 0 if successful, otherwise -ENODEV.
6308 **/
6309static int
6310lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
6311{
6312 if (vf > LPFC_VIR_FUNC_MAX)
6313 return -ENODEV;
6314
6315 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05006316 vf * LPFC_VFR_PAGE_SIZE +
6317 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04006318 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05006319 vf * LPFC_VFR_PAGE_SIZE +
6320 LPFC_ULP0_WQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04006321 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6322 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
6323 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6324 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
6325 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6326 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
6327 return 0;
6328}
6329
6330/**
6331 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
6332 * @phba: pointer to lpfc hba data structure.
6333 *
6334 * This routine is invoked to create the bootstrap mailbox
6335 * region consistent with the SLI-4 interface spec. This
6336 * routine allocates all memory necessary to communicate
6337 * mailbox commands to the port and sets up all alignment
6338 * needs. No locks are expected to be held when calling
6339 * this routine.
6340 *
6341 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006342 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04006343 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04006344 **/
6345static int
6346lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
6347{
6348 uint32_t bmbx_size;
6349 struct lpfc_dmabuf *dmabuf;
6350 struct dma_address *dma_address;
6351 uint32_t pa_addr;
6352 uint64_t phys_addr;
6353
6354 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6355 if (!dmabuf)
6356 return -ENOMEM;
6357
6358 /*
6359 * The bootstrap mailbox region is comprised of 2 parts
6360 * plus an alignment restriction of 16 bytes.
6361 */
6362 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
6363 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
6364 bmbx_size,
6365 &dmabuf->phys,
6366 GFP_KERNEL);
6367 if (!dmabuf->virt) {
6368 kfree(dmabuf);
6369 return -ENOMEM;
6370 }
6371 memset(dmabuf->virt, 0, bmbx_size);
6372
6373 /*
6374 * Initialize the bootstrap mailbox pointers now so that the register
6375 * operations are simple later. The mailbox dma address is required
6376 * to be 16-byte aligned. Also align the virtual memory as each
6377 * maibox is copied into the bmbx mailbox region before issuing the
6378 * command to the port.
6379 */
6380 phba->sli4_hba.bmbx.dmabuf = dmabuf;
6381 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
6382
6383 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
6384 LPFC_ALIGN_16_BYTE);
6385 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
6386 LPFC_ALIGN_16_BYTE);
6387
6388 /*
6389 * Set the high and low physical addresses now. The SLI4 alignment
6390 * requirement is 16 bytes and the mailbox is posted to the port
6391 * as two 30-bit addresses. The other data is a bit marking whether
6392 * the 30-bit address is the high or low address.
6393 * Upcast bmbx aphys to 64bits so shift instruction compiles
6394 * clean on 32 bit machines.
6395 */
6396 dma_address = &phba->sli4_hba.bmbx.dma_address;
6397 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
6398 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
6399 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
6400 LPFC_BMBX_BIT1_ADDR_HI);
6401
6402 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
6403 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
6404 LPFC_BMBX_BIT1_ADDR_LO);
6405 return 0;
6406}
6407
6408/**
6409 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
6410 * @phba: pointer to lpfc hba data structure.
6411 *
6412 * This routine is invoked to teardown the bootstrap mailbox
6413 * region and release all host resources. This routine requires
6414 * the caller to ensure all mailbox commands recovered, no
6415 * additional mailbox comands are sent, and interrupts are disabled
6416 * before calling this routine.
6417 *
6418 **/
6419static void
6420lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
6421{
6422 dma_free_coherent(&phba->pcidev->dev,
6423 phba->sli4_hba.bmbx.bmbx_size,
6424 phba->sli4_hba.bmbx.dmabuf->virt,
6425 phba->sli4_hba.bmbx.dmabuf->phys);
6426
6427 kfree(phba->sli4_hba.bmbx.dmabuf);
6428 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
6429}
6430
6431/**
6432 * lpfc_sli4_read_config - Get the config parameters.
6433 * @phba: pointer to lpfc hba data structure.
6434 *
6435 * This routine is invoked to read the configuration parameters from the HBA.
6436 * The configuration parameters are used to set the base and maximum values
6437 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
6438 * allocation for the port.
6439 *
6440 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006441 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006442 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006443 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006444 **/
James Smartff78d8f2011-12-13 13:21:35 -05006445int
James Smartda0436e2009-05-22 14:51:39 -04006446lpfc_sli4_read_config(struct lpfc_hba *phba)
6447{
6448 LPFC_MBOXQ_t *pmb;
6449 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04006450 union lpfc_sli4_cfg_shdr *shdr;
6451 uint32_t shdr_status, shdr_add_status;
6452 struct lpfc_mbx_get_func_cfg *get_func_cfg;
6453 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04006454 char *pdesc_0;
James Smart912e3ac2011-05-24 11:42:11 -04006455 uint32_t desc_count;
James Smart8aa134a2012-08-14 14:25:29 -04006456 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04006457
6458 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6459 if (!pmb) {
6460 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6461 "2011 Unable to allocate memory for issuing "
6462 "SLI_CONFIG_SPECIAL mailbox command\n");
6463 return -ENOMEM;
6464 }
6465
6466 lpfc_read_config(phba, pmb);
6467
6468 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
6469 if (rc != MBX_SUCCESS) {
6470 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6471 "2012 Mailbox failed , mbxCmd x%x "
6472 "READ_CONFIG, mbxStatus x%x\n",
6473 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6474 bf_get(lpfc_mqe_status, &pmb->u.mqe));
6475 rc = -EIO;
6476 } else {
6477 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05006478 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
6479 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
6480 phba->sli4_hba.lnk_info.lnk_tp =
6481 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
6482 phba->sli4_hba.lnk_info.lnk_no =
6483 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
6484 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6485 "3081 lnk_type:%d, lnk_numb:%d\n",
6486 phba->sli4_hba.lnk_info.lnk_tp,
6487 phba->sli4_hba.lnk_info.lnk_no);
6488 } else
6489 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6490 "3082 Mailbox (x%x) returned ldv:x0\n",
6491 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart6d368e52011-05-24 11:44:12 -04006492 phba->sli4_hba.extents_in_use =
6493 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04006494 phba->sli4_hba.max_cfg_param.max_xri =
6495 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
6496 phba->sli4_hba.max_cfg_param.xri_base =
6497 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
6498 phba->sli4_hba.max_cfg_param.max_vpi =
6499 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
6500 phba->sli4_hba.max_cfg_param.vpi_base =
6501 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
6502 phba->sli4_hba.max_cfg_param.max_rpi =
6503 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
6504 phba->sli4_hba.max_cfg_param.rpi_base =
6505 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
6506 phba->sli4_hba.max_cfg_param.max_vfi =
6507 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
6508 phba->sli4_hba.max_cfg_param.vfi_base =
6509 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
6510 phba->sli4_hba.max_cfg_param.max_fcfi =
6511 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04006512 phba->sli4_hba.max_cfg_param.max_eq =
6513 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
6514 phba->sli4_hba.max_cfg_param.max_rq =
6515 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
6516 phba->sli4_hba.max_cfg_param.max_wq =
6517 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
6518 phba->sli4_hba.max_cfg_param.max_cq =
6519 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
6520 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
6521 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
6522 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
6523 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05006524 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
6525 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04006526 phba->max_vports = phba->max_vpi;
6527 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04006528 "2003 cfg params Extents? %d "
6529 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04006530 "VPI(B:%d M:%d) "
6531 "VFI(B:%d M:%d) "
6532 "RPI(B:%d M:%d) "
James Smart6d368e52011-05-24 11:44:12 -04006533 "FCFI(Count:%d)\n",
6534 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04006535 phba->sli4_hba.max_cfg_param.xri_base,
6536 phba->sli4_hba.max_cfg_param.max_xri,
6537 phba->sli4_hba.max_cfg_param.vpi_base,
6538 phba->sli4_hba.max_cfg_param.max_vpi,
6539 phba->sli4_hba.max_cfg_param.vfi_base,
6540 phba->sli4_hba.max_cfg_param.max_vfi,
6541 phba->sli4_hba.max_cfg_param.rpi_base,
6542 phba->sli4_hba.max_cfg_param.max_rpi,
James Smartda0436e2009-05-22 14:51:39 -04006543 phba->sli4_hba.max_cfg_param.max_fcfi);
6544 }
James Smart912e3ac2011-05-24 11:42:11 -04006545
6546 if (rc)
6547 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04006548
6549 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smartb92938b2010-06-07 15:24:12 -04006550 if (phba->cfg_hba_queue_depth >
6551 (phba->sli4_hba.max_cfg_param.max_xri -
6552 lpfc_sli4_get_els_iocb_cnt(phba)))
James Smartda0436e2009-05-22 14:51:39 -04006553 phba->cfg_hba_queue_depth =
James Smartb92938b2010-06-07 15:24:12 -04006554 phba->sli4_hba.max_cfg_param.max_xri -
6555 lpfc_sli4_get_els_iocb_cnt(phba);
James Smart912e3ac2011-05-24 11:42:11 -04006556
6557 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
6558 LPFC_SLI_INTF_IF_TYPE_2)
6559 goto read_cfg_out;
6560
6561 /* get the pf# and vf# for SLI4 if_type 2 port */
6562 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
6563 sizeof(struct lpfc_sli4_cfg_mhdr));
6564 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
6565 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
6566 length, LPFC_SLI4_MBX_EMBED);
6567
James Smart8aa134a2012-08-14 14:25:29 -04006568 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04006569 shdr = (union lpfc_sli4_cfg_shdr *)
6570 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
6571 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6572 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04006573 if (rc2 || shdr_status || shdr_add_status) {
James Smart912e3ac2011-05-24 11:42:11 -04006574 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6575 "3026 Mailbox failed , mbxCmd x%x "
6576 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
6577 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6578 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04006579 goto read_cfg_out;
6580 }
6581
6582 /* search for fc_fcoe resrouce descriptor */
6583 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
6584 desc_count = get_func_cfg->func_cfg.rsrc_desc_count;
6585
James Smart8aa134a2012-08-14 14:25:29 -04006586 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
6587 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
6588 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
6589 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
6590 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
6591 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
6592 goto read_cfg_out;
6593
James Smart912e3ac2011-05-24 11:42:11 -04006594 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04006595 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04006596 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04006597 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04006598 phba->sli4_hba.iov.pf_number =
6599 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
6600 phba->sli4_hba.iov.vf_number =
6601 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
6602 break;
6603 }
6604 }
6605
6606 if (i < LPFC_RSRC_DESC_MAX_NUM)
6607 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6608 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
6609 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
6610 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04006611 else
James Smart912e3ac2011-05-24 11:42:11 -04006612 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6613 "3028 GET_FUNCTION_CONFIG: failed to find "
6614 "Resrouce Descriptor:x%x\n",
6615 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04006616
6617read_cfg_out:
6618 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04006619 return rc;
6620}
6621
6622/**
James Smart2fcee4b2010-12-15 17:57:46 -05006623 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04006624 * @phba: pointer to lpfc hba data structure.
6625 *
James Smart2fcee4b2010-12-15 17:57:46 -05006626 * This routine is invoked to setup the port-side endian order when
6627 * the port if_type is 0. This routine has no function for other
6628 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04006629 *
6630 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006631 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006632 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006633 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006634 **/
6635static int
6636lpfc_setup_endian_order(struct lpfc_hba *phba)
6637{
6638 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05006639 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04006640 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
6641 HOST_ENDIAN_HIGH_WORD1};
6642
James Smart2fcee4b2010-12-15 17:57:46 -05006643 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
6644 switch (if_type) {
6645 case LPFC_SLI_INTF_IF_TYPE_0:
6646 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
6647 GFP_KERNEL);
6648 if (!mboxq) {
6649 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6650 "0492 Unable to allocate memory for "
6651 "issuing SLI_CONFIG_SPECIAL mailbox "
6652 "command\n");
6653 return -ENOMEM;
6654 }
James Smartda0436e2009-05-22 14:51:39 -04006655
James Smart2fcee4b2010-12-15 17:57:46 -05006656 /*
6657 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
6658 * two words to contain special data values and no other data.
6659 */
6660 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
6661 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
6662 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6663 if (rc != MBX_SUCCESS) {
6664 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6665 "0493 SLI_CONFIG_SPECIAL mailbox "
6666 "failed with status x%x\n",
6667 rc);
6668 rc = -EIO;
6669 }
6670 mempool_free(mboxq, phba->mbox_mem_pool);
6671 break;
6672 case LPFC_SLI_INTF_IF_TYPE_2:
6673 case LPFC_SLI_INTF_IF_TYPE_1:
6674 default:
6675 break;
James Smartda0436e2009-05-22 14:51:39 -04006676 }
James Smartda0436e2009-05-22 14:51:39 -04006677 return rc;
6678}
6679
6680/**
James Smart5350d872011-10-10 21:33:49 -04006681 * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts
James Smartda0436e2009-05-22 14:51:39 -04006682 * @phba: pointer to lpfc hba data structure.
6683 *
James Smart5350d872011-10-10 21:33:49 -04006684 * This routine is invoked to check the user settable queue counts for EQs and
6685 * CQs. after this routine is called the counts will be set to valid values that
6686 * adhere to the constraints of the system's interrupt vectors and the port's
6687 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04006688 *
6689 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006690 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006691 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04006692 **/
6693static int
James Smart5350d872011-10-10 21:33:49 -04006694lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04006695{
James Smart67d12732012-08-03 12:36:13 -04006696 int cfg_fcp_io_channel;
James Smart90695ee2012-08-14 14:25:36 -04006697 uint32_t cpu;
6698 uint32_t i = 0;
6699
James Smartda0436e2009-05-22 14:51:39 -04006700
6701 /*
James Smart67d12732012-08-03 12:36:13 -04006702 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04006703 * device parameters
6704 */
6705
James Smart67d12732012-08-03 12:36:13 -04006706 /* Sanity check on HBA EQ parameters */
6707 cfg_fcp_io_channel = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04006708
James Smart90695ee2012-08-14 14:25:36 -04006709 /* It doesn't make sense to have more io channels then CPUs */
6710 for_each_online_cpu(cpu) {
6711 i++;
6712 }
6713 if (i < cfg_fcp_io_channel) {
James Smart82c3e9b2012-09-29 11:29:50 -04006714 lpfc_printf_log(phba,
6715 KERN_ERR, LOG_INIT,
James Smart90695ee2012-08-14 14:25:36 -04006716 "3188 Reducing IO channels to match number of "
6717 "CPUs: from %d to %d\n", cfg_fcp_io_channel, i);
6718 cfg_fcp_io_channel = i;
6719 }
6720
James Smart67d12732012-08-03 12:36:13 -04006721 if (cfg_fcp_io_channel >
6722 phba->sli4_hba.max_cfg_param.max_eq) {
James Smart82c3e9b2012-09-29 11:29:50 -04006723 if (phba->sli4_hba.max_cfg_param.max_eq <
6724 LPFC_FCP_IO_CHAN_MIN) {
James Smartda0436e2009-05-22 14:51:39 -04006725 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6726 "2574 Not enough EQs (%d) from the "
6727 "pci function for supporting FCP "
6728 "EQs (%d)\n",
6729 phba->sli4_hba.max_cfg_param.max_eq,
James Smart67d12732012-08-03 12:36:13 -04006730 phba->cfg_fcp_io_channel);
James Smartda0436e2009-05-22 14:51:39 -04006731 goto out_error;
6732 }
James Smart82c3e9b2012-09-29 11:29:50 -04006733 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6734 "2575 Reducing IO channels to match number of "
6735 "available EQs: from %d to %d\n",
6736 cfg_fcp_io_channel,
6737 phba->sli4_hba.max_cfg_param.max_eq);
6738 cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq;
James Smartda0436e2009-05-22 14:51:39 -04006739 }
James Smart67d12732012-08-03 12:36:13 -04006740
6741 /* Eventually cfg_fcp_eq_count / cfg_fcp_wq_count will be depricated */
6742
James Smartda0436e2009-05-22 14:51:39 -04006743 /* The actual number of FCP event queues adopted */
James Smart67d12732012-08-03 12:36:13 -04006744 phba->cfg_fcp_eq_count = cfg_fcp_io_channel;
6745 phba->cfg_fcp_wq_count = cfg_fcp_io_channel;
6746 phba->cfg_fcp_io_channel = cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04006747
James Smartda0436e2009-05-22 14:51:39 -04006748 /* Get EQ depth from module parameter, fake the default for now */
6749 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
6750 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
6751
James Smart5350d872011-10-10 21:33:49 -04006752 /* Get CQ depth from module parameter, fake the default for now */
6753 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
6754 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
6755
6756 return 0;
6757out_error:
6758 return -ENOMEM;
6759}
6760
6761/**
6762 * lpfc_sli4_queue_create - Create all the SLI4 queues
6763 * @phba: pointer to lpfc hba data structure.
6764 *
6765 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
6766 * operation. For each SLI4 queue type, the parameters such as queue entry
6767 * count (queue depth) shall be taken from the module parameter. For now,
6768 * we just use some constant number as place holder.
6769 *
6770 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07006771 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04006772 * -ENOMEM - No availble memory
6773 * -EIO - The mailbox failed to complete successfully.
6774 **/
6775int
6776lpfc_sli4_queue_create(struct lpfc_hba *phba)
6777{
6778 struct lpfc_queue *qdesc;
James Smart67d12732012-08-03 12:36:13 -04006779 int idx;
James Smart5350d872011-10-10 21:33:49 -04006780
6781 /*
James Smart67d12732012-08-03 12:36:13 -04006782 * Create HBA Record arrays.
James Smart5350d872011-10-10 21:33:49 -04006783 */
James Smart67d12732012-08-03 12:36:13 -04006784 if (!phba->cfg_fcp_io_channel)
6785 return -ERANGE;
James Smart5350d872011-10-10 21:33:49 -04006786
James Smart67d12732012-08-03 12:36:13 -04006787 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
6788 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
6789 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
6790 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
6791 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
6792 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
6793
6794 phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) *
6795 phba->cfg_fcp_io_channel), GFP_KERNEL);
6796 if (!phba->sli4_hba.hba_eq) {
James Smartda0436e2009-05-22 14:51:39 -04006797 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04006798 "2576 Failed allocate memory for "
6799 "fast-path EQ record array\n");
James Smartda0436e2009-05-22 14:51:39 -04006800 goto out_error;
6801 }
James Smart67d12732012-08-03 12:36:13 -04006802
6803 phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
6804 phba->cfg_fcp_io_channel), GFP_KERNEL);
6805 if (!phba->sli4_hba.fcp_cq) {
6806 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6807 "2577 Failed allocate memory for fast-path "
6808 "CQ record array\n");
6809 goto out_error;
6810 }
6811
6812 phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
6813 phba->cfg_fcp_io_channel), GFP_KERNEL);
6814 if (!phba->sli4_hba.fcp_wq) {
6815 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6816 "2578 Failed allocate memory for fast-path "
6817 "WQ record array\n");
6818 goto out_error;
6819 }
James Smartda0436e2009-05-22 14:51:39 -04006820
James Smart5350d872011-10-10 21:33:49 -04006821 /*
James Smart67d12732012-08-03 12:36:13 -04006822 * Since the first EQ can have multiple CQs associated with it,
6823 * this array is used to quickly see if we have a FCP fast-path
6824 * CQ match.
James Smart5350d872011-10-10 21:33:49 -04006825 */
James Smart67d12732012-08-03 12:36:13 -04006826 phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) *
6827 phba->cfg_fcp_io_channel), GFP_KERNEL);
6828 if (!phba->sli4_hba.fcp_cq_map) {
6829 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6830 "2545 Failed allocate memory for fast-path "
6831 "CQ map\n");
6832 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04006833 }
James Smart67d12732012-08-03 12:36:13 -04006834
6835 /*
6836 * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies
6837 * how many EQs to create.
6838 */
6839 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
6840
6841 /* Create EQs */
James Smartda0436e2009-05-22 14:51:39 -04006842 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
6843 phba->sli4_hba.eq_ecount);
6844 if (!qdesc) {
6845 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04006846 "0497 Failed allocate EQ (%d)\n", idx);
6847 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04006848 }
James Smart67d12732012-08-03 12:36:13 -04006849 phba->sli4_hba.hba_eq[idx] = qdesc;
6850
6851 /* Create Fast Path FCP CQs */
6852 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
6853 phba->sli4_hba.cq_ecount);
6854 if (!qdesc) {
6855 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6856 "0499 Failed allocate fast-path FCP "
6857 "CQ (%d)\n", idx);
6858 goto out_error;
6859 }
6860 phba->sli4_hba.fcp_cq[idx] = qdesc;
6861
6862 /* Create Fast Path FCP WQs */
6863 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
6864 phba->sli4_hba.wq_ecount);
6865 if (!qdesc) {
6866 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6867 "0503 Failed allocate fast-path FCP "
6868 "WQ (%d)\n", idx);
6869 goto out_error;
6870 }
6871 phba->sli4_hba.fcp_wq[idx] = qdesc;
James Smartda0436e2009-05-22 14:51:39 -04006872 }
6873
James Smart67d12732012-08-03 12:36:13 -04006874
James Smartda0436e2009-05-22 14:51:39 -04006875 /*
James Smart67d12732012-08-03 12:36:13 -04006876 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04006877 */
6878
James Smartda0436e2009-05-22 14:51:39 -04006879 /* Create slow-path Mailbox Command Complete Queue */
6880 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
6881 phba->sli4_hba.cq_ecount);
6882 if (!qdesc) {
6883 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6884 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04006885 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04006886 }
6887 phba->sli4_hba.mbx_cq = qdesc;
6888
6889 /* Create slow-path ELS 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 "0501 Failed allocate slow-path ELS 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.els_cq = qdesc;
6898
James Smartda0436e2009-05-22 14:51:39 -04006899
James Smart5350d872011-10-10 21:33:49 -04006900 /*
James Smart67d12732012-08-03 12:36:13 -04006901 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04006902 */
James Smartda0436e2009-05-22 14:51:39 -04006903
6904 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04006905
6906 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
6907 phba->sli4_hba.mq_ecount);
6908 if (!qdesc) {
6909 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6910 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04006911 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04006912 }
6913 phba->sli4_hba.mbx_wq = qdesc;
6914
6915 /*
James Smart67d12732012-08-03 12:36:13 -04006916 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04006917 */
James Smartda0436e2009-05-22 14:51:39 -04006918
6919 /* Create slow-path ELS Work Queue */
6920 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
6921 phba->sli4_hba.wq_ecount);
6922 if (!qdesc) {
6923 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6924 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04006925 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04006926 }
6927 phba->sli4_hba.els_wq = qdesc;
6928
James Smartda0436e2009-05-22 14:51:39 -04006929 /*
6930 * Create Receive Queue (RQ)
6931 */
James Smartda0436e2009-05-22 14:51:39 -04006932
6933 /* Create Receive Queue for header */
6934 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
6935 phba->sli4_hba.rq_ecount);
6936 if (!qdesc) {
6937 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6938 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04006939 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04006940 }
6941 phba->sli4_hba.hdr_rq = qdesc;
6942
6943 /* Create Receive Queue for data */
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 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04006949 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04006950 }
6951 phba->sli4_hba.dat_rq = qdesc;
6952
6953 return 0;
6954
James Smartda0436e2009-05-22 14:51:39 -04006955out_error:
James Smart67d12732012-08-03 12:36:13 -04006956 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04006957 return -ENOMEM;
6958}
6959
6960/**
6961 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
6962 * @phba: pointer to lpfc hba data structure.
6963 *
6964 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
6965 * operation.
6966 *
6967 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006968 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006969 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006970 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006971 **/
James Smart5350d872011-10-10 21:33:49 -04006972void
James Smartda0436e2009-05-22 14:51:39 -04006973lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
6974{
James Smart67d12732012-08-03 12:36:13 -04006975 int idx;
6976
6977 if (phba->sli4_hba.hba_eq != NULL) {
6978 /* Release HBA event queue */
6979 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
6980 if (phba->sli4_hba.hba_eq[idx] != NULL) {
6981 lpfc_sli4_queue_free(
6982 phba->sli4_hba.hba_eq[idx]);
6983 phba->sli4_hba.hba_eq[idx] = NULL;
6984 }
6985 }
6986 kfree(phba->sli4_hba.hba_eq);
6987 phba->sli4_hba.hba_eq = NULL;
6988 }
6989
6990 if (phba->sli4_hba.fcp_cq != NULL) {
6991 /* Release FCP completion queue */
6992 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
6993 if (phba->sli4_hba.fcp_cq[idx] != NULL) {
6994 lpfc_sli4_queue_free(
6995 phba->sli4_hba.fcp_cq[idx]);
6996 phba->sli4_hba.fcp_cq[idx] = NULL;
6997 }
6998 }
6999 kfree(phba->sli4_hba.fcp_cq);
7000 phba->sli4_hba.fcp_cq = NULL;
7001 }
7002
7003 if (phba->sli4_hba.fcp_wq != NULL) {
7004 /* Release FCP work queue */
7005 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7006 if (phba->sli4_hba.fcp_wq[idx] != NULL) {
7007 lpfc_sli4_queue_free(
7008 phba->sli4_hba.fcp_wq[idx]);
7009 phba->sli4_hba.fcp_wq[idx] = NULL;
7010 }
7011 }
7012 kfree(phba->sli4_hba.fcp_wq);
7013 phba->sli4_hba.fcp_wq = NULL;
7014 }
7015
James Smart962bc512013-01-03 15:44:00 -05007016 if (phba->pci_bar0_memmap_p) {
7017 iounmap(phba->pci_bar0_memmap_p);
7018 phba->pci_bar0_memmap_p = NULL;
7019 }
7020 if (phba->pci_bar2_memmap_p) {
7021 iounmap(phba->pci_bar2_memmap_p);
7022 phba->pci_bar2_memmap_p = NULL;
7023 }
7024 if (phba->pci_bar4_memmap_p) {
7025 iounmap(phba->pci_bar4_memmap_p);
7026 phba->pci_bar4_memmap_p = NULL;
7027 }
7028
James Smart67d12732012-08-03 12:36:13 -04007029 /* Release FCP CQ mapping array */
7030 if (phba->sli4_hba.fcp_cq_map != NULL) {
7031 kfree(phba->sli4_hba.fcp_cq_map);
7032 phba->sli4_hba.fcp_cq_map = NULL;
7033 }
James Smartda0436e2009-05-22 14:51:39 -04007034
7035 /* Release mailbox command work queue */
James Smart67d12732012-08-03 12:36:13 -04007036 if (phba->sli4_hba.mbx_wq != NULL) {
7037 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
7038 phba->sli4_hba.mbx_wq = NULL;
7039 }
James Smartda0436e2009-05-22 14:51:39 -04007040
7041 /* Release ELS work queue */
James Smart67d12732012-08-03 12:36:13 -04007042 if (phba->sli4_hba.els_wq != NULL) {
7043 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
7044 phba->sli4_hba.els_wq = NULL;
7045 }
James Smartda0436e2009-05-22 14:51:39 -04007046
7047 /* Release unsolicited receive queue */
James Smart67d12732012-08-03 12:36:13 -04007048 if (phba->sli4_hba.hdr_rq != NULL) {
7049 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
7050 phba->sli4_hba.hdr_rq = NULL;
7051 }
7052 if (phba->sli4_hba.dat_rq != NULL) {
7053 lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
7054 phba->sli4_hba.dat_rq = NULL;
7055 }
James Smartda0436e2009-05-22 14:51:39 -04007056
James Smartda0436e2009-05-22 14:51:39 -04007057 /* Release ELS complete queue */
James Smart67d12732012-08-03 12:36:13 -04007058 if (phba->sli4_hba.els_cq != NULL) {
7059 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
7060 phba->sli4_hba.els_cq = NULL;
7061 }
James Smartda0436e2009-05-22 14:51:39 -04007062
7063 /* Release mailbox command complete queue */
James Smart67d12732012-08-03 12:36:13 -04007064 if (phba->sli4_hba.mbx_cq != NULL) {
7065 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
7066 phba->sli4_hba.mbx_cq = NULL;
7067 }
James Smartda0436e2009-05-22 14:51:39 -04007068
7069 return;
7070}
7071
7072/**
7073 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
7074 * @phba: pointer to lpfc hba data structure.
7075 *
7076 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
7077 * operation.
7078 *
7079 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007080 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007081 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007082 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007083 **/
7084int
7085lpfc_sli4_queue_setup(struct lpfc_hba *phba)
7086{
James Smart2a76a282012-08-03 12:35:54 -04007087 struct lpfc_sli *psli = &phba->sli;
7088 struct lpfc_sli_ring *pring;
James Smartda0436e2009-05-22 14:51:39 -04007089 int rc = -ENOMEM;
7090 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
7091 int fcp_cq_index = 0;
James Smart962bc512013-01-03 15:44:00 -05007092 uint32_t shdr_status, shdr_add_status;
7093 union lpfc_sli4_cfg_shdr *shdr;
7094 LPFC_MBOXQ_t *mboxq;
7095 uint32_t length;
7096
7097 /* Check for dual-ULP support */
7098 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7099 if (!mboxq) {
7100 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7101 "3249 Unable to allocate memory for "
7102 "QUERY_FW_CFG mailbox command\n");
7103 return -ENOMEM;
7104 }
7105 length = (sizeof(struct lpfc_mbx_query_fw_config) -
7106 sizeof(struct lpfc_sli4_cfg_mhdr));
7107 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
7108 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
7109 length, LPFC_SLI4_MBX_EMBED);
7110
7111 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7112
7113 shdr = (union lpfc_sli4_cfg_shdr *)
7114 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
7115 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7116 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7117 if (shdr_status || shdr_add_status || rc) {
7118 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7119 "3250 QUERY_FW_CFG mailbox failed with status "
7120 "x%x add_status x%x, mbx status x%x\n",
7121 shdr_status, shdr_add_status, rc);
7122 if (rc != MBX_TIMEOUT)
7123 mempool_free(mboxq, phba->mbox_mem_pool);
7124 rc = -ENXIO;
7125 goto out_error;
7126 }
7127
7128 phba->sli4_hba.fw_func_mode =
7129 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
7130 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
7131 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
7132 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7133 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
7134 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
7135 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
7136
7137 if (rc != MBX_TIMEOUT)
7138 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04007139
7140 /*
James Smart67d12732012-08-03 12:36:13 -04007141 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04007142 */
7143
James Smart67d12732012-08-03 12:36:13 -04007144 /* Set up HBA event queue */
7145 if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) {
James Smart2e90f4b2011-12-13 13:22:37 -05007146 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7147 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007148 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007149 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05007150 }
James Smart67d12732012-08-03 12:36:13 -04007151 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
7152 if (!phba->sli4_hba.hba_eq[fcp_eqidx]) {
James Smartda0436e2009-05-22 14:51:39 -04007153 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7154 "0522 Fast-path EQ (%d) not "
7155 "allocated\n", fcp_eqidx);
James Smart1b511972011-12-13 13:23:09 -05007156 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007157 goto out_destroy_hba_eq;
James Smartda0436e2009-05-22 14:51:39 -04007158 }
James Smart67d12732012-08-03 12:36:13 -04007159 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx],
James Smartbf8dae82012-08-03 12:36:24 -04007160 (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel));
James Smartda0436e2009-05-22 14:51:39 -04007161 if (rc) {
7162 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7163 "0523 Failed setup of fast-path EQ "
7164 "(%d), rc = 0x%x\n", fcp_eqidx, rc);
James Smart67d12732012-08-03 12:36:13 -04007165 goto out_destroy_hba_eq;
James Smartda0436e2009-05-22 14:51:39 -04007166 }
7167 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007168 "2584 HBA EQ setup: "
James Smartda0436e2009-05-22 14:51:39 -04007169 "queue[%d]-id=%d\n", fcp_eqidx,
James Smart67d12732012-08-03 12:36:13 -04007170 phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007171 }
7172
James Smart67d12732012-08-03 12:36:13 -04007173 /* Set up fast-path FCP Response Complete Queue */
7174 if (!phba->sli4_hba.fcp_cq) {
7175 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7176 "3148 Fast-path FCP CQ array not "
7177 "allocated\n");
7178 rc = -ENOMEM;
7179 goto out_destroy_hba_eq;
7180 }
7181
7182 for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) {
7183 if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
7184 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7185 "0526 Fast-path FCP CQ (%d) not "
7186 "allocated\n", fcp_cqidx);
7187 rc = -ENOMEM;
7188 goto out_destroy_fcp_cq;
7189 }
7190 rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
7191 phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP);
7192 if (rc) {
7193 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7194 "0527 Failed setup of fast-path FCP "
7195 "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc);
7196 goto out_destroy_fcp_cq;
7197 }
7198
7199 /* Setup fcp_cq_map for fast lookup */
7200 phba->sli4_hba.fcp_cq_map[fcp_cqidx] =
7201 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id;
7202
7203 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7204 "2588 FCP CQ setup: cq[%d]-id=%d, "
7205 "parent seq[%d]-id=%d\n",
7206 fcp_cqidx,
7207 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
7208 fcp_cqidx,
7209 phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id);
7210 }
7211
7212 /* Set up fast-path FCP Work Queue */
7213 if (!phba->sli4_hba.fcp_wq) {
7214 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7215 "3149 Fast-path FCP WQ array not "
7216 "allocated\n");
7217 rc = -ENOMEM;
7218 goto out_destroy_fcp_cq;
7219 }
7220
7221 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) {
7222 if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
7223 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7224 "0534 Fast-path FCP WQ (%d) not "
7225 "allocated\n", fcp_wqidx);
7226 rc = -ENOMEM;
7227 goto out_destroy_fcp_wq;
7228 }
7229 rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
7230 phba->sli4_hba.fcp_cq[fcp_wqidx],
7231 LPFC_FCP);
7232 if (rc) {
7233 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7234 "0535 Failed setup of fast-path FCP "
7235 "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc);
7236 goto out_destroy_fcp_wq;
7237 }
7238
7239 /* Bind this WQ to the next FCP ring */
7240 pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx];
7241 pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx];
7242 phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring;
7243
7244 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7245 "2591 FCP WQ setup: wq[%d]-id=%d, "
7246 "parent cq[%d]-id=%d\n",
7247 fcp_wqidx,
7248 phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
7249 fcp_cq_index,
7250 phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id);
7251 }
James Smartda0436e2009-05-22 14:51:39 -04007252 /*
7253 * Set up Complete Queues (CQs)
7254 */
7255
7256 /* Set up slow-path MBOX Complete Queue as the first CQ */
7257 if (!phba->sli4_hba.mbx_cq) {
7258 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7259 "0528 Mailbox CQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007260 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007261 goto out_destroy_fcp_wq;
James Smartda0436e2009-05-22 14:51:39 -04007262 }
James Smart67d12732012-08-03 12:36:13 -04007263 rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq,
7264 phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04007265 if (rc) {
7266 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7267 "0529 Failed setup of slow-path mailbox CQ: "
7268 "rc = 0x%x\n", rc);
James Smart67d12732012-08-03 12:36:13 -04007269 goto out_destroy_fcp_wq;
James Smartda0436e2009-05-22 14:51:39 -04007270 }
7271 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7272 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
7273 phba->sli4_hba.mbx_cq->queue_id,
James Smart67d12732012-08-03 12:36:13 -04007274 phba->sli4_hba.hba_eq[0]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007275
7276 /* Set up slow-path ELS Complete Queue */
7277 if (!phba->sli4_hba.els_cq) {
7278 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7279 "0530 ELS CQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007280 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007281 goto out_destroy_mbx_cq;
7282 }
James Smart67d12732012-08-03 12:36:13 -04007283 rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq,
7284 phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04007285 if (rc) {
7286 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7287 "0531 Failed setup of slow-path ELS CQ: "
7288 "rc = 0x%x\n", rc);
7289 goto out_destroy_mbx_cq;
7290 }
7291 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7292 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
7293 phba->sli4_hba.els_cq->queue_id,
James Smart67d12732012-08-03 12:36:13 -04007294 phba->sli4_hba.hba_eq[0]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007295
7296 /*
7297 * Set up all the Work Queues (WQs)
7298 */
7299
7300 /* Set up Mailbox Command Queue */
7301 if (!phba->sli4_hba.mbx_wq) {
7302 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7303 "0538 Slow-path MQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007304 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007305 goto out_destroy_els_cq;
James Smartda0436e2009-05-22 14:51:39 -04007306 }
7307 rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
7308 phba->sli4_hba.mbx_cq, LPFC_MBOX);
7309 if (rc) {
7310 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7311 "0539 Failed setup of slow-path MQ: "
7312 "rc = 0x%x\n", rc);
James Smart67d12732012-08-03 12:36:13 -04007313 goto out_destroy_els_cq;
James Smartda0436e2009-05-22 14:51:39 -04007314 }
7315 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7316 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
7317 phba->sli4_hba.mbx_wq->queue_id,
7318 phba->sli4_hba.mbx_cq->queue_id);
7319
7320 /* Set up slow-path ELS Work Queue */
7321 if (!phba->sli4_hba.els_wq) {
7322 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7323 "0536 Slow-path ELS WQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007324 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007325 goto out_destroy_mbx_wq;
7326 }
7327 rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
7328 phba->sli4_hba.els_cq, LPFC_ELS);
7329 if (rc) {
7330 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7331 "0537 Failed setup of slow-path ELS WQ: "
7332 "rc = 0x%x\n", rc);
7333 goto out_destroy_mbx_wq;
7334 }
James Smart2a76a282012-08-03 12:35:54 -04007335
7336 /* Bind this WQ to the ELS ring */
7337 pring = &psli->ring[LPFC_ELS_RING];
7338 pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq;
7339 phba->sli4_hba.els_cq->pring = pring;
7340
James Smartda0436e2009-05-22 14:51:39 -04007341 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7342 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
7343 phba->sli4_hba.els_wq->queue_id,
7344 phba->sli4_hba.els_cq->queue_id);
7345
James Smartda0436e2009-05-22 14:51:39 -04007346 /*
7347 * Create Receive Queue (RQ)
7348 */
7349 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
7350 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7351 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007352 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007353 goto out_destroy_els_wq;
James Smartda0436e2009-05-22 14:51:39 -04007354 }
James Smart73d91e52011-10-10 21:32:10 -04007355
7356 lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
7357 lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
7358
James Smartda0436e2009-05-22 14:51:39 -04007359 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04007360 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04007361 if (rc) {
7362 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7363 "0541 Failed setup of Receive Queue: "
7364 "rc = 0x%x\n", rc);
7365 goto out_destroy_fcp_wq;
7366 }
James Smart73d91e52011-10-10 21:32:10 -04007367
James Smartda0436e2009-05-22 14:51:39 -04007368 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7369 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
7370 "parent cq-id=%d\n",
7371 phba->sli4_hba.hdr_rq->queue_id,
7372 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04007373 phba->sli4_hba.els_cq->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007374 return 0;
7375
James Smart2e90f4b2011-12-13 13:22:37 -05007376out_destroy_els_wq:
James Smartda0436e2009-05-22 14:51:39 -04007377 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7378out_destroy_mbx_wq:
7379 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
James Smart2e90f4b2011-12-13 13:22:37 -05007380out_destroy_els_cq:
James Smartda0436e2009-05-22 14:51:39 -04007381 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
7382out_destroy_mbx_cq:
7383 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
James Smart67d12732012-08-03 12:36:13 -04007384out_destroy_fcp_wq:
7385 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
7386 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
7387out_destroy_fcp_cq:
7388 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
7389 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
7390out_destroy_hba_eq:
James Smartda0436e2009-05-22 14:51:39 -04007391 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
James Smart67d12732012-08-03 12:36:13 -04007392 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]);
James Smartda0436e2009-05-22 14:51:39 -04007393out_error:
7394 return rc;
7395}
7396
7397/**
7398 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
7399 * @phba: pointer to lpfc hba data structure.
7400 *
7401 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
7402 * operation.
7403 *
7404 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007405 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007406 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007407 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007408 **/
7409void
7410lpfc_sli4_queue_unset(struct lpfc_hba *phba)
7411{
7412 int fcp_qidx;
7413
7414 /* Unset mailbox command work queue */
7415 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
7416 /* Unset ELS work queue */
7417 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7418 /* Unset unsolicited receive queue */
7419 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
7420 /* Unset FCP work queue */
James Smart67d12732012-08-03 12:36:13 -04007421 if (phba->sli4_hba.fcp_wq) {
7422 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
7423 fcp_qidx++)
7424 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
7425 }
James Smartda0436e2009-05-22 14:51:39 -04007426 /* Unset mailbox command complete queue */
7427 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
7428 /* Unset ELS complete queue */
7429 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
James Smartda0436e2009-05-22 14:51:39 -04007430 /* Unset FCP response complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05007431 if (phba->sli4_hba.fcp_cq) {
James Smart67d12732012-08-03 12:36:13 -04007432 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
7433 fcp_qidx++)
James Smart2e90f4b2011-12-13 13:22:37 -05007434 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
James Smart2e90f4b2011-12-13 13:22:37 -05007435 }
James Smartda0436e2009-05-22 14:51:39 -04007436 /* Unset fast-path event queue */
James Smart67d12732012-08-03 12:36:13 -04007437 if (phba->sli4_hba.hba_eq) {
7438 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
James Smart2e90f4b2011-12-13 13:22:37 -05007439 fcp_qidx++)
James Smart67d12732012-08-03 12:36:13 -04007440 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_qidx]);
James Smart2e90f4b2011-12-13 13:22:37 -05007441 }
James Smartda0436e2009-05-22 14:51:39 -04007442}
7443
7444/**
7445 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
7446 * @phba: pointer to lpfc hba data structure.
7447 *
7448 * This routine is invoked to allocate and set up a pool of completion queue
7449 * events. The body of the completion queue event is a completion queue entry
7450 * CQE. For now, this pool is used for the interrupt service routine to queue
7451 * the following HBA completion queue events for the worker thread to process:
7452 * - Mailbox asynchronous events
7453 * - Receive queue completion unsolicited events
7454 * Later, this can be used for all the slow-path events.
7455 *
7456 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007457 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007458 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007459 **/
7460static int
7461lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
7462{
7463 struct lpfc_cq_event *cq_event;
7464 int i;
7465
7466 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
7467 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
7468 if (!cq_event)
7469 goto out_pool_create_fail;
7470 list_add_tail(&cq_event->list,
7471 &phba->sli4_hba.sp_cqe_event_pool);
7472 }
7473 return 0;
7474
7475out_pool_create_fail:
7476 lpfc_sli4_cq_event_pool_destroy(phba);
7477 return -ENOMEM;
7478}
7479
7480/**
7481 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
7482 * @phba: pointer to lpfc hba data structure.
7483 *
7484 * This routine is invoked to free the pool of completion queue events at
7485 * driver unload time. Note that, it is the responsibility of the driver
7486 * cleanup routine to free all the outstanding completion-queue events
7487 * allocated from this pool back into the pool before invoking this routine
7488 * to destroy the pool.
7489 **/
7490static void
7491lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
7492{
7493 struct lpfc_cq_event *cq_event, *next_cq_event;
7494
7495 list_for_each_entry_safe(cq_event, next_cq_event,
7496 &phba->sli4_hba.sp_cqe_event_pool, list) {
7497 list_del(&cq_event->list);
7498 kfree(cq_event);
7499 }
7500}
7501
7502/**
7503 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7504 * @phba: pointer to lpfc hba data structure.
7505 *
7506 * This routine is the lock free version of the API invoked to allocate a
7507 * completion-queue event from the free pool.
7508 *
7509 * Return: Pointer to the newly allocated completion-queue event if successful
7510 * NULL otherwise.
7511 **/
7512struct lpfc_cq_event *
7513__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
7514{
7515 struct lpfc_cq_event *cq_event = NULL;
7516
7517 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
7518 struct lpfc_cq_event, list);
7519 return cq_event;
7520}
7521
7522/**
7523 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7524 * @phba: pointer to lpfc hba data structure.
7525 *
7526 * This routine is the lock version of the API invoked to allocate a
7527 * completion-queue event from the free pool.
7528 *
7529 * Return: Pointer to the newly allocated completion-queue event if successful
7530 * NULL otherwise.
7531 **/
7532struct lpfc_cq_event *
7533lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
7534{
7535 struct lpfc_cq_event *cq_event;
7536 unsigned long iflags;
7537
7538 spin_lock_irqsave(&phba->hbalock, iflags);
7539 cq_event = __lpfc_sli4_cq_event_alloc(phba);
7540 spin_unlock_irqrestore(&phba->hbalock, iflags);
7541 return cq_event;
7542}
7543
7544/**
7545 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7546 * @phba: pointer to lpfc hba data structure.
7547 * @cq_event: pointer to the completion queue event to be freed.
7548 *
7549 * This routine is the lock free version of the API invoked to release a
7550 * completion-queue event back into the free pool.
7551 **/
7552void
7553__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
7554 struct lpfc_cq_event *cq_event)
7555{
7556 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
7557}
7558
7559/**
7560 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7561 * @phba: pointer to lpfc hba data structure.
7562 * @cq_event: pointer to the completion queue event to be freed.
7563 *
7564 * This routine is the lock version of the API invoked to release a
7565 * completion-queue event back into the free pool.
7566 **/
7567void
7568lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
7569 struct lpfc_cq_event *cq_event)
7570{
7571 unsigned long iflags;
7572 spin_lock_irqsave(&phba->hbalock, iflags);
7573 __lpfc_sli4_cq_event_release(phba, cq_event);
7574 spin_unlock_irqrestore(&phba->hbalock, iflags);
7575}
7576
7577/**
7578 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
7579 * @phba: pointer to lpfc hba data structure.
7580 *
7581 * This routine is to free all the pending completion-queue events to the
7582 * back into the free pool for device reset.
7583 **/
7584static void
7585lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
7586{
7587 LIST_HEAD(cqelist);
7588 struct lpfc_cq_event *cqe;
7589 unsigned long iflags;
7590
7591 /* Retrieve all the pending WCQEs from pending WCQE lists */
7592 spin_lock_irqsave(&phba->hbalock, iflags);
7593 /* Pending FCP XRI abort events */
7594 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
7595 &cqelist);
7596 /* Pending ELS XRI abort events */
7597 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
7598 &cqelist);
7599 /* Pending asynnc events */
7600 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
7601 &cqelist);
7602 spin_unlock_irqrestore(&phba->hbalock, iflags);
7603
7604 while (!list_empty(&cqelist)) {
7605 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
7606 lpfc_sli4_cq_event_release(phba, cqe);
7607 }
7608}
7609
7610/**
7611 * lpfc_pci_function_reset - Reset pci function.
7612 * @phba: pointer to lpfc hba data structure.
7613 *
7614 * This routine is invoked to request a PCI function reset. It will destroys
7615 * all resources assigned to the PCI function which originates this request.
7616 *
7617 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007618 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007619 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007620 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007621 **/
7622int
7623lpfc_pci_function_reset(struct lpfc_hba *phba)
7624{
7625 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05007626 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04007627 uint32_t shdr_status, shdr_add_status;
James Smart2fcee4b2010-12-15 17:57:46 -05007628 uint32_t rdy_chk, num_resets = 0, reset_again = 0;
James Smartda0436e2009-05-22 14:51:39 -04007629 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05007630 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -05007631 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -04007632
James Smart2fcee4b2010-12-15 17:57:46 -05007633 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7634 switch (if_type) {
7635 case LPFC_SLI_INTF_IF_TYPE_0:
7636 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7637 GFP_KERNEL);
7638 if (!mboxq) {
7639 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7640 "0494 Unable to allocate memory for "
7641 "issuing SLI_FUNCTION_RESET mailbox "
7642 "command\n");
7643 return -ENOMEM;
7644 }
7645
7646 /* Setup PCI function reset mailbox-ioctl command */
7647 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
7648 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
7649 LPFC_SLI4_MBX_EMBED);
7650 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7651 shdr = (union lpfc_sli4_cfg_shdr *)
7652 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
7653 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7654 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
7655 &shdr->response);
7656 if (rc != MBX_TIMEOUT)
7657 mempool_free(mboxq, phba->mbox_mem_pool);
7658 if (shdr_status || shdr_add_status || rc) {
7659 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7660 "0495 SLI_FUNCTION_RESET mailbox "
7661 "failed with status x%x add_status x%x,"
7662 " mbx status x%x\n",
7663 shdr_status, shdr_add_status, rc);
7664 rc = -ENXIO;
7665 }
7666 break;
7667 case LPFC_SLI_INTF_IF_TYPE_2:
7668 for (num_resets = 0;
7669 num_resets < MAX_IF_TYPE_2_RESETS;
7670 num_resets++) {
7671 reg_data.word0 = 0;
7672 bf_set(lpfc_sliport_ctrl_end, &reg_data,
7673 LPFC_SLIPORT_LITTLE_ENDIAN);
7674 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
7675 LPFC_SLIPORT_INIT_PORT);
7676 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
7677 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -05007678 /* flush */
James Smart2b81f942012-03-01 22:37:18 -05007679 pci_read_config_word(phba->pcidev,
7680 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -05007681 /*
7682 * Poll the Port Status Register and wait for RDY for
7683 * up to 10 seconds. If the port doesn't respond, treat
7684 * it as an error. If the port responds with RN, start
7685 * the loop again.
7686 */
7687 for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) {
James Smart73d91e52011-10-10 21:32:10 -04007688 msleep(10);
James Smart9940b972011-03-11 16:06:12 -05007689 if (lpfc_readl(phba->sli4_hba.u.if_type2.
7690 STATUSregaddr, &reg_data.word0)) {
7691 rc = -ENODEV;
James Smart73d91e52011-10-10 21:32:10 -04007692 goto out;
James Smart9940b972011-03-11 16:06:12 -05007693 }
James Smart6b5151f2012-01-18 16:24:06 -05007694 if (bf_get(lpfc_sliport_status_rn, &reg_data))
7695 reset_again++;
James Smart2fcee4b2010-12-15 17:57:46 -05007696 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
7697 break;
James Smart2fcee4b2010-12-15 17:57:46 -05007698 }
7699
7700 /*
7701 * If the port responds to the init request with
7702 * reset needed, delay for a bit and restart the loop.
7703 */
James Smart6b5151f2012-01-18 16:24:06 -05007704 if (reset_again && (rdy_chk < 1000)) {
James Smart2fcee4b2010-12-15 17:57:46 -05007705 msleep(10);
7706 reset_again = 0;
7707 continue;
7708 }
7709
7710 /* Detect any port errors. */
James Smart2fcee4b2010-12-15 17:57:46 -05007711 if ((bf_get(lpfc_sliport_status_err, &reg_data)) ||
7712 (rdy_chk >= 1000)) {
7713 phba->work_status[0] = readl(
7714 phba->sli4_hba.u.if_type2.ERR1regaddr);
7715 phba->work_status[1] = readl(
7716 phba->sli4_hba.u.if_type2.ERR2regaddr);
7717 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05007718 "2890 Port error detected during port "
James Smart8a9d2e82012-05-09 21:16:12 -04007719 "reset(%d): wait_tmo:%d ms, "
7720 "port status reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05007721 "error 1=0x%x, error 2=0x%x\n",
James Smart8a9d2e82012-05-09 21:16:12 -04007722 num_resets, rdy_chk*10,
7723 reg_data.word0,
James Smart2fcee4b2010-12-15 17:57:46 -05007724 phba->work_status[0],
7725 phba->work_status[1]);
7726 rc = -ENODEV;
7727 }
7728
7729 /*
7730 * Terminate the outer loop provided the Port indicated
7731 * ready within 10 seconds.
7732 */
7733 if (rdy_chk < 1000)
7734 break;
7735 }
James Smart05580562011-05-24 11:40:48 -04007736 /* delay driver action following IF_TYPE_2 function reset */
7737 msleep(100);
James Smart2fcee4b2010-12-15 17:57:46 -05007738 break;
7739 case LPFC_SLI_INTF_IF_TYPE_1:
7740 default:
7741 break;
James Smartda0436e2009-05-22 14:51:39 -04007742 }
7743
James Smart73d91e52011-10-10 21:32:10 -04007744out:
James Smart2fcee4b2010-12-15 17:57:46 -05007745 /* Catch the not-ready port failure after a port reset. */
7746 if (num_resets >= MAX_IF_TYPE_2_RESETS)
7747 rc = -ENODEV;
7748
James Smartda0436e2009-05-22 14:51:39 -04007749 return rc;
7750}
7751
7752/**
James Smartda0436e2009-05-22 14:51:39 -04007753 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
7754 * @phba: pointer to lpfc hba data structure.
7755 *
7756 * This routine is invoked to set up the PCI device memory space for device
7757 * with SLI-4 interface spec.
7758 *
7759 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007760 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04007761 * other values - error
7762 **/
7763static int
7764lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
7765{
7766 struct pci_dev *pdev;
7767 unsigned long bar0map_len, bar1map_len, bar2map_len;
7768 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05007769 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04007770
7771 /* Obtain PCI device reference */
7772 if (!phba->pcidev)
7773 return error;
7774 else
7775 pdev = phba->pcidev;
7776
7777 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05007778 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
7779 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
7780 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
7781 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smartda0436e2009-05-22 14:51:39 -04007782 return error;
Michael Reed8e685972009-09-18 12:02:05 -05007783 }
7784 }
James Smartda0436e2009-05-22 14:51:39 -04007785
James Smart2fcee4b2010-12-15 17:57:46 -05007786 /*
7787 * The BARs and register set definitions and offset locations are
7788 * dependent on the if_type.
7789 */
7790 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
7791 &phba->sli4_hba.sli_intf.word0)) {
7792 return error;
7793 }
7794
7795 /* There is no SLI3 failback for SLI4 devices. */
7796 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
7797 LPFC_SLI_INTF_VALID) {
7798 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7799 "2894 SLI_INTF reg contents invalid "
7800 "sli_intf reg 0x%x\n",
7801 phba->sli4_hba.sli_intf.word0);
7802 return error;
7803 }
7804
7805 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7806 /*
7807 * Get the bus address of SLI4 device Bar regions and the
7808 * number of bytes required by each mapping. The mapping of the
7809 * particular PCI BARs regions is dependent on the type of
7810 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04007811 */
James Smart1dfb5a42010-02-12 14:40:50 -05007812 if (pci_resource_start(pdev, 0)) {
7813 phba->pci_bar0_map = pci_resource_start(pdev, 0);
7814 bar0map_len = pci_resource_len(pdev, 0);
James Smart2fcee4b2010-12-15 17:57:46 -05007815
7816 /*
7817 * Map SLI4 PCI Config Space Register base to a kernel virtual
7818 * addr
7819 */
7820 phba->sli4_hba.conf_regs_memmap_p =
7821 ioremap(phba->pci_bar0_map, bar0map_len);
7822 if (!phba->sli4_hba.conf_regs_memmap_p) {
7823 dev_printk(KERN_ERR, &pdev->dev,
7824 "ioremap failed for SLI4 PCI config "
7825 "registers.\n");
7826 goto out;
7827 }
7828 /* Set up BAR0 PCI config space register memory map */
7829 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05007830 } else {
7831 phba->pci_bar0_map = pci_resource_start(pdev, 1);
7832 bar0map_len = pci_resource_len(pdev, 1);
James Smart2fcee4b2010-12-15 17:57:46 -05007833 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
7834 dev_printk(KERN_ERR, &pdev->dev,
7835 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
7836 goto out;
7837 }
7838 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04007839 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05007840 if (!phba->sli4_hba.conf_regs_memmap_p) {
7841 dev_printk(KERN_ERR, &pdev->dev,
7842 "ioremap failed for SLI4 PCI config "
7843 "registers.\n");
7844 goto out;
7845 }
7846 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04007847 }
7848
James Smartc31098c2011-04-16 11:03:33 -04007849 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
7850 (pci_resource_start(pdev, 2))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007851 /*
7852 * Map SLI4 if type 0 HBA Control Register base to a kernel
7853 * virtual address and setup the registers.
7854 */
7855 phba->pci_bar1_map = pci_resource_start(pdev, 2);
7856 bar1map_len = pci_resource_len(pdev, 2);
7857 phba->sli4_hba.ctrl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04007858 ioremap(phba->pci_bar1_map, bar1map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05007859 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
7860 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04007861 "ioremap failed for SLI4 HBA control registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05007862 goto out_iounmap_conf;
7863 }
7864 lpfc_sli4_bar1_register_memmap(phba);
James Smartda0436e2009-05-22 14:51:39 -04007865 }
7866
James Smartc31098c2011-04-16 11:03:33 -04007867 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
7868 (pci_resource_start(pdev, 4))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007869 /*
7870 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
7871 * virtual address and setup the registers.
7872 */
7873 phba->pci_bar2_map = pci_resource_start(pdev, 4);
7874 bar2map_len = pci_resource_len(pdev, 4);
7875 phba->sli4_hba.drbl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04007876 ioremap(phba->pci_bar2_map, bar2map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05007877 if (!phba->sli4_hba.drbl_regs_memmap_p) {
7878 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04007879 "ioremap failed for SLI4 HBA doorbell registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05007880 goto out_iounmap_ctrl;
7881 }
7882 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
7883 if (error)
7884 goto out_iounmap_all;
James Smartda0436e2009-05-22 14:51:39 -04007885 }
7886
James Smartda0436e2009-05-22 14:51:39 -04007887 return 0;
7888
7889out_iounmap_all:
7890 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
7891out_iounmap_ctrl:
7892 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
7893out_iounmap_conf:
7894 iounmap(phba->sli4_hba.conf_regs_memmap_p);
7895out:
7896 return error;
7897}
7898
7899/**
7900 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
7901 * @phba: pointer to lpfc hba data structure.
7902 *
7903 * This routine is invoked to unset the PCI device memory space for device
7904 * with SLI-4 interface spec.
7905 **/
7906static void
7907lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
7908{
James Smart2e90f4b2011-12-13 13:22:37 -05007909 uint32_t if_type;
7910 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -04007911
James Smart2e90f4b2011-12-13 13:22:37 -05007912 switch (if_type) {
7913 case LPFC_SLI_INTF_IF_TYPE_0:
7914 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
7915 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
7916 iounmap(phba->sli4_hba.conf_regs_memmap_p);
7917 break;
7918 case LPFC_SLI_INTF_IF_TYPE_2:
7919 iounmap(phba->sli4_hba.conf_regs_memmap_p);
7920 break;
7921 case LPFC_SLI_INTF_IF_TYPE_1:
7922 default:
7923 dev_printk(KERN_ERR, &phba->pcidev->dev,
7924 "FATAL - unsupported SLI4 interface type - %d\n",
7925 if_type);
7926 break;
7927 }
James Smartda0436e2009-05-22 14:51:39 -04007928}
7929
7930/**
James Smart3772a992009-05-22 14:50:54 -04007931 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
7932 * @phba: pointer to lpfc hba data structure.
7933 *
7934 * This routine is invoked to enable the MSI-X interrupt vectors to device
7935 * with SLI-3 interface specs. The kernel function pci_enable_msix() is
7936 * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
7937 * invoked, enables either all or nothing, depending on the current
7938 * availability of PCI vector resources. The device driver is responsible
7939 * for calling the individual request_irq() to register each MSI-X vector
7940 * with a interrupt handler, which is done in this function. Note that
7941 * later when device is unloading, the driver should always call free_irq()
7942 * on all MSI-X vectors it has done request_irq() on before calling
7943 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
7944 * will be left with MSI-X enabled and leaks its vectors.
7945 *
7946 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007947 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007948 * other values - error
7949 **/
7950static int
7951lpfc_sli_enable_msix(struct lpfc_hba *phba)
7952{
7953 int rc, i;
7954 LPFC_MBOXQ_t *pmb;
7955
7956 /* Set up MSI-X multi-message vectors */
7957 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
7958 phba->msix_entries[i].entry = i;
7959
7960 /* Configure MSI-X capability structure */
7961 rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
7962 ARRAY_SIZE(phba->msix_entries));
7963 if (rc) {
7964 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7965 "0420 PCI enable MSI-X failed (%d)\n", rc);
7966 goto msi_fail_out;
7967 }
7968 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
7969 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7970 "0477 MSI-X entry[%d]: vector=x%x "
7971 "message=%d\n", i,
7972 phba->msix_entries[i].vector,
7973 phba->msix_entries[i].entry);
7974 /*
7975 * Assign MSI-X vectors to interrupt handlers
7976 */
7977
7978 /* vector-0 is associated to slow-path handler */
7979 rc = request_irq(phba->msix_entries[0].vector,
7980 &lpfc_sli_sp_intr_handler, IRQF_SHARED,
7981 LPFC_SP_DRIVER_HANDLER_NAME, phba);
7982 if (rc) {
7983 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7984 "0421 MSI-X slow-path request_irq failed "
7985 "(%d)\n", rc);
7986 goto msi_fail_out;
7987 }
7988
7989 /* vector-1 is associated to fast-path handler */
7990 rc = request_irq(phba->msix_entries[1].vector,
7991 &lpfc_sli_fp_intr_handler, IRQF_SHARED,
7992 LPFC_FP_DRIVER_HANDLER_NAME, phba);
7993
7994 if (rc) {
7995 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7996 "0429 MSI-X fast-path request_irq failed "
7997 "(%d)\n", rc);
7998 goto irq_fail_out;
7999 }
8000
8001 /*
8002 * Configure HBA MSI-X attention conditions to messages
8003 */
8004 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8005
8006 if (!pmb) {
8007 rc = -ENOMEM;
8008 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8009 "0474 Unable to allocate memory for issuing "
8010 "MBOX_CONFIG_MSI command\n");
8011 goto mem_fail_out;
8012 }
8013 rc = lpfc_config_msi(phba, pmb);
8014 if (rc)
8015 goto mbx_fail_out;
8016 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
8017 if (rc != MBX_SUCCESS) {
8018 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
8019 "0351 Config MSI mailbox command failed, "
8020 "mbxCmd x%x, mbxStatus x%x\n",
8021 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
8022 goto mbx_fail_out;
8023 }
8024
8025 /* Free memory allocated for mailbox command */
8026 mempool_free(pmb, phba->mbox_mem_pool);
8027 return rc;
8028
8029mbx_fail_out:
8030 /* Free memory allocated for mailbox command */
8031 mempool_free(pmb, phba->mbox_mem_pool);
8032
8033mem_fail_out:
8034 /* free the irq already requested */
8035 free_irq(phba->msix_entries[1].vector, phba);
8036
8037irq_fail_out:
8038 /* free the irq already requested */
8039 free_irq(phba->msix_entries[0].vector, phba);
8040
8041msi_fail_out:
8042 /* Unconfigure MSI-X capability structure */
8043 pci_disable_msix(phba->pcidev);
8044 return rc;
8045}
8046
8047/**
8048 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
8049 * @phba: pointer to lpfc hba data structure.
8050 *
8051 * This routine is invoked to release the MSI-X vectors and then disable the
8052 * MSI-X interrupt mode to device with SLI-3 interface spec.
8053 **/
8054static void
8055lpfc_sli_disable_msix(struct lpfc_hba *phba)
8056{
8057 int i;
8058
8059 /* Free up MSI-X multi-message vectors */
8060 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8061 free_irq(phba->msix_entries[i].vector, phba);
8062 /* Disable MSI-X */
8063 pci_disable_msix(phba->pcidev);
8064
8065 return;
8066}
8067
8068/**
8069 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
8070 * @phba: pointer to lpfc hba data structure.
8071 *
8072 * This routine is invoked to enable the MSI interrupt mode to device with
8073 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
8074 * enable the MSI vector. The device driver is responsible for calling the
8075 * request_irq() to register MSI vector with a interrupt the handler, which
8076 * is done in this function.
8077 *
8078 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008079 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008080 * other values - error
8081 */
8082static int
8083lpfc_sli_enable_msi(struct lpfc_hba *phba)
8084{
8085 int rc;
8086
8087 rc = pci_enable_msi(phba->pcidev);
8088 if (!rc)
8089 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8090 "0462 PCI enable MSI mode success.\n");
8091 else {
8092 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8093 "0471 PCI enable MSI mode failed (%d)\n", rc);
8094 return rc;
8095 }
8096
8097 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
8098 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8099 if (rc) {
8100 pci_disable_msi(phba->pcidev);
8101 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8102 "0478 MSI request_irq failed (%d)\n", rc);
8103 }
8104 return rc;
8105}
8106
8107/**
8108 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
8109 * @phba: pointer to lpfc hba data structure.
8110 *
8111 * This routine is invoked to disable the MSI interrupt mode to device with
8112 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
8113 * done request_irq() on before calling pci_disable_msi(). Failure to do so
8114 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
8115 * its vector.
8116 */
8117static void
8118lpfc_sli_disable_msi(struct lpfc_hba *phba)
8119{
8120 free_irq(phba->pcidev->irq, phba);
8121 pci_disable_msi(phba->pcidev);
8122 return;
8123}
8124
8125/**
8126 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
8127 * @phba: pointer to lpfc hba data structure.
8128 *
8129 * This routine is invoked to enable device interrupt and associate driver's
8130 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
8131 * spec. Depends on the interrupt mode configured to the driver, the driver
8132 * will try to fallback from the configured interrupt mode to an interrupt
8133 * mode which is supported by the platform, kernel, and device in the order
8134 * of:
8135 * MSI-X -> MSI -> IRQ.
8136 *
8137 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008138 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008139 * other values - error
8140 **/
8141static uint32_t
8142lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
8143{
8144 uint32_t intr_mode = LPFC_INTR_ERROR;
8145 int retval;
8146
8147 if (cfg_mode == 2) {
8148 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
8149 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
8150 if (!retval) {
8151 /* Now, try to enable MSI-X interrupt mode */
8152 retval = lpfc_sli_enable_msix(phba);
8153 if (!retval) {
8154 /* Indicate initialization to MSI-X mode */
8155 phba->intr_type = MSIX;
8156 intr_mode = 2;
8157 }
8158 }
8159 }
8160
8161 /* Fallback to MSI if MSI-X initialization failed */
8162 if (cfg_mode >= 1 && phba->intr_type == NONE) {
8163 retval = lpfc_sli_enable_msi(phba);
8164 if (!retval) {
8165 /* Indicate initialization to MSI mode */
8166 phba->intr_type = MSI;
8167 intr_mode = 1;
8168 }
8169 }
8170
8171 /* Fallback to INTx if both MSI-X/MSI initalization failed */
8172 if (phba->intr_type == NONE) {
8173 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
8174 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8175 if (!retval) {
8176 /* Indicate initialization to INTx mode */
8177 phba->intr_type = INTx;
8178 intr_mode = 0;
8179 }
8180 }
8181 return intr_mode;
8182}
8183
8184/**
8185 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
8186 * @phba: pointer to lpfc hba data structure.
8187 *
8188 * This routine is invoked to disable device interrupt and disassociate the
8189 * driver's interrupt handler(s) from interrupt vector(s) to device with
8190 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
8191 * release the interrupt vector(s) for the message signaled interrupt.
8192 **/
8193static void
8194lpfc_sli_disable_intr(struct lpfc_hba *phba)
8195{
8196 /* Disable the currently initialized interrupt mode */
8197 if (phba->intr_type == MSIX)
8198 lpfc_sli_disable_msix(phba);
8199 else if (phba->intr_type == MSI)
8200 lpfc_sli_disable_msi(phba);
8201 else if (phba->intr_type == INTx)
8202 free_irq(phba->pcidev->irq, phba);
8203
8204 /* Reset interrupt management states */
8205 phba->intr_type = NONE;
8206 phba->sli.slistat.sli_intr = 0;
8207
8208 return;
8209}
8210
8211/**
James Smartda0436e2009-05-22 14:51:39 -04008212 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
8213 * @phba: pointer to lpfc hba data structure.
8214 *
8215 * This routine is invoked to enable the MSI-X interrupt vectors to device
8216 * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
8217 * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
8218 * enables either all or nothing, depending on the current availability of
8219 * PCI vector resources. The device driver is responsible for calling the
8220 * individual request_irq() to register each MSI-X vector with a interrupt
8221 * handler, which is done in this function. Note that later when device is
8222 * unloading, the driver should always call free_irq() on all MSI-X vectors
8223 * it has done request_irq() on before calling pci_disable_msix(). Failure
8224 * to do so results in a BUG_ON() and a device will be left with MSI-X
8225 * enabled and leaks its vectors.
8226 *
8227 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008228 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008229 * other values - error
8230 **/
8231static int
8232lpfc_sli4_enable_msix(struct lpfc_hba *phba)
8233{
James Smart75baf692010-06-08 18:31:21 -04008234 int vectors, rc, index;
James Smartda0436e2009-05-22 14:51:39 -04008235
8236 /* Set up MSI-X multi-message vectors */
James Smart82c3e9b2012-09-29 11:29:50 -04008237 for (index = 0; index < phba->cfg_fcp_io_channel; index++)
James Smartda0436e2009-05-22 14:51:39 -04008238 phba->sli4_hba.msix_entries[index].entry = index;
8239
8240 /* Configure MSI-X capability structure */
James Smart82c3e9b2012-09-29 11:29:50 -04008241 vectors = phba->cfg_fcp_io_channel;
James Smart75baf692010-06-08 18:31:21 -04008242enable_msix_vectors:
James Smartda0436e2009-05-22 14:51:39 -04008243 rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries,
James Smart75baf692010-06-08 18:31:21 -04008244 vectors);
8245 if (rc > 1) {
8246 vectors = rc;
8247 goto enable_msix_vectors;
8248 } else if (rc) {
James Smartda0436e2009-05-22 14:51:39 -04008249 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8250 "0484 PCI enable MSI-X failed (%d)\n", rc);
8251 goto msi_fail_out;
8252 }
James Smart75baf692010-06-08 18:31:21 -04008253
James Smartda0436e2009-05-22 14:51:39 -04008254 /* Log MSI-X vector assignment */
James Smart75baf692010-06-08 18:31:21 -04008255 for (index = 0; index < vectors; index++)
James Smartda0436e2009-05-22 14:51:39 -04008256 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8257 "0489 MSI-X entry[%d]: vector=x%x "
8258 "message=%d\n", index,
8259 phba->sli4_hba.msix_entries[index].vector,
8260 phba->sli4_hba.msix_entries[index].entry);
James Smart67d12732012-08-03 12:36:13 -04008261
James Smartda0436e2009-05-22 14:51:39 -04008262 /*
8263 * Assign MSI-X vectors to interrupt handlers
8264 */
James Smart67d12732012-08-03 12:36:13 -04008265 for (index = 0; index < vectors; index++) {
James Smart4305f182012-08-03 12:36:33 -04008266 memset(&phba->sli4_hba.handler_name[index], 0, 16);
8267 sprintf((char *)&phba->sli4_hba.handler_name[index],
8268 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -04008269
James Smart67d12732012-08-03 12:36:13 -04008270 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
8271 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
James Smartba20c852012-08-03 12:36:52 -04008272 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].fcp_eq_in_use, 1);
James Smartda0436e2009-05-22 14:51:39 -04008273 rc = request_irq(phba->sli4_hba.msix_entries[index].vector,
James Smart67d12732012-08-03 12:36:13 -04008274 &lpfc_sli4_hba_intr_handler, IRQF_SHARED,
James Smart4305f182012-08-03 12:36:33 -04008275 (char *)&phba->sli4_hba.handler_name[index],
James Smart67d12732012-08-03 12:36:13 -04008276 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -04008277 if (rc) {
8278 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8279 "0486 MSI-X fast-path (%d) "
8280 "request_irq failed (%d)\n", index, rc);
8281 goto cfg_fail_out;
8282 }
8283 }
8284
James Smart82c3e9b2012-09-29 11:29:50 -04008285 if (vectors != phba->cfg_fcp_io_channel) {
8286 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8287 "3238 Reducing IO channels to match number of "
8288 "MSI-X vectors, requested %d got %d\n",
8289 phba->cfg_fcp_io_channel, vectors);
8290 phba->cfg_fcp_io_channel = vectors;
8291 }
James Smartda0436e2009-05-22 14:51:39 -04008292 return rc;
8293
8294cfg_fail_out:
8295 /* free the irq already requested */
James Smart67d12732012-08-03 12:36:13 -04008296 for (--index; index >= 0; index--)
8297 free_irq(phba->sli4_hba.msix_entries[index].vector,
8298 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -04008299
8300msi_fail_out:
8301 /* Unconfigure MSI-X capability structure */
8302 pci_disable_msix(phba->pcidev);
8303 return rc;
8304}
8305
8306/**
8307 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
8308 * @phba: pointer to lpfc hba data structure.
8309 *
8310 * This routine is invoked to release the MSI-X vectors and then disable the
8311 * MSI-X interrupt mode to device with SLI-4 interface spec.
8312 **/
8313static void
8314lpfc_sli4_disable_msix(struct lpfc_hba *phba)
8315{
8316 int index;
8317
8318 /* Free up MSI-X multi-message vectors */
James Smart82c3e9b2012-09-29 11:29:50 -04008319 for (index = 0; index < phba->cfg_fcp_io_channel; index++)
James Smartda0436e2009-05-22 14:51:39 -04008320 free_irq(phba->sli4_hba.msix_entries[index].vector,
James Smart67d12732012-08-03 12:36:13 -04008321 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smart75baf692010-06-08 18:31:21 -04008322
James Smartda0436e2009-05-22 14:51:39 -04008323 /* Disable MSI-X */
8324 pci_disable_msix(phba->pcidev);
8325
8326 return;
8327}
8328
8329/**
8330 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
8331 * @phba: pointer to lpfc hba data structure.
8332 *
8333 * This routine is invoked to enable the MSI interrupt mode to device with
8334 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
8335 * to enable the MSI vector. The device driver is responsible for calling
8336 * the request_irq() to register MSI vector with a interrupt the handler,
8337 * which is done in this function.
8338 *
8339 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008340 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008341 * other values - error
8342 **/
8343static int
8344lpfc_sli4_enable_msi(struct lpfc_hba *phba)
8345{
8346 int rc, index;
8347
8348 rc = pci_enable_msi(phba->pcidev);
8349 if (!rc)
8350 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8351 "0487 PCI enable MSI mode success.\n");
8352 else {
8353 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8354 "0488 PCI enable MSI mode failed (%d)\n", rc);
8355 return rc;
8356 }
8357
8358 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
8359 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8360 if (rc) {
8361 pci_disable_msi(phba->pcidev);
8362 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8363 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -04008364 return rc;
James Smartda0436e2009-05-22 14:51:39 -04008365 }
8366
James Smart67d12732012-08-03 12:36:13 -04008367 for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
James Smartda0436e2009-05-22 14:51:39 -04008368 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
8369 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
8370 }
8371
James Smart75baf692010-06-08 18:31:21 -04008372 return 0;
James Smartda0436e2009-05-22 14:51:39 -04008373}
8374
8375/**
8376 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
8377 * @phba: pointer to lpfc hba data structure.
8378 *
8379 * This routine is invoked to disable the MSI interrupt mode to device with
8380 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
8381 * done request_irq() on before calling pci_disable_msi(). Failure to do so
8382 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
8383 * its vector.
8384 **/
8385static void
8386lpfc_sli4_disable_msi(struct lpfc_hba *phba)
8387{
8388 free_irq(phba->pcidev->irq, phba);
8389 pci_disable_msi(phba->pcidev);
8390 return;
8391}
8392
8393/**
8394 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
8395 * @phba: pointer to lpfc hba data structure.
8396 *
8397 * This routine is invoked to enable device interrupt and associate driver's
8398 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
8399 * interface spec. Depends on the interrupt mode configured to the driver,
8400 * the driver will try to fallback from the configured interrupt mode to an
8401 * interrupt mode which is supported by the platform, kernel, and device in
8402 * the order of:
8403 * MSI-X -> MSI -> IRQ.
8404 *
8405 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008406 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008407 * other values - error
8408 **/
8409static uint32_t
8410lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
8411{
8412 uint32_t intr_mode = LPFC_INTR_ERROR;
8413 int retval, index;
8414
8415 if (cfg_mode == 2) {
8416 /* Preparation before conf_msi mbox cmd */
8417 retval = 0;
8418 if (!retval) {
8419 /* Now, try to enable MSI-X interrupt mode */
8420 retval = lpfc_sli4_enable_msix(phba);
8421 if (!retval) {
8422 /* Indicate initialization to MSI-X mode */
8423 phba->intr_type = MSIX;
8424 intr_mode = 2;
8425 }
8426 }
8427 }
8428
8429 /* Fallback to MSI if MSI-X initialization failed */
8430 if (cfg_mode >= 1 && phba->intr_type == NONE) {
8431 retval = lpfc_sli4_enable_msi(phba);
8432 if (!retval) {
8433 /* Indicate initialization to MSI mode */
8434 phba->intr_type = MSI;
8435 intr_mode = 1;
8436 }
8437 }
8438
8439 /* Fallback to INTx if both MSI-X/MSI initalization failed */
8440 if (phba->intr_type == NONE) {
8441 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
8442 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8443 if (!retval) {
8444 /* Indicate initialization to INTx mode */
8445 phba->intr_type = INTx;
8446 intr_mode = 0;
James Smart67d12732012-08-03 12:36:13 -04008447 for (index = 0; index < phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04008448 index++) {
8449 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
8450 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
James Smartba20c852012-08-03 12:36:52 -04008451 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
8452 fcp_eq_in_use, 1);
James Smartda0436e2009-05-22 14:51:39 -04008453 }
8454 }
8455 }
8456 return intr_mode;
8457}
8458
8459/**
8460 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
8461 * @phba: pointer to lpfc hba data structure.
8462 *
8463 * This routine is invoked to disable device interrupt and disassociate
8464 * the driver's interrupt handler(s) from interrupt vector(s) to device
8465 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
8466 * will release the interrupt vector(s) for the message signaled interrupt.
8467 **/
8468static void
8469lpfc_sli4_disable_intr(struct lpfc_hba *phba)
8470{
8471 /* Disable the currently initialized interrupt mode */
8472 if (phba->intr_type == MSIX)
8473 lpfc_sli4_disable_msix(phba);
8474 else if (phba->intr_type == MSI)
8475 lpfc_sli4_disable_msi(phba);
8476 else if (phba->intr_type == INTx)
8477 free_irq(phba->pcidev->irq, phba);
8478
8479 /* Reset interrupt management states */
8480 phba->intr_type = NONE;
8481 phba->sli.slistat.sli_intr = 0;
8482
8483 return;
8484}
8485
8486/**
James Smart3772a992009-05-22 14:50:54 -04008487 * lpfc_unset_hba - Unset SLI3 hba device initialization
8488 * @phba: pointer to lpfc hba data structure.
8489 *
8490 * This routine is invoked to unset the HBA device initialization steps to
8491 * a device with SLI-3 interface spec.
8492 **/
8493static void
8494lpfc_unset_hba(struct lpfc_hba *phba)
8495{
8496 struct lpfc_vport *vport = phba->pport;
8497 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8498
8499 spin_lock_irq(shost->host_lock);
8500 vport->load_flag |= FC_UNLOADING;
8501 spin_unlock_irq(shost->host_lock);
8502
James Smart72859902012-01-18 16:25:38 -05008503 kfree(phba->vpi_bmask);
8504 kfree(phba->vpi_ids);
8505
James Smart3772a992009-05-22 14:50:54 -04008506 lpfc_stop_hba_timers(phba);
8507
8508 phba->pport->work_port_events = 0;
8509
8510 lpfc_sli_hba_down(phba);
8511
8512 lpfc_sli_brdrestart(phba);
8513
8514 lpfc_sli_disable_intr(phba);
8515
8516 return;
8517}
8518
8519/**
James Smart5af5eee2010-10-22 11:06:38 -04008520 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
8521 * @phba: Pointer to HBA context object.
8522 *
8523 * This function is called in the SLI4 code path to wait for completion
8524 * of device's XRIs exchange busy. It will check the XRI exchange busy
8525 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
8526 * that, it will check the XRI exchange busy on outstanding FCP and ELS
8527 * I/Os every 30 seconds, log error message, and wait forever. Only when
8528 * all XRI exchange busy complete, the driver unload shall proceed with
8529 * invoking the function reset ioctl mailbox command to the CNA and the
8530 * the rest of the driver unload resource release.
8531 **/
8532static void
8533lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
8534{
8535 int wait_time = 0;
8536 int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
8537 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
8538
8539 while (!fcp_xri_cmpl || !els_xri_cmpl) {
8540 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
8541 if (!fcp_xri_cmpl)
8542 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8543 "2877 FCP XRI exchange busy "
8544 "wait time: %d seconds.\n",
8545 wait_time/1000);
8546 if (!els_xri_cmpl)
8547 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8548 "2878 ELS XRI exchange busy "
8549 "wait time: %d seconds.\n",
8550 wait_time/1000);
8551 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
8552 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
8553 } else {
8554 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
8555 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
8556 }
8557 fcp_xri_cmpl =
8558 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
8559 els_xri_cmpl =
8560 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
8561 }
8562}
8563
8564/**
James Smartda0436e2009-05-22 14:51:39 -04008565 * lpfc_sli4_hba_unset - Unset the fcoe hba
8566 * @phba: Pointer to HBA context object.
8567 *
8568 * This function is called in the SLI4 code path to reset the HBA's FCoE
8569 * function. The caller is not required to hold any lock. This routine
8570 * issues PCI function reset mailbox command to reset the FCoE function.
8571 * At the end of the function, it calls lpfc_hba_down_post function to
8572 * free any pending commands.
8573 **/
8574static void
8575lpfc_sli4_hba_unset(struct lpfc_hba *phba)
8576{
8577 int wait_cnt = 0;
8578 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -04008579 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -04008580
8581 lpfc_stop_hba_timers(phba);
8582 phba->sli4_hba.intr_enable = 0;
8583
8584 /*
8585 * Gracefully wait out the potential current outstanding asynchronous
8586 * mailbox command.
8587 */
8588
8589 /* First, block any pending async mailbox command from posted */
8590 spin_lock_irq(&phba->hbalock);
8591 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
8592 spin_unlock_irq(&phba->hbalock);
8593 /* Now, trying to wait it out if we can */
8594 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
8595 msleep(10);
8596 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
8597 break;
8598 }
8599 /* Forcefully release the outstanding mailbox command if timed out */
8600 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
8601 spin_lock_irq(&phba->hbalock);
8602 mboxq = phba->sli.mbox_active;
8603 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
8604 __lpfc_mbox_cmpl_put(phba, mboxq);
8605 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8606 phba->sli.mbox_active = NULL;
8607 spin_unlock_irq(&phba->hbalock);
8608 }
8609
James Smart5af5eee2010-10-22 11:06:38 -04008610 /* Abort all iocbs associated with the hba */
8611 lpfc_sli_hba_iocb_abort(phba);
8612
8613 /* Wait for completion of device XRI exchange busy */
8614 lpfc_sli4_xri_exchange_busy_wait(phba);
8615
James Smartda0436e2009-05-22 14:51:39 -04008616 /* Disable PCI subsystem interrupt */
8617 lpfc_sli4_disable_intr(phba);
8618
James Smart912e3ac2011-05-24 11:42:11 -04008619 /* Disable SR-IOV if enabled */
8620 if (phba->cfg_sriov_nr_virtfn)
8621 pci_disable_sriov(pdev);
8622
James Smartda0436e2009-05-22 14:51:39 -04008623 /* Stop kthread signal shall trigger work_done one more time */
8624 kthread_stop(phba->worker_thread);
8625
James Smart3677a3a2010-09-29 11:19:14 -04008626 /* Reset SLI4 HBA FCoE function */
8627 lpfc_pci_function_reset(phba);
James Smart5350d872011-10-10 21:33:49 -04008628 lpfc_sli4_queue_destroy(phba);
James Smart3677a3a2010-09-29 11:19:14 -04008629
James Smartda0436e2009-05-22 14:51:39 -04008630 /* Stop the SLI4 device port */
8631 phba->pport->work_port_events = 0;
8632}
8633
James Smart28baac72010-02-12 14:42:03 -05008634 /**
8635 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
8636 * @phba: Pointer to HBA context object.
8637 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
8638 *
8639 * This function is called in the SLI4 code path to read the port's
8640 * sli4 capabilities.
8641 *
8642 * This function may be be called from any context that can block-wait
8643 * for the completion. The expectation is that this routine is called
8644 * typically from probe_one or from the online routine.
8645 **/
8646int
8647lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
8648{
8649 int rc;
8650 struct lpfc_mqe *mqe;
8651 struct lpfc_pc_sli4_params *sli4_params;
8652 uint32_t mbox_tmo;
8653
8654 rc = 0;
8655 mqe = &mboxq->u.mqe;
8656
8657 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -05008658 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -05008659 if (!phba->sli4_hba.intr_enable)
8660 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8661 else {
James Smarta183a152011-10-10 21:32:43 -04008662 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -05008663 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
8664 }
8665
8666 if (unlikely(rc))
8667 return 1;
8668
8669 sli4_params = &phba->sli4_hba.pc_sli4_params;
8670 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
8671 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
8672 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
8673 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
8674 &mqe->un.sli4_params);
8675 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
8676 &mqe->un.sli4_params);
8677 sli4_params->proto_types = mqe->un.sli4_params.word3;
8678 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
8679 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
8680 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
8681 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
8682 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
8683 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
8684 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
8685 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
8686 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
8687 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
8688 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
8689 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
8690 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
8691 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
8692 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
8693 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
8694 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
8695 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
8696 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
8697 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -04008698
8699 /* Make sure that sge_supp_len can be handled by the driver */
8700 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
8701 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
8702
James Smart28baac72010-02-12 14:42:03 -05008703 return rc;
8704}
8705
James Smartda0436e2009-05-22 14:51:39 -04008706/**
James Smartfedd3b72011-02-16 12:39:24 -05008707 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
8708 * @phba: Pointer to HBA context object.
8709 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
8710 *
8711 * This function is called in the SLI4 code path to read the port's
8712 * sli4 capabilities.
8713 *
8714 * This function may be be called from any context that can block-wait
8715 * for the completion. The expectation is that this routine is called
8716 * typically from probe_one or from the online routine.
8717 **/
8718int
8719lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
8720{
8721 int rc;
8722 struct lpfc_mqe *mqe = &mboxq->u.mqe;
8723 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -04008724 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -05008725 int length;
8726 struct lpfc_sli4_parameters *mbx_sli4_parameters;
8727
James Smart6d368e52011-05-24 11:44:12 -04008728 /*
8729 * By default, the driver assumes the SLI4 port requires RPI
8730 * header postings. The SLI4_PARAM response will correct this
8731 * assumption.
8732 */
8733 phba->sli4_hba.rpi_hdrs_in_use = 1;
8734
James Smartfedd3b72011-02-16 12:39:24 -05008735 /* Read the port's SLI4 Config Parameters */
8736 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
8737 sizeof(struct lpfc_sli4_cfg_mhdr));
8738 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8739 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
8740 length, LPFC_SLI4_MBX_EMBED);
8741 if (!phba->sli4_hba.intr_enable)
8742 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -04008743 else {
8744 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
8745 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
8746 }
James Smartfedd3b72011-02-16 12:39:24 -05008747 if (unlikely(rc))
8748 return rc;
8749 sli4_params = &phba->sli4_hba.pc_sli4_params;
8750 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
8751 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
8752 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
8753 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
8754 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
8755 mbx_sli4_parameters);
8756 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
8757 mbx_sli4_parameters);
8758 if (bf_get(cfg_phwq, mbx_sli4_parameters))
8759 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
8760 else
8761 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
8762 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
8763 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
8764 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
8765 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
8766 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
8767 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
8768 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
8769 mbx_sli4_parameters);
8770 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
8771 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -04008772 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
8773 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart05580562011-05-24 11:40:48 -04008774
8775 /* Make sure that sge_supp_len can be handled by the driver */
8776 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
8777 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
8778
James Smartfedd3b72011-02-16 12:39:24 -05008779 return 0;
8780}
8781
8782/**
James Smart3772a992009-05-22 14:50:54 -04008783 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
8784 * @pdev: pointer to PCI device
8785 * @pid: pointer to PCI device identifier
8786 *
8787 * This routine is to be called to attach a device with SLI-3 interface spec
8788 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
8789 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
8790 * information of the device and driver to see if the driver state that it can
8791 * support this kind of device. If the match is successful, the driver core
8792 * invokes this routine. If this routine determines it can claim the HBA, it
8793 * does all the initialization that it needs to do to handle the HBA properly.
8794 *
8795 * Return code
8796 * 0 - driver can claim the device
8797 * negative value - driver can not claim the device
8798 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008799static int
James Smart3772a992009-05-22 14:50:54 -04008800lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
8801{
8802 struct lpfc_hba *phba;
8803 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -04008804 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -04008805 int error;
8806 uint32_t cfg_mode, intr_mode;
8807
8808 /* Allocate memory for HBA structure */
8809 phba = lpfc_hba_alloc(pdev);
8810 if (!phba)
8811 return -ENOMEM;
8812
8813 /* Perform generic PCI device enabling operation */
8814 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -04008815 if (error)
James Smart3772a992009-05-22 14:50:54 -04008816 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -04008817
8818 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
8819 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
8820 if (error)
8821 goto out_disable_pci_dev;
8822
8823 /* Set up SLI-3 specific device PCI memory space */
8824 error = lpfc_sli_pci_mem_setup(phba);
8825 if (error) {
8826 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8827 "1402 Failed to set up pci memory space.\n");
8828 goto out_disable_pci_dev;
8829 }
8830
8831 /* Set up phase-1 common device driver resources */
8832 error = lpfc_setup_driver_resource_phase1(phba);
8833 if (error) {
8834 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8835 "1403 Failed to set up driver resource.\n");
8836 goto out_unset_pci_mem_s3;
8837 }
8838
8839 /* Set up SLI-3 specific device driver resources */
8840 error = lpfc_sli_driver_resource_setup(phba);
8841 if (error) {
8842 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8843 "1404 Failed to set up driver resource.\n");
8844 goto out_unset_pci_mem_s3;
8845 }
8846
8847 /* Initialize and populate the iocb list per host */
8848 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
8849 if (error) {
8850 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8851 "1405 Failed to initialize iocb list.\n");
8852 goto out_unset_driver_resource_s3;
8853 }
8854
8855 /* Set up common device driver resources */
8856 error = lpfc_setup_driver_resource_phase2(phba);
8857 if (error) {
8858 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8859 "1406 Failed to set up driver resource.\n");
8860 goto out_free_iocb_list;
8861 }
8862
James Smart079b5c92011-08-21 21:48:49 -04008863 /* Get the default values for Model Name and Description */
8864 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
8865
James Smart3772a992009-05-22 14:50:54 -04008866 /* Create SCSI host to the physical port */
8867 error = lpfc_create_shost(phba);
8868 if (error) {
8869 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8870 "1407 Failed to create scsi host.\n");
8871 goto out_unset_driver_resource;
8872 }
8873
8874 /* Configure sysfs attributes */
8875 vport = phba->pport;
8876 error = lpfc_alloc_sysfs_attr(vport);
8877 if (error) {
8878 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8879 "1476 Failed to allocate sysfs attr\n");
8880 goto out_destroy_shost;
8881 }
8882
James Smart6669f9b2009-10-02 15:16:45 -04008883 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -04008884 /* Now, trying to enable interrupt and bring up the device */
8885 cfg_mode = phba->cfg_use_msi;
8886 while (true) {
8887 /* Put device to a known state before enabling interrupt */
8888 lpfc_stop_port(phba);
8889 /* Configure and enable interrupt */
8890 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
8891 if (intr_mode == LPFC_INTR_ERROR) {
8892 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8893 "0431 Failed to enable interrupt.\n");
8894 error = -ENODEV;
8895 goto out_free_sysfs_attr;
8896 }
8897 /* SLI-3 HBA setup */
8898 if (lpfc_sli_hba_setup(phba)) {
8899 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8900 "1477 Failed to set up hba\n");
8901 error = -ENODEV;
8902 goto out_remove_device;
8903 }
8904
8905 /* Wait 50ms for the interrupts of previous mailbox commands */
8906 msleep(50);
8907 /* Check active interrupts on message signaled interrupts */
8908 if (intr_mode == 0 ||
8909 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
8910 /* Log the current active interrupt mode */
8911 phba->intr_mode = intr_mode;
8912 lpfc_log_intr_mode(phba, intr_mode);
8913 break;
8914 } else {
8915 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8916 "0447 Configure interrupt mode (%d) "
8917 "failed active interrupt test.\n",
8918 intr_mode);
8919 /* Disable the current interrupt mode */
8920 lpfc_sli_disable_intr(phba);
8921 /* Try next level of interrupt mode */
8922 cfg_mode = --intr_mode;
8923 }
8924 }
8925
8926 /* Perform post initialization setup */
8927 lpfc_post_init_setup(phba);
8928
8929 /* Check if there are static vports to be created. */
8930 lpfc_create_static_vport(phba);
8931
8932 return 0;
8933
8934out_remove_device:
8935 lpfc_unset_hba(phba);
8936out_free_sysfs_attr:
8937 lpfc_free_sysfs_attr(vport);
8938out_destroy_shost:
8939 lpfc_destroy_shost(phba);
8940out_unset_driver_resource:
8941 lpfc_unset_driver_resource_phase2(phba);
8942out_free_iocb_list:
8943 lpfc_free_iocb_list(phba);
8944out_unset_driver_resource_s3:
8945 lpfc_sli_driver_resource_unset(phba);
8946out_unset_pci_mem_s3:
8947 lpfc_sli_pci_mem_unset(phba);
8948out_disable_pci_dev:
8949 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -04008950 if (shost)
8951 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -04008952out_free_phba:
8953 lpfc_hba_free(phba);
8954 return error;
8955}
8956
8957/**
8958 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -04008959 * @pdev: pointer to PCI device
8960 *
James Smart3772a992009-05-22 14:50:54 -04008961 * This routine is to be called to disattach a device with SLI-3 interface
8962 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
8963 * removed from PCI bus, it performs all the necessary cleanup for the HBA
8964 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -04008965 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008966static void
James Smart3772a992009-05-22 14:50:54 -04008967lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -05008968{
James Smart2e0fef82007-06-17 19:56:36 -05008969 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8970 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -05008971 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -05008972 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -05008973 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05008974 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
8975
James Smart549e55c2007-08-02 11:09:51 -04008976 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04008977 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04008978 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05008979
James Smart858c9f62007-06-17 19:56:39 -05008980 lpfc_free_sysfs_attr(vport);
8981
James Smarteada2722008-12-04 22:39:13 -05008982 /* Release all the vports against this physical port */
8983 vports = lpfc_create_vport_work_array(phba);
8984 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -04008985 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
8986 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
8987 continue;
James Smarteada2722008-12-04 22:39:13 -05008988 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -04008989 }
James Smarteada2722008-12-04 22:39:13 -05008990 lpfc_destroy_vport_work_array(phba, vports);
8991
8992 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -05008993 fc_remove_host(shost);
8994 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04008995 lpfc_cleanup(vport);
8996
James Smart2e0fef82007-06-17 19:56:36 -05008997 /*
8998 * Bring down the SLI Layer. This step disable all interrupts,
8999 * clears the rings, discards all mailbox commands, and resets
9000 * the HBA.
9001 */
James Smarta257bf92009-04-06 18:48:10 -04009002
Justin P. Mattock48e34d02010-12-30 15:07:58 -08009003 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -05009004 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -04009005 /* Stop kthread signal shall trigger work_done one more time */
9006 kthread_stop(phba->worker_thread);
9007 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -05009008 lpfc_sli_brdrestart(phba);
9009
James Smart72859902012-01-18 16:25:38 -05009010 kfree(phba->vpi_bmask);
9011 kfree(phba->vpi_ids);
9012
James Smart3772a992009-05-22 14:50:54 -04009013 lpfc_stop_hba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05009014 spin_lock_irq(&phba->hbalock);
9015 list_del_init(&vport->listentry);
9016 spin_unlock_irq(&phba->hbalock);
9017
James Smart858c9f62007-06-17 19:56:39 -05009018 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05009019
James Smart912e3ac2011-05-24 11:42:11 -04009020 /* Disable SR-IOV if enabled */
9021 if (phba->cfg_sriov_nr_virtfn)
9022 pci_disable_sriov(pdev);
9023
James Smart5b75da22008-12-04 22:39:35 -05009024 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009025 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -05009026
9027 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05009028 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05009029
9030 /*
9031 * Call scsi_free before mem_free since scsi bufs are released to their
9032 * corresponding pools here.
9033 */
9034 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -04009035 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -05009036
James Smart34b02dc2008-08-24 21:49:55 -04009037 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
9038 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -05009039
James Smart2e0fef82007-06-17 19:56:36 -05009040 /* Free resources associated with SLI2 interface */
9041 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -04009042 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -05009043
9044 /* unmap adapter SLIM and Control Registers */
9045 iounmap(phba->ctrl_regs_memmap_p);
9046 iounmap(phba->slim_memmap_p);
9047
James Smart3772a992009-05-22 14:50:54 -04009048 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -05009049
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05009050 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05009051 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05009052}
9053
Linas Vepstas8d63f372007-02-14 14:28:36 -06009054/**
James Smart3772a992009-05-22 14:50:54 -04009055 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05009056 * @pdev: pointer to PCI device
9057 * @msg: power management message
9058 *
James Smart3772a992009-05-22 14:50:54 -04009059 * This routine is to be called from the kernel's PCI subsystem to support
9060 * system Power Management (PM) to device with SLI-3 interface spec. When
9061 * PM invokes this method, it quiesces the device by stopping the driver's
9062 * worker thread for the device, turning off device's interrupt and DMA,
9063 * and bring the device offline. Note that as the driver implements the
9064 * minimum PM requirements to a power-aware driver's PM support for the
9065 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
9066 * to the suspend() method call will be treated as SUSPEND and the driver will
9067 * fully reinitialize its device during resume() method call, the driver will
9068 * set device to PCI_D3hot state in PCI config space instead of setting it
9069 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -05009070 *
9071 * Return code
James Smart3772a992009-05-22 14:50:54 -04009072 * 0 - driver suspended the device
9073 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05009074 **/
9075static int
James Smart3772a992009-05-22 14:50:54 -04009076lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -05009077{
9078 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9079 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9080
9081 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9082 "0473 PCI device Power Management suspend.\n");
9083
9084 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -04009085 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -05009086 lpfc_offline(phba);
9087 kthread_stop(phba->worker_thread);
9088
9089 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -04009090 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -05009091
9092 /* Save device state to PCI config space */
9093 pci_save_state(pdev);
9094 pci_set_power_state(pdev, PCI_D3hot);
9095
9096 return 0;
9097}
9098
9099/**
James Smart3772a992009-05-22 14:50:54 -04009100 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05009101 * @pdev: pointer to PCI device
9102 *
James Smart3772a992009-05-22 14:50:54 -04009103 * This routine is to be called from the kernel's PCI subsystem to support
9104 * system Power Management (PM) to device with SLI-3 interface spec. When PM
9105 * invokes this method, it restores the device's PCI config space state and
9106 * fully reinitializes the device and brings it online. Note that as the
9107 * driver implements the minimum PM requirements to a power-aware driver's
9108 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
9109 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
9110 * driver will fully reinitialize its device during resume() method call,
9111 * the device will be set to PCI_D0 directly in PCI config space before
9112 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -05009113 *
9114 * Return code
James Smart3772a992009-05-22 14:50:54 -04009115 * 0 - driver suspended the device
9116 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05009117 **/
9118static int
James Smart3772a992009-05-22 14:50:54 -04009119lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -05009120{
9121 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9122 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -05009123 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05009124 int error;
9125
9126 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9127 "0452 PCI device Power Management resume.\n");
9128
9129 /* Restore device state from PCI config space */
9130 pci_set_power_state(pdev, PCI_D0);
9131 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -04009132
James Smart1dfb5a42010-02-12 14:40:50 -05009133 /*
9134 * As the new kernel behavior of pci_restore_state() API call clears
9135 * device saved_state flag, need to save the restored state again.
9136 */
9137 pci_save_state(pdev);
9138
James Smart3a55b532008-12-04 22:38:54 -05009139 if (pdev->is_busmaster)
9140 pci_set_master(pdev);
9141
9142 /* Startup the kernel thread for this host adapter. */
9143 phba->worker_thread = kthread_run(lpfc_do_work, phba,
9144 "lpfc_worker_%d", phba->brd_no);
9145 if (IS_ERR(phba->worker_thread)) {
9146 error = PTR_ERR(phba->worker_thread);
9147 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9148 "0434 PM resume failed to start worker "
9149 "thread: error=x%x.\n", error);
9150 return error;
9151 }
9152
James Smart5b75da22008-12-04 22:39:35 -05009153 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009154 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05009155 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -05009156 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -05009157 "0430 PM resume Failed to enable interrupt\n");
9158 return -EIO;
9159 } else
9160 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05009161
9162 /* Restart HBA and bring it online */
9163 lpfc_sli_brdrestart(phba);
9164 lpfc_online(phba);
9165
James Smart5b75da22008-12-04 22:39:35 -05009166 /* Log the current active interrupt mode */
9167 lpfc_log_intr_mode(phba, phba->intr_mode);
9168
James Smart3a55b532008-12-04 22:38:54 -05009169 return 0;
9170}
9171
9172/**
James Smart891478a2009-11-18 15:40:23 -05009173 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
9174 * @phba: pointer to lpfc hba data structure.
9175 *
9176 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -04009177 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -05009178 **/
9179static void
9180lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
9181{
James Smarte2af0d22010-03-15 11:25:32 -04009182 struct lpfc_sli *psli = &phba->sli;
9183 struct lpfc_sli_ring *pring;
9184
James Smart891478a2009-11-18 15:40:23 -05009185 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9186 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -04009187
9188 /*
9189 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
9190 * and let the SCSI mid-layer to retry them to recover.
9191 */
9192 pring = &psli->ring[psli->fcp_ring];
9193 lpfc_sli_abort_iocb_ring(phba, pring);
James Smart891478a2009-11-18 15:40:23 -05009194}
9195
9196/**
James Smart0d878412009-10-02 15:16:56 -04009197 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
9198 * @phba: pointer to lpfc hba data structure.
9199 *
9200 * This routine is called to prepare the SLI3 device for PCI slot reset. It
9201 * disables the device interrupt and pci device, and aborts the internal FCP
9202 * pending I/Os.
9203 **/
9204static void
9205lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
9206{
James Smart0d878412009-10-02 15:16:56 -04009207 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -05009208 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -04009209
James Smart75baf692010-06-08 18:31:21 -04009210 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -04009211 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -04009212
James Smarte2af0d22010-03-15 11:25:32 -04009213 /* Block all SCSI devices' I/Os on the host */
9214 lpfc_scsi_dev_block(phba);
9215
9216 /* stop all timers */
9217 lpfc_stop_hba_timers(phba);
9218
James Smart0d878412009-10-02 15:16:56 -04009219 /* Disable interrupt and pci device */
9220 lpfc_sli_disable_intr(phba);
9221 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -04009222
James Smarte2af0d22010-03-15 11:25:32 -04009223 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9224 lpfc_sli_flush_fcp_rings(phba);
James Smart0d878412009-10-02 15:16:56 -04009225}
9226
9227/**
9228 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
9229 * @phba: pointer to lpfc hba data structure.
9230 *
9231 * This routine is called to prepare the SLI3 device for PCI slot permanently
9232 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
9233 * pending I/Os.
9234 **/
9235static void
James Smart75baf692010-06-08 18:31:21 -04009236lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -04009237{
9238 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -05009239 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -04009240 /* Block all SCSI devices' I/Os on the host */
9241 lpfc_scsi_dev_block(phba);
9242
9243 /* stop all timers */
9244 lpfc_stop_hba_timers(phba);
9245
James Smart0d878412009-10-02 15:16:56 -04009246 /* Clean up all driver's outstanding SCSI I/Os */
9247 lpfc_sli_flush_fcp_rings(phba);
9248}
9249
9250/**
James Smart3772a992009-05-22 14:50:54 -04009251 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -04009252 * @pdev: pointer to PCI device.
9253 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -06009254 *
James Smart3772a992009-05-22 14:50:54 -04009255 * This routine is called from the PCI subsystem for I/O error handling to
9256 * device with SLI-3 interface spec. This function is called by the PCI
9257 * subsystem after a PCI bus error affecting this device has been detected.
9258 * When this function is invoked, it will need to stop all the I/Os and
9259 * interrupt(s) to the device. Once that is done, it will return
9260 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
9261 * as desired.
James Smarte59058c2008-08-24 21:49:00 -04009262 *
9263 * Return codes
James Smart0d878412009-10-02 15:16:56 -04009264 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -04009265 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
9266 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -04009267 **/
James Smart3772a992009-05-22 14:50:54 -04009268static pci_ers_result_t
9269lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -06009270{
James Smart51ef4c22007-08-02 11:10:31 -04009271 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9272 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009273
James Smart0d878412009-10-02 15:16:56 -04009274 switch (state) {
9275 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -05009276 /* Non-fatal error, prepare for recovery */
9277 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -04009278 return PCI_ERS_RESULT_CAN_RECOVER;
9279 case pci_channel_io_frozen:
9280 /* Fatal error, prepare for slot reset */
9281 lpfc_sli_prep_dev_for_reset(phba);
9282 return PCI_ERS_RESULT_NEED_RESET;
9283 case pci_channel_io_perm_failure:
9284 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -04009285 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06009286 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -04009287 default:
9288 /* Unknown state, prepare and request slot reset */
9289 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9290 "0472 Unknown PCI error state: x%x\n", state);
9291 lpfc_sli_prep_dev_for_reset(phba);
9292 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -04009293 }
Linas Vepstas8d63f372007-02-14 14:28:36 -06009294}
9295
9296/**
James Smart3772a992009-05-22 14:50:54 -04009297 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -04009298 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -06009299 *
James Smart3772a992009-05-22 14:50:54 -04009300 * This routine is called from the PCI subsystem for error handling to
9301 * device with SLI-3 interface spec. This is called after PCI bus has been
9302 * reset to restart the PCI card from scratch, as if from a cold-boot.
9303 * During the PCI subsystem error recovery, after driver returns
9304 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
9305 * recovery and then call this routine before calling the .resume method
9306 * to recover the device. This function will initialize the HBA device,
9307 * enable the interrupt, but it will just put the HBA to offline state
9308 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -04009309 *
9310 * Return codes
James Smart3772a992009-05-22 14:50:54 -04009311 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
9312 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -06009313 */
James Smart3772a992009-05-22 14:50:54 -04009314static pci_ers_result_t
9315lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -06009316{
James Smart51ef4c22007-08-02 11:10:31 -04009317 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9318 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009319 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -05009320 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009321
9322 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11009323 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -06009324 printk(KERN_ERR "lpfc: Cannot re-enable "
9325 "PCI device after reset.\n");
9326 return PCI_ERS_RESULT_DISCONNECT;
9327 }
9328
James Smart97207482008-12-04 22:39:19 -05009329 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -05009330
9331 /*
9332 * As the new kernel behavior of pci_restore_state() API call clears
9333 * device saved_state flag, need to save the restored state again.
9334 */
9335 pci_save_state(pdev);
9336
James Smart97207482008-12-04 22:39:19 -05009337 if (pdev->is_busmaster)
9338 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -06009339
James Smart92d7f7b2007-06-17 19:56:38 -05009340 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -04009341 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05009342 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06009343
James Smart5b75da22008-12-04 22:39:35 -05009344 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009345 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05009346 if (intr_mode == LPFC_INTR_ERROR) {
9347 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9348 "0427 Cannot re-enable interrupt after "
9349 "slot reset.\n");
9350 return PCI_ERS_RESULT_DISCONNECT;
9351 } else
9352 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009353
James Smart75baf692010-06-08 18:31:21 -04009354 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -04009355 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -06009356 lpfc_offline(phba);
9357 lpfc_sli_brdrestart(phba);
9358
James Smart5b75da22008-12-04 22:39:35 -05009359 /* Log the current active interrupt mode */
9360 lpfc_log_intr_mode(phba, phba->intr_mode);
9361
Linas Vepstas8d63f372007-02-14 14:28:36 -06009362 return PCI_ERS_RESULT_RECOVERED;
9363}
9364
9365/**
James Smart3772a992009-05-22 14:50:54 -04009366 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -04009367 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -06009368 *
James Smart3772a992009-05-22 14:50:54 -04009369 * This routine is called from the PCI subsystem for error handling to device
9370 * with SLI-3 interface spec. It is called when kernel error recovery tells
9371 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
9372 * error recovery. After this call, traffic can start to flow from this device
9373 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -06009374 */
James Smart3772a992009-05-22 14:50:54 -04009375static void
9376lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -06009377{
James Smart51ef4c22007-08-02 11:10:31 -04009378 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9379 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009380
James Smarte2af0d22010-03-15 11:25:32 -04009381 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -04009382 lpfc_online(phba);
James Smart0d878412009-10-02 15:16:56 -04009383
9384 /* Clean up Advanced Error Reporting (AER) if needed */
9385 if (phba->hba_flag & HBA_AER_ENABLED)
9386 pci_cleanup_aer_uncorrect_error_status(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -06009387}
9388
James Smart3772a992009-05-22 14:50:54 -04009389/**
James Smartda0436e2009-05-22 14:51:39 -04009390 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
9391 * @phba: pointer to lpfc hba data structure.
9392 *
9393 * returns the number of ELS/CT IOCBs to reserve
9394 **/
9395int
9396lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
9397{
9398 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
9399
James Smartf1126682009-06-10 17:22:44 -04009400 if (phba->sli_rev == LPFC_SLI_REV4) {
9401 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -04009402 return 10;
James Smartf1126682009-06-10 17:22:44 -04009403 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -04009404 return 25;
James Smartf1126682009-06-10 17:22:44 -04009405 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -04009406 return 50;
James Smartf1126682009-06-10 17:22:44 -04009407 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -04009408 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -04009409 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -04009410 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -04009411 else if (max_xri <= 2048)
9412 return 200;
9413 else
9414 return 250;
James Smartf1126682009-06-10 17:22:44 -04009415 } else
9416 return 0;
James Smartda0436e2009-05-22 14:51:39 -04009417}
9418
9419/**
James Smart52d52442011-05-24 11:42:45 -04009420 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -04009421 * @fw: pointer to firmware image returned from request_firmware.
James Smartce396282012-09-29 11:30:56 -04009422 * @phba: pointer to lpfc hba data structure.
James Smart52d52442011-05-24 11:42:45 -04009423 *
James Smart52d52442011-05-24 11:42:45 -04009424 **/
James Smartce396282012-09-29 11:30:56 -04009425static void
9426lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -04009427{
James Smartce396282012-09-29 11:30:56 -04009428 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -05009429 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -04009430 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -04009431 struct list_head dma_buffer_list;
9432 int i, rc = 0;
9433 struct lpfc_dmabuf *dmabuf, *next;
9434 uint32_t offset = 0, temp_offset = 0;
9435
James Smartc71ab862012-10-31 14:44:33 -04009436 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -04009437 if (!fw) {
9438 rc = -ENXIO;
9439 goto out;
9440 }
9441 image = (struct lpfc_grp_hdr *)fw->data;
9442
James Smart52d52442011-05-24 11:42:45 -04009443 INIT_LIST_HEAD(&dma_buffer_list);
James Smart079b5c92011-08-21 21:48:49 -04009444 if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) ||
9445 (bf_get_be32(lpfc_grp_hdr_file_type, image) !=
9446 LPFC_FILE_TYPE_GROUP) ||
9447 (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) ||
9448 (be32_to_cpu(image->size) != fw->size)) {
James Smart52d52442011-05-24 11:42:45 -04009449 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9450 "3022 Invalid FW image found. "
James Smart079b5c92011-08-21 21:48:49 -04009451 "Magic:%x Type:%x ID:%x\n",
9452 be32_to_cpu(image->magic_number),
9453 bf_get_be32(lpfc_grp_hdr_file_type, image),
9454 bf_get_be32(lpfc_grp_hdr_id, image));
James Smartce396282012-09-29 11:30:56 -04009455 rc = -EINVAL;
9456 goto release_out;
James Smart52d52442011-05-24 11:42:45 -04009457 }
9458 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -04009459 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -04009460 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartce396282012-09-29 11:30:56 -04009461 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -04009462 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -04009463 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -04009464 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
9465 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
9466 GFP_KERNEL);
9467 if (!dmabuf) {
9468 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -04009469 goto release_out;
James Smart52d52442011-05-24 11:42:45 -04009470 }
9471 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
9472 SLI4_PAGE_SIZE,
9473 &dmabuf->phys,
9474 GFP_KERNEL);
9475 if (!dmabuf->virt) {
9476 kfree(dmabuf);
9477 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -04009478 goto release_out;
James Smart52d52442011-05-24 11:42:45 -04009479 }
9480 list_add_tail(&dmabuf->list, &dma_buffer_list);
9481 }
9482 while (offset < fw->size) {
9483 temp_offset = offset;
9484 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -04009485 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -04009486 memcpy(dmabuf->virt,
9487 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -04009488 fw->size - temp_offset);
9489 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -04009490 break;
9491 }
James Smart52d52442011-05-24 11:42:45 -04009492 memcpy(dmabuf->virt, fw->data + temp_offset,
9493 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -04009494 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -04009495 }
9496 rc = lpfc_wr_object(phba, &dma_buffer_list,
9497 (fw->size - offset), &offset);
James Smartce396282012-09-29 11:30:56 -04009498 if (rc)
9499 goto release_out;
James Smart52d52442011-05-24 11:42:45 -04009500 }
9501 rc = offset;
9502 }
James Smartce396282012-09-29 11:30:56 -04009503
9504release_out:
James Smart52d52442011-05-24 11:42:45 -04009505 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
9506 list_del(&dmabuf->list);
9507 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
9508 dmabuf->virt, dmabuf->phys);
9509 kfree(dmabuf);
9510 }
James Smartce396282012-09-29 11:30:56 -04009511 release_firmware(fw);
9512out:
9513 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc71ab862012-10-31 14:44:33 -04009514 "3024 Firmware update done: %d.\n", rc);
James Smartce396282012-09-29 11:30:56 -04009515 return;
James Smart52d52442011-05-24 11:42:45 -04009516}
9517
9518/**
James Smartc71ab862012-10-31 14:44:33 -04009519 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
9520 * @phba: pointer to lpfc hba data structure.
9521 *
9522 * This routine is called to perform Linux generic firmware upgrade on device
9523 * that supports such feature.
9524 **/
9525int
9526lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
9527{
9528 uint8_t file_name[ELX_MODEL_NAME_SIZE];
9529 int ret;
9530 const struct firmware *fw;
9531
9532 /* Only supported on SLI4 interface type 2 for now */
9533 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
9534 LPFC_SLI_INTF_IF_TYPE_2)
9535 return -EPERM;
9536
9537 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
9538
9539 if (fw_upgrade == INT_FW_UPGRADE) {
9540 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
9541 file_name, &phba->pcidev->dev,
9542 GFP_KERNEL, (void *)phba,
9543 lpfc_write_firmware);
9544 } else if (fw_upgrade == RUN_FW_UPGRADE) {
9545 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
9546 if (!ret)
9547 lpfc_write_firmware(fw, (void *)phba);
9548 } else {
9549 ret = -EINVAL;
9550 }
9551
9552 return ret;
9553}
9554
9555/**
James Smartda0436e2009-05-22 14:51:39 -04009556 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
9557 * @pdev: pointer to PCI device
9558 * @pid: pointer to PCI device identifier
9559 *
9560 * This routine is called from the kernel's PCI subsystem to device with
9561 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
9562 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
9563 * information of the device and driver to see if the driver state that it
9564 * can support this kind of device. If the match is successful, the driver
9565 * core invokes this routine. If this routine determines it can claim the HBA,
9566 * it does all the initialization that it needs to do to handle the HBA
9567 * properly.
9568 *
9569 * Return code
9570 * 0 - driver can claim the device
9571 * negative value - driver can not claim the device
9572 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009573static int
James Smartda0436e2009-05-22 14:51:39 -04009574lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
9575{
9576 struct lpfc_hba *phba;
9577 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -04009578 struct Scsi_Host *shost = NULL;
James Smartce396282012-09-29 11:30:56 -04009579 int error, ret;
James Smartda0436e2009-05-22 14:51:39 -04009580 uint32_t cfg_mode, intr_mode;
James Smart67d12732012-08-03 12:36:13 -04009581 int adjusted_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04009582
9583 /* Allocate memory for HBA structure */
9584 phba = lpfc_hba_alloc(pdev);
9585 if (!phba)
9586 return -ENOMEM;
9587
9588 /* Perform generic PCI device enabling operation */
9589 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -04009590 if (error)
James Smartda0436e2009-05-22 14:51:39 -04009591 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -04009592
9593 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
9594 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
9595 if (error)
9596 goto out_disable_pci_dev;
9597
9598 /* Set up SLI-4 specific device PCI memory space */
9599 error = lpfc_sli4_pci_mem_setup(phba);
9600 if (error) {
9601 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9602 "1410 Failed to set up pci memory space.\n");
9603 goto out_disable_pci_dev;
9604 }
9605
9606 /* Set up phase-1 common device driver resources */
9607 error = lpfc_setup_driver_resource_phase1(phba);
9608 if (error) {
9609 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9610 "1411 Failed to set up driver resource.\n");
9611 goto out_unset_pci_mem_s4;
9612 }
9613
9614 /* Set up SLI-4 Specific device driver resources */
9615 error = lpfc_sli4_driver_resource_setup(phba);
9616 if (error) {
9617 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9618 "1412 Failed to set up driver resource.\n");
9619 goto out_unset_pci_mem_s4;
9620 }
9621
9622 /* Initialize and populate the iocb list per host */
James Smart2a9bf3d2010-06-07 15:24:45 -04009623
9624 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9625 "2821 initialize iocb list %d.\n",
9626 phba->cfg_iocb_cnt*1024);
9627 error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
9628
James Smartda0436e2009-05-22 14:51:39 -04009629 if (error) {
9630 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9631 "1413 Failed to initialize iocb list.\n");
9632 goto out_unset_driver_resource_s4;
9633 }
9634
James Smart19ca7602010-11-20 23:11:55 -05009635 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -04009636 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -05009637
James Smartda0436e2009-05-22 14:51:39 -04009638 /* Set up common device driver resources */
9639 error = lpfc_setup_driver_resource_phase2(phba);
9640 if (error) {
9641 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9642 "1414 Failed to set up driver resource.\n");
9643 goto out_free_iocb_list;
9644 }
9645
James Smart079b5c92011-08-21 21:48:49 -04009646 /* Get the default values for Model Name and Description */
9647 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
9648
James Smartda0436e2009-05-22 14:51:39 -04009649 /* Create SCSI host to the physical port */
9650 error = lpfc_create_shost(phba);
9651 if (error) {
9652 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9653 "1415 Failed to create scsi host.\n");
9654 goto out_unset_driver_resource;
9655 }
9656
9657 /* Configure sysfs attributes */
9658 vport = phba->pport;
9659 error = lpfc_alloc_sysfs_attr(vport);
9660 if (error) {
9661 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9662 "1416 Failed to allocate sysfs attr\n");
9663 goto out_destroy_shost;
9664 }
9665
James Smart6669f9b2009-10-02 15:16:45 -04009666 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -04009667 /* Now, trying to enable interrupt and bring up the device */
9668 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -04009669
James Smart7b15db32013-01-03 15:43:29 -05009670 /* Put device to a known state before enabling interrupt */
9671 lpfc_stop_port(phba);
9672 /* Configure and enable interrupt */
9673 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
9674 if (intr_mode == LPFC_INTR_ERROR) {
9675 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9676 "0426 Failed to enable interrupt.\n");
9677 error = -ENODEV;
9678 goto out_free_sysfs_attr;
James Smartda0436e2009-05-22 14:51:39 -04009679 }
James Smart7b15db32013-01-03 15:43:29 -05009680 /* Default to single EQ for non-MSI-X */
9681 if (phba->intr_type != MSIX)
9682 adjusted_fcp_io_channel = 1;
9683 else
9684 adjusted_fcp_io_channel = phba->cfg_fcp_io_channel;
9685 phba->cfg_fcp_io_channel = adjusted_fcp_io_channel;
9686 /* Set up SLI-4 HBA */
9687 if (lpfc_sli4_hba_setup(phba)) {
9688 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9689 "1421 Failed to set up hba\n");
9690 error = -ENODEV;
9691 goto out_disable_intr;
9692 }
9693
9694 /* Log the current active interrupt mode */
9695 phba->intr_mode = intr_mode;
9696 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -04009697
9698 /* Perform post initialization setup */
9699 lpfc_post_init_setup(phba);
9700
James Smartc71ab862012-10-31 14:44:33 -04009701 /* check for firmware upgrade or downgrade */
9702 if (phba->cfg_request_firmware_upgrade)
9703 ret = lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -04009704
James Smart1c6834a2009-07-19 10:01:26 -04009705 /* Check if there are static vports to be created. */
9706 lpfc_create_static_vport(phba);
James Smartda0436e2009-05-22 14:51:39 -04009707 return 0;
9708
9709out_disable_intr:
9710 lpfc_sli4_disable_intr(phba);
9711out_free_sysfs_attr:
9712 lpfc_free_sysfs_attr(vport);
9713out_destroy_shost:
9714 lpfc_destroy_shost(phba);
9715out_unset_driver_resource:
9716 lpfc_unset_driver_resource_phase2(phba);
9717out_free_iocb_list:
9718 lpfc_free_iocb_list(phba);
9719out_unset_driver_resource_s4:
9720 lpfc_sli4_driver_resource_unset(phba);
9721out_unset_pci_mem_s4:
9722 lpfc_sli4_pci_mem_unset(phba);
9723out_disable_pci_dev:
9724 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -04009725 if (shost)
9726 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -04009727out_free_phba:
9728 lpfc_hba_free(phba);
9729 return error;
9730}
9731
9732/**
9733 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
9734 * @pdev: pointer to PCI device
9735 *
9736 * This routine is called from the kernel's PCI subsystem to device with
9737 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
9738 * removed from PCI bus, it performs all the necessary cleanup for the HBA
9739 * device to be removed from the PCI subsystem properly.
9740 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009741static void
James Smartda0436e2009-05-22 14:51:39 -04009742lpfc_pci_remove_one_s4(struct pci_dev *pdev)
9743{
9744 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9745 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
9746 struct lpfc_vport **vports;
9747 struct lpfc_hba *phba = vport->phba;
9748 int i;
9749
9750 /* Mark the device unloading flag */
9751 spin_lock_irq(&phba->hbalock);
9752 vport->load_flag |= FC_UNLOADING;
9753 spin_unlock_irq(&phba->hbalock);
9754
9755 /* Free the HBA sysfs attributes */
9756 lpfc_free_sysfs_attr(vport);
9757
9758 /* Release all the vports against this physical port */
9759 vports = lpfc_create_vport_work_array(phba);
9760 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -04009761 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9762 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
9763 continue;
James Smartda0436e2009-05-22 14:51:39 -04009764 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -04009765 }
James Smartda0436e2009-05-22 14:51:39 -04009766 lpfc_destroy_vport_work_array(phba, vports);
9767
9768 /* Remove FC host and then SCSI host with the physical port */
9769 fc_remove_host(shost);
9770 scsi_remove_host(shost);
9771
9772 /* Perform cleanup on the physical port */
9773 lpfc_cleanup(vport);
9774
9775 /*
9776 * Bring down the SLI Layer. This step disables all interrupts,
9777 * clears the rings, discards all mailbox commands, and resets
9778 * the HBA FCoE function.
9779 */
9780 lpfc_debugfs_terminate(vport);
9781 lpfc_sli4_hba_unset(phba);
9782
9783 spin_lock_irq(&phba->hbalock);
9784 list_del_init(&vport->listentry);
9785 spin_unlock_irq(&phba->hbalock);
9786
James Smart3677a3a2010-09-29 11:19:14 -04009787 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -04009788 * buffers are released to their corresponding pools here.
9789 */
9790 lpfc_scsi_free(phba);
James Smart67d12732012-08-03 12:36:13 -04009791
James Smartda0436e2009-05-22 14:51:39 -04009792 lpfc_sli4_driver_resource_unset(phba);
9793
9794 /* Unmap adapter Control and Doorbell registers */
9795 lpfc_sli4_pci_mem_unset(phba);
9796
9797 /* Release PCI resources and disable device's PCI function */
9798 scsi_host_put(shost);
9799 lpfc_disable_pci_dev(phba);
9800
9801 /* Finally, free the driver's device data structure */
9802 lpfc_hba_free(phba);
9803
9804 return;
9805}
9806
9807/**
9808 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
9809 * @pdev: pointer to PCI device
9810 * @msg: power management message
9811 *
9812 * This routine is called from the kernel's PCI subsystem to support system
9813 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
9814 * this method, it quiesces the device by stopping the driver's worker
9815 * thread for the device, turning off device's interrupt and DMA, and bring
9816 * the device offline. Note that as the driver implements the minimum PM
9817 * requirements to a power-aware driver's PM support for suspend/resume -- all
9818 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
9819 * method call will be treated as SUSPEND and the driver will fully
9820 * reinitialize its device during resume() method call, the driver will set
9821 * device to PCI_D3hot state in PCI config space instead of setting it
9822 * according to the @msg provided by the PM.
9823 *
9824 * Return code
9825 * 0 - driver suspended the device
9826 * Error otherwise
9827 **/
9828static int
9829lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
9830{
9831 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9832 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9833
9834 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -04009835 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -04009836
9837 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -04009838 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -04009839 lpfc_offline(phba);
9840 kthread_stop(phba->worker_thread);
9841
9842 /* Disable interrupt from device */
9843 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -04009844 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04009845
9846 /* Save device state to PCI config space */
9847 pci_save_state(pdev);
9848 pci_set_power_state(pdev, PCI_D3hot);
9849
9850 return 0;
9851}
9852
9853/**
9854 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
9855 * @pdev: pointer to PCI device
9856 *
9857 * This routine is called from the kernel's PCI subsystem to support system
9858 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
9859 * this method, it restores the device's PCI config space state and fully
9860 * reinitializes the device and brings it online. Note that as the driver
9861 * implements the minimum PM requirements to a power-aware driver's PM for
9862 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
9863 * to the suspend() method call will be treated as SUSPEND and the driver
9864 * will fully reinitialize its device during resume() method call, the device
9865 * will be set to PCI_D0 directly in PCI config space before restoring the
9866 * state.
9867 *
9868 * Return code
9869 * 0 - driver suspended the device
9870 * Error otherwise
9871 **/
9872static int
9873lpfc_pci_resume_one_s4(struct pci_dev *pdev)
9874{
9875 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9876 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9877 uint32_t intr_mode;
9878 int error;
9879
9880 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9881 "0292 PCI device Power Management resume.\n");
9882
9883 /* Restore device state from PCI config space */
9884 pci_set_power_state(pdev, PCI_D0);
9885 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -05009886
9887 /*
9888 * As the new kernel behavior of pci_restore_state() API call clears
9889 * device saved_state flag, need to save the restored state again.
9890 */
9891 pci_save_state(pdev);
9892
James Smartda0436e2009-05-22 14:51:39 -04009893 if (pdev->is_busmaster)
9894 pci_set_master(pdev);
9895
9896 /* Startup the kernel thread for this host adapter. */
9897 phba->worker_thread = kthread_run(lpfc_do_work, phba,
9898 "lpfc_worker_%d", phba->brd_no);
9899 if (IS_ERR(phba->worker_thread)) {
9900 error = PTR_ERR(phba->worker_thread);
9901 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9902 "0293 PM resume failed to start worker "
9903 "thread: error=x%x.\n", error);
9904 return error;
9905 }
9906
9907 /* Configure and enable interrupt */
9908 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
9909 if (intr_mode == LPFC_INTR_ERROR) {
9910 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9911 "0294 PM resume Failed to enable interrupt\n");
9912 return -EIO;
9913 } else
9914 phba->intr_mode = intr_mode;
9915
9916 /* Restart HBA and bring it online */
9917 lpfc_sli_brdrestart(phba);
9918 lpfc_online(phba);
9919
9920 /* Log the current active interrupt mode */
9921 lpfc_log_intr_mode(phba, phba->intr_mode);
9922
9923 return 0;
9924}
9925
9926/**
James Smart75baf692010-06-08 18:31:21 -04009927 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
9928 * @phba: pointer to lpfc hba data structure.
9929 *
9930 * This routine is called to prepare the SLI4 device for PCI slot recover. It
9931 * aborts all the outstanding SCSI I/Os to the pci device.
9932 **/
9933static void
9934lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
9935{
9936 struct lpfc_sli *psli = &phba->sli;
9937 struct lpfc_sli_ring *pring;
9938
9939 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9940 "2828 PCI channel I/O abort preparing for recovery\n");
9941 /*
9942 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
9943 * and let the SCSI mid-layer to retry them to recover.
9944 */
9945 pring = &psli->ring[psli->fcp_ring];
9946 lpfc_sli_abort_iocb_ring(phba, pring);
9947}
9948
9949/**
9950 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
9951 * @phba: pointer to lpfc hba data structure.
9952 *
9953 * This routine is called to prepare the SLI4 device for PCI slot reset. It
9954 * disables the device interrupt and pci device, and aborts the internal FCP
9955 * pending I/Os.
9956 **/
9957static void
9958lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
9959{
9960 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9961 "2826 PCI channel disable preparing for reset\n");
9962
9963 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -04009964 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -04009965
9966 /* Block all SCSI devices' I/Os on the host */
9967 lpfc_scsi_dev_block(phba);
9968
9969 /* stop all timers */
9970 lpfc_stop_hba_timers(phba);
9971
9972 /* Disable interrupt and pci device */
9973 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -04009974 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -04009975 pci_disable_device(phba->pcidev);
9976
9977 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9978 lpfc_sli_flush_fcp_rings(phba);
9979}
9980
9981/**
9982 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
9983 * @phba: pointer to lpfc hba data structure.
9984 *
9985 * This routine is called to prepare the SLI4 device for PCI slot permanently
9986 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
9987 * pending I/Os.
9988 **/
9989static void
9990lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
9991{
9992 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9993 "2827 PCI channel permanent disable for failure\n");
9994
9995 /* Block all SCSI devices' I/Os on the host */
9996 lpfc_scsi_dev_block(phba);
9997
9998 /* stop all timers */
9999 lpfc_stop_hba_timers(phba);
10000
10001 /* Clean up all driver's outstanding SCSI I/Os */
10002 lpfc_sli_flush_fcp_rings(phba);
10003}
10004
10005/**
James Smartda0436e2009-05-22 14:51:39 -040010006 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
10007 * @pdev: pointer to PCI device.
10008 * @state: the current PCI connection state.
10009 *
10010 * This routine is called from the PCI subsystem for error handling to device
10011 * with SLI-4 interface spec. This function is called by the PCI subsystem
10012 * after a PCI bus error affecting this device has been detected. When this
10013 * function is invoked, it will need to stop all the I/Os and interrupt(s)
10014 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
10015 * for the PCI subsystem to perform proper recovery as desired.
10016 *
10017 * Return codes
10018 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10019 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10020 **/
10021static pci_ers_result_t
10022lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
10023{
James Smart75baf692010-06-08 18:31:21 -040010024 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10025 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10026
10027 switch (state) {
10028 case pci_channel_io_normal:
10029 /* Non-fatal error, prepare for recovery */
10030 lpfc_sli4_prep_dev_for_recover(phba);
10031 return PCI_ERS_RESULT_CAN_RECOVER;
10032 case pci_channel_io_frozen:
10033 /* Fatal error, prepare for slot reset */
10034 lpfc_sli4_prep_dev_for_reset(phba);
10035 return PCI_ERS_RESULT_NEED_RESET;
10036 case pci_channel_io_perm_failure:
10037 /* Permanent failure, prepare for device down */
10038 lpfc_sli4_prep_dev_for_perm_failure(phba);
10039 return PCI_ERS_RESULT_DISCONNECT;
10040 default:
10041 /* Unknown state, prepare and request slot reset */
10042 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10043 "2825 Unknown PCI error state: x%x\n", state);
10044 lpfc_sli4_prep_dev_for_reset(phba);
10045 return PCI_ERS_RESULT_NEED_RESET;
10046 }
James Smartda0436e2009-05-22 14:51:39 -040010047}
10048
10049/**
10050 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
10051 * @pdev: pointer to PCI device.
10052 *
10053 * This routine is called from the PCI subsystem for error handling to device
10054 * with SLI-4 interface spec. It is called after PCI bus has been reset to
10055 * restart the PCI card from scratch, as if from a cold-boot. During the
10056 * PCI subsystem error recovery, after the driver returns
10057 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10058 * recovery and then call this routine before calling the .resume method to
10059 * recover the device. This function will initialize the HBA device, enable
10060 * the interrupt, but it will just put the HBA to offline state without
10061 * passing any I/O traffic.
10062 *
10063 * Return codes
10064 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10065 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10066 */
10067static pci_ers_result_t
10068lpfc_io_slot_reset_s4(struct pci_dev *pdev)
10069{
James Smart75baf692010-06-08 18:31:21 -040010070 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10071 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10072 struct lpfc_sli *psli = &phba->sli;
10073 uint32_t intr_mode;
10074
10075 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
10076 if (pci_enable_device_mem(pdev)) {
10077 printk(KERN_ERR "lpfc: Cannot re-enable "
10078 "PCI device after reset.\n");
10079 return PCI_ERS_RESULT_DISCONNECT;
10080 }
10081
10082 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040010083
10084 /*
10085 * As the new kernel behavior of pci_restore_state() API call clears
10086 * device saved_state flag, need to save the restored state again.
10087 */
10088 pci_save_state(pdev);
10089
James Smart75baf692010-06-08 18:31:21 -040010090 if (pdev->is_busmaster)
10091 pci_set_master(pdev);
10092
10093 spin_lock_irq(&phba->hbalock);
10094 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
10095 spin_unlock_irq(&phba->hbalock);
10096
10097 /* Configure and enable interrupt */
10098 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
10099 if (intr_mode == LPFC_INTR_ERROR) {
10100 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10101 "2824 Cannot re-enable interrupt after "
10102 "slot reset.\n");
10103 return PCI_ERS_RESULT_DISCONNECT;
10104 } else
10105 phba->intr_mode = intr_mode;
10106
10107 /* Log the current active interrupt mode */
10108 lpfc_log_intr_mode(phba, phba->intr_mode);
10109
James Smartda0436e2009-05-22 14:51:39 -040010110 return PCI_ERS_RESULT_RECOVERED;
10111}
10112
10113/**
10114 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
10115 * @pdev: pointer to PCI device
10116 *
10117 * This routine is called from the PCI subsystem for error handling to device
10118 * with SLI-4 interface spec. It is called when kernel error recovery tells
10119 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10120 * error recovery. After this call, traffic can start to flow from this device
10121 * again.
10122 **/
10123static void
10124lpfc_io_resume_s4(struct pci_dev *pdev)
10125{
James Smart75baf692010-06-08 18:31:21 -040010126 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10127 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10128
10129 /*
10130 * In case of slot reset, as function reset is performed through
10131 * mailbox command which needs DMA to be enabled, this operation
10132 * has to be moved to the io resume phase. Taking device offline
10133 * will perform the necessary cleanup.
10134 */
10135 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
10136 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040010137 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010138 lpfc_offline(phba);
10139 lpfc_sli_brdrestart(phba);
10140 /* Bring the device back online */
10141 lpfc_online(phba);
10142 }
10143
10144 /* Clean up Advanced Error Reporting (AER) if needed */
10145 if (phba->hba_flag & HBA_AER_ENABLED)
10146 pci_cleanup_aer_uncorrect_error_status(pdev);
James Smartda0436e2009-05-22 14:51:39 -040010147}
10148
10149/**
James Smart3772a992009-05-22 14:50:54 -040010150 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
10151 * @pdev: pointer to PCI device
10152 * @pid: pointer to PCI device identifier
10153 *
10154 * This routine is to be registered to the kernel's PCI subsystem. When an
10155 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
10156 * at PCI device-specific information of the device and driver to see if the
10157 * driver state that it can support this kind of device. If the match is
10158 * successful, the driver core invokes this routine. This routine dispatches
10159 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
10160 * do all the initialization that it needs to do to handle the HBA device
10161 * properly.
10162 *
10163 * Return code
10164 * 0 - driver can claim the device
10165 * negative value - driver can not claim the device
10166 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010167static int
James Smart3772a992009-05-22 14:50:54 -040010168lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
10169{
10170 int rc;
James Smart8fa38512009-07-19 10:01:03 -040010171 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040010172
James Smart28baac72010-02-12 14:42:03 -050010173 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040010174 return -ENODEV;
10175
James Smart8fa38512009-07-19 10:01:03 -040010176 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050010177 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040010178 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040010179 else
James Smart3772a992009-05-22 14:50:54 -040010180 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040010181
James Smart3772a992009-05-22 14:50:54 -040010182 return rc;
10183}
10184
10185/**
10186 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
10187 * @pdev: pointer to PCI device
10188 *
10189 * This routine is to be registered to the kernel's PCI subsystem. When an
10190 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
10191 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
10192 * remove routine, which will perform all the necessary cleanup for the
10193 * device to be removed from the PCI subsystem properly.
10194 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010195static void
James Smart3772a992009-05-22 14:50:54 -040010196lpfc_pci_remove_one(struct pci_dev *pdev)
10197{
10198 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10199 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10200
10201 switch (phba->pci_dev_grp) {
10202 case LPFC_PCI_DEV_LP:
10203 lpfc_pci_remove_one_s3(pdev);
10204 break;
James Smartda0436e2009-05-22 14:51:39 -040010205 case LPFC_PCI_DEV_OC:
10206 lpfc_pci_remove_one_s4(pdev);
10207 break;
James Smart3772a992009-05-22 14:50:54 -040010208 default:
10209 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10210 "1424 Invalid PCI device group: 0x%x\n",
10211 phba->pci_dev_grp);
10212 break;
10213 }
10214 return;
10215}
10216
10217/**
10218 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
10219 * @pdev: pointer to PCI device
10220 * @msg: power management message
10221 *
10222 * This routine is to be registered to the kernel's PCI subsystem to support
10223 * system Power Management (PM). When PM invokes this method, it dispatches
10224 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
10225 * suspend the device.
10226 *
10227 * Return code
10228 * 0 - driver suspended the device
10229 * Error otherwise
10230 **/
10231static int
10232lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
10233{
10234 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10235 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10236 int rc = -ENODEV;
10237
10238 switch (phba->pci_dev_grp) {
10239 case LPFC_PCI_DEV_LP:
10240 rc = lpfc_pci_suspend_one_s3(pdev, msg);
10241 break;
James Smartda0436e2009-05-22 14:51:39 -040010242 case LPFC_PCI_DEV_OC:
10243 rc = lpfc_pci_suspend_one_s4(pdev, msg);
10244 break;
James Smart3772a992009-05-22 14:50:54 -040010245 default:
10246 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10247 "1425 Invalid PCI device group: 0x%x\n",
10248 phba->pci_dev_grp);
10249 break;
10250 }
10251 return rc;
10252}
10253
10254/**
10255 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
10256 * @pdev: pointer to PCI device
10257 *
10258 * This routine is to be registered to the kernel's PCI subsystem to support
10259 * system Power Management (PM). When PM invokes this method, it dispatches
10260 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
10261 * resume the device.
10262 *
10263 * Return code
10264 * 0 - driver suspended the device
10265 * Error otherwise
10266 **/
10267static int
10268lpfc_pci_resume_one(struct pci_dev *pdev)
10269{
10270 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10271 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10272 int rc = -ENODEV;
10273
10274 switch (phba->pci_dev_grp) {
10275 case LPFC_PCI_DEV_LP:
10276 rc = lpfc_pci_resume_one_s3(pdev);
10277 break;
James Smartda0436e2009-05-22 14:51:39 -040010278 case LPFC_PCI_DEV_OC:
10279 rc = lpfc_pci_resume_one_s4(pdev);
10280 break;
James Smart3772a992009-05-22 14:50:54 -040010281 default:
10282 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10283 "1426 Invalid PCI device group: 0x%x\n",
10284 phba->pci_dev_grp);
10285 break;
10286 }
10287 return rc;
10288}
10289
10290/**
10291 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
10292 * @pdev: pointer to PCI device.
10293 * @state: the current PCI connection state.
10294 *
10295 * This routine is registered to the PCI subsystem for error handling. This
10296 * function is called by the PCI subsystem after a PCI bus error affecting
10297 * this device has been detected. When this routine is invoked, it dispatches
10298 * the action to the proper SLI-3 or SLI-4 device error detected handling
10299 * routine, which will perform the proper error detected operation.
10300 *
10301 * Return codes
10302 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10303 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10304 **/
10305static pci_ers_result_t
10306lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
10307{
10308 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10309 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10310 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
10311
10312 switch (phba->pci_dev_grp) {
10313 case LPFC_PCI_DEV_LP:
10314 rc = lpfc_io_error_detected_s3(pdev, state);
10315 break;
James Smartda0436e2009-05-22 14:51:39 -040010316 case LPFC_PCI_DEV_OC:
10317 rc = lpfc_io_error_detected_s4(pdev, state);
10318 break;
James Smart3772a992009-05-22 14:50:54 -040010319 default:
10320 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10321 "1427 Invalid PCI device group: 0x%x\n",
10322 phba->pci_dev_grp);
10323 break;
10324 }
10325 return rc;
10326}
10327
10328/**
10329 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
10330 * @pdev: pointer to PCI device.
10331 *
10332 * This routine is registered to the PCI subsystem for error handling. This
10333 * function is called after PCI bus has been reset to restart the PCI card
10334 * from scratch, as if from a cold-boot. When this routine is invoked, it
10335 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
10336 * routine, which will perform the proper device reset.
10337 *
10338 * Return codes
10339 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10340 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10341 **/
10342static pci_ers_result_t
10343lpfc_io_slot_reset(struct pci_dev *pdev)
10344{
10345 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10346 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10347 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
10348
10349 switch (phba->pci_dev_grp) {
10350 case LPFC_PCI_DEV_LP:
10351 rc = lpfc_io_slot_reset_s3(pdev);
10352 break;
James Smartda0436e2009-05-22 14:51:39 -040010353 case LPFC_PCI_DEV_OC:
10354 rc = lpfc_io_slot_reset_s4(pdev);
10355 break;
James Smart3772a992009-05-22 14:50:54 -040010356 default:
10357 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10358 "1428 Invalid PCI device group: 0x%x\n",
10359 phba->pci_dev_grp);
10360 break;
10361 }
10362 return rc;
10363}
10364
10365/**
10366 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
10367 * @pdev: pointer to PCI device
10368 *
10369 * This routine is registered to the PCI subsystem for error handling. It
10370 * is called when kernel error recovery tells the lpfc driver that it is
10371 * OK to resume normal PCI operation after PCI bus error recovery. When
10372 * this routine is invoked, it dispatches the action to the proper SLI-3
10373 * or SLI-4 device io_resume routine, which will resume the device operation.
10374 **/
10375static void
10376lpfc_io_resume(struct pci_dev *pdev)
10377{
10378 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10379 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10380
10381 switch (phba->pci_dev_grp) {
10382 case LPFC_PCI_DEV_LP:
10383 lpfc_io_resume_s3(pdev);
10384 break;
James Smartda0436e2009-05-22 14:51:39 -040010385 case LPFC_PCI_DEV_OC:
10386 lpfc_io_resume_s4(pdev);
10387 break;
James Smart3772a992009-05-22 14:50:54 -040010388 default:
10389 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10390 "1429 Invalid PCI device group: 0x%x\n",
10391 phba->pci_dev_grp);
10392 break;
10393 }
10394 return;
10395}
10396
James Smart3ef6d242012-01-18 16:23:48 -050010397/**
10398 * lpfc_mgmt_open - method called when 'lpfcmgmt' is opened from userspace
10399 * @inode: pointer to the inode representing the lpfcmgmt device
10400 * @filep: pointer to the file representing the open lpfcmgmt device
10401 *
10402 * This routine puts a reference count on the lpfc module whenever the
10403 * character device is opened
10404 **/
10405static int
10406lpfc_mgmt_open(struct inode *inode, struct file *filep)
10407{
10408 try_module_get(THIS_MODULE);
10409 return 0;
10410}
10411
10412/**
10413 * lpfc_mgmt_release - method called when 'lpfcmgmt' is closed in userspace
10414 * @inode: pointer to the inode representing the lpfcmgmt device
10415 * @filep: pointer to the file representing the open lpfcmgmt device
10416 *
10417 * This routine removes a reference count from the lpfc module when the
10418 * character device is closed
10419 **/
10420static int
10421lpfc_mgmt_release(struct inode *inode, struct file *filep)
10422{
10423 module_put(THIS_MODULE);
10424 return 0;
10425}
10426
dea31012005-04-17 16:05:31 -050010427static struct pci_device_id lpfc_id_table[] = {
10428 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
10429 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -040010430 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
10431 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050010432 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
10433 PCI_ANY_ID, PCI_ANY_ID, },
10434 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
10435 PCI_ANY_ID, PCI_ANY_ID, },
10436 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
10437 PCI_ANY_ID, PCI_ANY_ID, },
10438 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
10439 PCI_ANY_ID, PCI_ANY_ID, },
10440 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
10441 PCI_ANY_ID, PCI_ANY_ID, },
10442 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
10443 PCI_ANY_ID, PCI_ANY_ID, },
10444 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
10445 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050010446 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
10447 PCI_ANY_ID, PCI_ANY_ID, },
10448 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
10449 PCI_ANY_ID, PCI_ANY_ID, },
10450 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
10451 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050010452 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
10453 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050010454 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
10455 PCI_ANY_ID, PCI_ANY_ID, },
10456 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
10457 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050010458 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
10459 PCI_ANY_ID, PCI_ANY_ID, },
10460 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
10461 PCI_ANY_ID, PCI_ANY_ID, },
10462 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
10463 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -040010464 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
10465 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050010466 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
10467 PCI_ANY_ID, PCI_ANY_ID, },
10468 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
10469 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050010470 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
10471 PCI_ANY_ID, PCI_ANY_ID, },
10472 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
10473 PCI_ANY_ID, PCI_ANY_ID, },
10474 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
10475 PCI_ANY_ID, PCI_ANY_ID, },
10476 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
10477 PCI_ANY_ID, PCI_ANY_ID, },
10478 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
10479 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050010480 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
10481 PCI_ANY_ID, PCI_ANY_ID, },
10482 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
10483 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -040010484 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
10485 PCI_ANY_ID, PCI_ANY_ID, },
10486 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
10487 PCI_ANY_ID, PCI_ANY_ID, },
10488 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
10489 PCI_ANY_ID, PCI_ANY_ID, },
10490 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
10491 PCI_ANY_ID, PCI_ANY_ID, },
10492 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
10493 PCI_ANY_ID, PCI_ANY_ID, },
10494 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
10495 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -040010496 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
10497 PCI_ANY_ID, PCI_ANY_ID, },
10498 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
10499 PCI_ANY_ID, PCI_ANY_ID, },
10500 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
10501 PCI_ANY_ID, PCI_ANY_ID, },
James Smart3772a992009-05-22 14:50:54 -040010502 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
10503 PCI_ANY_ID, PCI_ANY_ID, },
James Smarta747c9c2009-11-18 15:41:10 -050010504 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT,
10505 PCI_ANY_ID, PCI_ANY_ID, },
10506 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON,
James Smart6669f9b2009-10-02 15:16:45 -040010507 PCI_ANY_ID, PCI_ANY_ID, },
James Smart98fc5dd2010-06-07 15:24:29 -040010508 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS,
10509 PCI_ANY_ID, PCI_ANY_ID, },
James Smart085c6472010-11-20 23:11:37 -050010510 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC,
10511 PCI_ANY_ID, PCI_ANY_ID, },
10512 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE,
10513 PCI_ANY_ID, PCI_ANY_ID, },
James Smartc0c11512011-05-24 11:41:34 -040010514 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF,
10515 PCI_ANY_ID, PCI_ANY_ID, },
10516 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF,
10517 PCI_ANY_ID, PCI_ANY_ID, },
James Smartf8cafd32012-08-03 12:42:51 -040010518 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK,
10519 PCI_ANY_ID, PCI_ANY_ID, },
10520 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF,
10521 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050010522 { 0 }
10523};
10524
10525MODULE_DEVICE_TABLE(pci, lpfc_id_table);
10526
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070010527static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060010528 .error_detected = lpfc_io_error_detected,
10529 .slot_reset = lpfc_io_slot_reset,
10530 .resume = lpfc_io_resume,
10531};
10532
dea31012005-04-17 16:05:31 -050010533static struct pci_driver lpfc_driver = {
10534 .name = LPFC_DRIVER_NAME,
10535 .id_table = lpfc_id_table,
10536 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010537 .remove = lpfc_pci_remove_one,
James Smart3a55b532008-12-04 22:38:54 -050010538 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040010539 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050010540 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050010541};
10542
James Smart3ef6d242012-01-18 16:23:48 -050010543static const struct file_operations lpfc_mgmt_fop = {
10544 .open = lpfc_mgmt_open,
10545 .release = lpfc_mgmt_release,
10546};
10547
10548static struct miscdevice lpfc_mgmt_dev = {
10549 .minor = MISC_DYNAMIC_MINOR,
10550 .name = "lpfcmgmt",
10551 .fops = &lpfc_mgmt_fop,
10552};
10553
James Smarte59058c2008-08-24 21:49:00 -040010554/**
James Smart3621a712009-04-06 18:47:14 -040010555 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040010556 *
10557 * This routine is to be invoked when the lpfc module is loaded into the
10558 * kernel. The special kernel macro module_init() is used to indicate the
10559 * role of this routine to the kernel as lpfc module entry point.
10560 *
10561 * Return codes
10562 * 0 - successful
10563 * -ENOMEM - FC attach transport failed
10564 * all others - failed
10565 */
dea31012005-04-17 16:05:31 -050010566static int __init
10567lpfc_init(void)
10568{
10569 int error = 0;
10570
10571 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010572 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050010573
James Smart3ef6d242012-01-18 16:23:48 -050010574 error = misc_register(&lpfc_mgmt_dev);
10575 if (error)
10576 printk(KERN_ERR "Could not register lpfcmgmt device, "
10577 "misc_register returned with status %d", error);
10578
James Smart7ee5d432007-10-27 13:37:17 -040010579 if (lpfc_enable_npiv) {
10580 lpfc_transport_functions.vport_create = lpfc_vport_create;
10581 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
10582 }
dea31012005-04-17 16:05:31 -050010583 lpfc_transport_template =
10584 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040010585 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050010586 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040010587 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -040010588 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -040010589 fc_attach_transport(&lpfc_vport_transport_functions);
10590 if (lpfc_vport_transport_template == NULL) {
10591 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040010592 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -040010593 }
James Smart7ee5d432007-10-27 13:37:17 -040010594 }
dea31012005-04-17 16:05:31 -050010595 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050010596 if (error) {
dea31012005-04-17 16:05:31 -050010597 fc_release_transport(lpfc_transport_template);
James Smartd7c255b2008-08-24 21:50:00 -040010598 if (lpfc_enable_npiv)
10599 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050010600 }
dea31012005-04-17 16:05:31 -050010601
10602 return error;
10603}
10604
James Smarte59058c2008-08-24 21:49:00 -040010605/**
James Smart3621a712009-04-06 18:47:14 -040010606 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040010607 *
10608 * This routine is invoked when the lpfc module is removed from the kernel.
10609 * The special kernel macro module_exit() is used to indicate the role of
10610 * this routine to the kernel as lpfc module exit point.
10611 */
dea31012005-04-17 16:05:31 -050010612static void __exit
10613lpfc_exit(void)
10614{
James Smart3ef6d242012-01-18 16:23:48 -050010615 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050010616 pci_unregister_driver(&lpfc_driver);
10617 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040010618 if (lpfc_enable_npiv)
10619 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050010620 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040010621 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
10622 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050010623 (1L << _dump_buf_data_order), _dump_buf_data);
10624 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
10625 }
10626
10627 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040010628 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
10629 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050010630 (1L << _dump_buf_dif_order), _dump_buf_dif);
10631 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
10632 }
dea31012005-04-17 16:05:31 -050010633}
10634
10635module_init(lpfc_init);
10636module_exit(lpfc_exit);
10637MODULE_LICENSE("GPL");
10638MODULE_DESCRIPTION(LPFC_MODULE_DESC);
10639MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
10640MODULE_VERSION("0:" LPFC_DRIVER_VERSION);