blob: 45c15208be9fc5e4d0e4705558fc1d116bf6c89d [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 Smarta4bc3372006-12-02 13:34:16 -0500483 if (psli->ring[psli->extra_ring].cmdringaddr)
484 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500485 if (psli->ring[psli->fcp_ring].cmdringaddr)
486 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
487 if (psli->ring[psli->next_ring].cmdringaddr)
488 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);
842 pring->txcmplq_cnt = 0;
843 spin_unlock_irq(&phba->hbalock);
844
James Smarta257bf92009-04-06 18:48:10 -0400845 /* Cancel all the IOCBs from the completions list */
846 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
847 IOERR_SLI_ABORTED);
James Smart09372822008-01-11 01:52:54 -0500848
Jamie Wellnitz41415862006-02-28 19:25:27 -0500849 lpfc_sli_abort_iocb_ring(phba, pring);
James Smart09372822008-01-11 01:52:54 -0500850 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500851 }
James Smart09372822008-01-11 01:52:54 -0500852 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500853
854 return 0;
855}
James Smart5af5eee2010-10-22 11:06:38 -0400856
James Smartda0436e2009-05-22 14:51:39 -0400857/**
858 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
859 * @phba: pointer to lpfc HBA data structure.
860 *
861 * This routine will do uninitialization after the HBA is reset when bring
862 * down the SLI Layer.
863 *
864 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200865 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -0400866 * Any other value - error.
867 **/
868static int
869lpfc_hba_down_post_s4(struct lpfc_hba *phba)
870{
871 struct lpfc_scsi_buf *psb, *psb_next;
872 LIST_HEAD(aborts);
873 int ret;
874 unsigned long iflag = 0;
James Smart0f65ff62010-02-26 14:14:23 -0500875 struct lpfc_sglq *sglq_entry = NULL;
876
James Smartda0436e2009-05-22 14:51:39 -0400877 ret = lpfc_hba_down_post_s3(phba);
878 if (ret)
879 return ret;
880 /* At this point in time the HBA is either reset or DOA. Either
881 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
882 * on the lpfc_sgl_list so that it can either be freed if the
883 * driver is unloading or reposted if the driver is restarting
884 * the port.
885 */
886 spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */
887 /* scsl_buf_list */
888 /* abts_sgl_list_lock required because worker thread uses this
889 * list.
890 */
891 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -0500892 list_for_each_entry(sglq_entry,
893 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
894 sglq_entry->state = SGL_FREED;
895
James Smartda0436e2009-05-22 14:51:39 -0400896 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
897 &phba->sli4_hba.lpfc_sgl_list);
898 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
899 /* abts_scsi_buf_list_lock required because worker thread uses this
900 * list.
901 */
902 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
903 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
904 &aborts);
905 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
906 spin_unlock_irq(&phba->hbalock);
907
908 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
909 psb->pCmd = NULL;
910 psb->status = IOSTAT_SUCCESS;
911 }
912 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
913 list_splice(&aborts, &phba->lpfc_scsi_buf_list);
914 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
915 return 0;
916}
917
918/**
919 * lpfc_hba_down_post - Wrapper func for hba down post routine
920 * @phba: pointer to lpfc HBA data structure.
921 *
922 * This routine wraps the actual SLI3 or SLI4 routine for performing
923 * uninitialization after the HBA is reset when bring down the SLI Layer.
924 *
925 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200926 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -0400927 * Any other value - error.
928 **/
929int
930lpfc_hba_down_post(struct lpfc_hba *phba)
931{
932 return (*phba->lpfc_hba_down_post)(phba);
933}
Jamie Wellnitz41415862006-02-28 19:25:27 -0500934
James Smarte59058c2008-08-24 21:49:00 -0400935/**
James Smart3621a712009-04-06 18:47:14 -0400936 * lpfc_hb_timeout - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -0400937 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
938 *
939 * This is the HBA-timer timeout handler registered to the lpfc driver. When
940 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
941 * work-port-events bitmap and the worker thread is notified. This timeout
942 * event will be used by the worker thread to invoke the actual timeout
943 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
944 * be performed in the timeout handler and the HBA timeout event bit shall
945 * be cleared by the worker thread after it has taken the event bitmap out.
946 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +0100947static void
James Smart858c9f62007-06-17 19:56:39 -0500948lpfc_hb_timeout(unsigned long ptr)
949{
950 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -0400951 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -0500952 unsigned long iflag;
953
954 phba = (struct lpfc_hba *)ptr;
James Smart93996272008-08-24 21:50:30 -0400955
956 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -0500957 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -0400958 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
959 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -0500960 phba->pport->work_port_events |= WORKER_HB_TMO;
961 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
962
James Smart93996272008-08-24 21:50:30 -0400963 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -0400964 if (!tmo_posted)
965 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -0500966 return;
967}
968
James Smarte59058c2008-08-24 21:49:00 -0400969/**
James Smart19ca7602010-11-20 23:11:55 -0500970 * lpfc_rrq_timeout - The RRQ-timer timeout handler
971 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
972 *
973 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
974 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
975 * work-port-events bitmap and the worker thread is notified. This timeout
976 * event will be used by the worker thread to invoke the actual timeout
977 * handler routine, lpfc_rrq_handler. Any periodical operations will
978 * be performed in the timeout handler and the RRQ timeout event bit shall
979 * be cleared by the worker thread after it has taken the event bitmap out.
980 **/
981static void
982lpfc_rrq_timeout(unsigned long ptr)
983{
984 struct lpfc_hba *phba;
James Smart19ca7602010-11-20 23:11:55 -0500985 unsigned long iflag;
986
987 phba = (struct lpfc_hba *)ptr;
988 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart1151e3e2011-02-16 12:39:35 -0500989 phba->hba_flag |= HBA_RRQ_ACTIVE;
James Smart19ca7602010-11-20 23:11:55 -0500990 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
James Smart1151e3e2011-02-16 12:39:35 -0500991 lpfc_worker_wake_up(phba);
James Smart19ca7602010-11-20 23:11:55 -0500992}
993
994/**
James Smart3621a712009-04-06 18:47:14 -0400995 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -0400996 * @phba: pointer to lpfc hba data structure.
997 * @pmboxq: pointer to the driver internal queue element for mailbox command.
998 *
999 * This is the callback function to the lpfc heart-beat mailbox command.
1000 * If configured, the lpfc driver issues the heart-beat mailbox command to
1001 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1002 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1003 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1004 * heart-beat outstanding state. Once the mailbox command comes back and
1005 * no error conditions detected, the heart-beat mailbox command timer is
1006 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1007 * state is cleared for the next heart-beat. If the timer expired with the
1008 * heart-beat outstanding state set, the driver will put the HBA offline.
1009 **/
James Smart858c9f62007-06-17 19:56:39 -05001010static void
1011lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1012{
1013 unsigned long drvr_flag;
1014
1015 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1016 phba->hb_outstanding = 0;
1017 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1018
James Smart93996272008-08-24 21:50:30 -04001019 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -05001020 mempool_free(pmboxq, phba->mbox_mem_pool);
1021 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1022 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -04001023 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -05001024 mod_timer(&phba->hb_tmofunc,
1025 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
1026 return;
1027}
1028
James Smarte59058c2008-08-24 21:49:00 -04001029/**
James Smart3621a712009-04-06 18:47:14 -04001030 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001031 * @phba: pointer to lpfc hba data structure.
1032 *
1033 * This is the actual HBA-timer timeout handler to be invoked by the worker
1034 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1035 * handler performs any periodic operations needed for the device. If such
1036 * periodic event has already been attended to either in the interrupt handler
1037 * or by processing slow-ring or fast-ring events within the HBA-timer
1038 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1039 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1040 * is configured and there is no heart-beat mailbox command outstanding, a
1041 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1042 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1043 * to offline.
1044 **/
James Smart858c9f62007-06-17 19:56:39 -05001045void
1046lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1047{
James Smart45ed1192009-10-02 15:17:02 -04001048 struct lpfc_vport **vports;
James Smart858c9f62007-06-17 19:56:39 -05001049 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -05001050 struct lpfc_dmabuf *buf_ptr;
James Smart45ed1192009-10-02 15:17:02 -04001051 int retval, i;
James Smart858c9f62007-06-17 19:56:39 -05001052 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -05001053 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -05001054
James Smart45ed1192009-10-02 15:17:02 -04001055 vports = lpfc_create_vport_work_array(phba);
1056 if (vports != NULL)
1057 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
1058 lpfc_rcv_seq_check_edtov(vports[i]);
1059 lpfc_destroy_vport_work_array(phba, vports);
1060
James Smart858c9f62007-06-17 19:56:39 -05001061 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -04001062 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -05001063 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1064 return;
1065
1066 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -05001067
1068 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
1069 jiffies)) {
1070 spin_unlock_irq(&phba->pport->work_port_lock);
1071 if (!phba->hb_outstanding)
1072 mod_timer(&phba->hb_tmofunc,
1073 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
1074 else
1075 mod_timer(&phba->hb_tmofunc,
1076 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
1077 return;
1078 }
1079 spin_unlock_irq(&phba->pport->work_port_lock);
1080
James Smart0ff10d42008-01-11 01:52:36 -05001081 if (phba->elsbuf_cnt &&
1082 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1083 spin_lock_irq(&phba->hbalock);
1084 list_splice_init(&phba->elsbuf, &completions);
1085 phba->elsbuf_cnt = 0;
1086 phba->elsbuf_prev_cnt = 0;
1087 spin_unlock_irq(&phba->hbalock);
1088
1089 while (!list_empty(&completions)) {
1090 list_remove_head(&completions, buf_ptr,
1091 struct lpfc_dmabuf, list);
1092 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1093 kfree(buf_ptr);
1094 }
1095 }
1096 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1097
James Smart858c9f62007-06-17 19:56:39 -05001098 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -05001099 if (phba->cfg_enable_hba_heartbeat) {
1100 if (!phba->hb_outstanding) {
James Smartbc739052010-08-04 16:11:18 -04001101 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1102 (list_empty(&psli->mboxq))) {
1103 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1104 GFP_KERNEL);
1105 if (!pmboxq) {
1106 mod_timer(&phba->hb_tmofunc,
1107 jiffies +
1108 HZ * LPFC_HB_MBOX_INTERVAL);
1109 return;
1110 }
James Smart13815c82008-01-11 01:52:48 -05001111
James Smartbc739052010-08-04 16:11:18 -04001112 lpfc_heart_beat(phba, pmboxq);
1113 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1114 pmboxq->vport = phba->pport;
1115 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1116 MBX_NOWAIT);
James Smart13815c82008-01-11 01:52:48 -05001117
James Smartbc739052010-08-04 16:11:18 -04001118 if (retval != MBX_BUSY &&
1119 retval != MBX_SUCCESS) {
1120 mempool_free(pmboxq,
1121 phba->mbox_mem_pool);
1122 mod_timer(&phba->hb_tmofunc,
1123 jiffies +
1124 HZ * LPFC_HB_MBOX_INTERVAL);
1125 return;
1126 }
1127 phba->skipped_hb = 0;
1128 phba->hb_outstanding = 1;
1129 } else if (time_before_eq(phba->last_completion_time,
1130 phba->skipped_hb)) {
1131 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1132 "2857 Last completion time not "
1133 " updated in %d ms\n",
1134 jiffies_to_msecs(jiffies
1135 - phba->last_completion_time));
1136 } else
1137 phba->skipped_hb = jiffies;
1138
James Smart858c9f62007-06-17 19:56:39 -05001139 mod_timer(&phba->hb_tmofunc,
James Smart13815c82008-01-11 01:52:48 -05001140 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
James Smart858c9f62007-06-17 19:56:39 -05001141 return;
James Smart13815c82008-01-11 01:52:48 -05001142 } else {
1143 /*
1144 * If heart beat timeout called with hb_outstanding set
James Smartdcf2a4e2010-09-29 11:18:53 -04001145 * we need to give the hb mailbox cmd a chance to
1146 * complete or TMO.
James Smart13815c82008-01-11 01:52:48 -05001147 */
James Smartdcf2a4e2010-09-29 11:18:53 -04001148 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1149 "0459 Adapter heartbeat still out"
1150 "standing:last compl time was %d ms.\n",
1151 jiffies_to_msecs(jiffies
1152 - phba->last_completion_time));
1153 mod_timer(&phba->hb_tmofunc,
1154 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
James Smart858c9f62007-06-17 19:56:39 -05001155 }
James Smart858c9f62007-06-17 19:56:39 -05001156 }
1157}
1158
James Smarte59058c2008-08-24 21:49:00 -04001159/**
James Smart3621a712009-04-06 18:47:14 -04001160 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -04001161 * @phba: pointer to lpfc hba data structure.
1162 *
1163 * This routine is called to bring the HBA offline when HBA hardware error
1164 * other than Port Error 6 has been detected.
1165 **/
James Smart09372822008-01-11 01:52:54 -05001166static void
1167lpfc_offline_eratt(struct lpfc_hba *phba)
1168{
1169 struct lpfc_sli *psli = &phba->sli;
1170
1171 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001172 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -05001173 spin_unlock_irq(&phba->hbalock);
James Smart618a5232012-06-12 13:54:36 -04001174 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart09372822008-01-11 01:52:54 -05001175
1176 lpfc_offline(phba);
1177 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001178 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001179 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001180 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001181 lpfc_hba_down_post(phba);
1182 lpfc_sli_brdready(phba, HS_MBRDY);
1183 lpfc_unblock_mgmt_io(phba);
1184 phba->link_state = LPFC_HBA_ERROR;
1185 return;
1186}
1187
James Smarte59058c2008-08-24 21:49:00 -04001188/**
James Smartda0436e2009-05-22 14:51:39 -04001189 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1190 * @phba: pointer to lpfc hba data structure.
1191 *
1192 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1193 * other than Port Error 6 has been detected.
1194 **/
1195static void
1196lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1197{
James Smart618a5232012-06-12 13:54:36 -04001198 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smartda0436e2009-05-22 14:51:39 -04001199 lpfc_offline(phba);
1200 lpfc_sli4_brdreset(phba);
1201 lpfc_hba_down_post(phba);
1202 lpfc_sli4_post_status_check(phba);
1203 lpfc_unblock_mgmt_io(phba);
1204 phba->link_state = LPFC_HBA_ERROR;
1205}
1206
1207/**
James Smarta257bf92009-04-06 18:48:10 -04001208 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1209 * @phba: pointer to lpfc hba data structure.
1210 *
1211 * This routine is invoked to handle the deferred HBA hardware error
1212 * conditions. This type of error is indicated by HBA by setting ER1
1213 * and another ER bit in the host status register. The driver will
1214 * wait until the ER1 bit clears before handling the error condition.
1215 **/
1216static void
1217lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1218{
1219 uint32_t old_host_status = phba->work_hs;
1220 struct lpfc_sli_ring *pring;
1221 struct lpfc_sli *psli = &phba->sli;
1222
James Smartf4b4c682009-05-22 14:53:12 -04001223 /* If the pci channel is offline, ignore possible errors,
1224 * since we cannot communicate with the pci card anyway.
1225 */
1226 if (pci_channel_offline(phba->pcidev)) {
1227 spin_lock_irq(&phba->hbalock);
1228 phba->hba_flag &= ~DEFER_ERATT;
1229 spin_unlock_irq(&phba->hbalock);
1230 return;
1231 }
1232
James Smarta257bf92009-04-06 18:48:10 -04001233 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1234 "0479 Deferred Adapter Hardware Error "
1235 "Data: x%x x%x x%x\n",
1236 phba->work_hs,
1237 phba->work_status[0], phba->work_status[1]);
1238
1239 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001240 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001241 spin_unlock_irq(&phba->hbalock);
1242
1243
1244 /*
1245 * Firmware stops when it triggred erratt. That could cause the I/Os
1246 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1247 * SCSI layer retry it after re-establishing link.
1248 */
1249 pring = &psli->ring[psli->fcp_ring];
1250 lpfc_sli_abort_iocb_ring(phba, pring);
1251
1252 /*
1253 * There was a firmware error. Take the hba offline and then
1254 * attempt to restart it.
1255 */
James Smart618a5232012-06-12 13:54:36 -04001256 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smarta257bf92009-04-06 18:48:10 -04001257 lpfc_offline(phba);
1258
1259 /* Wait for the ER1 bit to clear.*/
1260 while (phba->work_hs & HS_FFER1) {
1261 msleep(100);
James Smart9940b972011-03-11 16:06:12 -05001262 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1263 phba->work_hs = UNPLUG_ERR ;
1264 break;
1265 }
James Smarta257bf92009-04-06 18:48:10 -04001266 /* If driver is unloading let the worker thread continue */
1267 if (phba->pport->load_flag & FC_UNLOADING) {
1268 phba->work_hs = 0;
1269 break;
1270 }
1271 }
1272
1273 /*
1274 * This is to ptrotect against a race condition in which
1275 * first write to the host attention register clear the
1276 * host status register.
1277 */
1278 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1279 phba->work_hs = old_host_status & ~HS_FFER1;
1280
James Smart3772a992009-05-22 14:50:54 -04001281 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001282 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001283 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001284 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1285 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1286}
1287
James Smart3772a992009-05-22 14:50:54 -04001288static void
1289lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1290{
1291 struct lpfc_board_event_header board_event;
1292 struct Scsi_Host *shost;
1293
1294 board_event.event_type = FC_REG_BOARD_EVENT;
1295 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1296 shost = lpfc_shost_from_vport(phba->pport);
1297 fc_host_post_vendor_event(shost, fc_get_event_number(),
1298 sizeof(board_event),
1299 (char *) &board_event,
1300 LPFC_NL_VENDOR_ID);
1301}
1302
James Smarta257bf92009-04-06 18:48:10 -04001303/**
James Smart3772a992009-05-22 14:50:54 -04001304 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001305 * @phba: pointer to lpfc hba data structure.
1306 *
1307 * This routine is invoked to handle the following HBA hardware error
1308 * conditions:
1309 * 1 - HBA error attention interrupt
1310 * 2 - DMA ring index out of range
1311 * 3 - Mailbox command came back as unknown
1312 **/
James Smart3772a992009-05-22 14:50:54 -04001313static void
1314lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001315{
James Smart2e0fef82007-06-17 19:56:36 -05001316 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001317 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001318 struct lpfc_sli_ring *pring;
James Smartd2873e42006-08-18 17:46:43 -04001319 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001320 unsigned long temperature;
1321 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001322 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001323
Linas Vepstas8d63f372007-02-14 14:28:36 -06001324 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001325 * since we cannot communicate with the pci card anyway.
1326 */
1327 if (pci_channel_offline(phba->pcidev)) {
1328 spin_lock_irq(&phba->hbalock);
1329 phba->hba_flag &= ~DEFER_ERATT;
1330 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001331 return;
James Smart3772a992009-05-22 14:50:54 -04001332 }
1333
James Smart13815c82008-01-11 01:52:48 -05001334 /* If resets are disabled then leave the HBA alone and return */
1335 if (!phba->cfg_enable_hba_reset)
1336 return;
dea31012005-04-17 16:05:31 -05001337
James Smartea2151b2008-09-07 11:52:10 -04001338 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001339 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001340
James Smarta257bf92009-04-06 18:48:10 -04001341 if (phba->hba_flag & DEFER_ERATT)
1342 lpfc_handle_deferred_eratt(phba);
1343
James Smartdcf2a4e2010-09-29 11:18:53 -04001344 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1345 if (phba->work_hs & HS_FFER6)
1346 /* Re-establishing Link */
1347 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1348 "1301 Re-establishing Link "
1349 "Data: x%x x%x x%x\n",
1350 phba->work_hs, phba->work_status[0],
1351 phba->work_status[1]);
1352 if (phba->work_hs & HS_FFER8)
1353 /* Device Zeroization */
1354 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1355 "2861 Host Authentication device "
1356 "zeroization Data:x%x x%x x%x\n",
1357 phba->work_hs, phba->work_status[0],
1358 phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001359
James Smart92d7f7b2007-06-17 19:56:38 -05001360 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001361 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001362 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001363
1364 /*
1365 * Firmware stops when it triggled erratt with HS_FFER6.
1366 * That could cause the I/Os dropped by the firmware.
1367 * Error iocb (I/O) on txcmplq and let the SCSI layer
1368 * retry it after re-establishing link.
1369 */
1370 pring = &psli->ring[psli->fcp_ring];
1371 lpfc_sli_abort_iocb_ring(phba, pring);
1372
dea31012005-04-17 16:05:31 -05001373 /*
1374 * There was a firmware error. Take the hba offline and then
1375 * attempt to restart it.
1376 */
James Smart618a5232012-06-12 13:54:36 -04001377 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
dea31012005-04-17 16:05:31 -05001378 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001379 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001380 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001381 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001382 return;
1383 }
James Smart46fa3112007-04-25 09:51:45 -04001384 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001385 } else if (phba->work_hs & HS_CRIT_TEMP) {
1386 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1387 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1388 temp_event_data.event_code = LPFC_CRIT_TEMP;
1389 temp_event_data.data = (uint32_t)temperature;
1390
1391 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001392 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001393 "(%ld), taking this port offline "
1394 "Data: x%x x%x x%x\n",
1395 temperature, phba->work_hs,
1396 phba->work_status[0], phba->work_status[1]);
1397
1398 shost = lpfc_shost_from_vport(phba->pport);
1399 fc_host_post_vendor_event(shost, fc_get_event_number(),
1400 sizeof(temp_event_data),
1401 (char *) &temp_event_data,
1402 SCSI_NL_VID_TYPE_PCI
1403 | PCI_VENDOR_ID_EMULEX);
1404
James Smart7af67052007-10-27 13:38:11 -04001405 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001406 phba->over_temp_state = HBA_OVER_TEMP;
1407 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001408 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001409
dea31012005-04-17 16:05:31 -05001410 } else {
1411 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001412 * failure is a value other than FFER6. Do not call the offline
1413 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001414 */
1415 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001416 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001417 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001418 phba->work_hs,
dea31012005-04-17 16:05:31 -05001419 phba->work_status[0], phba->work_status[1]);
1420
James Smartd2873e42006-08-18 17:46:43 -04001421 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001422 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001423 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001424 sizeof(event_data), (char *) &event_data,
1425 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1426
James Smart09372822008-01-11 01:52:54 -05001427 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001428 }
James Smart93996272008-08-24 21:50:30 -04001429 return;
dea31012005-04-17 16:05:31 -05001430}
1431
James Smarte59058c2008-08-24 21:49:00 -04001432/**
James Smart618a5232012-06-12 13:54:36 -04001433 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1434 * @phba: pointer to lpfc hba data structure.
1435 * @mbx_action: flag for mailbox shutdown action.
1436 *
1437 * This routine is invoked to perform an SLI4 port PCI function reset in
1438 * response to port status register polling attention. It waits for port
1439 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1440 * During this process, interrupt vectors are freed and later requested
1441 * for handling possible port resource change.
1442 **/
1443static int
1444lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action)
1445{
1446 int rc;
1447 uint32_t intr_mode;
1448
1449 /*
1450 * On error status condition, driver need to wait for port
1451 * ready before performing reset.
1452 */
1453 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1454 if (!rc) {
1455 /* need reset: attempt for port recovery */
1456 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1457 "2887 Reset Needed: Attempting Port "
1458 "Recovery...\n");
1459 lpfc_offline_prep(phba, mbx_action);
1460 lpfc_offline(phba);
1461 /* release interrupt for possible resource change */
1462 lpfc_sli4_disable_intr(phba);
1463 lpfc_sli_brdrestart(phba);
1464 /* request and enable interrupt */
1465 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1466 if (intr_mode == LPFC_INTR_ERROR) {
1467 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1468 "3175 Failed to enable interrupt\n");
1469 return -EIO;
1470 } else {
1471 phba->intr_mode = intr_mode;
1472 }
1473 rc = lpfc_online(phba);
1474 if (rc == 0)
1475 lpfc_unblock_mgmt_io(phba);
1476 }
1477 return rc;
1478}
1479
1480/**
James Smartda0436e2009-05-22 14:51:39 -04001481 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1482 * @phba: pointer to lpfc hba data structure.
1483 *
1484 * This routine is invoked to handle the SLI4 HBA hardware error attention
1485 * conditions.
1486 **/
1487static void
1488lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1489{
1490 struct lpfc_vport *vport = phba->pport;
1491 uint32_t event_data;
1492 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001493 uint32_t if_type;
James Smart2e90f4b2011-12-13 13:22:37 -05001494 struct lpfc_register portstat_reg = {0};
1495 uint32_t reg_err1, reg_err2;
1496 uint32_t uerrlo_reg, uemasklo_reg;
1497 uint32_t pci_rd_rc1, pci_rd_rc2;
James Smart73d91e52011-10-10 21:32:10 -04001498 int rc;
James Smartda0436e2009-05-22 14:51:39 -04001499
1500 /* If the pci channel is offline, ignore possible errors, since
1501 * we cannot communicate with the pci card anyway.
1502 */
1503 if (pci_channel_offline(phba->pcidev))
1504 return;
1505 /* If resets are disabled then leave the HBA alone and return */
1506 if (!phba->cfg_enable_hba_reset)
1507 return;
1508
James Smart2fcee4b2010-12-15 17:57:46 -05001509 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1510 switch (if_type) {
1511 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart2e90f4b2011-12-13 13:22:37 -05001512 pci_rd_rc1 = lpfc_readl(
1513 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1514 &uerrlo_reg);
1515 pci_rd_rc2 = lpfc_readl(
1516 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1517 &uemasklo_reg);
1518 /* consider PCI bus read error as pci_channel_offline */
1519 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1520 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001521 lpfc_sli4_offline_eratt(phba);
1522 break;
1523 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2e90f4b2011-12-13 13:22:37 -05001524 pci_rd_rc1 = lpfc_readl(
1525 phba->sli4_hba.u.if_type2.STATUSregaddr,
1526 &portstat_reg.word0);
1527 /* consider PCI bus read error as pci_channel_offline */
James Smart6b5151f2012-01-18 16:24:06 -05001528 if (pci_rd_rc1 == -EIO) {
1529 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1530 "3151 PCI bus read access failure: x%x\n",
1531 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
James Smart2e90f4b2011-12-13 13:22:37 -05001532 return;
James Smart6b5151f2012-01-18 16:24:06 -05001533 }
James Smart2e90f4b2011-12-13 13:22:37 -05001534 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1535 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
James Smart2fcee4b2010-12-15 17:57:46 -05001536 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
1537 /* TODO: Register for Overtemp async events. */
1538 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1539 "2889 Port Overtemperature event, "
James Smart026abb82011-12-13 13:20:45 -05001540 "taking port offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05001541 spin_lock_irq(&phba->hbalock);
1542 phba->over_temp_state = HBA_OVER_TEMP;
1543 spin_unlock_irq(&phba->hbalock);
1544 lpfc_sli4_offline_eratt(phba);
James Smart2e90f4b2011-12-13 13:22:37 -05001545 break;
James Smart2fcee4b2010-12-15 17:57:46 -05001546 }
James Smart2e90f4b2011-12-13 13:22:37 -05001547 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1548 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART)
1549 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1550 "3143 Port Down: Firmware Restarted\n");
1551 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1552 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1553 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1554 "3144 Port Down: Debug Dump\n");
1555 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1556 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1557 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1558 "3145 Port Down: Provisioning\n");
James Smart618a5232012-06-12 13:54:36 -04001559
1560 /* Check port status register for function reset */
1561 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT);
1562 if (rc == 0) {
1563 /* don't report event on forced debug dump */
1564 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1565 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1566 return;
1567 else
1568 break;
James Smart2fcee4b2010-12-15 17:57:46 -05001569 }
James Smart618a5232012-06-12 13:54:36 -04001570 /* fall through for not able to recover */
James Smart6b5151f2012-01-18 16:24:06 -05001571 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1572 "3152 Unrecoverable error, bring the port "
1573 "offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05001574 lpfc_sli4_offline_eratt(phba);
1575 break;
1576 case LPFC_SLI_INTF_IF_TYPE_1:
1577 default:
1578 break;
1579 }
James Smart2e90f4b2011-12-13 13:22:37 -05001580 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1581 "3123 Report dump event to upper layer\n");
1582 /* Send an internal error event to mgmt application */
1583 lpfc_board_errevt_to_mgmt(phba);
1584
1585 event_data = FC_REG_DUMP_EVENT;
1586 shost = lpfc_shost_from_vport(vport);
1587 fc_host_post_vendor_event(shost, fc_get_event_number(),
1588 sizeof(event_data), (char *) &event_data,
1589 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
James Smartda0436e2009-05-22 14:51:39 -04001590}
1591
1592/**
1593 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1594 * @phba: pointer to lpfc HBA data structure.
1595 *
1596 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1597 * routine from the API jump table function pointer from the lpfc_hba struct.
1598 *
1599 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001600 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001601 * Any other value - error.
1602 **/
1603void
1604lpfc_handle_eratt(struct lpfc_hba *phba)
1605{
1606 (*phba->lpfc_handle_eratt)(phba);
1607}
1608
1609/**
James Smart3621a712009-04-06 18:47:14 -04001610 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04001611 * @phba: pointer to lpfc hba data structure.
1612 *
1613 * This routine is invoked from the worker thread to handle a HBA host
1614 * attention link event.
1615 **/
dea31012005-04-17 16:05:31 -05001616void
James Smart2e0fef82007-06-17 19:56:36 -05001617lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001618{
James Smart2e0fef82007-06-17 19:56:36 -05001619 struct lpfc_vport *vport = phba->pport;
1620 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001621 LPFC_MBOXQ_t *pmb;
1622 volatile uint32_t control;
1623 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05001624 int rc = 0;
dea31012005-04-17 16:05:31 -05001625
1626 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001627 if (!pmb) {
1628 rc = 1;
dea31012005-04-17 16:05:31 -05001629 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05001630 }
dea31012005-04-17 16:05:31 -05001631
1632 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001633 if (!mp) {
1634 rc = 2;
dea31012005-04-17 16:05:31 -05001635 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05001636 }
dea31012005-04-17 16:05:31 -05001637
1638 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05001639 if (!mp->virt) {
1640 rc = 3;
dea31012005-04-17 16:05:31 -05001641 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05001642 }
dea31012005-04-17 16:05:31 -05001643
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001644 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04001645 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05001646
1647 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05001648 lpfc_read_topology(phba, pmb, mp);
1649 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05001650 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04001651 /* Block ELS IOCBs until we have processed this mbox command */
1652 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04001653 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05001654 if (rc == MBX_NOT_FINISHED) {
1655 rc = 4;
James Smart14691152006-12-02 13:34:28 -05001656 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05001657 }
dea31012005-04-17 16:05:31 -05001658
1659 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05001660 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001661 writel(HA_LATT, phba->HAregaddr);
1662 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001663 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001664
1665 return;
1666
James Smart14691152006-12-02 13:34:28 -05001667lpfc_handle_latt_free_mbuf:
James Smart0d2b6b82008-06-14 22:52:47 -04001668 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05001669 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05001670lpfc_handle_latt_free_mp:
1671 kfree(mp);
1672lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04001673 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001674lpfc_handle_latt_err_exit:
1675 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001676 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001677 psli->sli_flag |= LPFC_PROCESS_LA;
1678 control = readl(phba->HCregaddr);
1679 control |= HC_LAINT_ENA;
1680 writel(control, phba->HCregaddr);
1681 readl(phba->HCregaddr); /* flush */
1682
1683 /* Clear Link Attention in HA REG */
1684 writel(HA_LATT, phba->HAregaddr);
1685 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001686 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001687 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001688 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001689
James Smart09372822008-01-11 01:52:54 -05001690 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1691 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05001692
1693 return;
1694}
1695
James Smarte59058c2008-08-24 21:49:00 -04001696/**
James Smart3621a712009-04-06 18:47:14 -04001697 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04001698 * @phba: pointer to lpfc hba data structure.
1699 * @vpd: pointer to the vital product data.
1700 * @len: length of the vital product data in bytes.
1701 *
1702 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1703 * an array of characters. In this routine, the ModelName, ProgramType, and
1704 * ModelDesc, etc. fields of the phba data structure will be populated.
1705 *
1706 * Return codes
1707 * 0 - pointer to the VPD passed in is NULL
1708 * 1 - success
1709 **/
James Smart3772a992009-05-22 14:50:54 -04001710int
James Smart2e0fef82007-06-17 19:56:36 -05001711lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05001712{
1713 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05001714 int Length;
dea31012005-04-17 16:05:31 -05001715 int i, j;
1716 int finished = 0;
1717 int index = 0;
1718
1719 if (!vpd)
1720 return 0;
1721
1722 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05001723 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001724 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001725 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
1726 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001727 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05001728 switch (vpd[index]) {
1729 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001730 case 0x91:
dea31012005-04-17 16:05:31 -05001731 index += 1;
1732 lenlo = vpd[index];
1733 index += 1;
1734 lenhi = vpd[index];
1735 index += 1;
1736 i = ((((unsigned short)lenhi) << 8) + lenlo);
1737 index += i;
1738 break;
1739 case 0x90:
1740 index += 1;
1741 lenlo = vpd[index];
1742 index += 1;
1743 lenhi = vpd[index];
1744 index += 1;
1745 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001746 if (Length > len - index)
1747 Length = len - index;
dea31012005-04-17 16:05:31 -05001748 while (Length > 0) {
1749 /* Look for Serial Number */
1750 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
1751 index += 2;
1752 i = vpd[index];
1753 index += 1;
1754 j = 0;
1755 Length -= (3+i);
1756 while(i--) {
1757 phba->SerialNumber[j++] = vpd[index++];
1758 if (j == 31)
1759 break;
1760 }
1761 phba->SerialNumber[j] = 0;
1762 continue;
1763 }
1764 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
1765 phba->vpd_flag |= VPD_MODEL_DESC;
1766 index += 2;
1767 i = vpd[index];
1768 index += 1;
1769 j = 0;
1770 Length -= (3+i);
1771 while(i--) {
1772 phba->ModelDesc[j++] = vpd[index++];
1773 if (j == 255)
1774 break;
1775 }
1776 phba->ModelDesc[j] = 0;
1777 continue;
1778 }
1779 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
1780 phba->vpd_flag |= VPD_MODEL_NAME;
1781 index += 2;
1782 i = vpd[index];
1783 index += 1;
1784 j = 0;
1785 Length -= (3+i);
1786 while(i--) {
1787 phba->ModelName[j++] = vpd[index++];
1788 if (j == 79)
1789 break;
1790 }
1791 phba->ModelName[j] = 0;
1792 continue;
1793 }
1794 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
1795 phba->vpd_flag |= VPD_PROGRAM_TYPE;
1796 index += 2;
1797 i = vpd[index];
1798 index += 1;
1799 j = 0;
1800 Length -= (3+i);
1801 while(i--) {
1802 phba->ProgramType[j++] = vpd[index++];
1803 if (j == 255)
1804 break;
1805 }
1806 phba->ProgramType[j] = 0;
1807 continue;
1808 }
1809 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1810 phba->vpd_flag |= VPD_PORT;
1811 index += 2;
1812 i = vpd[index];
1813 index += 1;
1814 j = 0;
1815 Length -= (3+i);
1816 while(i--) {
James Smartcd1c8302011-10-10 21:33:25 -04001817 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1818 (phba->sli4_hba.pport_name_sta ==
1819 LPFC_SLI4_PPNAME_GET)) {
1820 j++;
1821 index++;
1822 } else
1823 phba->Port[j++] = vpd[index++];
1824 if (j == 19)
1825 break;
dea31012005-04-17 16:05:31 -05001826 }
James Smartcd1c8302011-10-10 21:33:25 -04001827 if ((phba->sli_rev != LPFC_SLI_REV4) ||
1828 (phba->sli4_hba.pport_name_sta ==
1829 LPFC_SLI4_PPNAME_NON))
1830 phba->Port[j] = 0;
dea31012005-04-17 16:05:31 -05001831 continue;
1832 }
1833 else {
1834 index += 2;
1835 i = vpd[index];
1836 index += 1;
1837 index += i;
1838 Length -= (3 + i);
1839 }
1840 }
1841 finished = 0;
1842 break;
1843 case 0x78:
1844 finished = 1;
1845 break;
1846 default:
1847 index ++;
1848 break;
1849 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001850 }
dea31012005-04-17 16:05:31 -05001851
1852 return(1);
1853}
1854
James Smarte59058c2008-08-24 21:49:00 -04001855/**
James Smart3621a712009-04-06 18:47:14 -04001856 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04001857 * @phba: pointer to lpfc hba data structure.
1858 * @mdp: pointer to the data structure to hold the derived model name.
1859 * @descp: pointer to the data structure to hold the derived description.
1860 *
1861 * This routine retrieves HBA's description based on its registered PCI device
1862 * ID. The @descp passed into this function points to an array of 256 chars. It
1863 * shall be returned with the model name, maximum speed, and the host bus type.
1864 * The @mdp passed into this function points to an array of 80 chars. When the
1865 * function returns, the @mdp will be filled with the model name.
1866 **/
dea31012005-04-17 16:05:31 -05001867static void
James Smart2e0fef82007-06-17 19:56:36 -05001868lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05001869{
1870 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05001871 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001872 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04001873 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04001874 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001875 struct {
James Smarta747c9c2009-11-18 15:41:10 -05001876 char *name;
1877 char *bus;
1878 char *function;
1879 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001880
1881 if (mdp && mdp[0] != '\0'
1882 && descp && descp[0] != '\0')
1883 return;
1884
James Smartc0c11512011-05-24 11:41:34 -04001885 if (phba->lmt & LMT_16Gb)
1886 max_speed = 16;
1887 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001888 max_speed = 10;
1889 else if (phba->lmt & LMT_8Gb)
1890 max_speed = 8;
1891 else if (phba->lmt & LMT_4Gb)
1892 max_speed = 4;
1893 else if (phba->lmt & LMT_2Gb)
1894 max_speed = 2;
1895 else
1896 max_speed = 1;
dea31012005-04-17 16:05:31 -05001897
1898 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05001899
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001900 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001901 case PCI_DEVICE_ID_FIREFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001902 m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001903 break;
dea31012005-04-17 16:05:31 -05001904 case PCI_DEVICE_ID_SUPERFLY:
1905 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smarta747c9c2009-11-18 15:41:10 -05001906 m = (typeof(m)){"LP7000", "PCI",
1907 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001908 else
James Smarta747c9c2009-11-18 15:41:10 -05001909 m = (typeof(m)){"LP7000E", "PCI",
1910 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001911 break;
1912 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001913 m = (typeof(m)){"LP8000", "PCI",
1914 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001915 break;
1916 case PCI_DEVICE_ID_CENTAUR:
1917 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smarta747c9c2009-11-18 15:41:10 -05001918 m = (typeof(m)){"LP9002", "PCI",
1919 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001920 else
James Smarta747c9c2009-11-18 15:41:10 -05001921 m = (typeof(m)){"LP9000", "PCI",
1922 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001923 break;
1924 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001925 m = (typeof(m)){"LP952", "PCI",
1926 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001927 break;
1928 case PCI_DEVICE_ID_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05001929 m = (typeof(m)){"LP9802", "PCI-X",
1930 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001931 break;
1932 case PCI_DEVICE_ID_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05001933 m = (typeof(m)){"LP10000", "PCI-X",
1934 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001935 break;
1936 case PCI_DEVICE_ID_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05001937 m = (typeof(m)){"LPX1000", "PCI-X",
1938 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001939 break;
1940 case PCI_DEVICE_ID_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001941 m = (typeof(m)){"LP982", "PCI-X",
1942 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001943 break;
1944 case PCI_DEVICE_ID_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001945 m = (typeof(m)){"LP1050", "PCI-X",
1946 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001947 break;
1948 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05001949 m = (typeof(m)){"LP11000", "PCI-X2",
1950 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001951 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001952 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001953 m = (typeof(m)){"LP11000-SP", "PCI-X2",
1954 "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001955 break;
1956 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001957 m = (typeof(m)){"LP11002-SP", "PCI-X2",
1958 "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001959 break;
1960 case PCI_DEVICE_ID_NEPTUNE:
James Smarta747c9c2009-11-18 15:41:10 -05001961 m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001962 break;
1963 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001964 m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001965 break;
1966 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001967 m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001968 break;
dea31012005-04-17 16:05:31 -05001969 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05001970 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001971 break;
1972 case PCI_DEVICE_ID_BSMB:
James Smarta747c9c2009-11-18 15:41:10 -05001973 m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001974 break;
1975 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05001976 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001977 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001978 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001979 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001980 break;
1981 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001982 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04001983 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001984 break;
dea31012005-04-17 16:05:31 -05001985 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05001986 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001987 break;
1988 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05001989 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001990 break;
1991 case PCI_DEVICE_ID_LP101:
James Smarta747c9c2009-11-18 15:41:10 -05001992 m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001993 break;
1994 case PCI_DEVICE_ID_LP10000S:
James Smarta747c9c2009-11-18 15:41:10 -05001995 m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001996 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001997 case PCI_DEVICE_ID_LP11000S:
James Smarta747c9c2009-11-18 15:41:10 -05001998 m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05001999 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002000 case PCI_DEVICE_ID_LPE11000S:
James Smarta747c9c2009-11-18 15:41:10 -05002001 m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002002 break;
James Smartb87eab32007-04-25 09:53:28 -04002003 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05002004 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002005 break;
2006 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05002007 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002008 break;
2009 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05002010 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002011 break;
2012 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002013 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002014 break;
2015 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002016 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002017 break;
2018 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05002019 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002020 break;
James Smart84774a42008-08-24 21:50:06 -04002021 case PCI_DEVICE_ID_HORNET:
James Smarta747c9c2009-11-18 15:41:10 -05002022 m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002023 GE = 1;
2024 break;
2025 case PCI_DEVICE_ID_PROTEUS_VF:
James Smarta747c9c2009-11-18 15:41:10 -05002026 m = (typeof(m)){"LPev12000", "PCIe IOV",
2027 "Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002028 break;
2029 case PCI_DEVICE_ID_PROTEUS_PF:
James Smarta747c9c2009-11-18 15:41:10 -05002030 m = (typeof(m)){"LPev12000", "PCIe IOV",
2031 "Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002032 break;
2033 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05002034 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
2035 "Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002036 break;
James Smartda0436e2009-05-22 14:51:39 -04002037 case PCI_DEVICE_ID_TIGERSHARK:
2038 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002039 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04002040 break;
James Smarta747c9c2009-11-18 15:41:10 -05002041 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04002042 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002043 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2044 break;
2045 case PCI_DEVICE_ID_FALCON:
2046 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2047 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04002048 break;
James Smart98fc5dd2010-06-07 15:24:29 -04002049 case PCI_DEVICE_ID_BALIUS:
2050 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
2051 "Fibre Channel Adapter"};
2052 break;
James Smart085c6472010-11-20 23:11:37 -05002053 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04002054 case PCI_DEVICE_ID_LANCER_FC_VF:
2055 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05002056 break;
2057 case PCI_DEVICE_ID_LANCER_FCOE:
James Smartc0c11512011-05-24 11:41:34 -04002058 case PCI_DEVICE_ID_LANCER_FCOE_VF:
James Smart085c6472010-11-20 23:11:37 -05002059 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04002060 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05002061 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002062 default:
James Smarta747c9c2009-11-18 15:41:10 -05002063 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002064 break;
dea31012005-04-17 16:05:31 -05002065 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002066
2067 if (mdp && mdp[0] == '\0')
2068 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04002069 /*
2070 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04002071 * and we put the port number on the end
2072 */
2073 if (descp && descp[0] == '\0') {
2074 if (oneConnect)
2075 snprintf(descp, 255,
James Smarta747c9c2009-11-18 15:41:10 -05002076 "Emulex OneConnect %s, %s Initiator, Port %s",
2077 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04002078 phba->Port);
2079 else
2080 snprintf(descp, 255,
2081 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05002082 m.name, max_speed, (GE) ? "GE" : "Gb",
2083 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002084 }
dea31012005-04-17 16:05:31 -05002085}
2086
James Smarte59058c2008-08-24 21:49:00 -04002087/**
James Smart3621a712009-04-06 18:47:14 -04002088 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04002089 * @phba: pointer to lpfc hba data structure.
2090 * @pring: pointer to a IOCB ring.
2091 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2092 *
2093 * This routine posts a given number of IOCBs with the associated DMA buffer
2094 * descriptors specified by the cnt argument to the given IOCB ring.
2095 *
2096 * Return codes
2097 * The number of IOCBs NOT able to be posted to the IOCB ring.
2098 **/
dea31012005-04-17 16:05:31 -05002099int
James Smart495a7142008-06-14 22:52:59 -04002100lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002101{
2102 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002103 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002104 struct lpfc_dmabuf *mp1, *mp2;
2105
2106 cnt += pring->missbufcnt;
2107
2108 /* While there are buffers to post */
2109 while (cnt > 0) {
2110 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002111 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002112 if (iocb == NULL) {
2113 pring->missbufcnt = cnt;
2114 return cnt;
2115 }
dea31012005-04-17 16:05:31 -05002116 icmd = &iocb->iocb;
2117
2118 /* 2 buffers can be posted per command */
2119 /* Allocate buffer to post */
2120 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2121 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002122 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2123 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002124 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002125 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002126 pring->missbufcnt = cnt;
2127 return cnt;
2128 }
2129
2130 INIT_LIST_HEAD(&mp1->list);
2131 /* Allocate buffer to post */
2132 if (cnt > 1) {
2133 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2134 if (mp2)
2135 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2136 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002137 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002138 kfree(mp2);
dea31012005-04-17 16:05:31 -05002139 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2140 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002141 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002142 pring->missbufcnt = cnt;
2143 return cnt;
2144 }
2145
2146 INIT_LIST_HEAD(&mp2->list);
2147 } else {
2148 mp2 = NULL;
2149 }
2150
2151 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2152 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2153 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2154 icmd->ulpBdeCount = 1;
2155 cnt--;
2156 if (mp2) {
2157 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2158 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2159 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2160 cnt--;
2161 icmd->ulpBdeCount = 2;
2162 }
2163
2164 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2165 icmd->ulpLe = 1;
2166
James Smart3772a992009-05-22 14:50:54 -04002167 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2168 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002169 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2170 kfree(mp1);
2171 cnt++;
2172 if (mp2) {
2173 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2174 kfree(mp2);
2175 cnt++;
2176 }
James Bottomley604a3e32005-10-29 10:28:33 -05002177 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002178 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002179 return cnt;
2180 }
dea31012005-04-17 16:05:31 -05002181 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002182 if (mp2)
dea31012005-04-17 16:05:31 -05002183 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002184 }
2185 pring->missbufcnt = 0;
2186 return 0;
2187}
2188
James Smarte59058c2008-08-24 21:49:00 -04002189/**
James Smart3621a712009-04-06 18:47:14 -04002190 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002191 * @phba: pointer to lpfc hba data structure.
2192 *
2193 * This routine posts initial receive IOCB buffers to the ELS ring. The
2194 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2195 * set to 64 IOCBs.
2196 *
2197 * Return codes
2198 * 0 - success (currently always success)
2199 **/
dea31012005-04-17 16:05:31 -05002200static int
James Smart2e0fef82007-06-17 19:56:36 -05002201lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002202{
2203 struct lpfc_sli *psli = &phba->sli;
2204
2205 /* Ring 0, ELS / CT buffers */
James Smart495a7142008-06-14 22:52:59 -04002206 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002207 /* Ring 2 - FCP no buffers needed */
2208
2209 return 0;
2210}
2211
2212#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2213
James Smarte59058c2008-08-24 21:49:00 -04002214/**
James Smart3621a712009-04-06 18:47:14 -04002215 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002216 * @HashResultPointer: pointer to an array as hash table.
2217 *
2218 * This routine sets up the initial values to the array of hash table entries
2219 * for the LC HBAs.
2220 **/
dea31012005-04-17 16:05:31 -05002221static void
2222lpfc_sha_init(uint32_t * HashResultPointer)
2223{
2224 HashResultPointer[0] = 0x67452301;
2225 HashResultPointer[1] = 0xEFCDAB89;
2226 HashResultPointer[2] = 0x98BADCFE;
2227 HashResultPointer[3] = 0x10325476;
2228 HashResultPointer[4] = 0xC3D2E1F0;
2229}
2230
James Smarte59058c2008-08-24 21:49:00 -04002231/**
James Smart3621a712009-04-06 18:47:14 -04002232 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002233 * @HashResultPointer: pointer to an initial/result hash table.
2234 * @HashWorkingPointer: pointer to an working hash table.
2235 *
2236 * This routine iterates an initial hash table pointed by @HashResultPointer
2237 * with the values from the working hash table pointeed by @HashWorkingPointer.
2238 * The results are putting back to the initial hash table, returned through
2239 * the @HashResultPointer as the result hash table.
2240 **/
dea31012005-04-17 16:05:31 -05002241static void
2242lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2243{
2244 int t;
2245 uint32_t TEMP;
2246 uint32_t A, B, C, D, E;
2247 t = 16;
2248 do {
2249 HashWorkingPointer[t] =
2250 S(1,
2251 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2252 8] ^
2253 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2254 } while (++t <= 79);
2255 t = 0;
2256 A = HashResultPointer[0];
2257 B = HashResultPointer[1];
2258 C = HashResultPointer[2];
2259 D = HashResultPointer[3];
2260 E = HashResultPointer[4];
2261
2262 do {
2263 if (t < 20) {
2264 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2265 } else if (t < 40) {
2266 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2267 } else if (t < 60) {
2268 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2269 } else {
2270 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2271 }
2272 TEMP += S(5, A) + E + HashWorkingPointer[t];
2273 E = D;
2274 D = C;
2275 C = S(30, B);
2276 B = A;
2277 A = TEMP;
2278 } while (++t <= 79);
2279
2280 HashResultPointer[0] += A;
2281 HashResultPointer[1] += B;
2282 HashResultPointer[2] += C;
2283 HashResultPointer[3] += D;
2284 HashResultPointer[4] += E;
2285
2286}
2287
James Smarte59058c2008-08-24 21:49:00 -04002288/**
James Smart3621a712009-04-06 18:47:14 -04002289 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002290 * @RandomChallenge: pointer to the entry of host challenge random number array.
2291 * @HashWorking: pointer to the entry of the working hash array.
2292 *
2293 * This routine calculates the working hash array referred by @HashWorking
2294 * from the challenge random numbers associated with the host, referred by
2295 * @RandomChallenge. The result is put into the entry of the working hash
2296 * array and returned by reference through @HashWorking.
2297 **/
dea31012005-04-17 16:05:31 -05002298static void
2299lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2300{
2301 *HashWorking = (*RandomChallenge ^ *HashWorking);
2302}
2303
James Smarte59058c2008-08-24 21:49:00 -04002304/**
James Smart3621a712009-04-06 18:47:14 -04002305 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002306 * @phba: pointer to lpfc hba data structure.
2307 * @hbainit: pointer to an array of unsigned 32-bit integers.
2308 *
2309 * This routine performs the special handling for LC HBA initialization.
2310 **/
dea31012005-04-17 16:05:31 -05002311void
2312lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2313{
2314 int t;
2315 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002316 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002317
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002318 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002319 if (!HashWorking)
2320 return;
2321
dea31012005-04-17 16:05:31 -05002322 HashWorking[0] = HashWorking[78] = *pwwnn++;
2323 HashWorking[1] = HashWorking[79] = *pwwnn;
2324
2325 for (t = 0; t < 7; t++)
2326 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2327
2328 lpfc_sha_init(hbainit);
2329 lpfc_sha_iterate(hbainit, HashWorking);
2330 kfree(HashWorking);
2331}
2332
James Smarte59058c2008-08-24 21:49:00 -04002333/**
James Smart3621a712009-04-06 18:47:14 -04002334 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002335 * @vport: pointer to a virtual N_Port data structure.
2336 *
2337 * This routine performs the necessary cleanups before deleting the @vport.
2338 * It invokes the discovery state machine to perform necessary state
2339 * transitions and to release the ndlps associated with the @vport. Note,
2340 * the physical port is treated as @vport 0.
2341 **/
James Smart87af33f2007-10-27 13:37:43 -04002342void
James Smart2e0fef82007-06-17 19:56:36 -05002343lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002344{
James Smart87af33f2007-10-27 13:37:43 -04002345 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002346 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002347 int i = 0;
dea31012005-04-17 16:05:31 -05002348
James Smart87af33f2007-10-27 13:37:43 -04002349 if (phba->link_state > LPFC_LINK_DOWN)
2350 lpfc_port_link_failure(vport);
2351
2352 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002353 if (!NLP_CHK_NODE_ACT(ndlp)) {
2354 ndlp = lpfc_enable_node(vport, ndlp,
2355 NLP_STE_UNUSED_NODE);
2356 if (!ndlp)
2357 continue;
2358 spin_lock_irq(&phba->ndlp_lock);
2359 NLP_SET_FREE_REQ(ndlp);
2360 spin_unlock_irq(&phba->ndlp_lock);
2361 /* Trigger the release of the ndlp memory */
2362 lpfc_nlp_put(ndlp);
2363 continue;
2364 }
2365 spin_lock_irq(&phba->ndlp_lock);
2366 if (NLP_CHK_FREE_REQ(ndlp)) {
2367 /* The ndlp should not be in memory free mode already */
2368 spin_unlock_irq(&phba->ndlp_lock);
2369 continue;
2370 } else
2371 /* Indicate request for freeing ndlp memory */
2372 NLP_SET_FREE_REQ(ndlp);
2373 spin_unlock_irq(&phba->ndlp_lock);
2374
James Smart58da1ff2008-04-07 10:15:56 -04002375 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2376 ndlp->nlp_DID == Fabric_DID) {
2377 /* Just free up ndlp with Fabric_DID for vports */
2378 lpfc_nlp_put(ndlp);
2379 continue;
2380 }
2381
James Smarteff4a012012-01-18 16:25:25 -05002382 /* take care of nodes in unused state before the state
2383 * machine taking action.
2384 */
2385 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2386 lpfc_nlp_put(ndlp);
2387 continue;
2388 }
2389
James Smart87af33f2007-10-27 13:37:43 -04002390 if (ndlp->nlp_type & NLP_FABRIC)
2391 lpfc_disc_state_machine(vport, ndlp, NULL,
2392 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002393
James Smart87af33f2007-10-27 13:37:43 -04002394 lpfc_disc_state_machine(vport, ndlp, NULL,
2395 NLP_EVT_DEVICE_RM);
2396 }
2397
James Smarta8adb832007-10-27 13:37:53 -04002398 /* At this point, ALL ndlp's should be gone
2399 * because of the previous NLP_EVT_DEVICE_RM.
2400 * Lets wait for this to happen, if needed.
2401 */
James Smart87af33f2007-10-27 13:37:43 -04002402 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002403 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04002404 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04002405 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002406 list_for_each_entry_safe(ndlp, next_ndlp,
2407 &vport->fc_nodes, nlp_listp) {
2408 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2409 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04002410 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05002411 "usgmap:x%x refcnt:%d\n",
2412 ndlp->nlp_DID, (void *)ndlp,
2413 ndlp->nlp_usg_map,
2414 atomic_read(
2415 &ndlp->kref.refcount));
2416 }
James Smarta8adb832007-10-27 13:37:53 -04002417 break;
James Smart87af33f2007-10-27 13:37:43 -04002418 }
James Smarta8adb832007-10-27 13:37:53 -04002419
2420 /* Wait for any activity on ndlps to settle */
2421 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002422 }
James Smart1151e3e2011-02-16 12:39:35 -05002423 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002424}
2425
James Smarte59058c2008-08-24 21:49:00 -04002426/**
James Smart3621a712009-04-06 18:47:14 -04002427 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002428 * @vport: pointer to a virtual N_Port data structure.
2429 *
2430 * This routine stops all the timers associated with a @vport. This function
2431 * is invoked before disabling or deleting a @vport. Note that the physical
2432 * port is treated as @vport 0.
2433 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002434void
2435lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002436{
James Smart92d7f7b2007-06-17 19:56:38 -05002437 del_timer_sync(&vport->els_tmofunc);
2438 del_timer_sync(&vport->fc_fdmitmo);
James Smart92494142011-02-16 12:39:44 -05002439 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002440 lpfc_can_disctmo(vport);
2441 return;
dea31012005-04-17 16:05:31 -05002442}
2443
James Smarte59058c2008-08-24 21:49:00 -04002444/**
James Smartecfd03c2010-02-12 14:41:27 -05002445 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2446 * @phba: pointer to lpfc hba data structure.
2447 *
2448 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2449 * caller of this routine should already hold the host lock.
2450 **/
2451void
2452__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2453{
James Smart5ac6b302010-10-22 11:05:36 -04002454 /* Clear pending FCF rediscovery wait flag */
2455 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2456
James Smartecfd03c2010-02-12 14:41:27 -05002457 /* Now, try to stop the timer */
2458 del_timer(&phba->fcf.redisc_wait);
2459}
2460
2461/**
2462 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2463 * @phba: pointer to lpfc hba data structure.
2464 *
2465 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2466 * checks whether the FCF rediscovery wait timer is pending with the host
2467 * lock held before proceeding with disabling the timer and clearing the
2468 * wait timer pendig flag.
2469 **/
2470void
2471lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2472{
2473 spin_lock_irq(&phba->hbalock);
2474 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2475 /* FCF rediscovery timer already fired or stopped */
2476 spin_unlock_irq(&phba->hbalock);
2477 return;
2478 }
2479 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002480 /* Clear failover in progress flags */
2481 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002482 spin_unlock_irq(&phba->hbalock);
2483}
2484
2485/**
James Smart3772a992009-05-22 14:50:54 -04002486 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002487 * @phba: pointer to lpfc hba data structure.
2488 *
2489 * This routine stops all the timers associated with a HBA. This function is
2490 * invoked before either putting a HBA offline or unloading the driver.
2491 **/
James Smart3772a992009-05-22 14:50:54 -04002492void
2493lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002494{
James Smart51ef4c22007-08-02 11:10:31 -04002495 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05002496 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002497 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002498 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002499 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002500 if (phba->sli_rev == LPFC_SLI_REV4) {
2501 del_timer_sync(&phba->rrq_tmr);
2502 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2503 }
James Smart3772a992009-05-22 14:50:54 -04002504 phba->hb_outstanding = 0;
2505
2506 switch (phba->pci_dev_grp) {
2507 case LPFC_PCI_DEV_LP:
2508 /* Stop any LightPulse device specific driver timers */
2509 del_timer_sync(&phba->fcp_poll_timer);
2510 break;
2511 case LPFC_PCI_DEV_OC:
2512 /* Stop any OneConnect device sepcific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002513 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002514 break;
2515 default:
2516 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2517 "0297 Invalid device group (x%x)\n",
2518 phba->pci_dev_grp);
2519 break;
2520 }
James Smart2e0fef82007-06-17 19:56:36 -05002521 return;
dea31012005-04-17 16:05:31 -05002522}
2523
James Smarte59058c2008-08-24 21:49:00 -04002524/**
James Smart3621a712009-04-06 18:47:14 -04002525 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002526 * @phba: pointer to lpfc hba data structure.
2527 *
2528 * This routine marks a HBA's management interface as blocked. Once the HBA's
2529 * management interface is marked as blocked, all the user space access to
2530 * the HBA, whether they are from sysfs interface or libdfc interface will
2531 * all be blocked. The HBA is set to block the management interface when the
2532 * driver prepares the HBA interface for online or offline.
2533 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01002534static void
James Smart618a5232012-06-12 13:54:36 -04002535lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
Adrian Bunka6ababd2007-11-05 18:07:33 +01002536{
2537 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04002538 uint8_t actcmd = MBX_HEARTBEAT;
2539 unsigned long timeout;
2540
Adrian Bunka6ababd2007-11-05 18:07:33 +01002541 spin_lock_irqsave(&phba->hbalock, iflag);
2542 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart618a5232012-06-12 13:54:36 -04002543 spin_unlock_irqrestore(&phba->hbalock, iflag);
2544 if (mbx_action == LPFC_MBX_NO_WAIT)
2545 return;
2546 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2547 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002548 if (phba->sli.mbox_active) {
James Smart6e7288d2010-06-07 15:23:35 -04002549 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
James Smarta183a152011-10-10 21:32:43 -04002550 /* Determine how long we might wait for the active mailbox
2551 * command to be gracefully completed by firmware.
2552 */
2553 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
2554 phba->sli.mbox_active) * 1000) + jiffies;
2555 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002556 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002557
James Smart6e7288d2010-06-07 15:23:35 -04002558 /* Wait for the outstnading mailbox command to complete */
2559 while (phba->sli.mbox_active) {
2560 /* Check active mailbox complete status every 2ms */
2561 msleep(2);
2562 if (time_after(jiffies, timeout)) {
2563 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2564 "2813 Mgmt IO is Blocked %x "
2565 "- mbox cmd %x still active\n",
2566 phba->sli.sli_flag, actcmd);
2567 break;
2568 }
2569 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002570}
2571
James Smarte59058c2008-08-24 21:49:00 -04002572/**
James Smart6b5151f2012-01-18 16:24:06 -05002573 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
2574 * @phba: pointer to lpfc hba data structure.
2575 *
2576 * Allocate RPIs for all active remote nodes. This is needed whenever
2577 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
2578 * is to fixup the temporary rpi assignments.
2579 **/
2580void
2581lpfc_sli4_node_prep(struct lpfc_hba *phba)
2582{
2583 struct lpfc_nodelist *ndlp, *next_ndlp;
2584 struct lpfc_vport **vports;
2585 int i;
2586
2587 if (phba->sli_rev != LPFC_SLI_REV4)
2588 return;
2589
2590 vports = lpfc_create_vport_work_array(phba);
2591 if (vports != NULL) {
2592 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2593 if (vports[i]->load_flag & FC_UNLOADING)
2594 continue;
2595
2596 list_for_each_entry_safe(ndlp, next_ndlp,
2597 &vports[i]->fc_nodes,
2598 nlp_listp) {
2599 if (NLP_CHK_NODE_ACT(ndlp))
2600 ndlp->nlp_rpi =
2601 lpfc_sli4_alloc_rpi(phba);
2602 }
2603 }
2604 }
2605 lpfc_destroy_vport_work_array(phba, vports);
2606}
2607
2608/**
James Smart3621a712009-04-06 18:47:14 -04002609 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04002610 * @phba: pointer to lpfc hba data structure.
2611 *
2612 * This routine initializes the HBA and brings a HBA online. During this
2613 * process, the management interface is blocked to prevent user space access
2614 * to the HBA interfering with the driver initialization.
2615 *
2616 * Return codes
2617 * 0 - successful
2618 * 1 - failed
2619 **/
dea31012005-04-17 16:05:31 -05002620int
James Smart2e0fef82007-06-17 19:56:36 -05002621lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002622{
Julia Lawall372bd282008-12-16 16:15:08 +01002623 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04002624 struct lpfc_vport **vports;
2625 int i;
James Smart2e0fef82007-06-17 19:56:36 -05002626
dea31012005-04-17 16:05:31 -05002627 if (!phba)
2628 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01002629 vport = phba->pport;
dea31012005-04-17 16:05:31 -05002630
James Smart2e0fef82007-06-17 19:56:36 -05002631 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05002632 return 0;
2633
James Smarted957682007-06-17 19:56:37 -05002634 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002635 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05002636
James Smart618a5232012-06-12 13:54:36 -04002637 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05002638
James Smart46fa3112007-04-25 09:51:45 -04002639 if (!lpfc_sli_queue_setup(phba)) {
2640 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002641 return 1;
James Smart46fa3112007-04-25 09:51:45 -04002642 }
2643
James Smartda0436e2009-05-22 14:51:39 -04002644 if (phba->sli_rev == LPFC_SLI_REV4) {
2645 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
2646 lpfc_unblock_mgmt_io(phba);
2647 return 1;
2648 }
2649 } else {
2650 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
2651 lpfc_unblock_mgmt_io(phba);
2652 return 1;
2653 }
James Smart46fa3112007-04-25 09:51:45 -04002654 }
dea31012005-04-17 16:05:31 -05002655
James Smart549e55c2007-08-02 11:09:51 -04002656 vports = lpfc_create_vport_work_array(phba);
2657 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002658 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002659 struct Scsi_Host *shost;
2660 shost = lpfc_shost_from_vport(vports[i]);
2661 spin_lock_irq(shost->host_lock);
2662 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
2663 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2664 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart1c6834a2009-07-19 10:01:26 -04002665 if (phba->sli_rev == LPFC_SLI_REV4)
2666 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart549e55c2007-08-02 11:09:51 -04002667 spin_unlock_irq(shost->host_lock);
2668 }
James Smart09372822008-01-11 01:52:54 -05002669 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002670
James Smart46fa3112007-04-25 09:51:45 -04002671 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002672 return 0;
2673}
2674
James Smarte59058c2008-08-24 21:49:00 -04002675/**
James Smart3621a712009-04-06 18:47:14 -04002676 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04002677 * @phba: pointer to lpfc hba data structure.
2678 *
2679 * This routine marks a HBA's management interface as not blocked. Once the
2680 * HBA's management interface is marked as not blocked, all the user space
2681 * access to the HBA, whether they are from sysfs interface or libdfc
2682 * interface will be allowed. The HBA is set to block the management interface
2683 * when the driver prepares the HBA interface for online or offline and then
2684 * set to unblock the management interface afterwards.
2685 **/
James Smart46fa3112007-04-25 09:51:45 -04002686void
James Smart46fa3112007-04-25 09:51:45 -04002687lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
2688{
2689 unsigned long iflag;
2690
James Smart2e0fef82007-06-17 19:56:36 -05002691 spin_lock_irqsave(&phba->hbalock, iflag);
2692 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
2693 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04002694}
2695
James Smarte59058c2008-08-24 21:49:00 -04002696/**
James Smart3621a712009-04-06 18:47:14 -04002697 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04002698 * @phba: pointer to lpfc hba data structure.
2699 *
2700 * This routine is invoked to prepare a HBA to be brought offline. It performs
2701 * unregistration login to all the nodes on all vports and flushes the mailbox
2702 * queue to make it ready to be brought offline.
2703 **/
James Smart46fa3112007-04-25 09:51:45 -04002704void
James Smart618a5232012-06-12 13:54:36 -04002705lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04002706{
James Smart2e0fef82007-06-17 19:56:36 -05002707 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04002708 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04002709 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05002710 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04002711 int i;
dea31012005-04-17 16:05:31 -05002712
James Smart2e0fef82007-06-17 19:56:36 -05002713 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002714 return;
dea31012005-04-17 16:05:31 -05002715
James Smart618a5232012-06-12 13:54:36 -04002716 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05002717
2718 lpfc_linkdown(phba);
2719
James Smart87af33f2007-10-27 13:37:43 -04002720 /* Issue an unreg_login to all nodes on all vports */
2721 vports = lpfc_create_vport_work_array(phba);
2722 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04002723 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04002724 if (vports[i]->load_flag & FC_UNLOADING)
2725 continue;
James Smart72100cc2010-02-12 14:43:01 -05002726 shost = lpfc_shost_from_vport(vports[i]);
2727 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05002728 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002729 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2730 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05002731 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05002732
James Smart87af33f2007-10-27 13:37:43 -04002733 shost = lpfc_shost_from_vport(vports[i]);
2734 list_for_each_entry_safe(ndlp, next_ndlp,
2735 &vports[i]->fc_nodes,
2736 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002737 if (!NLP_CHK_NODE_ACT(ndlp))
2738 continue;
James Smart87af33f2007-10-27 13:37:43 -04002739 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2740 continue;
2741 if (ndlp->nlp_type & NLP_FABRIC) {
2742 lpfc_disc_state_machine(vports[i], ndlp,
2743 NULL, NLP_EVT_DEVICE_RECOVERY);
2744 lpfc_disc_state_machine(vports[i], ndlp,
2745 NULL, NLP_EVT_DEVICE_RM);
2746 }
2747 spin_lock_irq(shost->host_lock);
2748 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart401ee0c2012-03-01 22:35:34 -05002749 spin_unlock_irq(shost->host_lock);
James Smart6b5151f2012-01-18 16:24:06 -05002750 /*
2751 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05002752 * RPI. Get a new RPI when the adapter port
2753 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05002754 */
2755 if (phba->sli_rev == LPFC_SLI_REV4)
2756 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04002757 lpfc_unreg_rpi(vports[i], ndlp);
2758 }
2759 }
2760 }
James Smart09372822008-01-11 01:52:54 -05002761 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002762
James Smart618a5232012-06-12 13:54:36 -04002763 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
James Smart46fa3112007-04-25 09:51:45 -04002764}
2765
James Smarte59058c2008-08-24 21:49:00 -04002766/**
James Smart3621a712009-04-06 18:47:14 -04002767 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04002768 * @phba: pointer to lpfc hba data structure.
2769 *
2770 * This routine actually brings a HBA offline. It stops all the timers
2771 * associated with the HBA, brings down the SLI layer, and eventually
2772 * marks the HBA as in offline state for the upper layer protocol.
2773 **/
James Smart46fa3112007-04-25 09:51:45 -04002774void
James Smart2e0fef82007-06-17 19:56:36 -05002775lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04002776{
James Smart549e55c2007-08-02 11:09:51 -04002777 struct Scsi_Host *shost;
2778 struct lpfc_vport **vports;
2779 int i;
James Smart46fa3112007-04-25 09:51:45 -04002780
James Smart549e55c2007-08-02 11:09:51 -04002781 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002782 return;
James Smart688a8862006-07-06 15:49:56 -04002783
James Smartda0436e2009-05-22 14:51:39 -04002784 /* stop port and all timers associated with this hba */
2785 lpfc_stop_port(phba);
James Smart51ef4c22007-08-02 11:10:31 -04002786 vports = lpfc_create_vport_work_array(phba);
2787 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002788 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04002789 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05002790 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05002791 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002792 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05002793 /* Bring down the SLI Layer and cleanup. The HBA is offline
2794 now. */
2795 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002796 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04002797 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05002798 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04002799 vports = lpfc_create_vport_work_array(phba);
2800 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002801 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002802 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04002803 spin_lock_irq(shost->host_lock);
2804 vports[i]->work_port_events = 0;
2805 vports[i]->fc_flag |= FC_OFFLINE_MODE;
2806 spin_unlock_irq(shost->host_lock);
2807 }
James Smart09372822008-01-11 01:52:54 -05002808 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002809}
2810
James Smarte59058c2008-08-24 21:49:00 -04002811/**
James Smart3621a712009-04-06 18:47:14 -04002812 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04002813 * @phba: pointer to lpfc hba data structure.
2814 *
2815 * This routine is to free all the SCSI buffers and IOCBs from the driver
2816 * list back to kernel. It is called from lpfc_pci_remove_one to free
2817 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04002818 **/
James Smart8a9d2e82012-05-09 21:16:12 -04002819static void
James Smart2e0fef82007-06-17 19:56:36 -05002820lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002821{
2822 struct lpfc_scsi_buf *sb, *sb_next;
2823 struct lpfc_iocbq *io, *io_next;
2824
James Smart2e0fef82007-06-17 19:56:36 -05002825 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002826 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smart1c6f4ef52009-11-18 15:40:49 -05002827 spin_lock(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05002828 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
2829 list_del(&sb->list);
2830 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05002831 sb->dma_handle);
dea31012005-04-17 16:05:31 -05002832 kfree(sb);
2833 phba->total_scsi_bufs--;
2834 }
James Smart1c6f4ef52009-11-18 15:40:49 -05002835 spin_unlock(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05002836
2837 /* Release all the lpfc_iocbq entries maintained by this host. */
2838 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
2839 list_del(&io->list);
2840 kfree(io);
2841 phba->total_iocbq_bufs--;
2842 }
James Smart6d368e52011-05-24 11:44:12 -04002843
James Smart2e0fef82007-06-17 19:56:36 -05002844 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04002845}
2846
2847/**
2848 * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping
2849 * @phba: pointer to lpfc hba data structure.
2850 *
2851 * This routine first calculates the sizes of the current els and allocated
2852 * scsi sgl lists, and then goes through all sgls to updates the physical
2853 * XRIs assigned due to port function reset. During port initialization, the
2854 * current els and allocated scsi sgl lists are 0s.
2855 *
2856 * Return codes
2857 * 0 - successful (for now, it always returns 0)
2858 **/
2859int
2860lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba)
2861{
2862 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
2863 struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL;
2864 uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt;
2865 LIST_HEAD(els_sgl_list);
2866 LIST_HEAD(scsi_sgl_list);
2867 int rc;
2868
2869 /*
2870 * update on pci function's els xri-sgl list
2871 */
2872 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
2873 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
2874 /* els xri-sgl expanded */
2875 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
2876 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2877 "3157 ELS xri-sgl count increased from "
2878 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
2879 els_xri_cnt);
2880 /* allocate the additional els sgls */
2881 for (i = 0; i < xri_cnt; i++) {
2882 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
2883 GFP_KERNEL);
2884 if (sglq_entry == NULL) {
2885 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2886 "2562 Failure to allocate an "
2887 "ELS sgl entry:%d\n", i);
2888 rc = -ENOMEM;
2889 goto out_free_mem;
2890 }
2891 sglq_entry->buff_type = GEN_BUFF_TYPE;
2892 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
2893 &sglq_entry->phys);
2894 if (sglq_entry->virt == NULL) {
2895 kfree(sglq_entry);
2896 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2897 "2563 Failure to allocate an "
2898 "ELS mbuf:%d\n", i);
2899 rc = -ENOMEM;
2900 goto out_free_mem;
2901 }
2902 sglq_entry->sgl = sglq_entry->virt;
2903 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
2904 sglq_entry->state = SGL_FREED;
2905 list_add_tail(&sglq_entry->list, &els_sgl_list);
2906 }
2907 spin_lock(&phba->hbalock);
2908 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
2909 spin_unlock(&phba->hbalock);
2910 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
2911 /* els xri-sgl shrinked */
2912 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
2913 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2914 "3158 ELS xri-sgl count decreased from "
2915 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
2916 els_xri_cnt);
2917 spin_lock_irq(&phba->hbalock);
2918 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list);
2919 spin_unlock_irq(&phba->hbalock);
2920 /* release extra els sgls from list */
2921 for (i = 0; i < xri_cnt; i++) {
2922 list_remove_head(&els_sgl_list,
2923 sglq_entry, struct lpfc_sglq, list);
2924 if (sglq_entry) {
2925 lpfc_mbuf_free(phba, sglq_entry->virt,
2926 sglq_entry->phys);
2927 kfree(sglq_entry);
2928 }
2929 }
2930 spin_lock_irq(&phba->hbalock);
2931 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
2932 spin_unlock_irq(&phba->hbalock);
2933 } else
2934 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2935 "3163 ELS xri-sgl count unchanged: %d\n",
2936 els_xri_cnt);
2937 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
2938
2939 /* update xris to els sgls on the list */
2940 sglq_entry = NULL;
2941 sglq_entry_next = NULL;
2942 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
2943 &phba->sli4_hba.lpfc_sgl_list, list) {
2944 lxri = lpfc_sli4_next_xritag(phba);
2945 if (lxri == NO_XRI) {
2946 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2947 "2400 Failed to allocate xri for "
2948 "ELS sgl\n");
2949 rc = -ENOMEM;
2950 goto out_free_mem;
2951 }
2952 sglq_entry->sli4_lxritag = lxri;
2953 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
2954 }
2955
2956 /*
2957 * update on pci function's allocated scsi xri-sgl list
2958 */
2959 phba->total_scsi_bufs = 0;
2960
2961 /* maximum number of xris available for scsi buffers */
2962 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
2963 els_xri_cnt;
2964
2965 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2966 "2401 Current allocated SCSI xri-sgl count:%d, "
2967 "maximum SCSI xri count:%d\n",
2968 phba->sli4_hba.scsi_xri_cnt,
2969 phba->sli4_hba.scsi_xri_max);
2970
2971 spin_lock_irq(&phba->scsi_buf_list_lock);
2972 list_splice_init(&phba->lpfc_scsi_buf_list, &scsi_sgl_list);
2973 spin_unlock_irq(&phba->scsi_buf_list_lock);
2974
2975 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
2976 /* max scsi xri shrinked below the allocated scsi buffers */
2977 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
2978 phba->sli4_hba.scsi_xri_max;
2979 /* release the extra allocated scsi buffers */
2980 for (i = 0; i < scsi_xri_cnt; i++) {
2981 list_remove_head(&scsi_sgl_list, psb,
2982 struct lpfc_scsi_buf, list);
2983 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, psb->data,
2984 psb->dma_handle);
2985 kfree(psb);
2986 }
2987 spin_lock_irq(&phba->scsi_buf_list_lock);
2988 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
2989 spin_unlock_irq(&phba->scsi_buf_list_lock);
2990 }
2991
2992 /* update xris associated to remaining allocated scsi buffers */
2993 psb = NULL;
2994 psb_next = NULL;
2995 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
2996 lxri = lpfc_sli4_next_xritag(phba);
2997 if (lxri == NO_XRI) {
2998 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2999 "2560 Failed to allocate xri for "
3000 "scsi buffer\n");
3001 rc = -ENOMEM;
3002 goto out_free_mem;
3003 }
3004 psb->cur_iocbq.sli4_lxritag = lxri;
3005 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3006 }
3007 spin_lock(&phba->scsi_buf_list_lock);
3008 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list);
3009 spin_unlock(&phba->scsi_buf_list_lock);
3010
dea31012005-04-17 16:05:31 -05003011 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003012
3013out_free_mem:
3014 lpfc_free_els_sgl_list(phba);
3015 lpfc_scsi_free(phba);
3016 return rc;
dea31012005-04-17 16:05:31 -05003017}
3018
James Smarte59058c2008-08-24 21:49:00 -04003019/**
James Smart3621a712009-04-06 18:47:14 -04003020 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04003021 * @phba: pointer to lpfc hba data structure.
3022 * @instance: a unique integer ID to this FC port.
3023 * @dev: pointer to the device data structure.
3024 *
3025 * This routine creates a FC port for the upper layer protocol. The FC port
3026 * can be created on top of either a physical port or a virtual port provided
3027 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3028 * and associates the FC port created before adding the shost into the SCSI
3029 * layer.
3030 *
3031 * Return codes
3032 * @vport - pointer to the virtual N_Port data structure.
3033 * NULL - port create failed.
3034 **/
James Smart2e0fef82007-06-17 19:56:36 -05003035struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04003036lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04003037{
James Smart2e0fef82007-06-17 19:56:36 -05003038 struct lpfc_vport *vport;
3039 struct Scsi_Host *shost;
3040 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04003041
James Smart3de2a652007-08-02 11:09:59 -04003042 if (dev != &phba->pcidev->dev)
3043 shost = scsi_host_alloc(&lpfc_vport_template,
3044 sizeof(struct lpfc_vport));
3045 else
3046 shost = scsi_host_alloc(&lpfc_template,
3047 sizeof(struct lpfc_vport));
James Smart2e0fef82007-06-17 19:56:36 -05003048 if (!shost)
3049 goto out;
James Smart47a86172007-04-25 09:53:22 -04003050
James Smart2e0fef82007-06-17 19:56:36 -05003051 vport = (struct lpfc_vport *) shost->hostdata;
3052 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05003053 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05003054 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05003055 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04003056
James Smart3de2a652007-08-02 11:09:59 -04003057 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05003058 shost->unique_id = instance;
3059 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04003060 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05003061 shost->this_id = -1;
3062 shost->max_cmd_len = 16;
James Smartda0436e2009-05-22 14:51:39 -04003063 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05003064 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04003065 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smartda0436e2009-05-22 14:51:39 -04003066 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
3067 }
James Smart81301a92008-12-04 22:39:46 -05003068
James Smart47a86172007-04-25 09:53:22 -04003069 /*
James Smart2e0fef82007-06-17 19:56:36 -05003070 * Set initial can_queue value since 0 is no longer supported and
3071 * scsi_add_host will fail. This will be adjusted later based on the
3072 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04003073 */
James Smart2e0fef82007-06-17 19:56:36 -05003074 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04003075 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05003076 shost->transportt = lpfc_vport_transport_template;
3077 vport->port_type = LPFC_NPIV_PORT;
3078 } else {
3079 shost->transportt = lpfc_transport_template;
3080 vport->port_type = LPFC_PHYSICAL_PORT;
3081 }
James Smart47a86172007-04-25 09:53:22 -04003082
James Smart2e0fef82007-06-17 19:56:36 -05003083 /* Initialize all internally managed lists. */
3084 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04003085 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05003086 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04003087
James Smart2e0fef82007-06-17 19:56:36 -05003088 init_timer(&vport->fc_disctmo);
3089 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003090 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04003091
James Smart2e0fef82007-06-17 19:56:36 -05003092 init_timer(&vport->fc_fdmitmo);
3093 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
James Smart92d7f7b2007-06-17 19:56:38 -05003094 vport->fc_fdmitmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04003095
James Smart2e0fef82007-06-17 19:56:36 -05003096 init_timer(&vport->els_tmofunc);
3097 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003098 vport->els_tmofunc.data = (unsigned long)vport;
James Smart92494142011-02-16 12:39:44 -05003099
3100 init_timer(&vport->delayed_disc_tmo);
3101 vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
3102 vport->delayed_disc_tmo.data = (unsigned long)vport;
3103
James Bottomleyd139b9b2009-11-05 13:33:12 -06003104 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05003105 if (error)
3106 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04003107
James Smart549e55c2007-08-02 11:09:51 -04003108 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003109 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04003110 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003111 return vport;
James Smart47a86172007-04-25 09:53:22 -04003112
James Smart2e0fef82007-06-17 19:56:36 -05003113out_put_shost:
3114 scsi_host_put(shost);
3115out:
3116 return NULL;
James Smart47a86172007-04-25 09:53:22 -04003117}
3118
James Smarte59058c2008-08-24 21:49:00 -04003119/**
James Smart3621a712009-04-06 18:47:14 -04003120 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04003121 * @vport: pointer to an lpfc virtual N_Port data structure.
3122 *
3123 * This routine destroys a FC port from the upper layer protocol. All the
3124 * resources associated with the port are released.
3125 **/
James Smart2e0fef82007-06-17 19:56:36 -05003126void
3127destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04003128{
James Smart92d7f7b2007-06-17 19:56:38 -05003129 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3130 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003131
James Smart858c9f62007-06-17 19:56:39 -05003132 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05003133 fc_remove_host(shost);
3134 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04003135
James Smart92d7f7b2007-06-17 19:56:38 -05003136 spin_lock_irq(&phba->hbalock);
3137 list_del_init(&vport->listentry);
3138 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04003139
James Smart92d7f7b2007-06-17 19:56:38 -05003140 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04003141 return;
James Smart47a86172007-04-25 09:53:22 -04003142}
3143
James Smarte59058c2008-08-24 21:49:00 -04003144/**
James Smart3621a712009-04-06 18:47:14 -04003145 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04003146 *
3147 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3148 * uses the kernel idr facility to perform the task.
3149 *
3150 * Return codes:
3151 * instance - a unique integer ID allocated as the new instance.
3152 * -1 - lpfc get instance failed.
3153 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003154int
3155lpfc_get_instance(void)
3156{
3157 int instance = 0;
3158
3159 /* Assign an unused number */
3160 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
3161 return -1;
3162 if (idr_get_new(&lpfc_hba_index, NULL, &instance))
3163 return -1;
3164 return instance;
3165}
3166
James Smarte59058c2008-08-24 21:49:00 -04003167/**
James Smart3621a712009-04-06 18:47:14 -04003168 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04003169 * @shost: pointer to SCSI host data structure.
3170 * @time: elapsed time of the scan in jiffies.
3171 *
3172 * This routine is called by the SCSI layer with a SCSI host to determine
3173 * whether the scan host is finished.
3174 *
3175 * Note: there is no scan_start function as adapter initialization will have
3176 * asynchronously kicked off the link initialization.
3177 *
3178 * Return codes
3179 * 0 - SCSI host scan is not over yet.
3180 * 1 - SCSI host scan is over.
3181 **/
James Smart47a86172007-04-25 09:53:22 -04003182int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
3183{
James Smart2e0fef82007-06-17 19:56:36 -05003184 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3185 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05003186 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04003187
James Smart858c9f62007-06-17 19:56:39 -05003188 spin_lock_irq(shost->host_lock);
3189
James Smart51ef4c22007-08-02 11:10:31 -04003190 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05003191 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003192 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05003193 }
James Smart2e0fef82007-06-17 19:56:36 -05003194 if (time >= 30 * HZ) {
3195 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003196 "0461 Scanning longer than 30 "
3197 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003198 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003199 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003200 }
3201 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
3202 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003203 "0465 Link down longer than 15 "
3204 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003205 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05003206 goto finished;
James Smart47a86172007-04-25 09:53:22 -04003207 }
3208
James Smart2e0fef82007-06-17 19:56:36 -05003209 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05003210 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003211 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05003212 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003213 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
James Smart858c9f62007-06-17 19:56:39 -05003214 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003215 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05003216 goto finished;
3217
3218 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003219
3220finished:
James Smart858c9f62007-06-17 19:56:39 -05003221 spin_unlock_irq(shost->host_lock);
3222 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003223}
3224
James Smarte59058c2008-08-24 21:49:00 -04003225/**
James Smart3621a712009-04-06 18:47:14 -04003226 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04003227 * @shost: pointer to SCSI host data structure.
3228 *
3229 * This routine initializes a given SCSI host attributes on a FC port. The
3230 * SCSI host can be either on top of a physical port or a virtual port.
3231 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003232void lpfc_host_attrib_init(struct Scsi_Host *shost)
3233{
3234 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3235 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003236 /*
James Smart2e0fef82007-06-17 19:56:36 -05003237 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04003238 */
3239
James Smart2e0fef82007-06-17 19:56:36 -05003240 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
3241 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04003242 fc_host_supported_classes(shost) = FC_COS_CLASS3;
3243
3244 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003245 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003246 fc_host_supported_fc4s(shost)[2] = 1;
3247 fc_host_supported_fc4s(shost)[7] = 1;
3248
James Smart92d7f7b2007-06-17 19:56:38 -05003249 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
3250 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04003251
3252 fc_host_supported_speeds(shost) = 0;
James Smart88a2cfb2011-07-22 18:36:33 -04003253 if (phba->lmt & LMT_16Gb)
3254 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
James Smart47a86172007-04-25 09:53:22 -04003255 if (phba->lmt & LMT_10Gb)
3256 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04003257 if (phba->lmt & LMT_8Gb)
3258 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04003259 if (phba->lmt & LMT_4Gb)
3260 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
3261 if (phba->lmt & LMT_2Gb)
3262 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
3263 if (phba->lmt & LMT_1Gb)
3264 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
3265
3266 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05003267 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
3268 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04003269
Mike Christie0af5d702010-09-15 16:52:31 -05003270 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
3271
James Smart47a86172007-04-25 09:53:22 -04003272 /* This value is also unchanging */
3273 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003274 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003275 fc_host_active_fc4s(shost)[2] = 1;
3276 fc_host_active_fc4s(shost)[7] = 1;
3277
James Smart92d7f7b2007-06-17 19:56:38 -05003278 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04003279 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04003280 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04003281 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04003282}
dea31012005-04-17 16:05:31 -05003283
James Smarte59058c2008-08-24 21:49:00 -04003284/**
James Smartda0436e2009-05-22 14:51:39 -04003285 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04003286 * @phba: pointer to lpfc hba data structure.
3287 *
James Smartda0436e2009-05-22 14:51:39 -04003288 * This routine is invoked to stop an SLI3 device port, it stops the device
3289 * from generating interrupts and stops the device driver's timers for the
3290 * device.
James Smarte59058c2008-08-24 21:49:00 -04003291 **/
James Smartdb2378e2008-02-08 18:49:51 -05003292static void
James Smartda0436e2009-05-22 14:51:39 -04003293lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05003294{
James Smartda0436e2009-05-22 14:51:39 -04003295 /* Clear all interrupt enable conditions */
3296 writel(0, phba->HCregaddr);
3297 readl(phba->HCregaddr); /* flush */
3298 /* Clear all pending interrupts */
3299 writel(0xffffffff, phba->HAregaddr);
3300 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04003301
James Smartda0436e2009-05-22 14:51:39 -04003302 /* Reset some HBA SLI setup states */
3303 lpfc_stop_hba_timers(phba);
3304 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05003305}
3306
James Smarte59058c2008-08-24 21:49:00 -04003307/**
James Smartda0436e2009-05-22 14:51:39 -04003308 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05003309 * @phba: pointer to lpfc hba data structure.
3310 *
James Smartda0436e2009-05-22 14:51:39 -04003311 * This routine is invoked to stop an SLI4 device port, it stops the device
3312 * from generating interrupts and stops the device driver's timers for the
3313 * device.
3314 **/
3315static void
3316lpfc_stop_port_s4(struct lpfc_hba *phba)
3317{
3318 /* Reset some HBA SLI4 setup states */
3319 lpfc_stop_hba_timers(phba);
3320 phba->pport->work_port_events = 0;
3321 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04003322}
3323
3324/**
3325 * lpfc_stop_port - Wrapper function for stopping hba port
3326 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05003327 *
James Smartda0436e2009-05-22 14:51:39 -04003328 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3329 * the API jump table function pointer from the lpfc_hba struct.
3330 **/
3331void
3332lpfc_stop_port(struct lpfc_hba *phba)
3333{
3334 phba->lpfc_stop_port(phba);
3335}
3336
3337/**
James Smartecfd03c2010-02-12 14:41:27 -05003338 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3339 * @phba: Pointer to hba for which this call is being executed.
3340 *
3341 * This routine starts the timer waiting for the FCF rediscovery to complete.
3342 **/
3343void
3344lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
3345{
3346 unsigned long fcf_redisc_wait_tmo =
3347 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
3348 /* Start fcf rediscovery wait period timer */
3349 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
3350 spin_lock_irq(&phba->hbalock);
3351 /* Allow action to new fcf asynchronous event */
3352 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
3353 /* Mark the FCF rediscovery pending state */
3354 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
3355 spin_unlock_irq(&phba->hbalock);
3356}
3357
3358/**
3359 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
3360 * @ptr: Map to lpfc_hba data structure pointer.
3361 *
3362 * This routine is invoked when waiting for FCF table rediscover has been
3363 * timed out. If new FCF record(s) has (have) been discovered during the
3364 * wait period, a new FCF event shall be added to the FCOE async event
3365 * list, and then worker thread shall be waked up for processing from the
3366 * worker thread context.
3367 **/
3368void
3369lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
3370{
3371 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
3372
3373 /* Don't send FCF rediscovery event if timer cancelled */
3374 spin_lock_irq(&phba->hbalock);
3375 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
3376 spin_unlock_irq(&phba->hbalock);
3377 return;
3378 }
3379 /* Clear FCF rediscovery timer pending flag */
3380 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
3381 /* FCF rediscovery event to worker thread */
3382 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
3383 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003384 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04003385 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05003386 /* wake up worker thread */
3387 lpfc_worker_wake_up(phba);
3388}
3389
3390/**
James Smartda0436e2009-05-22 14:51:39 -04003391 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
3392 * @phba: pointer to lpfc hba data structure.
3393 * @acqe_link: pointer to the async link completion queue entry.
3394 *
3395 * This routine is to parse the SLI4 link-attention link fault code and
3396 * translate it into the base driver's read link attention mailbox command
3397 * status.
3398 *
3399 * Return: Link-attention status in terms of base driver's coding.
3400 **/
3401static uint16_t
3402lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
3403 struct lpfc_acqe_link *acqe_link)
3404{
3405 uint16_t latt_fault;
3406
3407 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
3408 case LPFC_ASYNC_LINK_FAULT_NONE:
3409 case LPFC_ASYNC_LINK_FAULT_LOCAL:
3410 case LPFC_ASYNC_LINK_FAULT_REMOTE:
3411 latt_fault = 0;
3412 break;
3413 default:
3414 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3415 "0398 Invalid link fault code: x%x\n",
3416 bf_get(lpfc_acqe_link_fault, acqe_link));
3417 latt_fault = MBXERR_ERROR;
3418 break;
3419 }
3420 return latt_fault;
3421}
3422
3423/**
3424 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
3425 * @phba: pointer to lpfc hba data structure.
3426 * @acqe_link: pointer to the async link completion queue entry.
3427 *
3428 * This routine is to parse the SLI4 link attention type and translate it
3429 * into the base driver's link attention type coding.
3430 *
3431 * Return: Link attention type in terms of base driver's coding.
3432 **/
3433static uint8_t
3434lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
3435 struct lpfc_acqe_link *acqe_link)
3436{
3437 uint8_t att_type;
3438
3439 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
3440 case LPFC_ASYNC_LINK_STATUS_DOWN:
3441 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05003442 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04003443 break;
3444 case LPFC_ASYNC_LINK_STATUS_UP:
3445 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05003446 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003447 break;
3448 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05003449 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04003450 break;
3451 default:
3452 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3453 "0399 Invalid link attention type: x%x\n",
3454 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003455 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003456 break;
3457 }
3458 return att_type;
3459}
3460
3461/**
3462 * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
3463 * @phba: pointer to lpfc hba data structure.
3464 * @acqe_link: pointer to the async link completion queue entry.
3465 *
3466 * This routine is to parse the SLI4 link-attention link speed and translate
3467 * it into the base driver's link-attention link speed coding.
3468 *
3469 * Return: Link-attention link speed in terms of base driver's coding.
3470 **/
3471static uint8_t
3472lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba,
3473 struct lpfc_acqe_link *acqe_link)
3474{
3475 uint8_t link_speed;
3476
3477 switch (bf_get(lpfc_acqe_link_speed, acqe_link)) {
3478 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smartda0436e2009-05-22 14:51:39 -04003479 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smartda0436e2009-05-22 14:51:39 -04003480 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart76a95d72010-11-20 23:11:48 -05003481 link_speed = LPFC_LINK_SPEED_UNKNOWN;
James Smartda0436e2009-05-22 14:51:39 -04003482 break;
3483 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart76a95d72010-11-20 23:11:48 -05003484 link_speed = LPFC_LINK_SPEED_1GHZ;
James Smartda0436e2009-05-22 14:51:39 -04003485 break;
3486 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart76a95d72010-11-20 23:11:48 -05003487 link_speed = LPFC_LINK_SPEED_10GHZ;
James Smartda0436e2009-05-22 14:51:39 -04003488 break;
3489 default:
3490 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3491 "0483 Invalid link-attention link speed: x%x\n",
3492 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003493 link_speed = LPFC_LINK_SPEED_UNKNOWN;
James Smartda0436e2009-05-22 14:51:39 -04003494 break;
3495 }
3496 return link_speed;
3497}
3498
3499/**
James Smart70f3c072010-12-15 17:57:33 -05003500 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04003501 * @phba: pointer to lpfc hba data structure.
3502 * @acqe_link: pointer to the async link completion queue entry.
3503 *
James Smart70f3c072010-12-15 17:57:33 -05003504 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04003505 **/
3506static void
3507lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
3508 struct lpfc_acqe_link *acqe_link)
3509{
3510 struct lpfc_dmabuf *mp;
3511 LPFC_MBOXQ_t *pmb;
3512 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05003513 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04003514 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05003515 int rc;
James Smartda0436e2009-05-22 14:51:39 -04003516
3517 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05003518 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04003519 return;
James Smart32b97932009-07-19 10:01:21 -04003520 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04003521 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3522 if (!pmb) {
3523 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3524 "0395 The mboxq allocation failed\n");
3525 return;
3526 }
3527 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3528 if (!mp) {
3529 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3530 "0396 The lpfc_dmabuf allocation failed\n");
3531 goto out_free_pmb;
3532 }
3533 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
3534 if (!mp->virt) {
3535 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3536 "0397 The mbuf allocation failed\n");
3537 goto out_free_dmabuf;
3538 }
3539
3540 /* Cleanup any outstanding ELS commands */
3541 lpfc_els_flush_all_cmd(phba);
3542
3543 /* Block ELS IOCBs until we have done process link event */
3544 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
3545
3546 /* Update link event statistics */
3547 phba->sli.slistat.link_event++;
3548
James Smart76a95d72010-11-20 23:11:48 -05003549 /* Create lpfc_handle_latt mailbox command from link ACQE */
3550 lpfc_read_topology(phba, pmb, mp);
3551 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04003552 pmb->vport = phba->pport;
3553
James Smartda0436e2009-05-22 14:51:39 -04003554 /* Keep the link status for extra SLI4 state machine reference */
3555 phba->sli4_hba.link_state.speed =
3556 bf_get(lpfc_acqe_link_speed, acqe_link);
3557 phba->sli4_hba.link_state.duplex =
3558 bf_get(lpfc_acqe_link_duplex, acqe_link);
3559 phba->sli4_hba.link_state.status =
3560 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05003561 phba->sli4_hba.link_state.type =
3562 bf_get(lpfc_acqe_link_type, acqe_link);
3563 phba->sli4_hba.link_state.number =
3564 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04003565 phba->sli4_hba.link_state.fault =
3566 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05003567 phba->sli4_hba.link_state.logical_speed =
James Smart70f3c072010-12-15 17:57:33 -05003568 bf_get(lpfc_acqe_logical_link_speed, acqe_link);
3569 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04003570 "2900 Async FC/FCoE Link event - Speed:%dGBit "
3571 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
3572 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05003573 phba->sli4_hba.link_state.speed,
3574 phba->sli4_hba.link_state.topology,
3575 phba->sli4_hba.link_state.status,
3576 phba->sli4_hba.link_state.type,
3577 phba->sli4_hba.link_state.number,
3578 phba->sli4_hba.link_state.logical_speed * 10,
3579 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05003580 /*
3581 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
3582 * topology info. Note: Optional for non FC-AL ports.
3583 */
3584 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3585 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3586 if (rc == MBX_NOT_FINISHED)
3587 goto out_free_dmabuf;
3588 return;
3589 }
3590 /*
3591 * For FCoE Mode: fill in all the topology information we need and call
3592 * the READ_TOPOLOGY completion routine to continue without actually
3593 * sending the READ_TOPOLOGY mailbox command to the port.
3594 */
3595 /* Parse and translate status field */
3596 mb = &pmb->u.mb;
3597 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
3598
3599 /* Parse and translate link attention fields */
3600 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3601 la->eventTag = acqe_link->event_tag;
3602 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
3603 bf_set(lpfc_mbx_read_top_link_spd, la,
3604 lpfc_sli4_parse_latt_link_speed(phba, acqe_link));
3605
3606 /* Fake the the following irrelvant fields */
3607 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
3608 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
3609 bf_set(lpfc_mbx_read_top_il, la, 0);
3610 bf_set(lpfc_mbx_read_top_pb, la, 0);
3611 bf_set(lpfc_mbx_read_top_fa, la, 0);
3612 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04003613
3614 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05003615 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04003616
3617 return;
3618
3619out_free_dmabuf:
3620 kfree(mp);
3621out_free_pmb:
3622 mempool_free(pmb, phba->mbox_mem_pool);
3623}
3624
3625/**
James Smart70f3c072010-12-15 17:57:33 -05003626 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
3627 * @phba: pointer to lpfc hba data structure.
3628 * @acqe_fc: pointer to the async fc completion queue entry.
3629 *
3630 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
3631 * that the event was received and then issue a read_topology mailbox command so
3632 * that the rest of the driver will treat it the same as SLI3.
3633 **/
3634static void
3635lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
3636{
3637 struct lpfc_dmabuf *mp;
3638 LPFC_MBOXQ_t *pmb;
3639 int rc;
3640
3641 if (bf_get(lpfc_trailer_type, acqe_fc) !=
3642 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
3643 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3644 "2895 Non FC link Event detected.(%d)\n",
3645 bf_get(lpfc_trailer_type, acqe_fc));
3646 return;
3647 }
3648 /* Keep the link status for extra SLI4 state machine reference */
3649 phba->sli4_hba.link_state.speed =
3650 bf_get(lpfc_acqe_fc_la_speed, acqe_fc);
3651 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
3652 phba->sli4_hba.link_state.topology =
3653 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
3654 phba->sli4_hba.link_state.status =
3655 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
3656 phba->sli4_hba.link_state.type =
3657 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
3658 phba->sli4_hba.link_state.number =
3659 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
3660 phba->sli4_hba.link_state.fault =
3661 bf_get(lpfc_acqe_link_fault, acqe_fc);
3662 phba->sli4_hba.link_state.logical_speed =
3663 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc);
3664 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3665 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
3666 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
3667 "%dMbps Fault:%d\n",
3668 phba->sli4_hba.link_state.speed,
3669 phba->sli4_hba.link_state.topology,
3670 phba->sli4_hba.link_state.status,
3671 phba->sli4_hba.link_state.type,
3672 phba->sli4_hba.link_state.number,
3673 phba->sli4_hba.link_state.logical_speed * 10,
3674 phba->sli4_hba.link_state.fault);
3675 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3676 if (!pmb) {
3677 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3678 "2897 The mboxq allocation failed\n");
3679 return;
3680 }
3681 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3682 if (!mp) {
3683 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3684 "2898 The lpfc_dmabuf allocation failed\n");
3685 goto out_free_pmb;
3686 }
3687 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
3688 if (!mp->virt) {
3689 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3690 "2899 The mbuf allocation failed\n");
3691 goto out_free_dmabuf;
3692 }
3693
3694 /* Cleanup any outstanding ELS commands */
3695 lpfc_els_flush_all_cmd(phba);
3696
3697 /* Block ELS IOCBs until we have done process link event */
3698 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
3699
3700 /* Update link event statistics */
3701 phba->sli.slistat.link_event++;
3702
3703 /* Create lpfc_handle_latt mailbox command from link ACQE */
3704 lpfc_read_topology(phba, pmb, mp);
3705 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
3706 pmb->vport = phba->pport;
3707
3708 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3709 if (rc == MBX_NOT_FINISHED)
3710 goto out_free_dmabuf;
3711 return;
3712
3713out_free_dmabuf:
3714 kfree(mp);
3715out_free_pmb:
3716 mempool_free(pmb, phba->mbox_mem_pool);
3717}
3718
3719/**
3720 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
3721 * @phba: pointer to lpfc hba data structure.
3722 * @acqe_fc: pointer to the async SLI completion queue entry.
3723 *
3724 * This routine is to handle the SLI4 asynchronous SLI events.
3725 **/
3726static void
3727lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
3728{
James Smart4b8bae02012-06-12 13:55:07 -04003729 char port_name;
3730 char message[80];
3731 uint8_t status;
3732 struct lpfc_acqe_misconfigured_event *misconfigured;
3733
3734 /* special case misconfigured event as it contains data for all ports */
3735 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3736 LPFC_SLI_INTF_IF_TYPE_2) ||
3737 (bf_get(lpfc_trailer_type, acqe_sli) !=
3738 LPFC_SLI_EVENT_TYPE_MISCONFIGURED)) {
3739 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3740 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
3741 "x%08x SLI Event Type:%d\n",
3742 acqe_sli->event_data1, acqe_sli->event_data2,
3743 bf_get(lpfc_trailer_type, acqe_sli));
3744 return;
3745 }
3746
3747 port_name = phba->Port[0];
3748 if (port_name == 0x00)
3749 port_name = '?'; /* get port name is empty */
3750
3751 misconfigured = (struct lpfc_acqe_misconfigured_event *)
3752 &acqe_sli->event_data1;
3753
3754 /* fetch the status for this port */
3755 switch (phba->sli4_hba.lnk_info.lnk_no) {
3756 case LPFC_LINK_NUMBER_0:
3757 status = bf_get(lpfc_sli_misconfigured_port0,
3758 &misconfigured->theEvent);
3759 break;
3760 case LPFC_LINK_NUMBER_1:
3761 status = bf_get(lpfc_sli_misconfigured_port1,
3762 &misconfigured->theEvent);
3763 break;
3764 case LPFC_LINK_NUMBER_2:
3765 status = bf_get(lpfc_sli_misconfigured_port2,
3766 &misconfigured->theEvent);
3767 break;
3768 case LPFC_LINK_NUMBER_3:
3769 status = bf_get(lpfc_sli_misconfigured_port3,
3770 &misconfigured->theEvent);
3771 break;
3772 default:
3773 status = ~LPFC_SLI_EVENT_STATUS_VALID;
3774 break;
3775 }
3776
3777 switch (status) {
3778 case LPFC_SLI_EVENT_STATUS_VALID:
3779 return; /* no message if the sfp is okay */
3780 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
3781 sprintf(message, "Not installed");
3782 break;
3783 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
3784 sprintf(message,
3785 "Optics of two types installed");
3786 break;
3787 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
3788 sprintf(message, "Incompatible optics");
3789 break;
3790 default:
3791 /* firmware is reporting a status we don't know about */
3792 sprintf(message, "Unknown event status x%02x", status);
3793 break;
3794 }
3795
3796 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3797 "3176 Misconfigured Physical Port - "
3798 "Port Name %c %s\n", port_name, message);
James Smart70f3c072010-12-15 17:57:33 -05003799}
3800
3801/**
James Smartfc2b9892010-02-26 14:15:29 -05003802 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
3803 * @vport: pointer to vport data structure.
3804 *
3805 * This routine is to perform Clear Virtual Link (CVL) on a vport in
3806 * response to a CVL event.
3807 *
3808 * Return the pointer to the ndlp with the vport if successful, otherwise
3809 * return NULL.
3810 **/
3811static struct lpfc_nodelist *
3812lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
3813{
3814 struct lpfc_nodelist *ndlp;
3815 struct Scsi_Host *shost;
3816 struct lpfc_hba *phba;
3817
3818 if (!vport)
3819 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05003820 phba = vport->phba;
3821 if (!phba)
3822 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04003823 ndlp = lpfc_findnode_did(vport, Fabric_DID);
3824 if (!ndlp) {
3825 /* Cannot find existing Fabric ndlp, so allocate a new one */
3826 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3827 if (!ndlp)
3828 return 0;
3829 lpfc_nlp_init(vport, ndlp, Fabric_DID);
3830 /* Set the node type */
3831 ndlp->nlp_type |= NLP_FABRIC;
3832 /* Put ndlp onto node list */
3833 lpfc_enqueue_node(vport, ndlp);
3834 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3835 /* re-setup ndlp without removing from node list */
3836 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3837 if (!ndlp)
3838 return 0;
3839 }
James Smart63e801c2010-11-20 23:14:19 -05003840 if ((phba->pport->port_state < LPFC_FLOGI) &&
3841 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05003842 return NULL;
3843 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05003844 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
3845 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05003846 return NULL;
3847 shost = lpfc_shost_from_vport(vport);
3848 if (!shost)
3849 return NULL;
3850 lpfc_linkdown_port(vport);
3851 lpfc_cleanup_pending_mbox(vport);
3852 spin_lock_irq(shost->host_lock);
3853 vport->fc_flag |= FC_VPORT_CVL_RCVD;
3854 spin_unlock_irq(shost->host_lock);
3855
3856 return ndlp;
3857}
3858
3859/**
3860 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
3861 * @vport: pointer to lpfc hba data structure.
3862 *
3863 * This routine is to perform Clear Virtual Link (CVL) on all vports in
3864 * response to a FCF dead event.
3865 **/
3866static void
3867lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
3868{
3869 struct lpfc_vport **vports;
3870 int i;
3871
3872 vports = lpfc_create_vport_work_array(phba);
3873 if (vports)
3874 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
3875 lpfc_sli4_perform_vport_cvl(vports[i]);
3876 lpfc_destroy_vport_work_array(phba, vports);
3877}
3878
3879/**
James Smart76a95d72010-11-20 23:11:48 -05003880 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04003881 * @phba: pointer to lpfc hba data structure.
3882 * @acqe_link: pointer to the async fcoe completion queue entry.
3883 *
3884 * This routine is to handle the SLI4 asynchronous fcoe event.
3885 **/
3886static void
James Smart76a95d72010-11-20 23:11:48 -05003887lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05003888 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04003889{
James Smart70f3c072010-12-15 17:57:33 -05003890 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04003891 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04003892 struct lpfc_vport *vport;
3893 struct lpfc_nodelist *ndlp;
3894 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05003895 int active_vlink_present;
3896 struct lpfc_vport **vports;
3897 int i;
James Smartda0436e2009-05-22 14:51:39 -04003898
James Smart70f3c072010-12-15 17:57:33 -05003899 phba->fc_eventTag = acqe_fip->event_tag;
3900 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04003901 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05003902 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
3903 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
3904 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04003905 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
3906 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04003907 "2546 New FCF event, evt_tag:x%x, "
3908 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05003909 acqe_fip->event_tag,
3910 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04003911 else
3912 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
3913 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04003914 "2788 FCF param modified event, "
3915 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05003916 acqe_fip->event_tag,
3917 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04003918 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05003919 /*
3920 * During period of FCF discovery, read the FCF
3921 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04003922 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05003923 */
3924 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
3925 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04003926 "2779 Read FCF (x%x) for updating "
3927 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05003928 acqe_fip->index);
3929 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05003930 }
James Smart38b92ef2010-08-04 16:11:39 -04003931
3932 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04003933 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04003934 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04003935 spin_unlock_irq(&phba->hbalock);
3936 break;
3937 }
3938 /* If fast FCF failover rescan event is pending, do nothing */
3939 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
3940 spin_unlock_irq(&phba->hbalock);
3941 break;
3942 }
3943
3944 /* If the FCF has been in discovered state, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04003945 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
3946 spin_unlock_irq(&phba->hbalock);
3947 break;
3948 }
3949 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04003950
James Smart0c9ab6f2010-02-26 14:15:57 -05003951 /* Otherwise, scan the entire FCF table and re-discover SAN */
3952 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04003953 "2770 Start FCF table scan per async FCF "
3954 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05003955 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05003956 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3957 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04003958 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05003959 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
3960 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04003961 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04003962 break;
3963
James Smart70f3c072010-12-15 17:57:33 -05003964 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04003965 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04003966 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05003967 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
3968 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04003969 break;
3970
James Smart70f3c072010-12-15 17:57:33 -05003971 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05003972 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05003973 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04003974 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05003975 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04003976 /*
3977 * If we are in the middle of FCF failover process, clear
3978 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04003979 */
James Smartfc2b9892010-02-26 14:15:29 -05003980 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003981 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05003982 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003983 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05003984 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05003985 break;
3986 }
James Smart38b92ef2010-08-04 16:11:39 -04003987 spin_unlock_irq(&phba->hbalock);
3988
3989 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05003990 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04003991 break;
3992
3993 /*
3994 * Otherwise, request the port to rediscover the entire FCF
3995 * table for a fast recovery from case that the current FCF
3996 * is no longer valid as we are not in the middle of FCF
3997 * failover process already.
3998 */
3999 spin_lock_irq(&phba->hbalock);
James Smartfc2b9892010-02-26 14:15:29 -05004000 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05004001 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004002 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04004003
James Smart0c9ab6f2010-02-26 14:15:57 -05004004 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
4005 "2771 Start FCF fast failover process due to "
4006 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
James Smart70f3c072010-12-15 17:57:33 -05004007 "\n", acqe_fip->event_tag, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004008 rc = lpfc_sli4_redisc_fcf_table(phba);
4009 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004010 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4011 LOG_DISCOVERY,
4012 "2772 Issue FCF rediscover mabilbox "
4013 "command failed, fail through to FCF "
4014 "dead event\n");
James Smartfc2b9892010-02-26 14:15:29 -05004015 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004016 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004017 spin_unlock_irq(&phba->hbalock);
4018 /*
4019 * Last resort will fail over by treating this
4020 * as a link down to FCF registration.
4021 */
4022 lpfc_sli4_fcf_dead_failthrough(phba);
James Smart38b92ef2010-08-04 16:11:39 -04004023 } else {
4024 /* Reset FCF roundrobin bmask for new discovery */
James Smart7d791df2011-07-22 18:37:52 -04004025 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart38b92ef2010-08-04 16:11:39 -04004026 /*
4027 * Handling fast FCF failover to a DEAD FCF event is
4028 * considered equalivant to receiving CVL to all vports.
James Smartfc2b9892010-02-26 14:15:29 -05004029 */
4030 lpfc_sli4_perform_all_vport_cvl(phba);
James Smart38b92ef2010-08-04 16:11:39 -04004031 }
James Smartda0436e2009-05-22 14:51:39 -04004032 break;
James Smart70f3c072010-12-15 17:57:33 -05004033 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05004034 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004035 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04004036 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05004037 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04004038
James Smart6669f9b2009-10-02 15:16:45 -04004039 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04004040 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004041 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004042 if (!ndlp)
4043 break;
James Smart695a8142010-01-26 23:08:03 -05004044 active_vlink_present = 0;
4045
4046 vports = lpfc_create_vport_work_array(phba);
4047 if (vports) {
4048 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
4049 i++) {
4050 if ((!(vports[i]->fc_flag &
4051 FC_VPORT_CVL_RCVD)) &&
4052 (vports[i]->port_state > LPFC_FDISC)) {
4053 active_vlink_present = 1;
4054 break;
4055 }
4056 }
4057 lpfc_destroy_vport_work_array(phba, vports);
4058 }
4059
4060 if (active_vlink_present) {
4061 /*
4062 * If there are other active VLinks present,
4063 * re-instantiate the Vlink using FDISC.
4064 */
James Smart6669f9b2009-10-02 15:16:45 -04004065 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
James Smartfc2b9892010-02-26 14:15:29 -05004066 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004067 spin_lock_irq(shost->host_lock);
4068 ndlp->nlp_flag |= NLP_DELAY_TMO;
4069 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05004070 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
4071 vport->port_state = LPFC_FDISC;
4072 } else {
James Smartecfd03c2010-02-12 14:41:27 -05004073 /*
4074 * Otherwise, we request port to rediscover
4075 * the entire FCF table for a fast recovery
4076 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05004077 * is no longer valid if we are not already
4078 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05004079 */
James Smartfc2b9892010-02-26 14:15:29 -05004080 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004081 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05004082 spin_unlock_irq(&phba->hbalock);
4083 break;
4084 }
4085 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05004086 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004087 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004088 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4089 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004090 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05004091 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05004092 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05004093 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004094 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4095 LOG_DISCOVERY,
4096 "2774 Issue FCF rediscover "
4097 "mabilbox command failed, "
4098 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05004099 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004100 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004101 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05004102 /*
4103 * Last resort will be re-try on the
4104 * the current registered FCF entry.
4105 */
4106 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04004107 } else
4108 /*
4109 * Reset FCF roundrobin bmask for new
4110 * discovery.
4111 */
James Smart7d791df2011-07-22 18:37:52 -04004112 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04004113 }
4114 break;
James Smartda0436e2009-05-22 14:51:39 -04004115 default:
4116 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4117 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05004118 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004119 break;
4120 }
4121}
4122
4123/**
4124 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
4125 * @phba: pointer to lpfc hba data structure.
4126 * @acqe_link: pointer to the async dcbx completion queue entry.
4127 *
4128 * This routine is to handle the SLI4 asynchronous dcbx event.
4129 **/
4130static void
4131lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
4132 struct lpfc_acqe_dcbx *acqe_dcbx)
4133{
James Smart4d9ab992009-10-02 15:16:39 -04004134 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004135 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4136 "0290 The SLI4 DCBX asynchronous event is not "
4137 "handled yet\n");
4138}
4139
4140/**
James Smartb19a0612010-04-06 14:48:51 -04004141 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
4142 * @phba: pointer to lpfc hba data structure.
4143 * @acqe_link: pointer to the async grp5 completion queue entry.
4144 *
4145 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
4146 * is an asynchronous notified of a logical link speed change. The Port
4147 * reports the logical link speed in units of 10Mbps.
4148 **/
4149static void
4150lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
4151 struct lpfc_acqe_grp5 *acqe_grp5)
4152{
4153 uint16_t prev_ll_spd;
4154
4155 phba->fc_eventTag = acqe_grp5->event_tag;
4156 phba->fcoe_eventtag = acqe_grp5->event_tag;
4157 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
4158 phba->sli4_hba.link_state.logical_speed =
4159 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5));
4160 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4161 "2789 GRP5 Async Event: Updating logical link speed "
4162 "from %dMbps to %dMbps\n", (prev_ll_spd * 10),
4163 (phba->sli4_hba.link_state.logical_speed*10));
4164}
4165
4166/**
James Smartda0436e2009-05-22 14:51:39 -04004167 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
4168 * @phba: pointer to lpfc hba data structure.
4169 *
4170 * This routine is invoked by the worker thread to process all the pending
4171 * SLI4 asynchronous events.
4172 **/
4173void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
4174{
4175 struct lpfc_cq_event *cq_event;
4176
4177 /* First, declare the async event has been handled */
4178 spin_lock_irq(&phba->hbalock);
4179 phba->hba_flag &= ~ASYNC_EVENT;
4180 spin_unlock_irq(&phba->hbalock);
4181 /* Now, handle all the async events */
4182 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
4183 /* Get the first event from the head of the event queue */
4184 spin_lock_irq(&phba->hbalock);
4185 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
4186 cq_event, struct lpfc_cq_event, list);
4187 spin_unlock_irq(&phba->hbalock);
4188 /* Process the asynchronous event */
4189 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
4190 case LPFC_TRAILER_CODE_LINK:
4191 lpfc_sli4_async_link_evt(phba,
4192 &cq_event->cqe.acqe_link);
4193 break;
4194 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05004195 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004196 break;
4197 case LPFC_TRAILER_CODE_DCBX:
4198 lpfc_sli4_async_dcbx_evt(phba,
4199 &cq_event->cqe.acqe_dcbx);
4200 break;
James Smartb19a0612010-04-06 14:48:51 -04004201 case LPFC_TRAILER_CODE_GRP5:
4202 lpfc_sli4_async_grp5_evt(phba,
4203 &cq_event->cqe.acqe_grp5);
4204 break;
James Smart70f3c072010-12-15 17:57:33 -05004205 case LPFC_TRAILER_CODE_FC:
4206 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
4207 break;
4208 case LPFC_TRAILER_CODE_SLI:
4209 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
4210 break;
James Smartda0436e2009-05-22 14:51:39 -04004211 default:
4212 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4213 "1804 Invalid asynchrous event code: "
4214 "x%x\n", bf_get(lpfc_trailer_code,
4215 &cq_event->cqe.mcqe_cmpl));
4216 break;
4217 }
4218 /* Free the completion event processed to the free pool */
4219 lpfc_sli4_cq_event_release(phba, cq_event);
4220 }
4221}
4222
4223/**
James Smartecfd03c2010-02-12 14:41:27 -05004224 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
4225 * @phba: pointer to lpfc hba data structure.
4226 *
4227 * This routine is invoked by the worker thread to process FCF table
4228 * rediscovery pending completion event.
4229 **/
4230void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
4231{
4232 int rc;
4233
4234 spin_lock_irq(&phba->hbalock);
4235 /* Clear FCF rediscovery timeout event */
4236 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
4237 /* Clear driver fast failover FCF record flag */
4238 phba->fcf.failover_rec.flag = 0;
4239 /* Set state for FCF fast failover */
4240 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
4241 spin_unlock_irq(&phba->hbalock);
4242
4243 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05004244 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004245 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05004246 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05004247 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004248 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4249 "2747 Issue FCF scan read FCF mailbox "
4250 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05004251}
4252
4253/**
James Smartda0436e2009-05-22 14:51:39 -04004254 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
4255 * @phba: pointer to lpfc hba data structure.
4256 * @dev_grp: The HBA PCI-Device group number.
4257 *
4258 * This routine is invoked to set up the per HBA PCI-Device group function
4259 * API jump table entries.
4260 *
4261 * Return: 0 if success, otherwise -ENODEV
4262 **/
4263int
4264lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05004265{
4266 int rc;
4267
James Smartda0436e2009-05-22 14:51:39 -04004268 /* Set up lpfc PCI-device group */
4269 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05004270
James Smartda0436e2009-05-22 14:51:39 -04004271 /* The LPFC_PCI_DEV_OC uses SLI4 */
4272 if (dev_grp == LPFC_PCI_DEV_OC)
4273 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05004274
James Smartda0436e2009-05-22 14:51:39 -04004275 /* Set up device INIT API function jump table */
4276 rc = lpfc_init_api_table_setup(phba, dev_grp);
4277 if (rc)
4278 return -ENODEV;
4279 /* Set up SCSI API function jump table */
4280 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
4281 if (rc)
4282 return -ENODEV;
4283 /* Set up SLI API function jump table */
4284 rc = lpfc_sli_api_table_setup(phba, dev_grp);
4285 if (rc)
4286 return -ENODEV;
4287 /* Set up MBOX API function jump table */
4288 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
4289 if (rc)
4290 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05004291
James Smartda0436e2009-05-22 14:51:39 -04004292 return 0;
James Smart5b75da22008-12-04 22:39:35 -05004293}
4294
4295/**
James Smart3621a712009-04-06 18:47:14 -04004296 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05004297 * @phba: pointer to lpfc hba data structure.
4298 * @intr_mode: active interrupt mode adopted.
4299 *
4300 * This routine it invoked to log the currently used active interrupt mode
4301 * to the device.
James Smart3772a992009-05-22 14:50:54 -04004302 **/
4303static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05004304{
4305 switch (intr_mode) {
4306 case 0:
4307 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4308 "0470 Enable INTx interrupt mode.\n");
4309 break;
4310 case 1:
4311 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4312 "0481 Enabled MSI interrupt mode.\n");
4313 break;
4314 case 2:
4315 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4316 "0480 Enabled MSI-X interrupt mode.\n");
4317 break;
4318 default:
4319 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4320 "0482 Illegal interrupt mode.\n");
4321 break;
4322 }
4323 return;
4324}
4325
James Smart5b75da22008-12-04 22:39:35 -05004326/**
James Smart3772a992009-05-22 14:50:54 -04004327 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05004328 * @phba: pointer to lpfc hba data structure.
4329 *
James Smart3772a992009-05-22 14:50:54 -04004330 * This routine is invoked to enable the PCI device that is common to all
4331 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05004332 *
4333 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004334 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004335 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05004336 **/
James Smart3772a992009-05-22 14:50:54 -04004337static int
4338lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05004339{
James Smart3772a992009-05-22 14:50:54 -04004340 struct pci_dev *pdev;
James Smart079b5c92011-08-21 21:48:49 -04004341 int bars = 0;
James Smart5b75da22008-12-04 22:39:35 -05004342
James Smart3772a992009-05-22 14:50:54 -04004343 /* Obtain PCI device reference */
4344 if (!phba->pcidev)
4345 goto out_error;
4346 else
4347 pdev = phba->pcidev;
4348 /* Select PCI BARs */
4349 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4350 /* Enable PCI device */
4351 if (pci_enable_device_mem(pdev))
4352 goto out_error;
4353 /* Request PCI resource for the device */
4354 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
4355 goto out_disable_device;
4356 /* Set up device as PCI master and save state for EEH */
4357 pci_set_master(pdev);
4358 pci_try_set_mwi(pdev);
4359 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05004360
James Smart05580562011-05-24 11:40:48 -04004361 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
4362 if (pci_find_capability(pdev, PCI_CAP_ID_EXP))
4363 pdev->needs_freset = 1;
4364
James Smart3772a992009-05-22 14:50:54 -04004365 return 0;
James Smart5b75da22008-12-04 22:39:35 -05004366
James Smart3772a992009-05-22 14:50:54 -04004367out_disable_device:
4368 pci_disable_device(pdev);
4369out_error:
James Smart079b5c92011-08-21 21:48:49 -04004370 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4371 "1401 Failed to enable pci device, bars:x%x\n", bars);
James Smart3772a992009-05-22 14:50:54 -04004372 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05004373}
4374
4375/**
James Smart3772a992009-05-22 14:50:54 -04004376 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05004377 * @phba: pointer to lpfc hba data structure.
4378 *
James Smart3772a992009-05-22 14:50:54 -04004379 * This routine is invoked to disable the PCI device that is common to all
4380 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05004381 **/
4382static void
James Smart3772a992009-05-22 14:50:54 -04004383lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05004384{
James Smart3772a992009-05-22 14:50:54 -04004385 struct pci_dev *pdev;
4386 int bars;
James Smart5b75da22008-12-04 22:39:35 -05004387
James Smart3772a992009-05-22 14:50:54 -04004388 /* Obtain PCI device reference */
4389 if (!phba->pcidev)
4390 return;
4391 else
4392 pdev = phba->pcidev;
4393 /* Select PCI BARs */
4394 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4395 /* Release PCI resource and disable PCI device */
4396 pci_release_selected_regions(pdev, bars);
4397 pci_disable_device(pdev);
4398 /* Null out PCI private reference to driver */
4399 pci_set_drvdata(pdev, NULL);
James Smart5b75da22008-12-04 22:39:35 -05004400
4401 return;
4402}
4403
4404/**
James Smart3772a992009-05-22 14:50:54 -04004405 * lpfc_reset_hba - Reset a hba
4406 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04004407 *
James Smart3772a992009-05-22 14:50:54 -04004408 * This routine is invoked to reset a hba device. It brings the HBA
4409 * offline, performs a board restart, and then brings the board back
4410 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
4411 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04004412 **/
James Smart3772a992009-05-22 14:50:54 -04004413void
4414lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05004415{
James Smart3772a992009-05-22 14:50:54 -04004416 /* If resets are disabled then set error state and return. */
4417 if (!phba->cfg_enable_hba_reset) {
4418 phba->link_state = LPFC_HBA_ERROR;
4419 return;
4420 }
James Smart618a5232012-06-12 13:54:36 -04004421 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3772a992009-05-22 14:50:54 -04004422 lpfc_offline(phba);
4423 lpfc_sli_brdrestart(phba);
4424 lpfc_online(phba);
4425 lpfc_unblock_mgmt_io(phba);
4426}
dea31012005-04-17 16:05:31 -05004427
James Smart3772a992009-05-22 14:50:54 -04004428/**
James Smart0a96e972011-07-22 18:37:28 -04004429 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
4430 * @phba: pointer to lpfc hba data structure.
4431 *
4432 * This function enables the PCI SR-IOV virtual functions to a physical
4433 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4434 * enable the number of virtual functions to the physical function. As
4435 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4436 * API call does not considered as an error condition for most of the device.
4437 **/
4438uint16_t
4439lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
4440{
4441 struct pci_dev *pdev = phba->pcidev;
4442 uint16_t nr_virtfn;
4443 int pos;
4444
James Smart0a96e972011-07-22 18:37:28 -04004445 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4446 if (pos == 0)
4447 return 0;
4448
4449 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
4450 return nr_virtfn;
4451}
4452
4453/**
James Smart912e3ac2011-05-24 11:42:11 -04004454 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
4455 * @phba: pointer to lpfc hba data structure.
4456 * @nr_vfn: number of virtual functions to be enabled.
4457 *
4458 * This function enables the PCI SR-IOV virtual functions to a physical
4459 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4460 * enable the number of virtual functions to the physical function. As
4461 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4462 * API call does not considered as an error condition for most of the device.
4463 **/
4464int
4465lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
4466{
4467 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04004468 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04004469 int rc;
4470
James Smart0a96e972011-07-22 18:37:28 -04004471 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
4472 if (nr_vfn > max_nr_vfn) {
4473 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4474 "3057 Requested vfs (%d) greater than "
4475 "supported vfs (%d)", nr_vfn, max_nr_vfn);
4476 return -EINVAL;
4477 }
4478
James Smart912e3ac2011-05-24 11:42:11 -04004479 rc = pci_enable_sriov(pdev, nr_vfn);
4480 if (rc) {
4481 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4482 "2806 Failed to enable sriov on this device "
4483 "with vfn number nr_vf:%d, rc:%d\n",
4484 nr_vfn, rc);
4485 } else
4486 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4487 "2807 Successful enable sriov on this device "
4488 "with vfn number nr_vf:%d\n", nr_vfn);
4489 return rc;
4490}
4491
4492/**
James Smart3772a992009-05-22 14:50:54 -04004493 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
4494 * @phba: pointer to lpfc hba data structure.
4495 *
4496 * This routine is invoked to set up the driver internal resources specific to
4497 * support the SLI-3 HBA device it attached to.
4498 *
4499 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004500 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004501 * other values - error
4502 **/
4503static int
4504lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
4505{
4506 struct lpfc_sli *psli;
James Smart912e3ac2011-05-24 11:42:11 -04004507 int rc;
dea31012005-04-17 16:05:31 -05004508
James Smart3772a992009-05-22 14:50:54 -04004509 /*
4510 * Initialize timers used by driver
4511 */
dea31012005-04-17 16:05:31 -05004512
James Smart3772a992009-05-22 14:50:54 -04004513 /* Heartbeat timer */
4514 init_timer(&phba->hb_tmofunc);
4515 phba->hb_tmofunc.function = lpfc_hb_timeout;
4516 phba->hb_tmofunc.data = (unsigned long)phba;
4517
4518 psli = &phba->sli;
4519 /* MBOX heartbeat timer */
4520 init_timer(&psli->mbox_tmo);
4521 psli->mbox_tmo.function = lpfc_mbox_timeout;
4522 psli->mbox_tmo.data = (unsigned long) phba;
4523 /* FCP polling mode timer */
4524 init_timer(&phba->fcp_poll_timer);
4525 phba->fcp_poll_timer.function = lpfc_poll_timeout;
4526 phba->fcp_poll_timer.data = (unsigned long) phba;
4527 /* Fabric block timer */
4528 init_timer(&phba->fabric_block_timer);
4529 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
4530 phba->fabric_block_timer.data = (unsigned long) phba;
4531 /* EA polling mode timer */
4532 init_timer(&phba->eratt_poll);
4533 phba->eratt_poll.function = lpfc_poll_eratt;
4534 phba->eratt_poll.data = (unsigned long) phba;
4535
4536 /* Host attention work mask setup */
4537 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
4538 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
4539
4540 /* Get all the module params for configuring this host */
4541 lpfc_get_cfgparam(phba);
James Smart49198b32010-04-06 15:04:33 -04004542 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
4543 phba->menlo_flag |= HBA_MENLO_SUPPORT;
4544 /* check for menlo minimum sg count */
4545 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
4546 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
4547 }
4548
James Smart3772a992009-05-22 14:50:54 -04004549 /*
4550 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
4551 * used to create the sg_dma_buf_pool must be dynamically calculated.
4552 * 2 segments are added since the IOCB needs a command and response bde.
4553 */
4554 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
4555 sizeof(struct fcp_rsp) +
4556 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
4557
4558 if (phba->cfg_enable_bg) {
4559 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT;
4560 phba->cfg_sg_dma_buf_size +=
4561 phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64);
4562 }
4563
4564 /* Also reinitialize the host templates with new values. */
4565 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4566 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4567
4568 phba->max_vpi = LPFC_MAX_VPI;
4569 /* This will be set to correct value after config_port mbox */
4570 phba->max_vports = 0;
4571
4572 /*
4573 * Initialize the SLI Layer to run with lpfc HBAs.
4574 */
4575 lpfc_sli_setup(phba);
4576 lpfc_sli_queue_setup(phba);
4577
4578 /* Allocate device driver memory */
4579 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
4580 return -ENOMEM;
4581
James Smart912e3ac2011-05-24 11:42:11 -04004582 /*
4583 * Enable sr-iov virtual functions if supported and configured
4584 * through the module parameter.
4585 */
4586 if (phba->cfg_sriov_nr_virtfn > 0) {
4587 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
4588 phba->cfg_sriov_nr_virtfn);
4589 if (rc) {
4590 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4591 "2808 Requested number of SR-IOV "
4592 "virtual functions (%d) is not "
4593 "supported\n",
4594 phba->cfg_sriov_nr_virtfn);
4595 phba->cfg_sriov_nr_virtfn = 0;
4596 }
4597 }
4598
James Smart3772a992009-05-22 14:50:54 -04004599 return 0;
4600}
4601
4602/**
4603 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
4604 * @phba: pointer to lpfc hba data structure.
4605 *
4606 * This routine is invoked to unset the driver internal resources set up
4607 * specific for supporting the SLI-3 HBA device it attached to.
4608 **/
4609static void
4610lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
4611{
4612 /* Free device driver memory allocated */
4613 lpfc_mem_free_all(phba);
4614
4615 return;
4616}
4617
4618/**
James Smartda0436e2009-05-22 14:51:39 -04004619 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
4620 * @phba: pointer to lpfc hba data structure.
4621 *
4622 * This routine is invoked to set up the driver internal resources specific to
4623 * support the SLI-4 HBA device it attached to.
4624 *
4625 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004626 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04004627 * other values - error
4628 **/
4629static int
4630lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
4631{
4632 struct lpfc_sli *psli;
James Smart28baac72010-02-12 14:42:03 -05004633 LPFC_MBOXQ_t *mboxq;
4634 int rc, i, hbq_count, buf_size, dma_buf_size, max_buf_size;
4635 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
4636 struct lpfc_mqe *mqe;
James Smart085c6472010-11-20 23:11:37 -05004637 int longs, sli_family;
James Smartacd68592012-01-18 16:25:09 -05004638 int sges_per_segment;
James Smartda0436e2009-05-22 14:51:39 -04004639
4640 /* Before proceed, wait for POST done and device ready */
4641 rc = lpfc_sli4_post_status_check(phba);
4642 if (rc)
4643 return -ENODEV;
4644
4645 /*
4646 * Initialize timers used by driver
4647 */
4648
4649 /* Heartbeat timer */
4650 init_timer(&phba->hb_tmofunc);
4651 phba->hb_tmofunc.function = lpfc_hb_timeout;
4652 phba->hb_tmofunc.data = (unsigned long)phba;
James Smart19ca7602010-11-20 23:11:55 -05004653 init_timer(&phba->rrq_tmr);
4654 phba->rrq_tmr.function = lpfc_rrq_timeout;
4655 phba->rrq_tmr.data = (unsigned long)phba;
James Smartda0436e2009-05-22 14:51:39 -04004656
4657 psli = &phba->sli;
4658 /* MBOX heartbeat timer */
4659 init_timer(&psli->mbox_tmo);
4660 psli->mbox_tmo.function = lpfc_mbox_timeout;
4661 psli->mbox_tmo.data = (unsigned long) phba;
4662 /* Fabric block timer */
4663 init_timer(&phba->fabric_block_timer);
4664 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
4665 phba->fabric_block_timer.data = (unsigned long) phba;
4666 /* EA polling mode timer */
4667 init_timer(&phba->eratt_poll);
4668 phba->eratt_poll.function = lpfc_poll_eratt;
4669 phba->eratt_poll.data = (unsigned long) phba;
James Smartecfd03c2010-02-12 14:41:27 -05004670 /* FCF rediscover timer */
4671 init_timer(&phba->fcf.redisc_wait);
4672 phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
4673 phba->fcf.redisc_wait.data = (unsigned long)phba;
4674
James Smartda0436e2009-05-22 14:51:39 -04004675 /*
James Smart7ad20aa2011-05-24 11:44:28 -04004676 * Control structure for handling external multi-buffer mailbox
4677 * command pass-through.
4678 */
4679 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
4680 sizeof(struct lpfc_mbox_ext_buf_ctx));
4681 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
4682
4683 /*
James Smartda0436e2009-05-22 14:51:39 -04004684 * We need to do a READ_CONFIG mailbox command here before
4685 * calling lpfc_get_cfgparam. For VFs this will report the
4686 * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings.
4687 * All of the resources allocated
4688 * for this Port are tied to these values.
4689 */
4690 /* Get all the module params for configuring this host */
4691 lpfc_get_cfgparam(phba);
4692 phba->max_vpi = LPFC_MAX_VPI;
4693 /* This will be set to correct value after the read_config mbox */
4694 phba->max_vports = 0;
4695
4696 /* Program the default value of vlan_id and fc_map */
4697 phba->valid_vlan = 0;
4698 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
4699 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
4700 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
4701
James Smartacd68592012-01-18 16:25:09 -05004702 /* With BlockGuard we can have multiple SGEs per Data Segemnt */
4703 sges_per_segment = 1;
4704 if (phba->cfg_enable_bg)
4705 sges_per_segment = 2;
4706
James Smartda0436e2009-05-22 14:51:39 -04004707 /*
4708 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
4709 * used to create the sg_dma_buf_pool must be dynamically calculated.
4710 * 2 segments are added since the IOCB needs a command and response bde.
4711 * To insure that the scsi sgl does not cross a 4k page boundary only
James Smart28baac72010-02-12 14:42:03 -05004712 * sgl sizes of must be a power of 2.
James Smartda0436e2009-05-22 14:51:39 -04004713 */
James Smart28baac72010-02-12 14:42:03 -05004714 buf_size = (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp) +
James Smartacd68592012-01-18 16:25:09 -05004715 (((phba->cfg_sg_seg_cnt * sges_per_segment) + 2) *
4716 sizeof(struct sli4_sge)));
James Smart085c6472010-11-20 23:11:37 -05004717
4718 sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf);
4719 max_buf_size = LPFC_SLI4_MAX_BUF_SIZE;
4720 switch (sli_family) {
4721 case LPFC_SLI_INTF_FAMILY_BE2:
4722 case LPFC_SLI_INTF_FAMILY_BE3:
4723 /* There is a single hint for BE - 2 pages per BPL. */
4724 if (bf_get(lpfc_sli_intf_sli_hint1, &phba->sli4_hba.sli_intf) ==
4725 LPFC_SLI_INTF_SLI_HINT1_1)
4726 max_buf_size = LPFC_SLI4_FL1_MAX_BUF_SIZE;
4727 break;
4728 case LPFC_SLI_INTF_FAMILY_LNCR_A0:
4729 case LPFC_SLI_INTF_FAMILY_LNCR_B0:
4730 default:
4731 break;
4732 }
James Smartacd68592012-01-18 16:25:09 -05004733
James Smart28baac72010-02-12 14:42:03 -05004734 for (dma_buf_size = LPFC_SLI4_MIN_BUF_SIZE;
4735 dma_buf_size < max_buf_size && buf_size > dma_buf_size;
4736 dma_buf_size = dma_buf_size << 1)
4737 ;
4738 if (dma_buf_size == max_buf_size)
4739 phba->cfg_sg_seg_cnt = (dma_buf_size -
4740 sizeof(struct fcp_cmnd) - sizeof(struct fcp_rsp) -
4741 (2 * sizeof(struct sli4_sge))) /
4742 sizeof(struct sli4_sge);
4743 phba->cfg_sg_dma_buf_size = dma_buf_size;
James Smartda0436e2009-05-22 14:51:39 -04004744
4745 /* Initialize buffer queue management fields */
4746 hbq_count = lpfc_sli_hbq_count();
4747 for (i = 0; i < hbq_count; ++i)
4748 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
4749 INIT_LIST_HEAD(&phba->rb_pend_list);
4750 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
4751 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
4752
4753 /*
4754 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
4755 */
4756 /* Initialize the Abort scsi buffer list used by driver */
4757 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
4758 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
4759 /* This abort list used by worker thread */
4760 spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
4761
4762 /*
James Smart6d368e52011-05-24 11:44:12 -04004763 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04004764 */
4765
4766 /* Driver internel slow-path CQ Event pool */
4767 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
4768 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04004769 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04004770 /* Asynchronous event CQ Event work queue list */
4771 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
4772 /* Fast-path XRI aborted CQ Event work queue list */
4773 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
4774 /* Slow-path XRI aborted CQ Event work queue list */
4775 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
4776 /* Receive queue CQ Event work queue list */
4777 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
4778
James Smart6d368e52011-05-24 11:44:12 -04004779 /* Initialize extent block lists. */
4780 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
4781 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
4782 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
4783 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
4784
James Smartda0436e2009-05-22 14:51:39 -04004785 /* Initialize the driver internal SLI layer lists. */
4786 lpfc_sli_setup(phba);
4787 lpfc_sli_queue_setup(phba);
4788
4789 /* Allocate device driver memory */
4790 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
4791 if (rc)
4792 return -ENOMEM;
4793
James Smart2fcee4b2010-12-15 17:57:46 -05004794 /* IF Type 2 ports get initialized now. */
4795 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
4796 LPFC_SLI_INTF_IF_TYPE_2) {
4797 rc = lpfc_pci_function_reset(phba);
4798 if (unlikely(rc))
4799 return -ENODEV;
4800 }
4801
James Smartda0436e2009-05-22 14:51:39 -04004802 /* Create the bootstrap mailbox command */
4803 rc = lpfc_create_bootstrap_mbox(phba);
4804 if (unlikely(rc))
4805 goto out_free_mem;
4806
4807 /* Set up the host's endian order with the device. */
4808 rc = lpfc_setup_endian_order(phba);
4809 if (unlikely(rc))
4810 goto out_free_bsmbx;
4811
4812 /* Set up the hba's configuration parameters. */
4813 rc = lpfc_sli4_read_config(phba);
4814 if (unlikely(rc))
4815 goto out_free_bsmbx;
4816
James Smart2fcee4b2010-12-15 17:57:46 -05004817 /* IF Type 0 ports get initialized now. */
4818 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
4819 LPFC_SLI_INTF_IF_TYPE_0) {
4820 rc = lpfc_pci_function_reset(phba);
4821 if (unlikely(rc))
4822 goto out_free_bsmbx;
4823 }
James Smartda0436e2009-05-22 14:51:39 -04004824
James Smartcb5172e2010-03-15 11:25:07 -04004825 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
4826 GFP_KERNEL);
4827 if (!mboxq) {
4828 rc = -ENOMEM;
4829 goto out_free_bsmbx;
4830 }
4831
James Smartfedd3b72011-02-16 12:39:24 -05004832 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04004833 lpfc_supported_pages(mboxq);
4834 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05004835 if (!rc) {
4836 mqe = &mboxq->u.mqe;
4837 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
4838 LPFC_MAX_SUPPORTED_PAGES);
4839 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
4840 switch (pn_page[i]) {
4841 case LPFC_SLI4_PARAMETERS:
4842 phba->sli4_hba.pc_sli4_params.supported = 1;
4843 break;
4844 default:
4845 break;
4846 }
4847 }
4848 /* Read the port's SLI4 Parameters capabilities if supported. */
4849 if (phba->sli4_hba.pc_sli4_params.supported)
4850 rc = lpfc_pc_sli4_params_get(phba, mboxq);
4851 if (rc) {
4852 mempool_free(mboxq, phba->mbox_mem_pool);
4853 rc = -EIO;
4854 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04004855 }
4856 }
James Smartfedd3b72011-02-16 12:39:24 -05004857 /*
4858 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04004859 * If this call fails, it isn't critical unless the SLI4 parameters come
4860 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05004861 */
James Smart6d368e52011-05-24 11:44:12 -04004862 rc = lpfc_get_sli4_parameters(phba, mboxq);
4863 if (rc) {
4864 if (phba->sli4_hba.extents_in_use &&
4865 phba->sli4_hba.rpi_hdrs_in_use) {
4866 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4867 "2999 Unsupported SLI4 Parameters "
4868 "Extents and RPI headers enabled.\n");
4869 goto out_free_bsmbx;
4870 }
4871 }
James Smartcb5172e2010-03-15 11:25:07 -04004872 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart5350d872011-10-10 21:33:49 -04004873 /* Verify all the SLI4 queues */
4874 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04004875 if (rc)
4876 goto out_free_bsmbx;
4877
4878 /* Create driver internal CQE event pool */
4879 rc = lpfc_sli4_cq_event_pool_create(phba);
4880 if (rc)
James Smart5350d872011-10-10 21:33:49 -04004881 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04004882
James Smart8a9d2e82012-05-09 21:16:12 -04004883 /* Initialize sgl lists per host */
4884 lpfc_init_sgl_list(phba);
4885
4886 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04004887 rc = lpfc_init_active_sgl_array(phba);
4888 if (rc) {
4889 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4890 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04004891 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04004892 }
James Smartda0436e2009-05-22 14:51:39 -04004893 rc = lpfc_sli4_init_rpi_hdrs(phba);
4894 if (rc) {
4895 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4896 "1432 Failed to initialize rpi headers.\n");
4897 goto out_free_active_sgl;
4898 }
4899
James Smarta93ff372010-10-22 11:06:08 -04004900 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05004901 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
4902 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
4903 GFP_KERNEL);
4904 if (!phba->fcf.fcf_rr_bmask) {
4905 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4906 "2759 Failed allocate memory for FCF round "
4907 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04004908 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05004909 goto out_remove_rpi_hdrs;
4910 }
4911
James Smart5350d872011-10-10 21:33:49 -04004912 /*
4913 * The cfg_fcp_eq_count can be zero whenever there is exactly one
4914 * interrupt vector. This is not an error
4915 */
4916 if (phba->cfg_fcp_eq_count) {
4917 phba->sli4_hba.fcp_eq_hdl =
4918 kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
James Smartda0436e2009-05-22 14:51:39 -04004919 phba->cfg_fcp_eq_count), GFP_KERNEL);
James Smart5350d872011-10-10 21:33:49 -04004920 if (!phba->sli4_hba.fcp_eq_hdl) {
4921 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4922 "2572 Failed allocate memory for "
4923 "fast-path per-EQ handle array\n");
4924 rc = -ENOMEM;
4925 goto out_free_fcf_rr_bmask;
4926 }
James Smartda0436e2009-05-22 14:51:39 -04004927 }
4928
4929 phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
4930 phba->sli4_hba.cfg_eqn), GFP_KERNEL);
4931 if (!phba->sli4_hba.msix_entries) {
4932 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4933 "2573 Failed allocate memory for msi-x "
4934 "interrupt vector entries\n");
James Smart05580562011-05-24 11:40:48 -04004935 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04004936 goto out_free_fcp_eq_hdl;
4937 }
4938
James Smart912e3ac2011-05-24 11:42:11 -04004939 /*
4940 * Enable sr-iov virtual functions if supported and configured
4941 * through the module parameter.
4942 */
4943 if (phba->cfg_sriov_nr_virtfn > 0) {
4944 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
4945 phba->cfg_sriov_nr_virtfn);
4946 if (rc) {
4947 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4948 "3020 Requested number of SR-IOV "
4949 "virtual functions (%d) is not "
4950 "supported\n",
4951 phba->cfg_sriov_nr_virtfn);
4952 phba->cfg_sriov_nr_virtfn = 0;
4953 }
4954 }
4955
James Smart5248a742011-07-22 18:37:06 -04004956 return 0;
James Smartda0436e2009-05-22 14:51:39 -04004957
4958out_free_fcp_eq_hdl:
4959 kfree(phba->sli4_hba.fcp_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05004960out_free_fcf_rr_bmask:
4961 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04004962out_remove_rpi_hdrs:
4963 lpfc_sli4_remove_rpi_hdrs(phba);
4964out_free_active_sgl:
4965 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04004966out_destroy_cq_event_pool:
4967 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04004968out_free_bsmbx:
4969 lpfc_destroy_bootstrap_mbox(phba);
4970out_free_mem:
4971 lpfc_mem_free(phba);
4972 return rc;
4973}
4974
4975/**
4976 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
4977 * @phba: pointer to lpfc hba data structure.
4978 *
4979 * This routine is invoked to unset the driver internal resources set up
4980 * specific for supporting the SLI-4 HBA device it attached to.
4981 **/
4982static void
4983lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
4984{
4985 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
4986
James Smartda0436e2009-05-22 14:51:39 -04004987 /* Free memory allocated for msi-x interrupt vector entries */
4988 kfree(phba->sli4_hba.msix_entries);
4989
4990 /* Free memory allocated for fast-path work queue handles */
4991 kfree(phba->sli4_hba.fcp_eq_hdl);
4992
4993 /* Free the allocated rpi headers. */
4994 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04004995 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04004996
James Smart0c9ab6f2010-02-26 14:15:57 -05004997 /* Free eligible FCF index bmask */
4998 kfree(phba->fcf.fcf_rr_bmask);
4999
James Smartda0436e2009-05-22 14:51:39 -04005000 /* Free the ELS sgl list */
5001 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04005002 lpfc_free_els_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04005003
James Smartda0436e2009-05-22 14:51:39 -04005004 /* Free the completion queue EQ event pool */
5005 lpfc_sli4_cq_event_release_all(phba);
5006 lpfc_sli4_cq_event_pool_destroy(phba);
5007
James Smart6d368e52011-05-24 11:44:12 -04005008 /* Release resource identifiers. */
5009 lpfc_sli4_dealloc_resource_identifiers(phba);
5010
James Smartda0436e2009-05-22 14:51:39 -04005011 /* Free the bsmbx region. */
5012 lpfc_destroy_bootstrap_mbox(phba);
5013
5014 /* Free the SLI Layer memory with SLI4 HBAs */
5015 lpfc_mem_free_all(phba);
5016
5017 /* Free the current connect table */
5018 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04005019 &phba->fcf_conn_rec_list, list) {
5020 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04005021 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04005022 }
James Smartda0436e2009-05-22 14:51:39 -04005023
5024 return;
5025}
5026
5027/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005028 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04005029 * @phba: The hba struct for which this call is being executed.
5030 * @dev_grp: The HBA PCI-Device group number.
5031 *
5032 * This routine sets up the device INIT interface API function jump table
5033 * in @phba struct.
5034 *
5035 * Returns: 0 - success, -ENODEV - failure.
5036 **/
5037int
5038lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5039{
James Smart84d1b002010-02-12 14:42:33 -05005040 phba->lpfc_hba_init_link = lpfc_hba_init_link;
5041 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05005042 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04005043 switch (dev_grp) {
5044 case LPFC_PCI_DEV_LP:
5045 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
5046 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
5047 phba->lpfc_stop_port = lpfc_stop_port_s3;
5048 break;
James Smartda0436e2009-05-22 14:51:39 -04005049 case LPFC_PCI_DEV_OC:
5050 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
5051 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
5052 phba->lpfc_stop_port = lpfc_stop_port_s4;
5053 break;
James Smart3772a992009-05-22 14:50:54 -04005054 default:
5055 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5056 "1431 Invalid HBA PCI-device group: 0x%x\n",
5057 dev_grp);
5058 return -ENODEV;
5059 break;
5060 }
5061 return 0;
5062}
5063
5064/**
5065 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
5066 * @phba: pointer to lpfc hba data structure.
5067 *
5068 * This routine is invoked to set up the driver internal resources before the
5069 * device specific resource setup to support the HBA device it attached to.
5070 *
5071 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005072 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005073 * other values - error
5074 **/
5075static int
5076lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
5077{
5078 /*
5079 * Driver resources common to all SLI revisions
5080 */
James Smartea2151b2008-09-07 11:52:10 -04005081 atomic_set(&phba->fast_event_count, 0);
James Smart2e0fef82007-06-17 19:56:36 -05005082 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005083
James Smarte47c9092008-02-08 18:49:26 -05005084 /* Initialize ndlp management spinlock */
5085 spin_lock_init(&phba->ndlp_lock);
5086
James Smart2e0fef82007-06-17 19:56:36 -05005087 INIT_LIST_HEAD(&phba->port_list);
James Smart3772a992009-05-22 14:50:54 -04005088 INIT_LIST_HEAD(&phba->work_list);
James Smart84774a42008-08-24 21:50:06 -04005089 init_waitqueue_head(&phba->wait_4_mlo_m_q);
dea31012005-04-17 16:05:31 -05005090
James Smart3772a992009-05-22 14:50:54 -04005091 /* Initialize the wait queue head for the kernel thread */
5092 init_waitqueue_head(&phba->work_waitq);
James Smart858c9f62007-06-17 19:56:39 -05005093
James Smart3772a992009-05-22 14:50:54 -04005094 /* Initialize the scsi buffer list used by driver for scsi IO */
5095 spin_lock_init(&phba->scsi_buf_list_lock);
5096 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
dea31012005-04-17 16:05:31 -05005097
James Smart3772a992009-05-22 14:50:54 -04005098 /* Initialize the fabric iocb list */
5099 INIT_LIST_HEAD(&phba->fabric_iocb_list);
dea31012005-04-17 16:05:31 -05005100
James Smart3772a992009-05-22 14:50:54 -04005101 /* Initialize list to save ELS buffers */
5102 INIT_LIST_HEAD(&phba->elsbuf);
dea31012005-04-17 16:05:31 -05005103
James Smart3772a992009-05-22 14:50:54 -04005104 /* Initialize FCF connection rec list */
5105 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
dea31012005-04-17 16:05:31 -05005106
James Smart3772a992009-05-22 14:50:54 -04005107 return 0;
5108}
dea31012005-04-17 16:05:31 -05005109
James Smart3772a992009-05-22 14:50:54 -04005110/**
5111 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
5112 * @phba: pointer to lpfc hba data structure.
5113 *
5114 * This routine is invoked to set up the driver internal resources after the
5115 * device specific resource setup to support the HBA device it attached to.
5116 *
5117 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005118 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005119 * other values - error
5120 **/
5121static int
5122lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
5123{
5124 int error;
5125
5126 /* Startup the kernel thread for this host adapter. */
5127 phba->worker_thread = kthread_run(lpfc_do_work, phba,
5128 "lpfc_worker_%d", phba->brd_no);
5129 if (IS_ERR(phba->worker_thread)) {
5130 error = PTR_ERR(phba->worker_thread);
5131 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005132 }
5133
James Smart3772a992009-05-22 14:50:54 -04005134 return 0;
5135}
5136
5137/**
5138 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
5139 * @phba: pointer to lpfc hba data structure.
5140 *
5141 * This routine is invoked to unset the driver internal resources set up after
5142 * the device specific resource setup for supporting the HBA device it
5143 * attached to.
5144 **/
5145static void
5146lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
5147{
5148 /* Stop kernel worker thread */
5149 kthread_stop(phba->worker_thread);
5150}
5151
5152/**
5153 * lpfc_free_iocb_list - Free iocb list.
5154 * @phba: pointer to lpfc hba data structure.
5155 *
5156 * This routine is invoked to free the driver's IOCB list and memory.
5157 **/
5158static void
5159lpfc_free_iocb_list(struct lpfc_hba *phba)
5160{
5161 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
5162
5163 spin_lock_irq(&phba->hbalock);
5164 list_for_each_entry_safe(iocbq_entry, iocbq_next,
5165 &phba->lpfc_iocb_list, list) {
5166 list_del(&iocbq_entry->list);
5167 kfree(iocbq_entry);
5168 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005169 }
James Smart3772a992009-05-22 14:50:54 -04005170 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005171
James Smart3772a992009-05-22 14:50:54 -04005172 return;
5173}
dea31012005-04-17 16:05:31 -05005174
James Smart3772a992009-05-22 14:50:54 -04005175/**
5176 * lpfc_init_iocb_list - Allocate and initialize iocb list.
5177 * @phba: pointer to lpfc hba data structure.
5178 *
5179 * This routine is invoked to allocate and initizlize the driver's IOCB
5180 * list and set up the IOCB tag array accordingly.
5181 *
5182 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005183 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005184 * other values - error
5185 **/
5186static int
5187lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
5188{
5189 struct lpfc_iocbq *iocbq_entry = NULL;
5190 uint16_t iotag;
5191 int i;
dea31012005-04-17 16:05:31 -05005192
5193 /* Initialize and populate the iocb list per host. */
5194 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04005195 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07005196 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05005197 if (iocbq_entry == NULL) {
5198 printk(KERN_ERR "%s: only allocated %d iocbs of "
5199 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07005200 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05005201 goto out_free_iocbq;
5202 }
5203
James Bottomley604a3e32005-10-29 10:28:33 -05005204 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
5205 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04005206 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05005207 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04005208 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05005209 goto out_free_iocbq;
5210 }
James Smart6d368e52011-05-24 11:44:12 -04005211 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04005212 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05005213
5214 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005215 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
5216 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05005217 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005218 }
5219
James Smart3772a992009-05-22 14:50:54 -04005220 return 0;
5221
5222out_free_iocbq:
5223 lpfc_free_iocb_list(phba);
5224
5225 return -ENOMEM;
5226}
5227
5228/**
James Smart8a9d2e82012-05-09 21:16:12 -04005229 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04005230 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04005231 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04005232 *
James Smart8a9d2e82012-05-09 21:16:12 -04005233 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04005234 **/
James Smart8a9d2e82012-05-09 21:16:12 -04005235void
5236lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04005237{
5238 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04005239
5240 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
5241 list_del(&sglq_entry->list);
5242 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
5243 kfree(sglq_entry);
5244 }
5245}
5246
5247/**
5248 * lpfc_free_els_sgl_list - Free els sgl list.
5249 * @phba: pointer to lpfc hba data structure.
5250 *
5251 * This routine is invoked to free the driver's els sgl list and memory.
5252 **/
5253static void
5254lpfc_free_els_sgl_list(struct lpfc_hba *phba)
5255{
James Smartda0436e2009-05-22 14:51:39 -04005256 LIST_HEAD(sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04005257
James Smart8a9d2e82012-05-09 21:16:12 -04005258 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04005259 spin_lock_irq(&phba->hbalock);
5260 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
5261 spin_unlock_irq(&phba->hbalock);
5262
James Smart8a9d2e82012-05-09 21:16:12 -04005263 /* Now free the sgl list */
5264 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04005265}
5266
5267/**
5268 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
5269 * @phba: pointer to lpfc hba data structure.
5270 *
5271 * This routine is invoked to allocate the driver's active sgl memory.
5272 * This array will hold the sglq_entry's for active IOs.
5273 **/
5274static int
5275lpfc_init_active_sgl_array(struct lpfc_hba *phba)
5276{
5277 int size;
5278 size = sizeof(struct lpfc_sglq *);
5279 size *= phba->sli4_hba.max_cfg_param.max_xri;
5280
5281 phba->sli4_hba.lpfc_sglq_active_list =
5282 kzalloc(size, GFP_KERNEL);
5283 if (!phba->sli4_hba.lpfc_sglq_active_list)
5284 return -ENOMEM;
5285 return 0;
5286}
5287
5288/**
5289 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
5290 * @phba: pointer to lpfc hba data structure.
5291 *
5292 * This routine is invoked to walk through the array of active sglq entries
5293 * and free all of the resources.
5294 * This is just a place holder for now.
5295 **/
5296static void
5297lpfc_free_active_sgl(struct lpfc_hba *phba)
5298{
5299 kfree(phba->sli4_hba.lpfc_sglq_active_list);
5300}
5301
5302/**
5303 * lpfc_init_sgl_list - Allocate and initialize sgl list.
5304 * @phba: pointer to lpfc hba data structure.
5305 *
5306 * This routine is invoked to allocate and initizlize the driver's sgl
5307 * list and set up the sgl xritag tag array accordingly.
5308 *
James Smartda0436e2009-05-22 14:51:39 -04005309 **/
James Smart8a9d2e82012-05-09 21:16:12 -04005310static void
James Smartda0436e2009-05-22 14:51:39 -04005311lpfc_init_sgl_list(struct lpfc_hba *phba)
5312{
James Smartda0436e2009-05-22 14:51:39 -04005313 /* Initialize and populate the sglq list per host/VF. */
5314 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
5315 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
5316
James Smart8a9d2e82012-05-09 21:16:12 -04005317 /* els xri-sgl book keeping */
5318 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04005319
James Smart8a9d2e82012-05-09 21:16:12 -04005320 /* scsi xri-buffer book keeping */
James Smartda0436e2009-05-22 14:51:39 -04005321 phba->sli4_hba.scsi_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04005322}
5323
5324/**
5325 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
5326 * @phba: pointer to lpfc hba data structure.
5327 *
5328 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04005329 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04005330 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04005331 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
5332 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04005333 *
5334 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005335 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04005336 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04005337 **/
5338int
5339lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
5340{
5341 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04005342 struct lpfc_rpi_hdr *rpi_hdr;
5343
5344 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05005345 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04005346 return rc;
James Smart6d368e52011-05-24 11:44:12 -04005347 if (phba->sli4_hba.extents_in_use)
5348 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04005349
5350 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
5351 if (!rpi_hdr) {
5352 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5353 "0391 Error during rpi post operation\n");
5354 lpfc_sli4_remove_rpis(phba);
5355 rc = -ENODEV;
5356 }
5357
5358 return rc;
5359}
5360
5361/**
5362 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
5363 * @phba: pointer to lpfc hba data structure.
5364 *
5365 * This routine is invoked to allocate a single 4KB memory region to
5366 * support rpis and stores them in the phba. This single region
5367 * provides support for up to 64 rpis. The region is used globally
5368 * by the device.
5369 *
5370 * Returns:
5371 * A valid rpi hdr on success.
5372 * A NULL pointer on any failure.
5373 **/
5374struct lpfc_rpi_hdr *
5375lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
5376{
5377 uint16_t rpi_limit, curr_rpi_range;
5378 struct lpfc_dmabuf *dmabuf;
5379 struct lpfc_rpi_hdr *rpi_hdr;
James Smart9589b0622011-04-16 11:03:17 -04005380 uint32_t rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04005381
James Smart6d368e52011-05-24 11:44:12 -04005382 /*
5383 * If the SLI4 port supports extents, posting the rpi header isn't
5384 * required. Set the expected maximum count and let the actual value
5385 * get set when extents are fully allocated.
5386 */
5387 if (!phba->sli4_hba.rpi_hdrs_in_use)
5388 return NULL;
5389 if (phba->sli4_hba.extents_in_use)
5390 return NULL;
5391
5392 /* The limit on the logical index is just the max_rpi count. */
James Smartda0436e2009-05-22 14:51:39 -04005393 rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
James Smart6d368e52011-05-24 11:44:12 -04005394 phba->sli4_hba.max_cfg_param.max_rpi - 1;
James Smartda0436e2009-05-22 14:51:39 -04005395
5396 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04005397 /*
5398 * Establish the starting RPI in this header block. The starting
5399 * rpi is normalized to a zero base because the physical rpi is
5400 * port based.
5401 */
James Smart97f2ecf2012-03-01 22:35:23 -05005402 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04005403 spin_unlock_irq(&phba->hbalock);
5404
5405 /*
5406 * The port has a limited number of rpis. The increment here
5407 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
5408 * and to allow the full max_rpi range per port.
5409 */
5410 if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
James Smart9589b0622011-04-16 11:03:17 -04005411 rpi_count = rpi_limit - curr_rpi_range;
5412 else
5413 rpi_count = LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04005414
James Smart6d368e52011-05-24 11:44:12 -04005415 if (!rpi_count)
5416 return NULL;
James Smartda0436e2009-05-22 14:51:39 -04005417 /*
5418 * First allocate the protocol header region for the port. The
5419 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
5420 */
5421 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5422 if (!dmabuf)
5423 return NULL;
5424
5425 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
5426 LPFC_HDR_TEMPLATE_SIZE,
5427 &dmabuf->phys,
5428 GFP_KERNEL);
5429 if (!dmabuf->virt) {
5430 rpi_hdr = NULL;
5431 goto err_free_dmabuf;
5432 }
5433
5434 memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE);
5435 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
5436 rpi_hdr = NULL;
5437 goto err_free_coherent;
5438 }
5439
5440 /* Save the rpi header data for cleanup later. */
5441 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
5442 if (!rpi_hdr)
5443 goto err_free_coherent;
5444
5445 rpi_hdr->dmabuf = dmabuf;
5446 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
5447 rpi_hdr->page_count = 1;
5448 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04005449
5450 /* The rpi_hdr stores the logical index only. */
5451 rpi_hdr->start_rpi = curr_rpi_range;
James Smartda0436e2009-05-22 14:51:39 -04005452 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
5453
5454 /*
James Smart6d368e52011-05-24 11:44:12 -04005455 * The next_rpi stores the next logical module-64 rpi value used
5456 * to post physical rpis in subsequent rpi postings.
James Smartda0436e2009-05-22 14:51:39 -04005457 */
James Smart9589b0622011-04-16 11:03:17 -04005458 phba->sli4_hba.next_rpi += rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04005459 spin_unlock_irq(&phba->hbalock);
5460 return rpi_hdr;
5461
5462 err_free_coherent:
5463 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
5464 dmabuf->virt, dmabuf->phys);
5465 err_free_dmabuf:
5466 kfree(dmabuf);
5467 return NULL;
5468}
5469
5470/**
5471 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
5472 * @phba: pointer to lpfc hba data structure.
5473 *
5474 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04005475 * to support rpis for SLI4 ports not supporting extents. This routine
5476 * presumes the caller has released all rpis consumed by fabric or port
5477 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04005478 **/
5479void
5480lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
5481{
5482 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
5483
James Smart6d368e52011-05-24 11:44:12 -04005484 if (!phba->sli4_hba.rpi_hdrs_in_use)
5485 goto exit;
5486
James Smartda0436e2009-05-22 14:51:39 -04005487 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
5488 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
5489 list_del(&rpi_hdr->list);
5490 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
5491 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
5492 kfree(rpi_hdr->dmabuf);
5493 kfree(rpi_hdr);
5494 }
James Smart6d368e52011-05-24 11:44:12 -04005495 exit:
5496 /* There are no rpis available to the port now. */
5497 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04005498}
5499
5500/**
James Smart3772a992009-05-22 14:50:54 -04005501 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
5502 * @pdev: pointer to pci device data structure.
5503 *
5504 * This routine is invoked to allocate the driver hba data structure for an
5505 * HBA device. If the allocation is successful, the phba reference to the
5506 * PCI device data structure is set.
5507 *
5508 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005509 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04005510 * NULL - error
5511 **/
5512static struct lpfc_hba *
5513lpfc_hba_alloc(struct pci_dev *pdev)
5514{
5515 struct lpfc_hba *phba;
5516
5517 /* Allocate memory for HBA structure */
5518 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
5519 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02005520 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04005521 return NULL;
5522 }
5523
5524 /* Set reference to PCI device in HBA structure */
5525 phba->pcidev = pdev;
5526
5527 /* Assign an unused board number */
5528 phba->brd_no = lpfc_get_instance();
5529 if (phba->brd_no < 0) {
5530 kfree(phba);
5531 return NULL;
5532 }
5533
James Smart4fede782010-01-26 23:08:55 -05005534 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04005535 INIT_LIST_HEAD(&phba->ct_ev_waiters);
5536
James Smart3772a992009-05-22 14:50:54 -04005537 return phba;
5538}
5539
5540/**
5541 * lpfc_hba_free - Free driver hba data structure with a device.
5542 * @phba: pointer to lpfc hba data structure.
5543 *
5544 * This routine is invoked to free the driver hba data structure with an
5545 * HBA device.
5546 **/
5547static void
5548lpfc_hba_free(struct lpfc_hba *phba)
5549{
5550 /* Release the driver assigned board number */
5551 idr_remove(&lpfc_hba_index, phba->brd_no);
5552
5553 kfree(phba);
5554 return;
5555}
5556
5557/**
5558 * lpfc_create_shost - Create hba physical port with associated scsi host.
5559 * @phba: pointer to lpfc hba data structure.
5560 *
5561 * This routine is invoked to create HBA physical port and associate a SCSI
5562 * host with it.
5563 *
5564 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005565 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005566 * other values - error
5567 **/
5568static int
5569lpfc_create_shost(struct lpfc_hba *phba)
5570{
5571 struct lpfc_vport *vport;
5572 struct Scsi_Host *shost;
5573
5574 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05005575 phba->fc_edtov = FF_DEF_EDTOV;
5576 phba->fc_ratov = FF_DEF_RATOV;
5577 phba->fc_altov = FF_DEF_ALTOV;
5578 phba->fc_arbtov = FF_DEF_ARBTOV;
5579
James Smartd7c47992010-06-08 18:31:54 -04005580 atomic_set(&phba->sdev_cnt, 0);
James Smart3de2a652007-08-02 11:09:59 -04005581 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05005582 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04005583 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05005584
5585 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05005586 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05005587 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04005588 /* Put reference to SCSI host to driver's device private data */
5589 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05005590
James Smart3772a992009-05-22 14:50:54 -04005591 return 0;
5592}
dea31012005-04-17 16:05:31 -05005593
James Smart3772a992009-05-22 14:50:54 -04005594/**
5595 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
5596 * @phba: pointer to lpfc hba data structure.
5597 *
5598 * This routine is invoked to destroy HBA physical port and the associated
5599 * SCSI host.
5600 **/
5601static void
5602lpfc_destroy_shost(struct lpfc_hba *phba)
5603{
5604 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04005605
James Smart3772a992009-05-22 14:50:54 -04005606 /* Destroy physical port that associated with the SCSI host */
5607 destroy_port(vport);
5608
5609 return;
5610}
5611
5612/**
5613 * lpfc_setup_bg - Setup Block guard structures and debug areas.
5614 * @phba: pointer to lpfc hba data structure.
5615 * @shost: the shost to be used to detect Block guard settings.
5616 *
5617 * This routine sets up the local Block guard protocol settings for @shost.
5618 * This routine also allocates memory for debugging bg buffers.
5619 **/
5620static void
5621lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
5622{
James Smartbbeb79b2012-06-12 13:54:27 -04005623 uint32_t old_mask;
5624 uint32_t old_guard;
5625
James Smart3772a992009-05-22 14:50:54 -04005626 int pagecnt = 10;
5627 if (lpfc_prot_mask && lpfc_prot_guard) {
5628 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5629 "1478 Registering BlockGuard with the "
5630 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04005631
5632 old_mask = lpfc_prot_mask;
5633 old_guard = lpfc_prot_guard;
5634
5635 /* Only allow supported values */
5636 lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
5637 SHOST_DIX_TYPE0_PROTECTION |
5638 SHOST_DIX_TYPE1_PROTECTION);
5639 lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC);
5640
5641 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
5642 if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
5643 lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
5644
5645 if (lpfc_prot_mask && lpfc_prot_guard) {
5646 if ((old_mask != lpfc_prot_mask) ||
5647 (old_guard != lpfc_prot_guard))
5648 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5649 "1475 Registering BlockGuard with the "
5650 "SCSI layer: mask %d guard %d\n",
5651 lpfc_prot_mask, lpfc_prot_guard);
5652
5653 scsi_host_set_prot(shost, lpfc_prot_mask);
5654 scsi_host_set_guard(shost, lpfc_prot_guard);
5655 } else
5656 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5657 "1479 Not Registering BlockGuard with the SCSI "
5658 "layer, Bad protection parameters: %d %d\n",
5659 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04005660 }
James Smartbbeb79b2012-06-12 13:54:27 -04005661
James Smart81301a92008-12-04 22:39:46 -05005662 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05005663 while (pagecnt) {
5664 spin_lock_init(&_dump_buf_lock);
5665 _dump_buf_data =
5666 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
5667 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04005668 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5669 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04005670 "_dump_buf_data at 0x%p\n",
5671 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05005672 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04005673 memset(_dump_buf_data, 0,
5674 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05005675 break;
James Smart3772a992009-05-22 14:50:54 -04005676 } else
James Smart81301a92008-12-04 22:39:46 -05005677 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05005678 }
James Smart81301a92008-12-04 22:39:46 -05005679 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04005680 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5681 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04005682 "memory for hexdump\n");
5683 } else
James Smart6a9c52c2009-10-02 15:16:51 -04005684 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5685 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05005686 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05005687 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05005688 while (pagecnt) {
5689 _dump_buf_dif =
5690 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
5691 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04005692 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5693 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04005694 "_dump_buf_dif at 0x%p\n",
5695 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05005696 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04005697 memset(_dump_buf_dif, 0,
5698 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05005699 break;
James Smart3772a992009-05-22 14:50:54 -04005700 } else
James Smart81301a92008-12-04 22:39:46 -05005701 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05005702 }
James Smart81301a92008-12-04 22:39:46 -05005703 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04005704 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5705 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04005706 "memory for hexdump\n");
5707 } else
James Smart6a9c52c2009-10-02 15:16:51 -04005708 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5709 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04005710 _dump_buf_dif);
5711}
5712
5713/**
5714 * lpfc_post_init_setup - Perform necessary device post initialization setup.
5715 * @phba: pointer to lpfc hba data structure.
5716 *
5717 * This routine is invoked to perform all the necessary post initialization
5718 * setup for the device.
5719 **/
5720static void
5721lpfc_post_init_setup(struct lpfc_hba *phba)
5722{
5723 struct Scsi_Host *shost;
5724 struct lpfc_adapter_event_header adapter_event;
5725
5726 /* Get the default values for Model Name and Description */
5727 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
5728
5729 /*
5730 * hba setup may have changed the hba_queue_depth so we need to
5731 * adjust the value of can_queue.
5732 */
5733 shost = pci_get_drvdata(phba->pcidev);
5734 shost->can_queue = phba->cfg_hba_queue_depth - 10;
5735 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
5736 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05005737
5738 lpfc_host_attrib_init(shost);
5739
James Smart2e0fef82007-06-17 19:56:36 -05005740 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
5741 spin_lock_irq(shost->host_lock);
5742 lpfc_poll_start_timer(phba);
5743 spin_unlock_irq(shost->host_lock);
5744 }
James Smart8f6d98d2006-08-01 07:34:00 -04005745
James Smart93996272008-08-24 21:50:30 -04005746 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5747 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04005748 /* Send board arrival event to upper layer */
5749 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
5750 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
5751 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04005752 sizeof(adapter_event),
5753 (char *) &adapter_event,
5754 LPFC_NL_VENDOR_ID);
5755 return;
5756}
5757
5758/**
5759 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
5760 * @phba: pointer to lpfc hba data structure.
5761 *
5762 * This routine is invoked to set up the PCI device memory space for device
5763 * with SLI-3 interface spec.
5764 *
5765 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005766 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005767 * other values - error
5768 **/
5769static int
5770lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
5771{
5772 struct pci_dev *pdev;
5773 unsigned long bar0map_len, bar2map_len;
5774 int i, hbq_count;
5775 void *ptr;
5776 int error = -ENODEV;
5777
5778 /* Obtain PCI device reference */
5779 if (!phba->pcidev)
5780 return error;
5781 else
5782 pdev = phba->pcidev;
5783
5784 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05005785 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
5786 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
5787 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
5788 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smart3772a992009-05-22 14:50:54 -04005789 return error;
Michael Reed8e685972009-09-18 12:02:05 -05005790 }
5791 }
James Smart3772a992009-05-22 14:50:54 -04005792
5793 /* Get the bus address of Bar0 and Bar2 and the number of bytes
5794 * required by each mapping.
5795 */
5796 phba->pci_bar0_map = pci_resource_start(pdev, 0);
5797 bar0map_len = pci_resource_len(pdev, 0);
5798
5799 phba->pci_bar2_map = pci_resource_start(pdev, 2);
5800 bar2map_len = pci_resource_len(pdev, 2);
5801
5802 /* Map HBA SLIM to a kernel virtual address. */
5803 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
5804 if (!phba->slim_memmap_p) {
5805 dev_printk(KERN_ERR, &pdev->dev,
5806 "ioremap failed for SLIM memory.\n");
5807 goto out;
5808 }
5809
5810 /* Map HBA Control Registers to a kernel virtual address. */
5811 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
5812 if (!phba->ctrl_regs_memmap_p) {
5813 dev_printk(KERN_ERR, &pdev->dev,
5814 "ioremap failed for HBA control registers.\n");
5815 goto out_iounmap_slim;
5816 }
5817
5818 /* Allocate memory for SLI-2 structures */
5819 phba->slim2p.virt = dma_alloc_coherent(&pdev->dev,
5820 SLI2_SLIM_SIZE,
5821 &phba->slim2p.phys,
5822 GFP_KERNEL);
5823 if (!phba->slim2p.virt)
5824 goto out_iounmap;
5825
5826 memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
5827 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04005828 phba->mbox_ext = (phba->slim2p.virt +
5829 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04005830 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
5831 phba->IOCBs = (phba->slim2p.virt +
5832 offsetof(struct lpfc_sli2_slim, IOCBs));
5833
5834 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
5835 lpfc_sli_hbq_size(),
5836 &phba->hbqslimp.phys,
5837 GFP_KERNEL);
5838 if (!phba->hbqslimp.virt)
5839 goto out_free_slim;
5840
5841 hbq_count = lpfc_sli_hbq_count();
5842 ptr = phba->hbqslimp.virt;
5843 for (i = 0; i < hbq_count; ++i) {
5844 phba->hbqs[i].hbq_virt = ptr;
5845 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
5846 ptr += (lpfc_hbq_defs[i]->entry_count *
5847 sizeof(struct lpfc_hbq_entry));
5848 }
5849 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
5850 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
5851
5852 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
5853
5854 INIT_LIST_HEAD(&phba->rb_pend_list);
5855
5856 phba->MBslimaddr = phba->slim_memmap_p;
5857 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
5858 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
5859 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
5860 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04005861
dea31012005-04-17 16:05:31 -05005862 return 0;
5863
dea31012005-04-17 16:05:31 -05005864out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04005865 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
5866 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05005867out_iounmap:
5868 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005869out_iounmap_slim:
dea31012005-04-17 16:05:31 -05005870 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05005871out:
5872 return error;
5873}
5874
James Smarte59058c2008-08-24 21:49:00 -04005875/**
James Smart3772a992009-05-22 14:50:54 -04005876 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
5877 * @phba: pointer to lpfc hba data structure.
5878 *
5879 * This routine is invoked to unset the PCI device memory space for device
5880 * with SLI-3 interface spec.
5881 **/
5882static void
5883lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
5884{
5885 struct pci_dev *pdev;
5886
5887 /* Obtain PCI device reference */
5888 if (!phba->pcidev)
5889 return;
5890 else
5891 pdev = phba->pcidev;
5892
5893 /* Free coherent DMA memory allocated */
5894 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
5895 phba->hbqslimp.virt, phba->hbqslimp.phys);
5896 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
5897 phba->slim2p.virt, phba->slim2p.phys);
5898
5899 /* I/O memory unmap */
5900 iounmap(phba->ctrl_regs_memmap_p);
5901 iounmap(phba->slim_memmap_p);
5902
5903 return;
5904}
5905
5906/**
James Smartda0436e2009-05-22 14:51:39 -04005907 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
5908 * @phba: pointer to lpfc hba data structure.
5909 *
5910 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
5911 * done and check status.
5912 *
5913 * Return 0 if successful, otherwise -ENODEV.
5914 **/
5915int
5916lpfc_sli4_post_status_check(struct lpfc_hba *phba)
5917{
James Smart2fcee4b2010-12-15 17:57:46 -05005918 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
5919 struct lpfc_register reg_data;
5920 int i, port_error = 0;
5921 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04005922
James Smart9940b972011-03-11 16:06:12 -05005923 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
5924 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05005925 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04005926 return -ENODEV;
5927
James Smartda0436e2009-05-22 14:51:39 -04005928 /* Wait up to 30 seconds for the SLI Port POST done and ready */
5929 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05005930 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
5931 &portsmphr_reg.word0) ||
5932 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05005933 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04005934 port_error = -ENODEV;
5935 break;
5936 }
James Smart2fcee4b2010-12-15 17:57:46 -05005937 if (LPFC_POST_STAGE_PORT_READY ==
5938 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04005939 break;
James Smartda0436e2009-05-22 14:51:39 -04005940 msleep(10);
5941 }
5942
James Smart2fcee4b2010-12-15 17:57:46 -05005943 /*
5944 * If there was a port error during POST, then don't proceed with
5945 * other register reads as the data may not be valid. Just exit.
5946 */
5947 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04005948 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05005949 "1408 Port Failed POST - portsmphr=0x%x, "
5950 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
5951 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
5952 portsmphr_reg.word0,
5953 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
5954 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
5955 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
5956 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
5957 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
5958 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
5959 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
5960 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
5961 } else {
James Smart28baac72010-02-12 14:42:03 -05005962 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05005963 "2534 Device Info: SLIFamily=0x%x, "
5964 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
5965 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05005966 bf_get(lpfc_sli_intf_sli_family,
5967 &phba->sli4_hba.sli_intf),
5968 bf_get(lpfc_sli_intf_slirev,
5969 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05005970 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05005971 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05005972 bf_get(lpfc_sli_intf_sli_hint1,
5973 &phba->sli4_hba.sli_intf),
5974 bf_get(lpfc_sli_intf_sli_hint2,
5975 &phba->sli4_hba.sli_intf),
5976 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05005977 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05005978 /*
5979 * Check for other Port errors during the initialization
5980 * process. Fail the load if the port did not come up
5981 * correctly.
5982 */
5983 if_type = bf_get(lpfc_sli_intf_if_type,
5984 &phba->sli4_hba.sli_intf);
5985 switch (if_type) {
5986 case LPFC_SLI_INTF_IF_TYPE_0:
5987 phba->sli4_hba.ue_mask_lo =
5988 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
5989 phba->sli4_hba.ue_mask_hi =
5990 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
5991 uerrlo_reg.word0 =
5992 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
5993 uerrhi_reg.word0 =
5994 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
5995 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
5996 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
5997 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5998 "1422 Unrecoverable Error "
5999 "Detected during POST "
6000 "uerr_lo_reg=0x%x, "
6001 "uerr_hi_reg=0x%x, "
6002 "ue_mask_lo_reg=0x%x, "
6003 "ue_mask_hi_reg=0x%x\n",
6004 uerrlo_reg.word0,
6005 uerrhi_reg.word0,
6006 phba->sli4_hba.ue_mask_lo,
6007 phba->sli4_hba.ue_mask_hi);
6008 port_error = -ENODEV;
6009 }
6010 break;
6011 case LPFC_SLI_INTF_IF_TYPE_2:
6012 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05006013 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
6014 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04006015 (bf_get(lpfc_sliport_status_err, &reg_data) &&
6016 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006017 phba->work_status[0] =
6018 readl(phba->sli4_hba.u.if_type2.
6019 ERR1regaddr);
6020 phba->work_status[1] =
6021 readl(phba->sli4_hba.u.if_type2.
6022 ERR2regaddr);
6023 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05006024 "2888 Unrecoverable port error "
6025 "following POST: port status reg "
6026 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05006027 "error 1=0x%x, error 2=0x%x\n",
6028 reg_data.word0,
6029 portsmphr_reg.word0,
6030 phba->work_status[0],
6031 phba->work_status[1]);
6032 port_error = -ENODEV;
6033 }
6034 break;
6035 case LPFC_SLI_INTF_IF_TYPE_1:
6036 default:
6037 break;
6038 }
James Smart28baac72010-02-12 14:42:03 -05006039 }
James Smartda0436e2009-05-22 14:51:39 -04006040 return port_error;
6041}
6042
6043/**
6044 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
6045 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05006046 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04006047 *
6048 * This routine is invoked to set up SLI4 BAR0 PCI config space register
6049 * memory map.
6050 **/
6051static void
James Smart2fcee4b2010-12-15 17:57:46 -05006052lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04006053{
James Smart2fcee4b2010-12-15 17:57:46 -05006054 switch (if_type) {
6055 case LPFC_SLI_INTF_IF_TYPE_0:
6056 phba->sli4_hba.u.if_type0.UERRLOregaddr =
6057 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
6058 phba->sli4_hba.u.if_type0.UERRHIregaddr =
6059 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
6060 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
6061 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
6062 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
6063 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
6064 phba->sli4_hba.SLIINTFregaddr =
6065 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6066 break;
6067 case LPFC_SLI_INTF_IF_TYPE_2:
6068 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006069 phba->sli4_hba.conf_regs_memmap_p +
6070 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006071 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006072 phba->sli4_hba.conf_regs_memmap_p +
6073 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006074 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006075 phba->sli4_hba.conf_regs_memmap_p +
6076 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006077 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006078 phba->sli4_hba.conf_regs_memmap_p +
6079 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006080 phba->sli4_hba.SLIINTFregaddr =
6081 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6082 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006083 phba->sli4_hba.conf_regs_memmap_p +
6084 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006085 phba->sli4_hba.RQDBregaddr =
6086 phba->sli4_hba.conf_regs_memmap_p + LPFC_RQ_DOORBELL;
6087 phba->sli4_hba.WQDBregaddr =
6088 phba->sli4_hba.conf_regs_memmap_p + LPFC_WQ_DOORBELL;
6089 phba->sli4_hba.EQCQDBregaddr =
6090 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
6091 phba->sli4_hba.MQDBregaddr =
6092 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
6093 phba->sli4_hba.BMBXregaddr =
6094 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
6095 break;
6096 case LPFC_SLI_INTF_IF_TYPE_1:
6097 default:
6098 dev_printk(KERN_ERR, &phba->pcidev->dev,
6099 "FATAL - unsupported SLI4 interface type - %d\n",
6100 if_type);
6101 break;
6102 }
James Smartda0436e2009-05-22 14:51:39 -04006103}
6104
6105/**
6106 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
6107 * @phba: pointer to lpfc hba data structure.
6108 *
6109 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
6110 * memory map.
6111 **/
6112static void
6113lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
6114{
James Smart2fcee4b2010-12-15 17:57:46 -05006115 phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
6116 LPFC_SLIPORT_IF0_SMPHR;
James Smartda0436e2009-05-22 14:51:39 -04006117 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006118 LPFC_HST_ISR0;
James Smartda0436e2009-05-22 14:51:39 -04006119 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006120 LPFC_HST_IMR0;
James Smartda0436e2009-05-22 14:51:39 -04006121 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006122 LPFC_HST_ISCR0;
James Smartda0436e2009-05-22 14:51:39 -04006123}
6124
6125/**
6126 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
6127 * @phba: pointer to lpfc hba data structure.
6128 * @vf: virtual function number
6129 *
6130 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
6131 * based on the given viftual function number, @vf.
6132 *
6133 * Return 0 if successful, otherwise -ENODEV.
6134 **/
6135static int
6136lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
6137{
6138 if (vf > LPFC_VIR_FUNC_MAX)
6139 return -ENODEV;
6140
6141 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6142 vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL);
6143 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6144 vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL);
6145 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6146 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
6147 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6148 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
6149 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6150 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
6151 return 0;
6152}
6153
6154/**
6155 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
6156 * @phba: pointer to lpfc hba data structure.
6157 *
6158 * This routine is invoked to create the bootstrap mailbox
6159 * region consistent with the SLI-4 interface spec. This
6160 * routine allocates all memory necessary to communicate
6161 * mailbox commands to the port and sets up all alignment
6162 * needs. No locks are expected to be held when calling
6163 * this routine.
6164 *
6165 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006166 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04006167 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04006168 **/
6169static int
6170lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
6171{
6172 uint32_t bmbx_size;
6173 struct lpfc_dmabuf *dmabuf;
6174 struct dma_address *dma_address;
6175 uint32_t pa_addr;
6176 uint64_t phys_addr;
6177
6178 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6179 if (!dmabuf)
6180 return -ENOMEM;
6181
6182 /*
6183 * The bootstrap mailbox region is comprised of 2 parts
6184 * plus an alignment restriction of 16 bytes.
6185 */
6186 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
6187 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
6188 bmbx_size,
6189 &dmabuf->phys,
6190 GFP_KERNEL);
6191 if (!dmabuf->virt) {
6192 kfree(dmabuf);
6193 return -ENOMEM;
6194 }
6195 memset(dmabuf->virt, 0, bmbx_size);
6196
6197 /*
6198 * Initialize the bootstrap mailbox pointers now so that the register
6199 * operations are simple later. The mailbox dma address is required
6200 * to be 16-byte aligned. Also align the virtual memory as each
6201 * maibox is copied into the bmbx mailbox region before issuing the
6202 * command to the port.
6203 */
6204 phba->sli4_hba.bmbx.dmabuf = dmabuf;
6205 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
6206
6207 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
6208 LPFC_ALIGN_16_BYTE);
6209 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
6210 LPFC_ALIGN_16_BYTE);
6211
6212 /*
6213 * Set the high and low physical addresses now. The SLI4 alignment
6214 * requirement is 16 bytes and the mailbox is posted to the port
6215 * as two 30-bit addresses. The other data is a bit marking whether
6216 * the 30-bit address is the high or low address.
6217 * Upcast bmbx aphys to 64bits so shift instruction compiles
6218 * clean on 32 bit machines.
6219 */
6220 dma_address = &phba->sli4_hba.bmbx.dma_address;
6221 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
6222 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
6223 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
6224 LPFC_BMBX_BIT1_ADDR_HI);
6225
6226 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
6227 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
6228 LPFC_BMBX_BIT1_ADDR_LO);
6229 return 0;
6230}
6231
6232/**
6233 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
6234 * @phba: pointer to lpfc hba data structure.
6235 *
6236 * This routine is invoked to teardown the bootstrap mailbox
6237 * region and release all host resources. This routine requires
6238 * the caller to ensure all mailbox commands recovered, no
6239 * additional mailbox comands are sent, and interrupts are disabled
6240 * before calling this routine.
6241 *
6242 **/
6243static void
6244lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
6245{
6246 dma_free_coherent(&phba->pcidev->dev,
6247 phba->sli4_hba.bmbx.bmbx_size,
6248 phba->sli4_hba.bmbx.dmabuf->virt,
6249 phba->sli4_hba.bmbx.dmabuf->phys);
6250
6251 kfree(phba->sli4_hba.bmbx.dmabuf);
6252 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
6253}
6254
6255/**
6256 * lpfc_sli4_read_config - Get the config parameters.
6257 * @phba: pointer to lpfc hba data structure.
6258 *
6259 * This routine is invoked to read the configuration parameters from the HBA.
6260 * The configuration parameters are used to set the base and maximum values
6261 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
6262 * allocation for the port.
6263 *
6264 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006265 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006266 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006267 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006268 **/
James Smartff78d8f2011-12-13 13:21:35 -05006269int
James Smartda0436e2009-05-22 14:51:39 -04006270lpfc_sli4_read_config(struct lpfc_hba *phba)
6271{
6272 LPFC_MBOXQ_t *pmb;
6273 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04006274 union lpfc_sli4_cfg_shdr *shdr;
6275 uint32_t shdr_status, shdr_add_status;
6276 struct lpfc_mbx_get_func_cfg *get_func_cfg;
6277 struct lpfc_rsrc_desc_fcfcoe *desc;
6278 uint32_t desc_count;
6279 int length, i, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04006280
6281 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6282 if (!pmb) {
6283 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6284 "2011 Unable to allocate memory for issuing "
6285 "SLI_CONFIG_SPECIAL mailbox command\n");
6286 return -ENOMEM;
6287 }
6288
6289 lpfc_read_config(phba, pmb);
6290
6291 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
6292 if (rc != MBX_SUCCESS) {
6293 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6294 "2012 Mailbox failed , mbxCmd x%x "
6295 "READ_CONFIG, mbxStatus x%x\n",
6296 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6297 bf_get(lpfc_mqe_status, &pmb->u.mqe));
6298 rc = -EIO;
6299 } else {
6300 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05006301 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
6302 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
6303 phba->sli4_hba.lnk_info.lnk_tp =
6304 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
6305 phba->sli4_hba.lnk_info.lnk_no =
6306 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
6307 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6308 "3081 lnk_type:%d, lnk_numb:%d\n",
6309 phba->sli4_hba.lnk_info.lnk_tp,
6310 phba->sli4_hba.lnk_info.lnk_no);
6311 } else
6312 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6313 "3082 Mailbox (x%x) returned ldv:x0\n",
6314 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart6d368e52011-05-24 11:44:12 -04006315 phba->sli4_hba.extents_in_use =
6316 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04006317 phba->sli4_hba.max_cfg_param.max_xri =
6318 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
6319 phba->sli4_hba.max_cfg_param.xri_base =
6320 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
6321 phba->sli4_hba.max_cfg_param.max_vpi =
6322 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
6323 phba->sli4_hba.max_cfg_param.vpi_base =
6324 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
6325 phba->sli4_hba.max_cfg_param.max_rpi =
6326 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
6327 phba->sli4_hba.max_cfg_param.rpi_base =
6328 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
6329 phba->sli4_hba.max_cfg_param.max_vfi =
6330 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
6331 phba->sli4_hba.max_cfg_param.vfi_base =
6332 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
6333 phba->sli4_hba.max_cfg_param.max_fcfi =
6334 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04006335 phba->sli4_hba.max_cfg_param.max_eq =
6336 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
6337 phba->sli4_hba.max_cfg_param.max_rq =
6338 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
6339 phba->sli4_hba.max_cfg_param.max_wq =
6340 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
6341 phba->sli4_hba.max_cfg_param.max_cq =
6342 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
6343 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
6344 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
6345 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
6346 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05006347 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
6348 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04006349 phba->max_vports = phba->max_vpi;
6350 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04006351 "2003 cfg params Extents? %d "
6352 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04006353 "VPI(B:%d M:%d) "
6354 "VFI(B:%d M:%d) "
6355 "RPI(B:%d M:%d) "
James Smart6d368e52011-05-24 11:44:12 -04006356 "FCFI(Count:%d)\n",
6357 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04006358 phba->sli4_hba.max_cfg_param.xri_base,
6359 phba->sli4_hba.max_cfg_param.max_xri,
6360 phba->sli4_hba.max_cfg_param.vpi_base,
6361 phba->sli4_hba.max_cfg_param.max_vpi,
6362 phba->sli4_hba.max_cfg_param.vfi_base,
6363 phba->sli4_hba.max_cfg_param.max_vfi,
6364 phba->sli4_hba.max_cfg_param.rpi_base,
6365 phba->sli4_hba.max_cfg_param.max_rpi,
James Smartda0436e2009-05-22 14:51:39 -04006366 phba->sli4_hba.max_cfg_param.max_fcfi);
6367 }
James Smart912e3ac2011-05-24 11:42:11 -04006368
6369 if (rc)
6370 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04006371
6372 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smartb92938b2010-06-07 15:24:12 -04006373 if (phba->cfg_hba_queue_depth >
6374 (phba->sli4_hba.max_cfg_param.max_xri -
6375 lpfc_sli4_get_els_iocb_cnt(phba)))
James Smartda0436e2009-05-22 14:51:39 -04006376 phba->cfg_hba_queue_depth =
James Smartb92938b2010-06-07 15:24:12 -04006377 phba->sli4_hba.max_cfg_param.max_xri -
6378 lpfc_sli4_get_els_iocb_cnt(phba);
James Smart912e3ac2011-05-24 11:42:11 -04006379
6380 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
6381 LPFC_SLI_INTF_IF_TYPE_2)
6382 goto read_cfg_out;
6383
6384 /* get the pf# and vf# for SLI4 if_type 2 port */
6385 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
6386 sizeof(struct lpfc_sli4_cfg_mhdr));
6387 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
6388 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
6389 length, LPFC_SLI4_MBX_EMBED);
6390
6391 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
6392 shdr = (union lpfc_sli4_cfg_shdr *)
6393 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
6394 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6395 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6396 if (rc || shdr_status || shdr_add_status) {
6397 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6398 "3026 Mailbox failed , mbxCmd x%x "
6399 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
6400 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6401 bf_get(lpfc_mqe_status, &pmb->u.mqe));
6402 rc = -EIO;
6403 goto read_cfg_out;
6404 }
6405
6406 /* search for fc_fcoe resrouce descriptor */
6407 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
6408 desc_count = get_func_cfg->func_cfg.rsrc_desc_count;
6409
6410 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
6411 desc = (struct lpfc_rsrc_desc_fcfcoe *)
6412 &get_func_cfg->func_cfg.desc[i];
6413 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
6414 bf_get(lpfc_rsrc_desc_pcie_type, desc)) {
6415 phba->sli4_hba.iov.pf_number =
6416 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
6417 phba->sli4_hba.iov.vf_number =
6418 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
6419 break;
6420 }
6421 }
6422
6423 if (i < LPFC_RSRC_DESC_MAX_NUM)
6424 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6425 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
6426 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
6427 phba->sli4_hba.iov.vf_number);
6428 else {
6429 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6430 "3028 GET_FUNCTION_CONFIG: failed to find "
6431 "Resrouce Descriptor:x%x\n",
6432 LPFC_RSRC_DESC_TYPE_FCFCOE);
6433 rc = -EIO;
6434 }
6435
6436read_cfg_out:
6437 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04006438 return rc;
6439}
6440
6441/**
James Smart2fcee4b2010-12-15 17:57:46 -05006442 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04006443 * @phba: pointer to lpfc hba data structure.
6444 *
James Smart2fcee4b2010-12-15 17:57:46 -05006445 * This routine is invoked to setup the port-side endian order when
6446 * the port if_type is 0. This routine has no function for other
6447 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04006448 *
6449 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006450 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006451 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006452 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006453 **/
6454static int
6455lpfc_setup_endian_order(struct lpfc_hba *phba)
6456{
6457 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05006458 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04006459 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
6460 HOST_ENDIAN_HIGH_WORD1};
6461
James Smart2fcee4b2010-12-15 17:57:46 -05006462 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
6463 switch (if_type) {
6464 case LPFC_SLI_INTF_IF_TYPE_0:
6465 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
6466 GFP_KERNEL);
6467 if (!mboxq) {
6468 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6469 "0492 Unable to allocate memory for "
6470 "issuing SLI_CONFIG_SPECIAL mailbox "
6471 "command\n");
6472 return -ENOMEM;
6473 }
James Smartda0436e2009-05-22 14:51:39 -04006474
James Smart2fcee4b2010-12-15 17:57:46 -05006475 /*
6476 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
6477 * two words to contain special data values and no other data.
6478 */
6479 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
6480 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
6481 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6482 if (rc != MBX_SUCCESS) {
6483 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6484 "0493 SLI_CONFIG_SPECIAL mailbox "
6485 "failed with status x%x\n",
6486 rc);
6487 rc = -EIO;
6488 }
6489 mempool_free(mboxq, phba->mbox_mem_pool);
6490 break;
6491 case LPFC_SLI_INTF_IF_TYPE_2:
6492 case LPFC_SLI_INTF_IF_TYPE_1:
6493 default:
6494 break;
James Smartda0436e2009-05-22 14:51:39 -04006495 }
James Smartda0436e2009-05-22 14:51:39 -04006496 return rc;
6497}
6498
6499/**
James Smart5350d872011-10-10 21:33:49 -04006500 * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts
James Smartda0436e2009-05-22 14:51:39 -04006501 * @phba: pointer to lpfc hba data structure.
6502 *
James Smart5350d872011-10-10 21:33:49 -04006503 * This routine is invoked to check the user settable queue counts for EQs and
6504 * CQs. after this routine is called the counts will be set to valid values that
6505 * adhere to the constraints of the system's interrupt vectors and the port's
6506 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04006507 *
6508 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006509 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006510 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04006511 **/
6512static int
James Smart5350d872011-10-10 21:33:49 -04006513lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04006514{
James Smartda0436e2009-05-22 14:51:39 -04006515 int cfg_fcp_wq_count;
6516 int cfg_fcp_eq_count;
6517
6518 /*
6519 * Sanity check for confiugred queue parameters against the run-time
6520 * device parameters
6521 */
6522
6523 /* Sanity check on FCP fast-path WQ parameters */
6524 cfg_fcp_wq_count = phba->cfg_fcp_wq_count;
6525 if (cfg_fcp_wq_count >
6526 (phba->sli4_hba.max_cfg_param.max_wq - LPFC_SP_WQN_DEF)) {
6527 cfg_fcp_wq_count = phba->sli4_hba.max_cfg_param.max_wq -
6528 LPFC_SP_WQN_DEF;
6529 if (cfg_fcp_wq_count < LPFC_FP_WQN_MIN) {
6530 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6531 "2581 Not enough WQs (%d) from "
6532 "the pci function for supporting "
6533 "FCP WQs (%d)\n",
6534 phba->sli4_hba.max_cfg_param.max_wq,
6535 phba->cfg_fcp_wq_count);
6536 goto out_error;
6537 }
6538 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6539 "2582 Not enough WQs (%d) from the pci "
6540 "function for supporting the requested "
6541 "FCP WQs (%d), the actual FCP WQs can "
6542 "be supported: %d\n",
6543 phba->sli4_hba.max_cfg_param.max_wq,
6544 phba->cfg_fcp_wq_count, cfg_fcp_wq_count);
6545 }
6546 /* The actual number of FCP work queues adopted */
6547 phba->cfg_fcp_wq_count = cfg_fcp_wq_count;
6548
6549 /* Sanity check on FCP fast-path EQ parameters */
6550 cfg_fcp_eq_count = phba->cfg_fcp_eq_count;
6551 if (cfg_fcp_eq_count >
6552 (phba->sli4_hba.max_cfg_param.max_eq - LPFC_SP_EQN_DEF)) {
6553 cfg_fcp_eq_count = phba->sli4_hba.max_cfg_param.max_eq -
6554 LPFC_SP_EQN_DEF;
6555 if (cfg_fcp_eq_count < LPFC_FP_EQN_MIN) {
6556 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6557 "2574 Not enough EQs (%d) from the "
6558 "pci function for supporting FCP "
6559 "EQs (%d)\n",
6560 phba->sli4_hba.max_cfg_param.max_eq,
6561 phba->cfg_fcp_eq_count);
6562 goto out_error;
6563 }
6564 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6565 "2575 Not enough EQs (%d) from the pci "
6566 "function for supporting the requested "
6567 "FCP EQs (%d), the actual FCP EQs can "
6568 "be supported: %d\n",
6569 phba->sli4_hba.max_cfg_param.max_eq,
6570 phba->cfg_fcp_eq_count, cfg_fcp_eq_count);
6571 }
6572 /* It does not make sense to have more EQs than WQs */
6573 if (cfg_fcp_eq_count > phba->cfg_fcp_wq_count) {
6574 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smart6a9c52c2009-10-02 15:16:51 -04006575 "2593 The FCP EQ count(%d) cannot be greater "
6576 "than the FCP WQ count(%d), limiting the "
6577 "FCP EQ count to %d\n", cfg_fcp_eq_count,
James Smartda0436e2009-05-22 14:51:39 -04006578 phba->cfg_fcp_wq_count,
6579 phba->cfg_fcp_wq_count);
6580 cfg_fcp_eq_count = phba->cfg_fcp_wq_count;
6581 }
6582 /* The actual number of FCP event queues adopted */
6583 phba->cfg_fcp_eq_count = cfg_fcp_eq_count;
6584 /* The overall number of event queues used */
6585 phba->sli4_hba.cfg_eqn = phba->cfg_fcp_eq_count + LPFC_SP_EQN_DEF;
6586
James Smartda0436e2009-05-22 14:51:39 -04006587 /* Get EQ depth from module parameter, fake the default for now */
6588 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
6589 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
6590
James Smart5350d872011-10-10 21:33:49 -04006591 /* Get CQ depth from module parameter, fake the default for now */
6592 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
6593 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
6594
6595 return 0;
6596out_error:
6597 return -ENOMEM;
6598}
6599
6600/**
6601 * lpfc_sli4_queue_create - Create all the SLI4 queues
6602 * @phba: pointer to lpfc hba data structure.
6603 *
6604 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
6605 * operation. For each SLI4 queue type, the parameters such as queue entry
6606 * count (queue depth) shall be taken from the module parameter. For now,
6607 * we just use some constant number as place holder.
6608 *
6609 * Return codes
6610 * 0 - sucessful
6611 * -ENOMEM - No availble memory
6612 * -EIO - The mailbox failed to complete successfully.
6613 **/
6614int
6615lpfc_sli4_queue_create(struct lpfc_hba *phba)
6616{
6617 struct lpfc_queue *qdesc;
6618 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
6619
6620 /*
6621 * Create Event Queues (EQs)
6622 */
6623
James Smartda0436e2009-05-22 14:51:39 -04006624 /* Create slow path event queue */
6625 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
6626 phba->sli4_hba.eq_ecount);
6627 if (!qdesc) {
6628 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6629 "0496 Failed allocate slow-path EQ\n");
6630 goto out_error;
6631 }
6632 phba->sli4_hba.sp_eq = qdesc;
6633
James Smart5350d872011-10-10 21:33:49 -04006634 /*
6635 * Create fast-path FCP Event Queue(s). The cfg_fcp_eq_count can be
6636 * zero whenever there is exactly one interrupt vector. This is not
6637 * an error.
6638 */
6639 if (phba->cfg_fcp_eq_count) {
6640 phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) *
6641 phba->cfg_fcp_eq_count), GFP_KERNEL);
6642 if (!phba->sli4_hba.fp_eq) {
6643 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6644 "2576 Failed allocate memory for "
6645 "fast-path EQ record array\n");
6646 goto out_free_sp_eq;
6647 }
James Smartda0436e2009-05-22 14:51:39 -04006648 }
6649 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
6650 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
6651 phba->sli4_hba.eq_ecount);
6652 if (!qdesc) {
6653 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6654 "0497 Failed allocate fast-path EQ\n");
6655 goto out_free_fp_eq;
6656 }
6657 phba->sli4_hba.fp_eq[fcp_eqidx] = qdesc;
6658 }
6659
6660 /*
6661 * Create Complete Queues (CQs)
6662 */
6663
James Smartda0436e2009-05-22 14:51:39 -04006664 /* Create slow-path Mailbox Command Complete Queue */
6665 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
6666 phba->sli4_hba.cq_ecount);
6667 if (!qdesc) {
6668 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6669 "0500 Failed allocate slow-path mailbox CQ\n");
6670 goto out_free_fp_eq;
6671 }
6672 phba->sli4_hba.mbx_cq = qdesc;
6673
6674 /* Create slow-path ELS Complete Queue */
6675 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
6676 phba->sli4_hba.cq_ecount);
6677 if (!qdesc) {
6678 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6679 "0501 Failed allocate slow-path ELS CQ\n");
6680 goto out_free_mbx_cq;
6681 }
6682 phba->sli4_hba.els_cq = qdesc;
6683
James Smartda0436e2009-05-22 14:51:39 -04006684
James Smart5350d872011-10-10 21:33:49 -04006685 /*
6686 * Create fast-path FCP Completion Queue(s), one-to-one with FCP EQs.
6687 * If there are no FCP EQs then create exactly one FCP CQ.
6688 */
6689 if (phba->cfg_fcp_eq_count)
6690 phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
6691 phba->cfg_fcp_eq_count),
6692 GFP_KERNEL);
6693 else
6694 phba->sli4_hba.fcp_cq = kzalloc(sizeof(struct lpfc_queue *),
6695 GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04006696 if (!phba->sli4_hba.fcp_cq) {
6697 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6698 "2577 Failed allocate memory for fast-path "
6699 "CQ record array\n");
James Smart4d9ab992009-10-02 15:16:39 -04006700 goto out_free_els_cq;
James Smartda0436e2009-05-22 14:51:39 -04006701 }
James Smart5350d872011-10-10 21:33:49 -04006702 fcp_cqidx = 0;
6703 do {
James Smartda0436e2009-05-22 14:51:39 -04006704 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
6705 phba->sli4_hba.cq_ecount);
6706 if (!qdesc) {
6707 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6708 "0499 Failed allocate fast-path FCP "
6709 "CQ (%d)\n", fcp_cqidx);
6710 goto out_free_fcp_cq;
6711 }
6712 phba->sli4_hba.fcp_cq[fcp_cqidx] = qdesc;
James Smart5350d872011-10-10 21:33:49 -04006713 } while (++fcp_cqidx < phba->cfg_fcp_eq_count);
James Smartda0436e2009-05-22 14:51:39 -04006714
6715 /* Create Mailbox Command Queue */
6716 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
6717 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
6718
6719 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
6720 phba->sli4_hba.mq_ecount);
6721 if (!qdesc) {
6722 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6723 "0505 Failed allocate slow-path MQ\n");
6724 goto out_free_fcp_cq;
6725 }
6726 phba->sli4_hba.mbx_wq = qdesc;
6727
6728 /*
6729 * Create all the Work Queues (WQs)
6730 */
6731 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
6732 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
6733
6734 /* Create slow-path ELS Work Queue */
6735 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
6736 phba->sli4_hba.wq_ecount);
6737 if (!qdesc) {
6738 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6739 "0504 Failed allocate slow-path ELS WQ\n");
6740 goto out_free_mbx_wq;
6741 }
6742 phba->sli4_hba.els_wq = qdesc;
6743
6744 /* Create fast-path FCP Work Queue(s) */
6745 phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
6746 phba->cfg_fcp_wq_count), GFP_KERNEL);
6747 if (!phba->sli4_hba.fcp_wq) {
6748 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6749 "2578 Failed allocate memory for fast-path "
6750 "WQ record array\n");
6751 goto out_free_els_wq;
6752 }
6753 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
6754 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
6755 phba->sli4_hba.wq_ecount);
6756 if (!qdesc) {
6757 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6758 "0503 Failed allocate fast-path FCP "
6759 "WQ (%d)\n", fcp_wqidx);
6760 goto out_free_fcp_wq;
6761 }
6762 phba->sli4_hba.fcp_wq[fcp_wqidx] = qdesc;
6763 }
6764
6765 /*
6766 * Create Receive Queue (RQ)
6767 */
6768 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
6769 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
6770
6771 /* Create Receive Queue for header */
6772 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
6773 phba->sli4_hba.rq_ecount);
6774 if (!qdesc) {
6775 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6776 "0506 Failed allocate receive HRQ\n");
6777 goto out_free_fcp_wq;
6778 }
6779 phba->sli4_hba.hdr_rq = qdesc;
6780
6781 /* Create Receive Queue for data */
6782 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
6783 phba->sli4_hba.rq_ecount);
6784 if (!qdesc) {
6785 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6786 "0507 Failed allocate receive DRQ\n");
6787 goto out_free_hdr_rq;
6788 }
6789 phba->sli4_hba.dat_rq = qdesc;
6790
6791 return 0;
6792
6793out_free_hdr_rq:
6794 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
6795 phba->sli4_hba.hdr_rq = NULL;
6796out_free_fcp_wq:
6797 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) {
6798 lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_wqidx]);
6799 phba->sli4_hba.fcp_wq[fcp_wqidx] = NULL;
6800 }
6801 kfree(phba->sli4_hba.fcp_wq);
James Smart2e90f4b2011-12-13 13:22:37 -05006802 phba->sli4_hba.fcp_wq = NULL;
James Smartda0436e2009-05-22 14:51:39 -04006803out_free_els_wq:
6804 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
6805 phba->sli4_hba.els_wq = NULL;
6806out_free_mbx_wq:
6807 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
6808 phba->sli4_hba.mbx_wq = NULL;
6809out_free_fcp_cq:
6810 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) {
6811 lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_cqidx]);
6812 phba->sli4_hba.fcp_cq[fcp_cqidx] = NULL;
6813 }
6814 kfree(phba->sli4_hba.fcp_cq);
James Smart2e90f4b2011-12-13 13:22:37 -05006815 phba->sli4_hba.fcp_cq = NULL;
James Smartda0436e2009-05-22 14:51:39 -04006816out_free_els_cq:
6817 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
6818 phba->sli4_hba.els_cq = NULL;
6819out_free_mbx_cq:
6820 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
6821 phba->sli4_hba.mbx_cq = NULL;
6822out_free_fp_eq:
6823 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) {
6824 lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_eqidx]);
6825 phba->sli4_hba.fp_eq[fcp_eqidx] = NULL;
6826 }
6827 kfree(phba->sli4_hba.fp_eq);
James Smart2e90f4b2011-12-13 13:22:37 -05006828 phba->sli4_hba.fp_eq = NULL;
James Smartda0436e2009-05-22 14:51:39 -04006829out_free_sp_eq:
6830 lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
6831 phba->sli4_hba.sp_eq = NULL;
6832out_error:
6833 return -ENOMEM;
6834}
6835
6836/**
6837 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
6838 * @phba: pointer to lpfc hba data structure.
6839 *
6840 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
6841 * operation.
6842 *
6843 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006844 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006845 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006846 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006847 **/
James Smart5350d872011-10-10 21:33:49 -04006848void
James Smartda0436e2009-05-22 14:51:39 -04006849lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
6850{
6851 int fcp_qidx;
6852
6853 /* Release mailbox command work queue */
6854 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
6855 phba->sli4_hba.mbx_wq = NULL;
6856
6857 /* Release ELS work queue */
6858 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
6859 phba->sli4_hba.els_wq = NULL;
6860
6861 /* Release FCP work queue */
James Smart2e90f4b2011-12-13 13:22:37 -05006862 if (phba->sli4_hba.fcp_wq != NULL)
6863 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count;
6864 fcp_qidx++)
6865 lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_qidx]);
James Smartda0436e2009-05-22 14:51:39 -04006866 kfree(phba->sli4_hba.fcp_wq);
6867 phba->sli4_hba.fcp_wq = NULL;
6868
6869 /* Release unsolicited receive queue */
6870 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
6871 phba->sli4_hba.hdr_rq = NULL;
6872 lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
6873 phba->sli4_hba.dat_rq = NULL;
6874
James Smartda0436e2009-05-22 14:51:39 -04006875 /* Release ELS complete queue */
6876 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
6877 phba->sli4_hba.els_cq = NULL;
6878
6879 /* Release mailbox command complete queue */
6880 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
6881 phba->sli4_hba.mbx_cq = NULL;
6882
6883 /* Release FCP response complete queue */
James Smart05580562011-05-24 11:40:48 -04006884 fcp_qidx = 0;
James Smart2e90f4b2011-12-13 13:22:37 -05006885 if (phba->sli4_hba.fcp_cq != NULL)
6886 do
6887 lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_qidx]);
6888 while (++fcp_qidx < phba->cfg_fcp_eq_count);
James Smartda0436e2009-05-22 14:51:39 -04006889 kfree(phba->sli4_hba.fcp_cq);
6890 phba->sli4_hba.fcp_cq = NULL;
6891
6892 /* Release fast-path event queue */
James Smart2e90f4b2011-12-13 13:22:37 -05006893 if (phba->sli4_hba.fp_eq != NULL)
6894 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count;
6895 fcp_qidx++)
6896 lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]);
James Smartda0436e2009-05-22 14:51:39 -04006897 kfree(phba->sli4_hba.fp_eq);
6898 phba->sli4_hba.fp_eq = NULL;
6899
6900 /* Release slow-path event queue */
6901 lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
6902 phba->sli4_hba.sp_eq = NULL;
6903
6904 return;
6905}
6906
6907/**
6908 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
6909 * @phba: pointer to lpfc hba data structure.
6910 *
6911 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
6912 * operation.
6913 *
6914 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006915 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006916 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006917 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006918 **/
6919int
6920lpfc_sli4_queue_setup(struct lpfc_hba *phba)
6921{
6922 int rc = -ENOMEM;
6923 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
6924 int fcp_cq_index = 0;
6925
6926 /*
6927 * Set up Event Queues (EQs)
6928 */
6929
6930 /* Set up slow-path event queue */
6931 if (!phba->sli4_hba.sp_eq) {
6932 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6933 "0520 Slow-path EQ not allocated\n");
6934 goto out_error;
6935 }
6936 rc = lpfc_eq_create(phba, phba->sli4_hba.sp_eq,
6937 LPFC_SP_DEF_IMAX);
6938 if (rc) {
6939 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6940 "0521 Failed setup of slow-path EQ: "
6941 "rc = 0x%x\n", rc);
6942 goto out_error;
6943 }
6944 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6945 "2583 Slow-path EQ setup: queue-id=%d\n",
6946 phba->sli4_hba.sp_eq->queue_id);
6947
6948 /* Set up fast-path event queue */
James Smart1b511972011-12-13 13:23:09 -05006949 if (phba->cfg_fcp_eq_count && !phba->sli4_hba.fp_eq) {
James Smart2e90f4b2011-12-13 13:22:37 -05006950 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6951 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05006952 rc = -ENOMEM;
James Smart2e90f4b2011-12-13 13:22:37 -05006953 goto out_destroy_sp_eq;
6954 }
James Smartda0436e2009-05-22 14:51:39 -04006955 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
6956 if (!phba->sli4_hba.fp_eq[fcp_eqidx]) {
6957 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6958 "0522 Fast-path EQ (%d) not "
6959 "allocated\n", fcp_eqidx);
James Smart1b511972011-12-13 13:23:09 -05006960 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04006961 goto out_destroy_fp_eq;
6962 }
6963 rc = lpfc_eq_create(phba, phba->sli4_hba.fp_eq[fcp_eqidx],
6964 phba->cfg_fcp_imax);
6965 if (rc) {
6966 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6967 "0523 Failed setup of fast-path EQ "
6968 "(%d), rc = 0x%x\n", fcp_eqidx, rc);
6969 goto out_destroy_fp_eq;
6970 }
6971 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6972 "2584 Fast-path EQ setup: "
6973 "queue[%d]-id=%d\n", fcp_eqidx,
6974 phba->sli4_hba.fp_eq[fcp_eqidx]->queue_id);
6975 }
6976
6977 /*
6978 * Set up Complete Queues (CQs)
6979 */
6980
6981 /* Set up slow-path MBOX Complete Queue as the first CQ */
6982 if (!phba->sli4_hba.mbx_cq) {
6983 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6984 "0528 Mailbox CQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05006985 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04006986 goto out_destroy_fp_eq;
6987 }
6988 rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, phba->sli4_hba.sp_eq,
6989 LPFC_MCQ, LPFC_MBOX);
6990 if (rc) {
6991 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6992 "0529 Failed setup of slow-path mailbox CQ: "
6993 "rc = 0x%x\n", rc);
6994 goto out_destroy_fp_eq;
6995 }
6996 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6997 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
6998 phba->sli4_hba.mbx_cq->queue_id,
6999 phba->sli4_hba.sp_eq->queue_id);
7000
7001 /* Set up slow-path ELS Complete Queue */
7002 if (!phba->sli4_hba.els_cq) {
7003 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7004 "0530 ELS CQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007005 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007006 goto out_destroy_mbx_cq;
7007 }
7008 rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, phba->sli4_hba.sp_eq,
7009 LPFC_WCQ, LPFC_ELS);
7010 if (rc) {
7011 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7012 "0531 Failed setup of slow-path ELS CQ: "
7013 "rc = 0x%x\n", rc);
7014 goto out_destroy_mbx_cq;
7015 }
7016 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7017 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
7018 phba->sli4_hba.els_cq->queue_id,
7019 phba->sli4_hba.sp_eq->queue_id);
7020
James Smartda0436e2009-05-22 14:51:39 -04007021 /* Set up fast-path FCP Response Complete Queue */
James Smart2e90f4b2011-12-13 13:22:37 -05007022 if (!phba->sli4_hba.fcp_cq) {
7023 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7024 "3148 Fast-path FCP CQ array not "
7025 "allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007026 rc = -ENOMEM;
James Smart2e90f4b2011-12-13 13:22:37 -05007027 goto out_destroy_els_cq;
7028 }
James Smart05580562011-05-24 11:40:48 -04007029 fcp_cqidx = 0;
7030 do {
James Smartda0436e2009-05-22 14:51:39 -04007031 if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
7032 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7033 "0526 Fast-path FCP CQ (%d) not "
7034 "allocated\n", fcp_cqidx);
James Smart1b511972011-12-13 13:23:09 -05007035 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007036 goto out_destroy_fcp_cq;
7037 }
James Smart05580562011-05-24 11:40:48 -04007038 if (phba->cfg_fcp_eq_count)
7039 rc = lpfc_cq_create(phba,
7040 phba->sli4_hba.fcp_cq[fcp_cqidx],
7041 phba->sli4_hba.fp_eq[fcp_cqidx],
7042 LPFC_WCQ, LPFC_FCP);
7043 else
7044 rc = lpfc_cq_create(phba,
7045 phba->sli4_hba.fcp_cq[fcp_cqidx],
7046 phba->sli4_hba.sp_eq,
7047 LPFC_WCQ, LPFC_FCP);
James Smartda0436e2009-05-22 14:51:39 -04007048 if (rc) {
7049 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7050 "0527 Failed setup of fast-path FCP "
7051 "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc);
7052 goto out_destroy_fcp_cq;
7053 }
7054 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7055 "2588 FCP CQ setup: cq[%d]-id=%d, "
James Smart05580562011-05-24 11:40:48 -04007056 "parent %seq[%d]-id=%d\n",
James Smartda0436e2009-05-22 14:51:39 -04007057 fcp_cqidx,
7058 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
James Smart05580562011-05-24 11:40:48 -04007059 (phba->cfg_fcp_eq_count) ? "" : "sp_",
James Smartda0436e2009-05-22 14:51:39 -04007060 fcp_cqidx,
James Smart05580562011-05-24 11:40:48 -04007061 (phba->cfg_fcp_eq_count) ?
7062 phba->sli4_hba.fp_eq[fcp_cqidx]->queue_id :
7063 phba->sli4_hba.sp_eq->queue_id);
7064 } while (++fcp_cqidx < phba->cfg_fcp_eq_count);
James Smartda0436e2009-05-22 14:51:39 -04007065
7066 /*
7067 * Set up all the Work Queues (WQs)
7068 */
7069
7070 /* Set up Mailbox Command Queue */
7071 if (!phba->sli4_hba.mbx_wq) {
7072 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7073 "0538 Slow-path MQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007074 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007075 goto out_destroy_fcp_cq;
7076 }
7077 rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
7078 phba->sli4_hba.mbx_cq, LPFC_MBOX);
7079 if (rc) {
7080 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7081 "0539 Failed setup of slow-path MQ: "
7082 "rc = 0x%x\n", rc);
7083 goto out_destroy_fcp_cq;
7084 }
7085 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7086 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
7087 phba->sli4_hba.mbx_wq->queue_id,
7088 phba->sli4_hba.mbx_cq->queue_id);
7089
7090 /* Set up slow-path ELS Work Queue */
7091 if (!phba->sli4_hba.els_wq) {
7092 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7093 "0536 Slow-path ELS WQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007094 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007095 goto out_destroy_mbx_wq;
7096 }
7097 rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
7098 phba->sli4_hba.els_cq, LPFC_ELS);
7099 if (rc) {
7100 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7101 "0537 Failed setup of slow-path ELS WQ: "
7102 "rc = 0x%x\n", rc);
7103 goto out_destroy_mbx_wq;
7104 }
7105 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7106 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
7107 phba->sli4_hba.els_wq->queue_id,
7108 phba->sli4_hba.els_cq->queue_id);
7109
7110 /* Set up fast-path FCP Work Queue */
James Smart2e90f4b2011-12-13 13:22:37 -05007111 if (!phba->sli4_hba.fcp_wq) {
7112 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7113 "3149 Fast-path FCP WQ array not "
7114 "allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007115 rc = -ENOMEM;
James Smart2e90f4b2011-12-13 13:22:37 -05007116 goto out_destroy_els_wq;
7117 }
James Smartda0436e2009-05-22 14:51:39 -04007118 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
7119 if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
7120 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7121 "0534 Fast-path FCP WQ (%d) not "
7122 "allocated\n", fcp_wqidx);
James Smart1b511972011-12-13 13:23:09 -05007123 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007124 goto out_destroy_fcp_wq;
7125 }
7126 rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
7127 phba->sli4_hba.fcp_cq[fcp_cq_index],
7128 LPFC_FCP);
7129 if (rc) {
7130 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7131 "0535 Failed setup of fast-path FCP "
7132 "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc);
7133 goto out_destroy_fcp_wq;
7134 }
7135 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7136 "2591 FCP WQ setup: wq[%d]-id=%d, "
7137 "parent cq[%d]-id=%d\n",
7138 fcp_wqidx,
7139 phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
7140 fcp_cq_index,
7141 phba->sli4_hba.fcp_cq[fcp_cq_index]->queue_id);
7142 /* Round robin FCP Work Queue's Completion Queue assignment */
James Smart05580562011-05-24 11:40:48 -04007143 if (phba->cfg_fcp_eq_count)
7144 fcp_cq_index = ((fcp_cq_index + 1) %
7145 phba->cfg_fcp_eq_count);
James Smartda0436e2009-05-22 14:51:39 -04007146 }
7147
7148 /*
7149 * Create Receive Queue (RQ)
7150 */
7151 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
7152 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7153 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007154 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007155 goto out_destroy_fcp_wq;
7156 }
James Smart73d91e52011-10-10 21:32:10 -04007157
7158 lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
7159 lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
7160
James Smartda0436e2009-05-22 14:51:39 -04007161 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04007162 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04007163 if (rc) {
7164 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7165 "0541 Failed setup of Receive Queue: "
7166 "rc = 0x%x\n", rc);
7167 goto out_destroy_fcp_wq;
7168 }
James Smart73d91e52011-10-10 21:32:10 -04007169
James Smartda0436e2009-05-22 14:51:39 -04007170 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7171 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
7172 "parent cq-id=%d\n",
7173 phba->sli4_hba.hdr_rq->queue_id,
7174 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04007175 phba->sli4_hba.els_cq->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007176 return 0;
7177
7178out_destroy_fcp_wq:
7179 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
7180 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
James Smart2e90f4b2011-12-13 13:22:37 -05007181out_destroy_els_wq:
James Smartda0436e2009-05-22 14:51:39 -04007182 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7183out_destroy_mbx_wq:
7184 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
7185out_destroy_fcp_cq:
7186 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
7187 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
James Smart2e90f4b2011-12-13 13:22:37 -05007188out_destroy_els_cq:
James Smartda0436e2009-05-22 14:51:39 -04007189 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
7190out_destroy_mbx_cq:
7191 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
7192out_destroy_fp_eq:
7193 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
7194 lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_eqidx]);
James Smart2e90f4b2011-12-13 13:22:37 -05007195out_destroy_sp_eq:
James Smartda0436e2009-05-22 14:51:39 -04007196 lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
7197out_error:
7198 return rc;
7199}
7200
7201/**
7202 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
7203 * @phba: pointer to lpfc hba data structure.
7204 *
7205 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
7206 * operation.
7207 *
7208 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007209 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007210 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007211 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007212 **/
7213void
7214lpfc_sli4_queue_unset(struct lpfc_hba *phba)
7215{
7216 int fcp_qidx;
7217
7218 /* Unset mailbox command work queue */
7219 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
7220 /* Unset ELS work queue */
7221 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7222 /* Unset unsolicited receive queue */
7223 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
7224 /* Unset FCP work queue */
7225 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
7226 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
7227 /* Unset mailbox command complete queue */
7228 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
7229 /* Unset ELS complete queue */
7230 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
James Smartda0436e2009-05-22 14:51:39 -04007231 /* Unset FCP response complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05007232 if (phba->sli4_hba.fcp_cq) {
7233 fcp_qidx = 0;
7234 do {
7235 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
7236 } while (++fcp_qidx < phba->cfg_fcp_eq_count);
7237 }
James Smartda0436e2009-05-22 14:51:39 -04007238 /* Unset fast-path event queue */
James Smart2e90f4b2011-12-13 13:22:37 -05007239 if (phba->sli4_hba.fp_eq) {
7240 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count;
7241 fcp_qidx++)
7242 lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_qidx]);
7243 }
James Smartda0436e2009-05-22 14:51:39 -04007244 /* Unset slow-path event queue */
7245 lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
7246}
7247
7248/**
7249 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
7250 * @phba: pointer to lpfc hba data structure.
7251 *
7252 * This routine is invoked to allocate and set up a pool of completion queue
7253 * events. The body of the completion queue event is a completion queue entry
7254 * CQE. For now, this pool is used for the interrupt service routine to queue
7255 * the following HBA completion queue events for the worker thread to process:
7256 * - Mailbox asynchronous events
7257 * - Receive queue completion unsolicited events
7258 * Later, this can be used for all the slow-path events.
7259 *
7260 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007261 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007262 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007263 **/
7264static int
7265lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
7266{
7267 struct lpfc_cq_event *cq_event;
7268 int i;
7269
7270 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
7271 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
7272 if (!cq_event)
7273 goto out_pool_create_fail;
7274 list_add_tail(&cq_event->list,
7275 &phba->sli4_hba.sp_cqe_event_pool);
7276 }
7277 return 0;
7278
7279out_pool_create_fail:
7280 lpfc_sli4_cq_event_pool_destroy(phba);
7281 return -ENOMEM;
7282}
7283
7284/**
7285 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
7286 * @phba: pointer to lpfc hba data structure.
7287 *
7288 * This routine is invoked to free the pool of completion queue events at
7289 * driver unload time. Note that, it is the responsibility of the driver
7290 * cleanup routine to free all the outstanding completion-queue events
7291 * allocated from this pool back into the pool before invoking this routine
7292 * to destroy the pool.
7293 **/
7294static void
7295lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
7296{
7297 struct lpfc_cq_event *cq_event, *next_cq_event;
7298
7299 list_for_each_entry_safe(cq_event, next_cq_event,
7300 &phba->sli4_hba.sp_cqe_event_pool, list) {
7301 list_del(&cq_event->list);
7302 kfree(cq_event);
7303 }
7304}
7305
7306/**
7307 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7308 * @phba: pointer to lpfc hba data structure.
7309 *
7310 * This routine is the lock free version of the API invoked to allocate a
7311 * completion-queue event from the free pool.
7312 *
7313 * Return: Pointer to the newly allocated completion-queue event if successful
7314 * NULL otherwise.
7315 **/
7316struct lpfc_cq_event *
7317__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
7318{
7319 struct lpfc_cq_event *cq_event = NULL;
7320
7321 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
7322 struct lpfc_cq_event, list);
7323 return cq_event;
7324}
7325
7326/**
7327 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7328 * @phba: pointer to lpfc hba data structure.
7329 *
7330 * This routine is the lock version of the API invoked to allocate a
7331 * completion-queue event from the free pool.
7332 *
7333 * Return: Pointer to the newly allocated completion-queue event if successful
7334 * NULL otherwise.
7335 **/
7336struct lpfc_cq_event *
7337lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
7338{
7339 struct lpfc_cq_event *cq_event;
7340 unsigned long iflags;
7341
7342 spin_lock_irqsave(&phba->hbalock, iflags);
7343 cq_event = __lpfc_sli4_cq_event_alloc(phba);
7344 spin_unlock_irqrestore(&phba->hbalock, iflags);
7345 return cq_event;
7346}
7347
7348/**
7349 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7350 * @phba: pointer to lpfc hba data structure.
7351 * @cq_event: pointer to the completion queue event to be freed.
7352 *
7353 * This routine is the lock free version of the API invoked to release a
7354 * completion-queue event back into the free pool.
7355 **/
7356void
7357__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
7358 struct lpfc_cq_event *cq_event)
7359{
7360 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
7361}
7362
7363/**
7364 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7365 * @phba: pointer to lpfc hba data structure.
7366 * @cq_event: pointer to the completion queue event to be freed.
7367 *
7368 * This routine is the lock version of the API invoked to release a
7369 * completion-queue event back into the free pool.
7370 **/
7371void
7372lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
7373 struct lpfc_cq_event *cq_event)
7374{
7375 unsigned long iflags;
7376 spin_lock_irqsave(&phba->hbalock, iflags);
7377 __lpfc_sli4_cq_event_release(phba, cq_event);
7378 spin_unlock_irqrestore(&phba->hbalock, iflags);
7379}
7380
7381/**
7382 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
7383 * @phba: pointer to lpfc hba data structure.
7384 *
7385 * This routine is to free all the pending completion-queue events to the
7386 * back into the free pool for device reset.
7387 **/
7388static void
7389lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
7390{
7391 LIST_HEAD(cqelist);
7392 struct lpfc_cq_event *cqe;
7393 unsigned long iflags;
7394
7395 /* Retrieve all the pending WCQEs from pending WCQE lists */
7396 spin_lock_irqsave(&phba->hbalock, iflags);
7397 /* Pending FCP XRI abort events */
7398 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
7399 &cqelist);
7400 /* Pending ELS XRI abort events */
7401 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
7402 &cqelist);
7403 /* Pending asynnc events */
7404 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
7405 &cqelist);
7406 spin_unlock_irqrestore(&phba->hbalock, iflags);
7407
7408 while (!list_empty(&cqelist)) {
7409 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
7410 lpfc_sli4_cq_event_release(phba, cqe);
7411 }
7412}
7413
7414/**
7415 * lpfc_pci_function_reset - Reset pci function.
7416 * @phba: pointer to lpfc hba data structure.
7417 *
7418 * This routine is invoked to request a PCI function reset. It will destroys
7419 * all resources assigned to the PCI function which originates this request.
7420 *
7421 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007422 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007423 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007424 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007425 **/
7426int
7427lpfc_pci_function_reset(struct lpfc_hba *phba)
7428{
7429 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05007430 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04007431 uint32_t shdr_status, shdr_add_status;
James Smart2fcee4b2010-12-15 17:57:46 -05007432 uint32_t rdy_chk, num_resets = 0, reset_again = 0;
James Smartda0436e2009-05-22 14:51:39 -04007433 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05007434 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -05007435 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -04007436
James Smart2fcee4b2010-12-15 17:57:46 -05007437 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7438 switch (if_type) {
7439 case LPFC_SLI_INTF_IF_TYPE_0:
7440 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7441 GFP_KERNEL);
7442 if (!mboxq) {
7443 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7444 "0494 Unable to allocate memory for "
7445 "issuing SLI_FUNCTION_RESET mailbox "
7446 "command\n");
7447 return -ENOMEM;
7448 }
7449
7450 /* Setup PCI function reset mailbox-ioctl command */
7451 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
7452 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
7453 LPFC_SLI4_MBX_EMBED);
7454 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7455 shdr = (union lpfc_sli4_cfg_shdr *)
7456 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
7457 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7458 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
7459 &shdr->response);
7460 if (rc != MBX_TIMEOUT)
7461 mempool_free(mboxq, phba->mbox_mem_pool);
7462 if (shdr_status || shdr_add_status || rc) {
7463 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7464 "0495 SLI_FUNCTION_RESET mailbox "
7465 "failed with status x%x add_status x%x,"
7466 " mbx status x%x\n",
7467 shdr_status, shdr_add_status, rc);
7468 rc = -ENXIO;
7469 }
7470 break;
7471 case LPFC_SLI_INTF_IF_TYPE_2:
7472 for (num_resets = 0;
7473 num_resets < MAX_IF_TYPE_2_RESETS;
7474 num_resets++) {
7475 reg_data.word0 = 0;
7476 bf_set(lpfc_sliport_ctrl_end, &reg_data,
7477 LPFC_SLIPORT_LITTLE_ENDIAN);
7478 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
7479 LPFC_SLIPORT_INIT_PORT);
7480 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
7481 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -05007482 /* flush */
James Smart2b81f942012-03-01 22:37:18 -05007483 pci_read_config_word(phba->pcidev,
7484 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -05007485 /*
7486 * Poll the Port Status Register and wait for RDY for
7487 * up to 10 seconds. If the port doesn't respond, treat
7488 * it as an error. If the port responds with RN, start
7489 * the loop again.
7490 */
7491 for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) {
James Smart73d91e52011-10-10 21:32:10 -04007492 msleep(10);
James Smart9940b972011-03-11 16:06:12 -05007493 if (lpfc_readl(phba->sli4_hba.u.if_type2.
7494 STATUSregaddr, &reg_data.word0)) {
7495 rc = -ENODEV;
James Smart73d91e52011-10-10 21:32:10 -04007496 goto out;
James Smart9940b972011-03-11 16:06:12 -05007497 }
James Smart6b5151f2012-01-18 16:24:06 -05007498 if (bf_get(lpfc_sliport_status_rn, &reg_data))
7499 reset_again++;
James Smart2fcee4b2010-12-15 17:57:46 -05007500 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
7501 break;
James Smart2fcee4b2010-12-15 17:57:46 -05007502 }
7503
7504 /*
7505 * If the port responds to the init request with
7506 * reset needed, delay for a bit and restart the loop.
7507 */
James Smart6b5151f2012-01-18 16:24:06 -05007508 if (reset_again && (rdy_chk < 1000)) {
James Smart2fcee4b2010-12-15 17:57:46 -05007509 msleep(10);
7510 reset_again = 0;
7511 continue;
7512 }
7513
7514 /* Detect any port errors. */
James Smart2fcee4b2010-12-15 17:57:46 -05007515 if ((bf_get(lpfc_sliport_status_err, &reg_data)) ||
7516 (rdy_chk >= 1000)) {
7517 phba->work_status[0] = readl(
7518 phba->sli4_hba.u.if_type2.ERR1regaddr);
7519 phba->work_status[1] = readl(
7520 phba->sli4_hba.u.if_type2.ERR2regaddr);
7521 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05007522 "2890 Port error detected during port "
James Smart8a9d2e82012-05-09 21:16:12 -04007523 "reset(%d): wait_tmo:%d ms, "
7524 "port status reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05007525 "error 1=0x%x, error 2=0x%x\n",
James Smart8a9d2e82012-05-09 21:16:12 -04007526 num_resets, rdy_chk*10,
7527 reg_data.word0,
James Smart2fcee4b2010-12-15 17:57:46 -05007528 phba->work_status[0],
7529 phba->work_status[1]);
7530 rc = -ENODEV;
7531 }
7532
7533 /*
7534 * Terminate the outer loop provided the Port indicated
7535 * ready within 10 seconds.
7536 */
7537 if (rdy_chk < 1000)
7538 break;
7539 }
James Smart05580562011-05-24 11:40:48 -04007540 /* delay driver action following IF_TYPE_2 function reset */
7541 msleep(100);
James Smart2fcee4b2010-12-15 17:57:46 -05007542 break;
7543 case LPFC_SLI_INTF_IF_TYPE_1:
7544 default:
7545 break;
James Smartda0436e2009-05-22 14:51:39 -04007546 }
7547
James Smart73d91e52011-10-10 21:32:10 -04007548out:
James Smart2fcee4b2010-12-15 17:57:46 -05007549 /* Catch the not-ready port failure after a port reset. */
7550 if (num_resets >= MAX_IF_TYPE_2_RESETS)
7551 rc = -ENODEV;
7552
James Smartda0436e2009-05-22 14:51:39 -04007553 return rc;
7554}
7555
7556/**
7557 * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands
7558 * @phba: pointer to lpfc hba data structure.
7559 * @cnt: number of nop mailbox commands to send.
7560 *
7561 * This routine is invoked to send a number @cnt of NOP mailbox command and
7562 * wait for each command to complete.
7563 *
7564 * Return: the number of NOP mailbox command completed.
7565 **/
7566static int
7567lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt)
7568{
7569 LPFC_MBOXQ_t *mboxq;
7570 int length, cmdsent;
7571 uint32_t mbox_tmo;
7572 uint32_t rc = 0;
7573 uint32_t shdr_status, shdr_add_status;
7574 union lpfc_sli4_cfg_shdr *shdr;
7575
7576 if (cnt == 0) {
7577 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7578 "2518 Requested to send 0 NOP mailbox cmd\n");
7579 return cnt;
7580 }
7581
7582 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7583 if (!mboxq) {
7584 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7585 "2519 Unable to allocate memory for issuing "
7586 "NOP mailbox command\n");
7587 return 0;
7588 }
7589
7590 /* Set up NOP SLI4_CONFIG mailbox-ioctl command */
7591 length = (sizeof(struct lpfc_mbx_nop) -
7592 sizeof(struct lpfc_sli4_cfg_mhdr));
7593 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
7594 LPFC_MBOX_OPCODE_NOP, length, LPFC_SLI4_MBX_EMBED);
7595
James Smartda0436e2009-05-22 14:51:39 -04007596 for (cmdsent = 0; cmdsent < cnt; cmdsent++) {
7597 if (!phba->sli4_hba.intr_enable)
7598 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -04007599 else {
7600 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smartda0436e2009-05-22 14:51:39 -04007601 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
James Smarta183a152011-10-10 21:32:43 -04007602 }
James Smartda0436e2009-05-22 14:51:39 -04007603 if (rc == MBX_TIMEOUT)
7604 break;
7605 /* Check return status */
7606 shdr = (union lpfc_sli4_cfg_shdr *)
7607 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
7608 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7609 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
7610 &shdr->response);
7611 if (shdr_status || shdr_add_status || rc) {
7612 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7613 "2520 NOP mailbox command failed "
7614 "status x%x add_status x%x mbx "
7615 "status x%x\n", shdr_status,
7616 shdr_add_status, rc);
7617 break;
7618 }
7619 }
7620
7621 if (rc != MBX_TIMEOUT)
7622 mempool_free(mboxq, phba->mbox_mem_pool);
7623
7624 return cmdsent;
7625}
7626
7627/**
James Smartda0436e2009-05-22 14:51:39 -04007628 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
7629 * @phba: pointer to lpfc hba data structure.
7630 *
7631 * This routine is invoked to set up the PCI device memory space for device
7632 * with SLI-4 interface spec.
7633 *
7634 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007635 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04007636 * other values - error
7637 **/
7638static int
7639lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
7640{
7641 struct pci_dev *pdev;
7642 unsigned long bar0map_len, bar1map_len, bar2map_len;
7643 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05007644 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04007645
7646 /* Obtain PCI device reference */
7647 if (!phba->pcidev)
7648 return error;
7649 else
7650 pdev = phba->pcidev;
7651
7652 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05007653 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
7654 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
7655 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
7656 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smartda0436e2009-05-22 14:51:39 -04007657 return error;
Michael Reed8e685972009-09-18 12:02:05 -05007658 }
7659 }
James Smartda0436e2009-05-22 14:51:39 -04007660
James Smart2fcee4b2010-12-15 17:57:46 -05007661 /*
7662 * The BARs and register set definitions and offset locations are
7663 * dependent on the if_type.
7664 */
7665 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
7666 &phba->sli4_hba.sli_intf.word0)) {
7667 return error;
7668 }
7669
7670 /* There is no SLI3 failback for SLI4 devices. */
7671 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
7672 LPFC_SLI_INTF_VALID) {
7673 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7674 "2894 SLI_INTF reg contents invalid "
7675 "sli_intf reg 0x%x\n",
7676 phba->sli4_hba.sli_intf.word0);
7677 return error;
7678 }
7679
7680 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7681 /*
7682 * Get the bus address of SLI4 device Bar regions and the
7683 * number of bytes required by each mapping. The mapping of the
7684 * particular PCI BARs regions is dependent on the type of
7685 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04007686 */
James Smart1dfb5a42010-02-12 14:40:50 -05007687 if (pci_resource_start(pdev, 0)) {
7688 phba->pci_bar0_map = pci_resource_start(pdev, 0);
7689 bar0map_len = pci_resource_len(pdev, 0);
James Smart2fcee4b2010-12-15 17:57:46 -05007690
7691 /*
7692 * Map SLI4 PCI Config Space Register base to a kernel virtual
7693 * addr
7694 */
7695 phba->sli4_hba.conf_regs_memmap_p =
7696 ioremap(phba->pci_bar0_map, bar0map_len);
7697 if (!phba->sli4_hba.conf_regs_memmap_p) {
7698 dev_printk(KERN_ERR, &pdev->dev,
7699 "ioremap failed for SLI4 PCI config "
7700 "registers.\n");
7701 goto out;
7702 }
7703 /* Set up BAR0 PCI config space register memory map */
7704 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05007705 } else {
7706 phba->pci_bar0_map = pci_resource_start(pdev, 1);
7707 bar0map_len = pci_resource_len(pdev, 1);
James Smart2fcee4b2010-12-15 17:57:46 -05007708 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
7709 dev_printk(KERN_ERR, &pdev->dev,
7710 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
7711 goto out;
7712 }
7713 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04007714 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05007715 if (!phba->sli4_hba.conf_regs_memmap_p) {
7716 dev_printk(KERN_ERR, &pdev->dev,
7717 "ioremap failed for SLI4 PCI config "
7718 "registers.\n");
7719 goto out;
7720 }
7721 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04007722 }
7723
James Smartc31098c2011-04-16 11:03:33 -04007724 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
7725 (pci_resource_start(pdev, 2))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007726 /*
7727 * Map SLI4 if type 0 HBA Control Register base to a kernel
7728 * virtual address and setup the registers.
7729 */
7730 phba->pci_bar1_map = pci_resource_start(pdev, 2);
7731 bar1map_len = pci_resource_len(pdev, 2);
7732 phba->sli4_hba.ctrl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04007733 ioremap(phba->pci_bar1_map, bar1map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05007734 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
7735 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04007736 "ioremap failed for SLI4 HBA control registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05007737 goto out_iounmap_conf;
7738 }
7739 lpfc_sli4_bar1_register_memmap(phba);
James Smartda0436e2009-05-22 14:51:39 -04007740 }
7741
James Smartc31098c2011-04-16 11:03:33 -04007742 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
7743 (pci_resource_start(pdev, 4))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007744 /*
7745 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
7746 * virtual address and setup the registers.
7747 */
7748 phba->pci_bar2_map = pci_resource_start(pdev, 4);
7749 bar2map_len = pci_resource_len(pdev, 4);
7750 phba->sli4_hba.drbl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04007751 ioremap(phba->pci_bar2_map, bar2map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05007752 if (!phba->sli4_hba.drbl_regs_memmap_p) {
7753 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04007754 "ioremap failed for SLI4 HBA doorbell registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05007755 goto out_iounmap_ctrl;
7756 }
7757 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
7758 if (error)
7759 goto out_iounmap_all;
James Smartda0436e2009-05-22 14:51:39 -04007760 }
7761
James Smartda0436e2009-05-22 14:51:39 -04007762 return 0;
7763
7764out_iounmap_all:
7765 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
7766out_iounmap_ctrl:
7767 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
7768out_iounmap_conf:
7769 iounmap(phba->sli4_hba.conf_regs_memmap_p);
7770out:
7771 return error;
7772}
7773
7774/**
7775 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
7776 * @phba: pointer to lpfc hba data structure.
7777 *
7778 * This routine is invoked to unset the PCI device memory space for device
7779 * with SLI-4 interface spec.
7780 **/
7781static void
7782lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
7783{
James Smart2e90f4b2011-12-13 13:22:37 -05007784 uint32_t if_type;
7785 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -04007786
James Smart2e90f4b2011-12-13 13:22:37 -05007787 switch (if_type) {
7788 case LPFC_SLI_INTF_IF_TYPE_0:
7789 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
7790 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
7791 iounmap(phba->sli4_hba.conf_regs_memmap_p);
7792 break;
7793 case LPFC_SLI_INTF_IF_TYPE_2:
7794 iounmap(phba->sli4_hba.conf_regs_memmap_p);
7795 break;
7796 case LPFC_SLI_INTF_IF_TYPE_1:
7797 default:
7798 dev_printk(KERN_ERR, &phba->pcidev->dev,
7799 "FATAL - unsupported SLI4 interface type - %d\n",
7800 if_type);
7801 break;
7802 }
James Smartda0436e2009-05-22 14:51:39 -04007803}
7804
7805/**
James Smart3772a992009-05-22 14:50:54 -04007806 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
7807 * @phba: pointer to lpfc hba data structure.
7808 *
7809 * This routine is invoked to enable the MSI-X interrupt vectors to device
7810 * with SLI-3 interface specs. The kernel function pci_enable_msix() is
7811 * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
7812 * invoked, enables either all or nothing, depending on the current
7813 * availability of PCI vector resources. The device driver is responsible
7814 * for calling the individual request_irq() to register each MSI-X vector
7815 * with a interrupt handler, which is done in this function. Note that
7816 * later when device is unloading, the driver should always call free_irq()
7817 * on all MSI-X vectors it has done request_irq() on before calling
7818 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
7819 * will be left with MSI-X enabled and leaks its vectors.
7820 *
7821 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007822 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007823 * other values - error
7824 **/
7825static int
7826lpfc_sli_enable_msix(struct lpfc_hba *phba)
7827{
7828 int rc, i;
7829 LPFC_MBOXQ_t *pmb;
7830
7831 /* Set up MSI-X multi-message vectors */
7832 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
7833 phba->msix_entries[i].entry = i;
7834
7835 /* Configure MSI-X capability structure */
7836 rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
7837 ARRAY_SIZE(phba->msix_entries));
7838 if (rc) {
7839 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7840 "0420 PCI enable MSI-X failed (%d)\n", rc);
7841 goto msi_fail_out;
7842 }
7843 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
7844 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7845 "0477 MSI-X entry[%d]: vector=x%x "
7846 "message=%d\n", i,
7847 phba->msix_entries[i].vector,
7848 phba->msix_entries[i].entry);
7849 /*
7850 * Assign MSI-X vectors to interrupt handlers
7851 */
7852
7853 /* vector-0 is associated to slow-path handler */
7854 rc = request_irq(phba->msix_entries[0].vector,
7855 &lpfc_sli_sp_intr_handler, IRQF_SHARED,
7856 LPFC_SP_DRIVER_HANDLER_NAME, phba);
7857 if (rc) {
7858 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7859 "0421 MSI-X slow-path request_irq failed "
7860 "(%d)\n", rc);
7861 goto msi_fail_out;
7862 }
7863
7864 /* vector-1 is associated to fast-path handler */
7865 rc = request_irq(phba->msix_entries[1].vector,
7866 &lpfc_sli_fp_intr_handler, IRQF_SHARED,
7867 LPFC_FP_DRIVER_HANDLER_NAME, phba);
7868
7869 if (rc) {
7870 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7871 "0429 MSI-X fast-path request_irq failed "
7872 "(%d)\n", rc);
7873 goto irq_fail_out;
7874 }
7875
7876 /*
7877 * Configure HBA MSI-X attention conditions to messages
7878 */
7879 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7880
7881 if (!pmb) {
7882 rc = -ENOMEM;
7883 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7884 "0474 Unable to allocate memory for issuing "
7885 "MBOX_CONFIG_MSI command\n");
7886 goto mem_fail_out;
7887 }
7888 rc = lpfc_config_msi(phba, pmb);
7889 if (rc)
7890 goto mbx_fail_out;
7891 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
7892 if (rc != MBX_SUCCESS) {
7893 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
7894 "0351 Config MSI mailbox command failed, "
7895 "mbxCmd x%x, mbxStatus x%x\n",
7896 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
7897 goto mbx_fail_out;
7898 }
7899
7900 /* Free memory allocated for mailbox command */
7901 mempool_free(pmb, phba->mbox_mem_pool);
7902 return rc;
7903
7904mbx_fail_out:
7905 /* Free memory allocated for mailbox command */
7906 mempool_free(pmb, phba->mbox_mem_pool);
7907
7908mem_fail_out:
7909 /* free the irq already requested */
7910 free_irq(phba->msix_entries[1].vector, phba);
7911
7912irq_fail_out:
7913 /* free the irq already requested */
7914 free_irq(phba->msix_entries[0].vector, phba);
7915
7916msi_fail_out:
7917 /* Unconfigure MSI-X capability structure */
7918 pci_disable_msix(phba->pcidev);
7919 return rc;
7920}
7921
7922/**
7923 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
7924 * @phba: pointer to lpfc hba data structure.
7925 *
7926 * This routine is invoked to release the MSI-X vectors and then disable the
7927 * MSI-X interrupt mode to device with SLI-3 interface spec.
7928 **/
7929static void
7930lpfc_sli_disable_msix(struct lpfc_hba *phba)
7931{
7932 int i;
7933
7934 /* Free up MSI-X multi-message vectors */
7935 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
7936 free_irq(phba->msix_entries[i].vector, phba);
7937 /* Disable MSI-X */
7938 pci_disable_msix(phba->pcidev);
7939
7940 return;
7941}
7942
7943/**
7944 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
7945 * @phba: pointer to lpfc hba data structure.
7946 *
7947 * This routine is invoked to enable the MSI interrupt mode to device with
7948 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
7949 * enable the MSI vector. The device driver is responsible for calling the
7950 * request_irq() to register MSI vector with a interrupt the handler, which
7951 * is done in this function.
7952 *
7953 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007954 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007955 * other values - error
7956 */
7957static int
7958lpfc_sli_enable_msi(struct lpfc_hba *phba)
7959{
7960 int rc;
7961
7962 rc = pci_enable_msi(phba->pcidev);
7963 if (!rc)
7964 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7965 "0462 PCI enable MSI mode success.\n");
7966 else {
7967 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7968 "0471 PCI enable MSI mode failed (%d)\n", rc);
7969 return rc;
7970 }
7971
7972 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
7973 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
7974 if (rc) {
7975 pci_disable_msi(phba->pcidev);
7976 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7977 "0478 MSI request_irq failed (%d)\n", rc);
7978 }
7979 return rc;
7980}
7981
7982/**
7983 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
7984 * @phba: pointer to lpfc hba data structure.
7985 *
7986 * This routine is invoked to disable the MSI interrupt mode to device with
7987 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
7988 * done request_irq() on before calling pci_disable_msi(). Failure to do so
7989 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
7990 * its vector.
7991 */
7992static void
7993lpfc_sli_disable_msi(struct lpfc_hba *phba)
7994{
7995 free_irq(phba->pcidev->irq, phba);
7996 pci_disable_msi(phba->pcidev);
7997 return;
7998}
7999
8000/**
8001 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
8002 * @phba: pointer to lpfc hba data structure.
8003 *
8004 * This routine is invoked to enable device interrupt and associate driver's
8005 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
8006 * spec. Depends on the interrupt mode configured to the driver, the driver
8007 * will try to fallback from the configured interrupt mode to an interrupt
8008 * mode which is supported by the platform, kernel, and device in the order
8009 * of:
8010 * MSI-X -> MSI -> IRQ.
8011 *
8012 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008013 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008014 * other values - error
8015 **/
8016static uint32_t
8017lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
8018{
8019 uint32_t intr_mode = LPFC_INTR_ERROR;
8020 int retval;
8021
8022 if (cfg_mode == 2) {
8023 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
8024 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
8025 if (!retval) {
8026 /* Now, try to enable MSI-X interrupt mode */
8027 retval = lpfc_sli_enable_msix(phba);
8028 if (!retval) {
8029 /* Indicate initialization to MSI-X mode */
8030 phba->intr_type = MSIX;
8031 intr_mode = 2;
8032 }
8033 }
8034 }
8035
8036 /* Fallback to MSI if MSI-X initialization failed */
8037 if (cfg_mode >= 1 && phba->intr_type == NONE) {
8038 retval = lpfc_sli_enable_msi(phba);
8039 if (!retval) {
8040 /* Indicate initialization to MSI mode */
8041 phba->intr_type = MSI;
8042 intr_mode = 1;
8043 }
8044 }
8045
8046 /* Fallback to INTx if both MSI-X/MSI initalization failed */
8047 if (phba->intr_type == NONE) {
8048 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
8049 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8050 if (!retval) {
8051 /* Indicate initialization to INTx mode */
8052 phba->intr_type = INTx;
8053 intr_mode = 0;
8054 }
8055 }
8056 return intr_mode;
8057}
8058
8059/**
8060 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
8061 * @phba: pointer to lpfc hba data structure.
8062 *
8063 * This routine is invoked to disable device interrupt and disassociate the
8064 * driver's interrupt handler(s) from interrupt vector(s) to device with
8065 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
8066 * release the interrupt vector(s) for the message signaled interrupt.
8067 **/
8068static void
8069lpfc_sli_disable_intr(struct lpfc_hba *phba)
8070{
8071 /* Disable the currently initialized interrupt mode */
8072 if (phba->intr_type == MSIX)
8073 lpfc_sli_disable_msix(phba);
8074 else if (phba->intr_type == MSI)
8075 lpfc_sli_disable_msi(phba);
8076 else if (phba->intr_type == INTx)
8077 free_irq(phba->pcidev->irq, phba);
8078
8079 /* Reset interrupt management states */
8080 phba->intr_type = NONE;
8081 phba->sli.slistat.sli_intr = 0;
8082
8083 return;
8084}
8085
8086/**
James Smartda0436e2009-05-22 14:51:39 -04008087 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
8088 * @phba: pointer to lpfc hba data structure.
8089 *
8090 * This routine is invoked to enable the MSI-X interrupt vectors to device
8091 * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
8092 * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
8093 * enables either all or nothing, depending on the current availability of
8094 * PCI vector resources. The device driver is responsible for calling the
8095 * individual request_irq() to register each MSI-X vector with a interrupt
8096 * handler, which is done in this function. Note that later when device is
8097 * unloading, the driver should always call free_irq() on all MSI-X vectors
8098 * it has done request_irq() on before calling pci_disable_msix(). Failure
8099 * to do so results in a BUG_ON() and a device will be left with MSI-X
8100 * enabled and leaks its vectors.
8101 *
8102 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008103 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008104 * other values - error
8105 **/
8106static int
8107lpfc_sli4_enable_msix(struct lpfc_hba *phba)
8108{
James Smart75baf692010-06-08 18:31:21 -04008109 int vectors, rc, index;
James Smartda0436e2009-05-22 14:51:39 -04008110
8111 /* Set up MSI-X multi-message vectors */
8112 for (index = 0; index < phba->sli4_hba.cfg_eqn; index++)
8113 phba->sli4_hba.msix_entries[index].entry = index;
8114
8115 /* Configure MSI-X capability structure */
James Smart75baf692010-06-08 18:31:21 -04008116 vectors = phba->sli4_hba.cfg_eqn;
8117enable_msix_vectors:
James Smartda0436e2009-05-22 14:51:39 -04008118 rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries,
James Smart75baf692010-06-08 18:31:21 -04008119 vectors);
8120 if (rc > 1) {
8121 vectors = rc;
8122 goto enable_msix_vectors;
8123 } else if (rc) {
James Smartda0436e2009-05-22 14:51:39 -04008124 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8125 "0484 PCI enable MSI-X failed (%d)\n", rc);
8126 goto msi_fail_out;
8127 }
James Smart75baf692010-06-08 18:31:21 -04008128
James Smartda0436e2009-05-22 14:51:39 -04008129 /* Log MSI-X vector assignment */
James Smart75baf692010-06-08 18:31:21 -04008130 for (index = 0; index < vectors; index++)
James Smartda0436e2009-05-22 14:51:39 -04008131 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8132 "0489 MSI-X entry[%d]: vector=x%x "
8133 "message=%d\n", index,
8134 phba->sli4_hba.msix_entries[index].vector,
8135 phba->sli4_hba.msix_entries[index].entry);
8136 /*
8137 * Assign MSI-X vectors to interrupt handlers
8138 */
James Smart05580562011-05-24 11:40:48 -04008139 if (vectors > 1)
8140 rc = request_irq(phba->sli4_hba.msix_entries[0].vector,
8141 &lpfc_sli4_sp_intr_handler, IRQF_SHARED,
8142 LPFC_SP_DRIVER_HANDLER_NAME, phba);
8143 else
8144 /* All Interrupts need to be handled by one EQ */
8145 rc = request_irq(phba->sli4_hba.msix_entries[0].vector,
8146 &lpfc_sli4_intr_handler, IRQF_SHARED,
8147 LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -04008148 if (rc) {
8149 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8150 "0485 MSI-X slow-path request_irq failed "
8151 "(%d)\n", rc);
8152 goto msi_fail_out;
8153 }
8154
8155 /* The rest of the vector(s) are associated to fast-path handler(s) */
James Smart75baf692010-06-08 18:31:21 -04008156 for (index = 1; index < vectors; index++) {
James Smartda0436e2009-05-22 14:51:39 -04008157 phba->sli4_hba.fcp_eq_hdl[index - 1].idx = index - 1;
8158 phba->sli4_hba.fcp_eq_hdl[index - 1].phba = phba;
8159 rc = request_irq(phba->sli4_hba.msix_entries[index].vector,
8160 &lpfc_sli4_fp_intr_handler, IRQF_SHARED,
8161 LPFC_FP_DRIVER_HANDLER_NAME,
8162 &phba->sli4_hba.fcp_eq_hdl[index - 1]);
8163 if (rc) {
8164 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8165 "0486 MSI-X fast-path (%d) "
8166 "request_irq failed (%d)\n", index, rc);
8167 goto cfg_fail_out;
8168 }
8169 }
James Smart75baf692010-06-08 18:31:21 -04008170 phba->sli4_hba.msix_vec_nr = vectors;
James Smartda0436e2009-05-22 14:51:39 -04008171
8172 return rc;
8173
8174cfg_fail_out:
8175 /* free the irq already requested */
8176 for (--index; index >= 1; index--)
8177 free_irq(phba->sli4_hba.msix_entries[index - 1].vector,
8178 &phba->sli4_hba.fcp_eq_hdl[index - 1]);
8179
8180 /* free the irq already requested */
8181 free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
8182
8183msi_fail_out:
8184 /* Unconfigure MSI-X capability structure */
8185 pci_disable_msix(phba->pcidev);
8186 return rc;
8187}
8188
8189/**
8190 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
8191 * @phba: pointer to lpfc hba data structure.
8192 *
8193 * This routine is invoked to release the MSI-X vectors and then disable the
8194 * MSI-X interrupt mode to device with SLI-4 interface spec.
8195 **/
8196static void
8197lpfc_sli4_disable_msix(struct lpfc_hba *phba)
8198{
8199 int index;
8200
8201 /* Free up MSI-X multi-message vectors */
8202 free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
8203
James Smart75baf692010-06-08 18:31:21 -04008204 for (index = 1; index < phba->sli4_hba.msix_vec_nr; index++)
James Smartda0436e2009-05-22 14:51:39 -04008205 free_irq(phba->sli4_hba.msix_entries[index].vector,
8206 &phba->sli4_hba.fcp_eq_hdl[index - 1]);
James Smart75baf692010-06-08 18:31:21 -04008207
James Smartda0436e2009-05-22 14:51:39 -04008208 /* Disable MSI-X */
8209 pci_disable_msix(phba->pcidev);
8210
8211 return;
8212}
8213
8214/**
8215 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
8216 * @phba: pointer to lpfc hba data structure.
8217 *
8218 * This routine is invoked to enable the MSI interrupt mode to device with
8219 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
8220 * to enable the MSI vector. The device driver is responsible for calling
8221 * the request_irq() to register MSI vector with a interrupt the handler,
8222 * which is done in this function.
8223 *
8224 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008225 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008226 * other values - error
8227 **/
8228static int
8229lpfc_sli4_enable_msi(struct lpfc_hba *phba)
8230{
8231 int rc, index;
8232
8233 rc = pci_enable_msi(phba->pcidev);
8234 if (!rc)
8235 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8236 "0487 PCI enable MSI mode success.\n");
8237 else {
8238 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8239 "0488 PCI enable MSI mode failed (%d)\n", rc);
8240 return rc;
8241 }
8242
8243 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
8244 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8245 if (rc) {
8246 pci_disable_msi(phba->pcidev);
8247 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8248 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -04008249 return rc;
James Smartda0436e2009-05-22 14:51:39 -04008250 }
8251
8252 for (index = 0; index < phba->cfg_fcp_eq_count; index++) {
8253 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
8254 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
8255 }
8256
James Smart75baf692010-06-08 18:31:21 -04008257 return 0;
James Smartda0436e2009-05-22 14:51:39 -04008258}
8259
8260/**
8261 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
8262 * @phba: pointer to lpfc hba data structure.
8263 *
8264 * This routine is invoked to disable the MSI interrupt mode to device with
8265 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
8266 * done request_irq() on before calling pci_disable_msi(). Failure to do so
8267 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
8268 * its vector.
8269 **/
8270static void
8271lpfc_sli4_disable_msi(struct lpfc_hba *phba)
8272{
8273 free_irq(phba->pcidev->irq, phba);
8274 pci_disable_msi(phba->pcidev);
8275 return;
8276}
8277
8278/**
8279 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
8280 * @phba: pointer to lpfc hba data structure.
8281 *
8282 * This routine is invoked to enable device interrupt and associate driver's
8283 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
8284 * interface spec. Depends on the interrupt mode configured to the driver,
8285 * the driver will try to fallback from the configured interrupt mode to an
8286 * interrupt mode which is supported by the platform, kernel, and device in
8287 * the order of:
8288 * MSI-X -> MSI -> IRQ.
8289 *
8290 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008291 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008292 * other values - error
8293 **/
8294static uint32_t
8295lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
8296{
8297 uint32_t intr_mode = LPFC_INTR_ERROR;
8298 int retval, index;
8299
8300 if (cfg_mode == 2) {
8301 /* Preparation before conf_msi mbox cmd */
8302 retval = 0;
8303 if (!retval) {
8304 /* Now, try to enable MSI-X interrupt mode */
8305 retval = lpfc_sli4_enable_msix(phba);
8306 if (!retval) {
8307 /* Indicate initialization to MSI-X mode */
8308 phba->intr_type = MSIX;
8309 intr_mode = 2;
8310 }
8311 }
8312 }
8313
8314 /* Fallback to MSI if MSI-X initialization failed */
8315 if (cfg_mode >= 1 && phba->intr_type == NONE) {
8316 retval = lpfc_sli4_enable_msi(phba);
8317 if (!retval) {
8318 /* Indicate initialization to MSI mode */
8319 phba->intr_type = MSI;
8320 intr_mode = 1;
8321 }
8322 }
8323
8324 /* Fallback to INTx if both MSI-X/MSI initalization failed */
8325 if (phba->intr_type == NONE) {
8326 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
8327 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8328 if (!retval) {
8329 /* Indicate initialization to INTx mode */
8330 phba->intr_type = INTx;
8331 intr_mode = 0;
8332 for (index = 0; index < phba->cfg_fcp_eq_count;
8333 index++) {
8334 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
8335 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
8336 }
8337 }
8338 }
8339 return intr_mode;
8340}
8341
8342/**
8343 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
8344 * @phba: pointer to lpfc hba data structure.
8345 *
8346 * This routine is invoked to disable device interrupt and disassociate
8347 * the driver's interrupt handler(s) from interrupt vector(s) to device
8348 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
8349 * will release the interrupt vector(s) for the message signaled interrupt.
8350 **/
8351static void
8352lpfc_sli4_disable_intr(struct lpfc_hba *phba)
8353{
8354 /* Disable the currently initialized interrupt mode */
8355 if (phba->intr_type == MSIX)
8356 lpfc_sli4_disable_msix(phba);
8357 else if (phba->intr_type == MSI)
8358 lpfc_sli4_disable_msi(phba);
8359 else if (phba->intr_type == INTx)
8360 free_irq(phba->pcidev->irq, phba);
8361
8362 /* Reset interrupt management states */
8363 phba->intr_type = NONE;
8364 phba->sli.slistat.sli_intr = 0;
8365
8366 return;
8367}
8368
8369/**
James Smart3772a992009-05-22 14:50:54 -04008370 * lpfc_unset_hba - Unset SLI3 hba device initialization
8371 * @phba: pointer to lpfc hba data structure.
8372 *
8373 * This routine is invoked to unset the HBA device initialization steps to
8374 * a device with SLI-3 interface spec.
8375 **/
8376static void
8377lpfc_unset_hba(struct lpfc_hba *phba)
8378{
8379 struct lpfc_vport *vport = phba->pport;
8380 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8381
8382 spin_lock_irq(shost->host_lock);
8383 vport->load_flag |= FC_UNLOADING;
8384 spin_unlock_irq(shost->host_lock);
8385
James Smart72859902012-01-18 16:25:38 -05008386 kfree(phba->vpi_bmask);
8387 kfree(phba->vpi_ids);
8388
James Smart3772a992009-05-22 14:50:54 -04008389 lpfc_stop_hba_timers(phba);
8390
8391 phba->pport->work_port_events = 0;
8392
8393 lpfc_sli_hba_down(phba);
8394
8395 lpfc_sli_brdrestart(phba);
8396
8397 lpfc_sli_disable_intr(phba);
8398
8399 return;
8400}
8401
8402/**
James Smartda0436e2009-05-22 14:51:39 -04008403 * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization.
8404 * @phba: pointer to lpfc hba data structure.
8405 *
8406 * This routine is invoked to unset the HBA device initialization steps to
8407 * a device with SLI-4 interface spec.
8408 **/
8409static void
8410lpfc_sli4_unset_hba(struct lpfc_hba *phba)
8411{
8412 struct lpfc_vport *vport = phba->pport;
8413 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8414
8415 spin_lock_irq(shost->host_lock);
8416 vport->load_flag |= FC_UNLOADING;
8417 spin_unlock_irq(shost->host_lock);
8418
8419 phba->pport->work_port_events = 0;
8420
James Smart3677a3a2010-09-29 11:19:14 -04008421 /* Stop the SLI4 device port */
8422 lpfc_stop_port(phba);
James Smartda0436e2009-05-22 14:51:39 -04008423
8424 lpfc_sli4_disable_intr(phba);
8425
James Smart3677a3a2010-09-29 11:19:14 -04008426 /* Reset SLI4 HBA FCoE function */
8427 lpfc_pci_function_reset(phba);
James Smart5350d872011-10-10 21:33:49 -04008428 lpfc_sli4_queue_destroy(phba);
James Smart3677a3a2010-09-29 11:19:14 -04008429
James Smartda0436e2009-05-22 14:51:39 -04008430 return;
8431}
8432
8433/**
James Smart5af5eee2010-10-22 11:06:38 -04008434 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
8435 * @phba: Pointer to HBA context object.
8436 *
8437 * This function is called in the SLI4 code path to wait for completion
8438 * of device's XRIs exchange busy. It will check the XRI exchange busy
8439 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
8440 * that, it will check the XRI exchange busy on outstanding FCP and ELS
8441 * I/Os every 30 seconds, log error message, and wait forever. Only when
8442 * all XRI exchange busy complete, the driver unload shall proceed with
8443 * invoking the function reset ioctl mailbox command to the CNA and the
8444 * the rest of the driver unload resource release.
8445 **/
8446static void
8447lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
8448{
8449 int wait_time = 0;
8450 int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
8451 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
8452
8453 while (!fcp_xri_cmpl || !els_xri_cmpl) {
8454 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
8455 if (!fcp_xri_cmpl)
8456 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8457 "2877 FCP XRI exchange busy "
8458 "wait time: %d seconds.\n",
8459 wait_time/1000);
8460 if (!els_xri_cmpl)
8461 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8462 "2878 ELS XRI exchange busy "
8463 "wait time: %d seconds.\n",
8464 wait_time/1000);
8465 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
8466 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
8467 } else {
8468 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
8469 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
8470 }
8471 fcp_xri_cmpl =
8472 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
8473 els_xri_cmpl =
8474 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
8475 }
8476}
8477
8478/**
James Smartda0436e2009-05-22 14:51:39 -04008479 * lpfc_sli4_hba_unset - Unset the fcoe hba
8480 * @phba: Pointer to HBA context object.
8481 *
8482 * This function is called in the SLI4 code path to reset the HBA's FCoE
8483 * function. The caller is not required to hold any lock. This routine
8484 * issues PCI function reset mailbox command to reset the FCoE function.
8485 * At the end of the function, it calls lpfc_hba_down_post function to
8486 * free any pending commands.
8487 **/
8488static void
8489lpfc_sli4_hba_unset(struct lpfc_hba *phba)
8490{
8491 int wait_cnt = 0;
8492 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -04008493 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -04008494
8495 lpfc_stop_hba_timers(phba);
8496 phba->sli4_hba.intr_enable = 0;
8497
8498 /*
8499 * Gracefully wait out the potential current outstanding asynchronous
8500 * mailbox command.
8501 */
8502
8503 /* First, block any pending async mailbox command from posted */
8504 spin_lock_irq(&phba->hbalock);
8505 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
8506 spin_unlock_irq(&phba->hbalock);
8507 /* Now, trying to wait it out if we can */
8508 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
8509 msleep(10);
8510 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
8511 break;
8512 }
8513 /* Forcefully release the outstanding mailbox command if timed out */
8514 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
8515 spin_lock_irq(&phba->hbalock);
8516 mboxq = phba->sli.mbox_active;
8517 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
8518 __lpfc_mbox_cmpl_put(phba, mboxq);
8519 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8520 phba->sli.mbox_active = NULL;
8521 spin_unlock_irq(&phba->hbalock);
8522 }
8523
James Smart5af5eee2010-10-22 11:06:38 -04008524 /* Abort all iocbs associated with the hba */
8525 lpfc_sli_hba_iocb_abort(phba);
8526
8527 /* Wait for completion of device XRI exchange busy */
8528 lpfc_sli4_xri_exchange_busy_wait(phba);
8529
James Smartda0436e2009-05-22 14:51:39 -04008530 /* Disable PCI subsystem interrupt */
8531 lpfc_sli4_disable_intr(phba);
8532
James Smart912e3ac2011-05-24 11:42:11 -04008533 /* Disable SR-IOV if enabled */
8534 if (phba->cfg_sriov_nr_virtfn)
8535 pci_disable_sriov(pdev);
8536
James Smartda0436e2009-05-22 14:51:39 -04008537 /* Stop kthread signal shall trigger work_done one more time */
8538 kthread_stop(phba->worker_thread);
8539
James Smart3677a3a2010-09-29 11:19:14 -04008540 /* Reset SLI4 HBA FCoE function */
8541 lpfc_pci_function_reset(phba);
James Smart5350d872011-10-10 21:33:49 -04008542 lpfc_sli4_queue_destroy(phba);
James Smart3677a3a2010-09-29 11:19:14 -04008543
James Smartda0436e2009-05-22 14:51:39 -04008544 /* Stop the SLI4 device port */
8545 phba->pport->work_port_events = 0;
8546}
8547
James Smart28baac72010-02-12 14:42:03 -05008548 /**
8549 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
8550 * @phba: Pointer to HBA context object.
8551 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
8552 *
8553 * This function is called in the SLI4 code path to read the port's
8554 * sli4 capabilities.
8555 *
8556 * This function may be be called from any context that can block-wait
8557 * for the completion. The expectation is that this routine is called
8558 * typically from probe_one or from the online routine.
8559 **/
8560int
8561lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
8562{
8563 int rc;
8564 struct lpfc_mqe *mqe;
8565 struct lpfc_pc_sli4_params *sli4_params;
8566 uint32_t mbox_tmo;
8567
8568 rc = 0;
8569 mqe = &mboxq->u.mqe;
8570
8571 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -05008572 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -05008573 if (!phba->sli4_hba.intr_enable)
8574 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8575 else {
James Smarta183a152011-10-10 21:32:43 -04008576 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -05008577 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
8578 }
8579
8580 if (unlikely(rc))
8581 return 1;
8582
8583 sli4_params = &phba->sli4_hba.pc_sli4_params;
8584 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
8585 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
8586 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
8587 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
8588 &mqe->un.sli4_params);
8589 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
8590 &mqe->un.sli4_params);
8591 sli4_params->proto_types = mqe->un.sli4_params.word3;
8592 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
8593 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
8594 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
8595 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
8596 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
8597 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
8598 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
8599 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
8600 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
8601 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
8602 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
8603 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
8604 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
8605 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
8606 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
8607 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
8608 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
8609 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
8610 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
8611 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -04008612
8613 /* Make sure that sge_supp_len can be handled by the driver */
8614 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
8615 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
8616
James Smart28baac72010-02-12 14:42:03 -05008617 return rc;
8618}
8619
James Smartda0436e2009-05-22 14:51:39 -04008620/**
James Smartfedd3b72011-02-16 12:39:24 -05008621 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
8622 * @phba: Pointer to HBA context object.
8623 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
8624 *
8625 * This function is called in the SLI4 code path to read the port's
8626 * sli4 capabilities.
8627 *
8628 * This function may be be called from any context that can block-wait
8629 * for the completion. The expectation is that this routine is called
8630 * typically from probe_one or from the online routine.
8631 **/
8632int
8633lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
8634{
8635 int rc;
8636 struct lpfc_mqe *mqe = &mboxq->u.mqe;
8637 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -04008638 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -05008639 int length;
8640 struct lpfc_sli4_parameters *mbx_sli4_parameters;
8641
James Smart6d368e52011-05-24 11:44:12 -04008642 /*
8643 * By default, the driver assumes the SLI4 port requires RPI
8644 * header postings. The SLI4_PARAM response will correct this
8645 * assumption.
8646 */
8647 phba->sli4_hba.rpi_hdrs_in_use = 1;
8648
James Smartfedd3b72011-02-16 12:39:24 -05008649 /* Read the port's SLI4 Config Parameters */
8650 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
8651 sizeof(struct lpfc_sli4_cfg_mhdr));
8652 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8653 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
8654 length, LPFC_SLI4_MBX_EMBED);
8655 if (!phba->sli4_hba.intr_enable)
8656 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -04008657 else {
8658 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
8659 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
8660 }
James Smartfedd3b72011-02-16 12:39:24 -05008661 if (unlikely(rc))
8662 return rc;
8663 sli4_params = &phba->sli4_hba.pc_sli4_params;
8664 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
8665 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
8666 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
8667 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
8668 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
8669 mbx_sli4_parameters);
8670 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
8671 mbx_sli4_parameters);
8672 if (bf_get(cfg_phwq, mbx_sli4_parameters))
8673 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
8674 else
8675 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
8676 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
8677 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
8678 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
8679 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
8680 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
8681 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
8682 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
8683 mbx_sli4_parameters);
8684 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
8685 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -04008686 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
8687 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart05580562011-05-24 11:40:48 -04008688
8689 /* Make sure that sge_supp_len can be handled by the driver */
8690 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
8691 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
8692
James Smartfedd3b72011-02-16 12:39:24 -05008693 return 0;
8694}
8695
8696/**
James Smart3772a992009-05-22 14:50:54 -04008697 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
8698 * @pdev: pointer to PCI device
8699 * @pid: pointer to PCI device identifier
8700 *
8701 * This routine is to be called to attach a device with SLI-3 interface spec
8702 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
8703 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
8704 * information of the device and driver to see if the driver state that it can
8705 * support this kind of device. If the match is successful, the driver core
8706 * invokes this routine. If this routine determines it can claim the HBA, it
8707 * does all the initialization that it needs to do to handle the HBA properly.
8708 *
8709 * Return code
8710 * 0 - driver can claim the device
8711 * negative value - driver can not claim the device
8712 **/
8713static int __devinit
8714lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
8715{
8716 struct lpfc_hba *phba;
8717 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -04008718 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -04008719 int error;
8720 uint32_t cfg_mode, intr_mode;
8721
8722 /* Allocate memory for HBA structure */
8723 phba = lpfc_hba_alloc(pdev);
8724 if (!phba)
8725 return -ENOMEM;
8726
8727 /* Perform generic PCI device enabling operation */
8728 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -04008729 if (error)
James Smart3772a992009-05-22 14:50:54 -04008730 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -04008731
8732 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
8733 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
8734 if (error)
8735 goto out_disable_pci_dev;
8736
8737 /* Set up SLI-3 specific device PCI memory space */
8738 error = lpfc_sli_pci_mem_setup(phba);
8739 if (error) {
8740 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8741 "1402 Failed to set up pci memory space.\n");
8742 goto out_disable_pci_dev;
8743 }
8744
8745 /* Set up phase-1 common device driver resources */
8746 error = lpfc_setup_driver_resource_phase1(phba);
8747 if (error) {
8748 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8749 "1403 Failed to set up driver resource.\n");
8750 goto out_unset_pci_mem_s3;
8751 }
8752
8753 /* Set up SLI-3 specific device driver resources */
8754 error = lpfc_sli_driver_resource_setup(phba);
8755 if (error) {
8756 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8757 "1404 Failed to set up driver resource.\n");
8758 goto out_unset_pci_mem_s3;
8759 }
8760
8761 /* Initialize and populate the iocb list per host */
8762 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
8763 if (error) {
8764 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8765 "1405 Failed to initialize iocb list.\n");
8766 goto out_unset_driver_resource_s3;
8767 }
8768
8769 /* Set up common device driver resources */
8770 error = lpfc_setup_driver_resource_phase2(phba);
8771 if (error) {
8772 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8773 "1406 Failed to set up driver resource.\n");
8774 goto out_free_iocb_list;
8775 }
8776
James Smart079b5c92011-08-21 21:48:49 -04008777 /* Get the default values for Model Name and Description */
8778 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
8779
James Smart3772a992009-05-22 14:50:54 -04008780 /* Create SCSI host to the physical port */
8781 error = lpfc_create_shost(phba);
8782 if (error) {
8783 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8784 "1407 Failed to create scsi host.\n");
8785 goto out_unset_driver_resource;
8786 }
8787
8788 /* Configure sysfs attributes */
8789 vport = phba->pport;
8790 error = lpfc_alloc_sysfs_attr(vport);
8791 if (error) {
8792 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8793 "1476 Failed to allocate sysfs attr\n");
8794 goto out_destroy_shost;
8795 }
8796
James Smart6669f9b2009-10-02 15:16:45 -04008797 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -04008798 /* Now, trying to enable interrupt and bring up the device */
8799 cfg_mode = phba->cfg_use_msi;
8800 while (true) {
8801 /* Put device to a known state before enabling interrupt */
8802 lpfc_stop_port(phba);
8803 /* Configure and enable interrupt */
8804 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
8805 if (intr_mode == LPFC_INTR_ERROR) {
8806 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8807 "0431 Failed to enable interrupt.\n");
8808 error = -ENODEV;
8809 goto out_free_sysfs_attr;
8810 }
8811 /* SLI-3 HBA setup */
8812 if (lpfc_sli_hba_setup(phba)) {
8813 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8814 "1477 Failed to set up hba\n");
8815 error = -ENODEV;
8816 goto out_remove_device;
8817 }
8818
8819 /* Wait 50ms for the interrupts of previous mailbox commands */
8820 msleep(50);
8821 /* Check active interrupts on message signaled interrupts */
8822 if (intr_mode == 0 ||
8823 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
8824 /* Log the current active interrupt mode */
8825 phba->intr_mode = intr_mode;
8826 lpfc_log_intr_mode(phba, intr_mode);
8827 break;
8828 } else {
8829 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8830 "0447 Configure interrupt mode (%d) "
8831 "failed active interrupt test.\n",
8832 intr_mode);
8833 /* Disable the current interrupt mode */
8834 lpfc_sli_disable_intr(phba);
8835 /* Try next level of interrupt mode */
8836 cfg_mode = --intr_mode;
8837 }
8838 }
8839
8840 /* Perform post initialization setup */
8841 lpfc_post_init_setup(phba);
8842
8843 /* Check if there are static vports to be created. */
8844 lpfc_create_static_vport(phba);
8845
8846 return 0;
8847
8848out_remove_device:
8849 lpfc_unset_hba(phba);
8850out_free_sysfs_attr:
8851 lpfc_free_sysfs_attr(vport);
8852out_destroy_shost:
8853 lpfc_destroy_shost(phba);
8854out_unset_driver_resource:
8855 lpfc_unset_driver_resource_phase2(phba);
8856out_free_iocb_list:
8857 lpfc_free_iocb_list(phba);
8858out_unset_driver_resource_s3:
8859 lpfc_sli_driver_resource_unset(phba);
8860out_unset_pci_mem_s3:
8861 lpfc_sli_pci_mem_unset(phba);
8862out_disable_pci_dev:
8863 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -04008864 if (shost)
8865 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -04008866out_free_phba:
8867 lpfc_hba_free(phba);
8868 return error;
8869}
8870
8871/**
8872 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -04008873 * @pdev: pointer to PCI device
8874 *
James Smart3772a992009-05-22 14:50:54 -04008875 * This routine is to be called to disattach a device with SLI-3 interface
8876 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
8877 * removed from PCI bus, it performs all the necessary cleanup for the HBA
8878 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -04008879 **/
dea31012005-04-17 16:05:31 -05008880static void __devexit
James Smart3772a992009-05-22 14:50:54 -04008881lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -05008882{
James Smart2e0fef82007-06-17 19:56:36 -05008883 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8884 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -05008885 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -05008886 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -05008887 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05008888 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
8889
James Smart549e55c2007-08-02 11:09:51 -04008890 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04008891 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04008892 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05008893
James Smart858c9f62007-06-17 19:56:39 -05008894 lpfc_free_sysfs_attr(vport);
8895
James Smarteada2722008-12-04 22:39:13 -05008896 /* Release all the vports against this physical port */
8897 vports = lpfc_create_vport_work_array(phba);
8898 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -04008899 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
8900 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
8901 continue;
James Smarteada2722008-12-04 22:39:13 -05008902 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -04008903 }
James Smarteada2722008-12-04 22:39:13 -05008904 lpfc_destroy_vport_work_array(phba, vports);
8905
8906 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -05008907 fc_remove_host(shost);
8908 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04008909 lpfc_cleanup(vport);
8910
James Smart2e0fef82007-06-17 19:56:36 -05008911 /*
8912 * Bring down the SLI Layer. This step disable all interrupts,
8913 * clears the rings, discards all mailbox commands, and resets
8914 * the HBA.
8915 */
James Smarta257bf92009-04-06 18:48:10 -04008916
Justin P. Mattock48e34d02010-12-30 15:07:58 -08008917 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -05008918 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -04008919 /* Stop kthread signal shall trigger work_done one more time */
8920 kthread_stop(phba->worker_thread);
8921 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -05008922 lpfc_sli_brdrestart(phba);
8923
James Smart72859902012-01-18 16:25:38 -05008924 kfree(phba->vpi_bmask);
8925 kfree(phba->vpi_ids);
8926
James Smart3772a992009-05-22 14:50:54 -04008927 lpfc_stop_hba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05008928 spin_lock_irq(&phba->hbalock);
8929 list_del_init(&vport->listentry);
8930 spin_unlock_irq(&phba->hbalock);
8931
James Smart858c9f62007-06-17 19:56:39 -05008932 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05008933
James Smart912e3ac2011-05-24 11:42:11 -04008934 /* Disable SR-IOV if enabled */
8935 if (phba->cfg_sriov_nr_virtfn)
8936 pci_disable_sriov(pdev);
8937
James Smart5b75da22008-12-04 22:39:35 -05008938 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -04008939 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -05008940
8941 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05008942 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05008943
8944 /*
8945 * Call scsi_free before mem_free since scsi bufs are released to their
8946 * corresponding pools here.
8947 */
8948 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -04008949 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -05008950
James Smart34b02dc2008-08-24 21:49:55 -04008951 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
8952 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -05008953
James Smart2e0fef82007-06-17 19:56:36 -05008954 /* Free resources associated with SLI2 interface */
8955 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -04008956 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -05008957
8958 /* unmap adapter SLIM and Control Registers */
8959 iounmap(phba->ctrl_regs_memmap_p);
8960 iounmap(phba->slim_memmap_p);
8961
James Smart3772a992009-05-22 14:50:54 -04008962 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -05008963
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05008964 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05008965 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05008966}
8967
Linas Vepstas8d63f372007-02-14 14:28:36 -06008968/**
James Smart3772a992009-05-22 14:50:54 -04008969 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05008970 * @pdev: pointer to PCI device
8971 * @msg: power management message
8972 *
James Smart3772a992009-05-22 14:50:54 -04008973 * This routine is to be called from the kernel's PCI subsystem to support
8974 * system Power Management (PM) to device with SLI-3 interface spec. When
8975 * PM invokes this method, it quiesces the device by stopping the driver's
8976 * worker thread for the device, turning off device's interrupt and DMA,
8977 * and bring the device offline. Note that as the driver implements the
8978 * minimum PM requirements to a power-aware driver's PM support for the
8979 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
8980 * to the suspend() method call will be treated as SUSPEND and the driver will
8981 * fully reinitialize its device during resume() method call, the driver will
8982 * set device to PCI_D3hot state in PCI config space instead of setting it
8983 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -05008984 *
8985 * Return code
James Smart3772a992009-05-22 14:50:54 -04008986 * 0 - driver suspended the device
8987 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05008988 **/
8989static int
James Smart3772a992009-05-22 14:50:54 -04008990lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -05008991{
8992 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8993 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
8994
8995 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8996 "0473 PCI device Power Management suspend.\n");
8997
8998 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -04008999 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -05009000 lpfc_offline(phba);
9001 kthread_stop(phba->worker_thread);
9002
9003 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -04009004 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -05009005
9006 /* Save device state to PCI config space */
9007 pci_save_state(pdev);
9008 pci_set_power_state(pdev, PCI_D3hot);
9009
9010 return 0;
9011}
9012
9013/**
James Smart3772a992009-05-22 14:50:54 -04009014 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05009015 * @pdev: pointer to PCI device
9016 *
James Smart3772a992009-05-22 14:50:54 -04009017 * This routine is to be called from the kernel's PCI subsystem to support
9018 * system Power Management (PM) to device with SLI-3 interface spec. When PM
9019 * invokes this method, it restores the device's PCI config space state and
9020 * fully reinitializes the device and brings it online. Note that as the
9021 * driver implements the minimum PM requirements to a power-aware driver's
9022 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
9023 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
9024 * driver will fully reinitialize its device during resume() method call,
9025 * the device will be set to PCI_D0 directly in PCI config space before
9026 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -05009027 *
9028 * Return code
James Smart3772a992009-05-22 14:50:54 -04009029 * 0 - driver suspended the device
9030 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05009031 **/
9032static int
James Smart3772a992009-05-22 14:50:54 -04009033lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -05009034{
9035 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9036 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -05009037 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05009038 int error;
9039
9040 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9041 "0452 PCI device Power Management resume.\n");
9042
9043 /* Restore device state from PCI config space */
9044 pci_set_power_state(pdev, PCI_D0);
9045 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -04009046
James Smart1dfb5a42010-02-12 14:40:50 -05009047 /*
9048 * As the new kernel behavior of pci_restore_state() API call clears
9049 * device saved_state flag, need to save the restored state again.
9050 */
9051 pci_save_state(pdev);
9052
James Smart3a55b532008-12-04 22:38:54 -05009053 if (pdev->is_busmaster)
9054 pci_set_master(pdev);
9055
9056 /* Startup the kernel thread for this host adapter. */
9057 phba->worker_thread = kthread_run(lpfc_do_work, phba,
9058 "lpfc_worker_%d", phba->brd_no);
9059 if (IS_ERR(phba->worker_thread)) {
9060 error = PTR_ERR(phba->worker_thread);
9061 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9062 "0434 PM resume failed to start worker "
9063 "thread: error=x%x.\n", error);
9064 return error;
9065 }
9066
James Smart5b75da22008-12-04 22:39:35 -05009067 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009068 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05009069 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -05009070 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -05009071 "0430 PM resume Failed to enable interrupt\n");
9072 return -EIO;
9073 } else
9074 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05009075
9076 /* Restart HBA and bring it online */
9077 lpfc_sli_brdrestart(phba);
9078 lpfc_online(phba);
9079
James Smart5b75da22008-12-04 22:39:35 -05009080 /* Log the current active interrupt mode */
9081 lpfc_log_intr_mode(phba, phba->intr_mode);
9082
James Smart3a55b532008-12-04 22:38:54 -05009083 return 0;
9084}
9085
9086/**
James Smart891478a2009-11-18 15:40:23 -05009087 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
9088 * @phba: pointer to lpfc hba data structure.
9089 *
9090 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -04009091 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -05009092 **/
9093static void
9094lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
9095{
James Smarte2af0d22010-03-15 11:25:32 -04009096 struct lpfc_sli *psli = &phba->sli;
9097 struct lpfc_sli_ring *pring;
9098
James Smart891478a2009-11-18 15:40:23 -05009099 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9100 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -04009101
9102 /*
9103 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
9104 * and let the SCSI mid-layer to retry them to recover.
9105 */
9106 pring = &psli->ring[psli->fcp_ring];
9107 lpfc_sli_abort_iocb_ring(phba, pring);
James Smart891478a2009-11-18 15:40:23 -05009108}
9109
9110/**
James Smart0d878412009-10-02 15:16:56 -04009111 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
9112 * @phba: pointer to lpfc hba data structure.
9113 *
9114 * This routine is called to prepare the SLI3 device for PCI slot reset. It
9115 * disables the device interrupt and pci device, and aborts the internal FCP
9116 * pending I/Os.
9117 **/
9118static void
9119lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
9120{
James Smart0d878412009-10-02 15:16:56 -04009121 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -05009122 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -04009123
James Smart75baf692010-06-08 18:31:21 -04009124 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -04009125 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -04009126
James Smarte2af0d22010-03-15 11:25:32 -04009127 /* Block all SCSI devices' I/Os on the host */
9128 lpfc_scsi_dev_block(phba);
9129
9130 /* stop all timers */
9131 lpfc_stop_hba_timers(phba);
9132
James Smart0d878412009-10-02 15:16:56 -04009133 /* Disable interrupt and pci device */
9134 lpfc_sli_disable_intr(phba);
9135 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -04009136
James Smarte2af0d22010-03-15 11:25:32 -04009137 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9138 lpfc_sli_flush_fcp_rings(phba);
James Smart0d878412009-10-02 15:16:56 -04009139}
9140
9141/**
9142 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
9143 * @phba: pointer to lpfc hba data structure.
9144 *
9145 * This routine is called to prepare the SLI3 device for PCI slot permanently
9146 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
9147 * pending I/Os.
9148 **/
9149static void
James Smart75baf692010-06-08 18:31:21 -04009150lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -04009151{
9152 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -05009153 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -04009154 /* Block all SCSI devices' I/Os on the host */
9155 lpfc_scsi_dev_block(phba);
9156
9157 /* stop all timers */
9158 lpfc_stop_hba_timers(phba);
9159
James Smart0d878412009-10-02 15:16:56 -04009160 /* Clean up all driver's outstanding SCSI I/Os */
9161 lpfc_sli_flush_fcp_rings(phba);
9162}
9163
9164/**
James Smart3772a992009-05-22 14:50:54 -04009165 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -04009166 * @pdev: pointer to PCI device.
9167 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -06009168 *
James Smart3772a992009-05-22 14:50:54 -04009169 * This routine is called from the PCI subsystem for I/O error handling to
9170 * device with SLI-3 interface spec. This function is called by the PCI
9171 * subsystem after a PCI bus error affecting this device has been detected.
9172 * When this function is invoked, it will need to stop all the I/Os and
9173 * interrupt(s) to the device. Once that is done, it will return
9174 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
9175 * as desired.
James Smarte59058c2008-08-24 21:49:00 -04009176 *
9177 * Return codes
James Smart0d878412009-10-02 15:16:56 -04009178 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -04009179 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
9180 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -04009181 **/
James Smart3772a992009-05-22 14:50:54 -04009182static pci_ers_result_t
9183lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -06009184{
James Smart51ef4c22007-08-02 11:10:31 -04009185 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9186 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009187
James Smart0d878412009-10-02 15:16:56 -04009188 switch (state) {
9189 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -05009190 /* Non-fatal error, prepare for recovery */
9191 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -04009192 return PCI_ERS_RESULT_CAN_RECOVER;
9193 case pci_channel_io_frozen:
9194 /* Fatal error, prepare for slot reset */
9195 lpfc_sli_prep_dev_for_reset(phba);
9196 return PCI_ERS_RESULT_NEED_RESET;
9197 case pci_channel_io_perm_failure:
9198 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -04009199 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06009200 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -04009201 default:
9202 /* Unknown state, prepare and request slot reset */
9203 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9204 "0472 Unknown PCI error state: x%x\n", state);
9205 lpfc_sli_prep_dev_for_reset(phba);
9206 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -04009207 }
Linas Vepstas8d63f372007-02-14 14:28:36 -06009208}
9209
9210/**
James Smart3772a992009-05-22 14:50:54 -04009211 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -04009212 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -06009213 *
James Smart3772a992009-05-22 14:50:54 -04009214 * This routine is called from the PCI subsystem for error handling to
9215 * device with SLI-3 interface spec. This is called after PCI bus has been
9216 * reset to restart the PCI card from scratch, as if from a cold-boot.
9217 * During the PCI subsystem error recovery, after driver returns
9218 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
9219 * recovery and then call this routine before calling the .resume method
9220 * to recover the device. This function will initialize the HBA device,
9221 * enable the interrupt, but it will just put the HBA to offline state
9222 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -04009223 *
9224 * Return codes
James Smart3772a992009-05-22 14:50:54 -04009225 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
9226 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -06009227 */
James Smart3772a992009-05-22 14:50:54 -04009228static pci_ers_result_t
9229lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -06009230{
James Smart51ef4c22007-08-02 11:10:31 -04009231 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9232 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009233 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -05009234 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009235
9236 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11009237 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -06009238 printk(KERN_ERR "lpfc: Cannot re-enable "
9239 "PCI device after reset.\n");
9240 return PCI_ERS_RESULT_DISCONNECT;
9241 }
9242
James Smart97207482008-12-04 22:39:19 -05009243 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -05009244
9245 /*
9246 * As the new kernel behavior of pci_restore_state() API call clears
9247 * device saved_state flag, need to save the restored state again.
9248 */
9249 pci_save_state(pdev);
9250
James Smart97207482008-12-04 22:39:19 -05009251 if (pdev->is_busmaster)
9252 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -06009253
James Smart92d7f7b2007-06-17 19:56:38 -05009254 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -04009255 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05009256 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06009257
James Smart5b75da22008-12-04 22:39:35 -05009258 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009259 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05009260 if (intr_mode == LPFC_INTR_ERROR) {
9261 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9262 "0427 Cannot re-enable interrupt after "
9263 "slot reset.\n");
9264 return PCI_ERS_RESULT_DISCONNECT;
9265 } else
9266 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009267
James Smart75baf692010-06-08 18:31:21 -04009268 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -04009269 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -06009270 lpfc_offline(phba);
9271 lpfc_sli_brdrestart(phba);
9272
James Smart5b75da22008-12-04 22:39:35 -05009273 /* Log the current active interrupt mode */
9274 lpfc_log_intr_mode(phba, phba->intr_mode);
9275
Linas Vepstas8d63f372007-02-14 14:28:36 -06009276 return PCI_ERS_RESULT_RECOVERED;
9277}
9278
9279/**
James Smart3772a992009-05-22 14:50:54 -04009280 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -04009281 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -06009282 *
James Smart3772a992009-05-22 14:50:54 -04009283 * This routine is called from the PCI subsystem for error handling to device
9284 * with SLI-3 interface spec. It is called when kernel error recovery tells
9285 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
9286 * error recovery. After this call, traffic can start to flow from this device
9287 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -06009288 */
James Smart3772a992009-05-22 14:50:54 -04009289static void
9290lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -06009291{
James Smart51ef4c22007-08-02 11:10:31 -04009292 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9293 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009294
James Smarte2af0d22010-03-15 11:25:32 -04009295 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -04009296 lpfc_online(phba);
James Smart0d878412009-10-02 15:16:56 -04009297
9298 /* Clean up Advanced Error Reporting (AER) if needed */
9299 if (phba->hba_flag & HBA_AER_ENABLED)
9300 pci_cleanup_aer_uncorrect_error_status(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -06009301}
9302
James Smart3772a992009-05-22 14:50:54 -04009303/**
James Smartda0436e2009-05-22 14:51:39 -04009304 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
9305 * @phba: pointer to lpfc hba data structure.
9306 *
9307 * returns the number of ELS/CT IOCBs to reserve
9308 **/
9309int
9310lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
9311{
9312 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
9313
James Smartf1126682009-06-10 17:22:44 -04009314 if (phba->sli_rev == LPFC_SLI_REV4) {
9315 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -04009316 return 10;
James Smartf1126682009-06-10 17:22:44 -04009317 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -04009318 return 25;
James Smartf1126682009-06-10 17:22:44 -04009319 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -04009320 return 50;
James Smartf1126682009-06-10 17:22:44 -04009321 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -04009322 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -04009323 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -04009324 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -04009325 else if (max_xri <= 2048)
9326 return 200;
9327 else
9328 return 250;
James Smartf1126682009-06-10 17:22:44 -04009329 } else
9330 return 0;
James Smartda0436e2009-05-22 14:51:39 -04009331}
9332
9333/**
James Smart52d52442011-05-24 11:42:45 -04009334 * lpfc_write_firmware - attempt to write a firmware image to the port
9335 * @phba: pointer to lpfc hba data structure.
9336 * @fw: pointer to firmware image returned from request_firmware.
9337 *
9338 * returns the number of bytes written if write is successful.
9339 * returns a negative error value if there were errors.
9340 * returns 0 if firmware matches currently active firmware on port.
9341 **/
9342int
9343lpfc_write_firmware(struct lpfc_hba *phba, const struct firmware *fw)
9344{
James Smart6b5151f2012-01-18 16:24:06 -05009345 char fwrev[FW_REV_STR_SIZE];
James Smart52d52442011-05-24 11:42:45 -04009346 struct lpfc_grp_hdr *image = (struct lpfc_grp_hdr *)fw->data;
9347 struct list_head dma_buffer_list;
9348 int i, rc = 0;
9349 struct lpfc_dmabuf *dmabuf, *next;
9350 uint32_t offset = 0, temp_offset = 0;
9351
9352 INIT_LIST_HEAD(&dma_buffer_list);
James Smart079b5c92011-08-21 21:48:49 -04009353 if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) ||
9354 (bf_get_be32(lpfc_grp_hdr_file_type, image) !=
9355 LPFC_FILE_TYPE_GROUP) ||
9356 (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) ||
9357 (be32_to_cpu(image->size) != fw->size)) {
James Smart52d52442011-05-24 11:42:45 -04009358 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9359 "3022 Invalid FW image found. "
James Smart079b5c92011-08-21 21:48:49 -04009360 "Magic:%x Type:%x ID:%x\n",
9361 be32_to_cpu(image->magic_number),
9362 bf_get_be32(lpfc_grp_hdr_file_type, image),
9363 bf_get_be32(lpfc_grp_hdr_id, image));
James Smart52d52442011-05-24 11:42:45 -04009364 return -EINVAL;
9365 }
9366 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -04009367 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -04009368 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9369 "3023 Updating Firmware. Current Version:%s "
9370 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -04009371 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -04009372 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
9373 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
9374 GFP_KERNEL);
9375 if (!dmabuf) {
9376 rc = -ENOMEM;
9377 goto out;
9378 }
9379 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
9380 SLI4_PAGE_SIZE,
9381 &dmabuf->phys,
9382 GFP_KERNEL);
9383 if (!dmabuf->virt) {
9384 kfree(dmabuf);
9385 rc = -ENOMEM;
9386 goto out;
9387 }
9388 list_add_tail(&dmabuf->list, &dma_buffer_list);
9389 }
9390 while (offset < fw->size) {
9391 temp_offset = offset;
9392 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -04009393 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -04009394 memcpy(dmabuf->virt,
9395 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -04009396 fw->size - temp_offset);
9397 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -04009398 break;
9399 }
James Smart52d52442011-05-24 11:42:45 -04009400 memcpy(dmabuf->virt, fw->data + temp_offset,
9401 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -04009402 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -04009403 }
9404 rc = lpfc_wr_object(phba, &dma_buffer_list,
9405 (fw->size - offset), &offset);
9406 if (rc) {
9407 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9408 "3024 Firmware update failed. "
9409 "%d\n", rc);
9410 goto out;
9411 }
9412 }
9413 rc = offset;
9414 }
9415out:
9416 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
9417 list_del(&dmabuf->list);
9418 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
9419 dmabuf->virt, dmabuf->phys);
9420 kfree(dmabuf);
9421 }
9422 return rc;
9423}
9424
9425/**
James Smartda0436e2009-05-22 14:51:39 -04009426 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
9427 * @pdev: pointer to PCI device
9428 * @pid: pointer to PCI device identifier
9429 *
9430 * This routine is called from the kernel's PCI subsystem to device with
9431 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
9432 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
9433 * information of the device and driver to see if the driver state that it
9434 * can support this kind of device. If the match is successful, the driver
9435 * core invokes this routine. If this routine determines it can claim the HBA,
9436 * it does all the initialization that it needs to do to handle the HBA
9437 * properly.
9438 *
9439 * Return code
9440 * 0 - driver can claim the device
9441 * negative value - driver can not claim the device
9442 **/
9443static int __devinit
9444lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
9445{
9446 struct lpfc_hba *phba;
9447 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -04009448 struct Scsi_Host *shost = NULL;
James Smartda0436e2009-05-22 14:51:39 -04009449 int error;
9450 uint32_t cfg_mode, intr_mode;
9451 int mcnt;
James Smart05580562011-05-24 11:40:48 -04009452 int adjusted_fcp_eq_count;
James Smart52d52442011-05-24 11:42:45 -04009453 const struct firmware *fw;
9454 uint8_t file_name[16];
James Smartda0436e2009-05-22 14:51:39 -04009455
9456 /* Allocate memory for HBA structure */
9457 phba = lpfc_hba_alloc(pdev);
9458 if (!phba)
9459 return -ENOMEM;
9460
9461 /* Perform generic PCI device enabling operation */
9462 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -04009463 if (error)
James Smartda0436e2009-05-22 14:51:39 -04009464 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -04009465
9466 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
9467 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
9468 if (error)
9469 goto out_disable_pci_dev;
9470
9471 /* Set up SLI-4 specific device PCI memory space */
9472 error = lpfc_sli4_pci_mem_setup(phba);
9473 if (error) {
9474 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9475 "1410 Failed to set up pci memory space.\n");
9476 goto out_disable_pci_dev;
9477 }
9478
9479 /* Set up phase-1 common device driver resources */
9480 error = lpfc_setup_driver_resource_phase1(phba);
9481 if (error) {
9482 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9483 "1411 Failed to set up driver resource.\n");
9484 goto out_unset_pci_mem_s4;
9485 }
9486
9487 /* Set up SLI-4 Specific device driver resources */
9488 error = lpfc_sli4_driver_resource_setup(phba);
9489 if (error) {
9490 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9491 "1412 Failed to set up driver resource.\n");
9492 goto out_unset_pci_mem_s4;
9493 }
9494
9495 /* Initialize and populate the iocb list per host */
James Smart2a9bf3d2010-06-07 15:24:45 -04009496
9497 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9498 "2821 initialize iocb list %d.\n",
9499 phba->cfg_iocb_cnt*1024);
9500 error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
9501
James Smartda0436e2009-05-22 14:51:39 -04009502 if (error) {
9503 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9504 "1413 Failed to initialize iocb list.\n");
9505 goto out_unset_driver_resource_s4;
9506 }
9507
James Smart19ca7602010-11-20 23:11:55 -05009508 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -04009509 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -05009510
James Smartda0436e2009-05-22 14:51:39 -04009511 /* Set up common device driver resources */
9512 error = lpfc_setup_driver_resource_phase2(phba);
9513 if (error) {
9514 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9515 "1414 Failed to set up driver resource.\n");
9516 goto out_free_iocb_list;
9517 }
9518
James Smart079b5c92011-08-21 21:48:49 -04009519 /* Get the default values for Model Name and Description */
9520 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
9521
James Smartda0436e2009-05-22 14:51:39 -04009522 /* Create SCSI host to the physical port */
9523 error = lpfc_create_shost(phba);
9524 if (error) {
9525 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9526 "1415 Failed to create scsi host.\n");
9527 goto out_unset_driver_resource;
9528 }
9529
9530 /* Configure sysfs attributes */
9531 vport = phba->pport;
9532 error = lpfc_alloc_sysfs_attr(vport);
9533 if (error) {
9534 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9535 "1416 Failed to allocate sysfs attr\n");
9536 goto out_destroy_shost;
9537 }
9538
James Smart6669f9b2009-10-02 15:16:45 -04009539 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -04009540 /* Now, trying to enable interrupt and bring up the device */
9541 cfg_mode = phba->cfg_use_msi;
9542 while (true) {
9543 /* Put device to a known state before enabling interrupt */
9544 lpfc_stop_port(phba);
9545 /* Configure and enable interrupt */
9546 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
9547 if (intr_mode == LPFC_INTR_ERROR) {
9548 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9549 "0426 Failed to enable interrupt.\n");
9550 error = -ENODEV;
9551 goto out_free_sysfs_attr;
9552 }
James Smart05580562011-05-24 11:40:48 -04009553 /* Default to single EQ for non-MSI-X */
James Smartdef9c7a2009-12-21 17:02:28 -05009554 if (phba->intr_type != MSIX)
James Smart05580562011-05-24 11:40:48 -04009555 adjusted_fcp_eq_count = 0;
9556 else if (phba->sli4_hba.msix_vec_nr <
9557 phba->cfg_fcp_eq_count + 1)
9558 adjusted_fcp_eq_count = phba->sli4_hba.msix_vec_nr - 1;
9559 else
9560 adjusted_fcp_eq_count = phba->cfg_fcp_eq_count;
James Smart05580562011-05-24 11:40:48 -04009561 phba->cfg_fcp_eq_count = adjusted_fcp_eq_count;
James Smartda0436e2009-05-22 14:51:39 -04009562 /* Set up SLI-4 HBA */
9563 if (lpfc_sli4_hba_setup(phba)) {
9564 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9565 "1421 Failed to set up hba\n");
9566 error = -ENODEV;
9567 goto out_disable_intr;
9568 }
9569
9570 /* Send NOP mbx cmds for non-INTx mode active interrupt test */
9571 if (intr_mode != 0)
9572 mcnt = lpfc_sli4_send_nop_mbox_cmds(phba,
9573 LPFC_ACT_INTR_CNT);
9574
9575 /* Check active interrupts received only for MSI/MSI-X */
9576 if (intr_mode == 0 ||
9577 phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) {
9578 /* Log the current active interrupt mode */
9579 phba->intr_mode = intr_mode;
9580 lpfc_log_intr_mode(phba, intr_mode);
9581 break;
9582 }
9583 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9584 "0451 Configure interrupt mode (%d) "
9585 "failed active interrupt test.\n",
9586 intr_mode);
James Smart2fcee4b2010-12-15 17:57:46 -05009587 /* Unset the previous SLI-4 HBA setup. */
9588 /*
9589 * TODO: Is this operation compatible with IF TYPE 2
9590 * devices? All port state is deleted and cleared.
9591 */
James Smartda0436e2009-05-22 14:51:39 -04009592 lpfc_sli4_unset_hba(phba);
9593 /* Try next level of interrupt mode */
9594 cfg_mode = --intr_mode;
9595 }
9596
9597 /* Perform post initialization setup */
9598 lpfc_post_init_setup(phba);
9599
James Smart026abb82011-12-13 13:20:45 -05009600 /* check for firmware upgrade or downgrade (if_type 2 only) */
9601 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
9602 LPFC_SLI_INTF_IF_TYPE_2) {
9603 snprintf(file_name, 16, "%s.grp", phba->ModelName);
9604 error = request_firmware(&fw, file_name, &phba->pcidev->dev);
9605 if (!error) {
9606 lpfc_write_firmware(phba, fw);
9607 release_firmware(fw);
9608 }
James Smart52d52442011-05-24 11:42:45 -04009609 }
9610
James Smart1c6834a2009-07-19 10:01:26 -04009611 /* Check if there are static vports to be created. */
9612 lpfc_create_static_vport(phba);
James Smartda0436e2009-05-22 14:51:39 -04009613 return 0;
9614
9615out_disable_intr:
9616 lpfc_sli4_disable_intr(phba);
9617out_free_sysfs_attr:
9618 lpfc_free_sysfs_attr(vport);
9619out_destroy_shost:
9620 lpfc_destroy_shost(phba);
9621out_unset_driver_resource:
9622 lpfc_unset_driver_resource_phase2(phba);
9623out_free_iocb_list:
9624 lpfc_free_iocb_list(phba);
9625out_unset_driver_resource_s4:
9626 lpfc_sli4_driver_resource_unset(phba);
9627out_unset_pci_mem_s4:
9628 lpfc_sli4_pci_mem_unset(phba);
9629out_disable_pci_dev:
9630 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -04009631 if (shost)
9632 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -04009633out_free_phba:
9634 lpfc_hba_free(phba);
9635 return error;
9636}
9637
9638/**
9639 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
9640 * @pdev: pointer to PCI device
9641 *
9642 * This routine is called from the kernel's PCI subsystem to device with
9643 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
9644 * removed from PCI bus, it performs all the necessary cleanup for the HBA
9645 * device to be removed from the PCI subsystem properly.
9646 **/
9647static void __devexit
9648lpfc_pci_remove_one_s4(struct pci_dev *pdev)
9649{
9650 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9651 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
9652 struct lpfc_vport **vports;
9653 struct lpfc_hba *phba = vport->phba;
9654 int i;
9655
9656 /* Mark the device unloading flag */
9657 spin_lock_irq(&phba->hbalock);
9658 vport->load_flag |= FC_UNLOADING;
9659 spin_unlock_irq(&phba->hbalock);
9660
9661 /* Free the HBA sysfs attributes */
9662 lpfc_free_sysfs_attr(vport);
9663
9664 /* Release all the vports against this physical port */
9665 vports = lpfc_create_vport_work_array(phba);
9666 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -04009667 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9668 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
9669 continue;
James Smartda0436e2009-05-22 14:51:39 -04009670 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -04009671 }
James Smartda0436e2009-05-22 14:51:39 -04009672 lpfc_destroy_vport_work_array(phba, vports);
9673
9674 /* Remove FC host and then SCSI host with the physical port */
9675 fc_remove_host(shost);
9676 scsi_remove_host(shost);
9677
9678 /* Perform cleanup on the physical port */
9679 lpfc_cleanup(vport);
9680
9681 /*
9682 * Bring down the SLI Layer. This step disables all interrupts,
9683 * clears the rings, discards all mailbox commands, and resets
9684 * the HBA FCoE function.
9685 */
9686 lpfc_debugfs_terminate(vport);
9687 lpfc_sli4_hba_unset(phba);
9688
9689 spin_lock_irq(&phba->hbalock);
9690 list_del_init(&vport->listentry);
9691 spin_unlock_irq(&phba->hbalock);
9692
James Smart3677a3a2010-09-29 11:19:14 -04009693 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -04009694 * buffers are released to their corresponding pools here.
9695 */
9696 lpfc_scsi_free(phba);
9697 lpfc_sli4_driver_resource_unset(phba);
9698
9699 /* Unmap adapter Control and Doorbell registers */
9700 lpfc_sli4_pci_mem_unset(phba);
9701
9702 /* Release PCI resources and disable device's PCI function */
9703 scsi_host_put(shost);
9704 lpfc_disable_pci_dev(phba);
9705
9706 /* Finally, free the driver's device data structure */
9707 lpfc_hba_free(phba);
9708
9709 return;
9710}
9711
9712/**
9713 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
9714 * @pdev: pointer to PCI device
9715 * @msg: power management message
9716 *
9717 * This routine is called from the kernel's PCI subsystem to support system
9718 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
9719 * this method, it quiesces the device by stopping the driver's worker
9720 * thread for the device, turning off device's interrupt and DMA, and bring
9721 * the device offline. Note that as the driver implements the minimum PM
9722 * requirements to a power-aware driver's PM support for suspend/resume -- all
9723 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
9724 * method call will be treated as SUSPEND and the driver will fully
9725 * reinitialize its device during resume() method call, the driver will set
9726 * device to PCI_D3hot state in PCI config space instead of setting it
9727 * according to the @msg provided by the PM.
9728 *
9729 * Return code
9730 * 0 - driver suspended the device
9731 * Error otherwise
9732 **/
9733static int
9734lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
9735{
9736 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9737 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9738
9739 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -04009740 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -04009741
9742 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -04009743 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -04009744 lpfc_offline(phba);
9745 kthread_stop(phba->worker_thread);
9746
9747 /* Disable interrupt from device */
9748 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -04009749 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04009750
9751 /* Save device state to PCI config space */
9752 pci_save_state(pdev);
9753 pci_set_power_state(pdev, PCI_D3hot);
9754
9755 return 0;
9756}
9757
9758/**
9759 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
9760 * @pdev: pointer to PCI device
9761 *
9762 * This routine is called from the kernel's PCI subsystem to support system
9763 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
9764 * this method, it restores the device's PCI config space state and fully
9765 * reinitializes the device and brings it online. Note that as the driver
9766 * implements the minimum PM requirements to a power-aware driver's PM for
9767 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
9768 * to the suspend() method call will be treated as SUSPEND and the driver
9769 * will fully reinitialize its device during resume() method call, the device
9770 * will be set to PCI_D0 directly in PCI config space before restoring the
9771 * state.
9772 *
9773 * Return code
9774 * 0 - driver suspended the device
9775 * Error otherwise
9776 **/
9777static int
9778lpfc_pci_resume_one_s4(struct pci_dev *pdev)
9779{
9780 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9781 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9782 uint32_t intr_mode;
9783 int error;
9784
9785 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9786 "0292 PCI device Power Management resume.\n");
9787
9788 /* Restore device state from PCI config space */
9789 pci_set_power_state(pdev, PCI_D0);
9790 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -05009791
9792 /*
9793 * As the new kernel behavior of pci_restore_state() API call clears
9794 * device saved_state flag, need to save the restored state again.
9795 */
9796 pci_save_state(pdev);
9797
James Smartda0436e2009-05-22 14:51:39 -04009798 if (pdev->is_busmaster)
9799 pci_set_master(pdev);
9800
9801 /* Startup the kernel thread for this host adapter. */
9802 phba->worker_thread = kthread_run(lpfc_do_work, phba,
9803 "lpfc_worker_%d", phba->brd_no);
9804 if (IS_ERR(phba->worker_thread)) {
9805 error = PTR_ERR(phba->worker_thread);
9806 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9807 "0293 PM resume failed to start worker "
9808 "thread: error=x%x.\n", error);
9809 return error;
9810 }
9811
9812 /* Configure and enable interrupt */
9813 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
9814 if (intr_mode == LPFC_INTR_ERROR) {
9815 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9816 "0294 PM resume Failed to enable interrupt\n");
9817 return -EIO;
9818 } else
9819 phba->intr_mode = intr_mode;
9820
9821 /* Restart HBA and bring it online */
9822 lpfc_sli_brdrestart(phba);
9823 lpfc_online(phba);
9824
9825 /* Log the current active interrupt mode */
9826 lpfc_log_intr_mode(phba, phba->intr_mode);
9827
9828 return 0;
9829}
9830
9831/**
James Smart75baf692010-06-08 18:31:21 -04009832 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
9833 * @phba: pointer to lpfc hba data structure.
9834 *
9835 * This routine is called to prepare the SLI4 device for PCI slot recover. It
9836 * aborts all the outstanding SCSI I/Os to the pci device.
9837 **/
9838static void
9839lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
9840{
9841 struct lpfc_sli *psli = &phba->sli;
9842 struct lpfc_sli_ring *pring;
9843
9844 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9845 "2828 PCI channel I/O abort preparing for recovery\n");
9846 /*
9847 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
9848 * and let the SCSI mid-layer to retry them to recover.
9849 */
9850 pring = &psli->ring[psli->fcp_ring];
9851 lpfc_sli_abort_iocb_ring(phba, pring);
9852}
9853
9854/**
9855 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
9856 * @phba: pointer to lpfc hba data structure.
9857 *
9858 * This routine is called to prepare the SLI4 device for PCI slot reset. It
9859 * disables the device interrupt and pci device, and aborts the internal FCP
9860 * pending I/Os.
9861 **/
9862static void
9863lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
9864{
9865 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9866 "2826 PCI channel disable preparing for reset\n");
9867
9868 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -04009869 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -04009870
9871 /* Block all SCSI devices' I/Os on the host */
9872 lpfc_scsi_dev_block(phba);
9873
9874 /* stop all timers */
9875 lpfc_stop_hba_timers(phba);
9876
9877 /* Disable interrupt and pci device */
9878 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -04009879 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -04009880 pci_disable_device(phba->pcidev);
9881
9882 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9883 lpfc_sli_flush_fcp_rings(phba);
9884}
9885
9886/**
9887 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
9888 * @phba: pointer to lpfc hba data structure.
9889 *
9890 * This routine is called to prepare the SLI4 device for PCI slot permanently
9891 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
9892 * pending I/Os.
9893 **/
9894static void
9895lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
9896{
9897 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9898 "2827 PCI channel permanent disable for failure\n");
9899
9900 /* Block all SCSI devices' I/Os on the host */
9901 lpfc_scsi_dev_block(phba);
9902
9903 /* stop all timers */
9904 lpfc_stop_hba_timers(phba);
9905
9906 /* Clean up all driver's outstanding SCSI I/Os */
9907 lpfc_sli_flush_fcp_rings(phba);
9908}
9909
9910/**
James Smartda0436e2009-05-22 14:51:39 -04009911 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
9912 * @pdev: pointer to PCI device.
9913 * @state: the current PCI connection state.
9914 *
9915 * This routine is called from the PCI subsystem for error handling to device
9916 * with SLI-4 interface spec. This function is called by the PCI subsystem
9917 * after a PCI bus error affecting this device has been detected. When this
9918 * function is invoked, it will need to stop all the I/Os and interrupt(s)
9919 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
9920 * for the PCI subsystem to perform proper recovery as desired.
9921 *
9922 * Return codes
9923 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
9924 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9925 **/
9926static pci_ers_result_t
9927lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
9928{
James Smart75baf692010-06-08 18:31:21 -04009929 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9930 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9931
9932 switch (state) {
9933 case pci_channel_io_normal:
9934 /* Non-fatal error, prepare for recovery */
9935 lpfc_sli4_prep_dev_for_recover(phba);
9936 return PCI_ERS_RESULT_CAN_RECOVER;
9937 case pci_channel_io_frozen:
9938 /* Fatal error, prepare for slot reset */
9939 lpfc_sli4_prep_dev_for_reset(phba);
9940 return PCI_ERS_RESULT_NEED_RESET;
9941 case pci_channel_io_perm_failure:
9942 /* Permanent failure, prepare for device down */
9943 lpfc_sli4_prep_dev_for_perm_failure(phba);
9944 return PCI_ERS_RESULT_DISCONNECT;
9945 default:
9946 /* Unknown state, prepare and request slot reset */
9947 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9948 "2825 Unknown PCI error state: x%x\n", state);
9949 lpfc_sli4_prep_dev_for_reset(phba);
9950 return PCI_ERS_RESULT_NEED_RESET;
9951 }
James Smartda0436e2009-05-22 14:51:39 -04009952}
9953
9954/**
9955 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
9956 * @pdev: pointer to PCI device.
9957 *
9958 * This routine is called from the PCI subsystem for error handling to device
9959 * with SLI-4 interface spec. It is called after PCI bus has been reset to
9960 * restart the PCI card from scratch, as if from a cold-boot. During the
9961 * PCI subsystem error recovery, after the driver returns
9962 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
9963 * recovery and then call this routine before calling the .resume method to
9964 * recover the device. This function will initialize the HBA device, enable
9965 * the interrupt, but it will just put the HBA to offline state without
9966 * passing any I/O traffic.
9967 *
9968 * Return codes
9969 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
9970 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9971 */
9972static pci_ers_result_t
9973lpfc_io_slot_reset_s4(struct pci_dev *pdev)
9974{
James Smart75baf692010-06-08 18:31:21 -04009975 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9976 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9977 struct lpfc_sli *psli = &phba->sli;
9978 uint32_t intr_mode;
9979
9980 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
9981 if (pci_enable_device_mem(pdev)) {
9982 printk(KERN_ERR "lpfc: Cannot re-enable "
9983 "PCI device after reset.\n");
9984 return PCI_ERS_RESULT_DISCONNECT;
9985 }
9986
9987 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -04009988
9989 /*
9990 * As the new kernel behavior of pci_restore_state() API call clears
9991 * device saved_state flag, need to save the restored state again.
9992 */
9993 pci_save_state(pdev);
9994
James Smart75baf692010-06-08 18:31:21 -04009995 if (pdev->is_busmaster)
9996 pci_set_master(pdev);
9997
9998 spin_lock_irq(&phba->hbalock);
9999 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
10000 spin_unlock_irq(&phba->hbalock);
10001
10002 /* Configure and enable interrupt */
10003 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
10004 if (intr_mode == LPFC_INTR_ERROR) {
10005 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10006 "2824 Cannot re-enable interrupt after "
10007 "slot reset.\n");
10008 return PCI_ERS_RESULT_DISCONNECT;
10009 } else
10010 phba->intr_mode = intr_mode;
10011
10012 /* Log the current active interrupt mode */
10013 lpfc_log_intr_mode(phba, phba->intr_mode);
10014
James Smartda0436e2009-05-22 14:51:39 -040010015 return PCI_ERS_RESULT_RECOVERED;
10016}
10017
10018/**
10019 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
10020 * @pdev: pointer to PCI device
10021 *
10022 * This routine is called from the PCI subsystem for error handling to device
10023 * with SLI-4 interface spec. It is called when kernel error recovery tells
10024 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10025 * error recovery. After this call, traffic can start to flow from this device
10026 * again.
10027 **/
10028static void
10029lpfc_io_resume_s4(struct pci_dev *pdev)
10030{
James Smart75baf692010-06-08 18:31:21 -040010031 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10032 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10033
10034 /*
10035 * In case of slot reset, as function reset is performed through
10036 * mailbox command which needs DMA to be enabled, this operation
10037 * has to be moved to the io resume phase. Taking device offline
10038 * will perform the necessary cleanup.
10039 */
10040 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
10041 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040010042 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010043 lpfc_offline(phba);
10044 lpfc_sli_brdrestart(phba);
10045 /* Bring the device back online */
10046 lpfc_online(phba);
10047 }
10048
10049 /* Clean up Advanced Error Reporting (AER) if needed */
10050 if (phba->hba_flag & HBA_AER_ENABLED)
10051 pci_cleanup_aer_uncorrect_error_status(pdev);
James Smartda0436e2009-05-22 14:51:39 -040010052}
10053
10054/**
James Smart3772a992009-05-22 14:50:54 -040010055 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
10056 * @pdev: pointer to PCI device
10057 * @pid: pointer to PCI device identifier
10058 *
10059 * This routine is to be registered to the kernel's PCI subsystem. When an
10060 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
10061 * at PCI device-specific information of the device and driver to see if the
10062 * driver state that it can support this kind of device. If the match is
10063 * successful, the driver core invokes this routine. This routine dispatches
10064 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
10065 * do all the initialization that it needs to do to handle the HBA device
10066 * properly.
10067 *
10068 * Return code
10069 * 0 - driver can claim the device
10070 * negative value - driver can not claim the device
10071 **/
10072static int __devinit
10073lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
10074{
10075 int rc;
James Smart8fa38512009-07-19 10:01:03 -040010076 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040010077
James Smart28baac72010-02-12 14:42:03 -050010078 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040010079 return -ENODEV;
10080
James Smart8fa38512009-07-19 10:01:03 -040010081 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050010082 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040010083 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040010084 else
James Smart3772a992009-05-22 14:50:54 -040010085 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040010086
James Smart3772a992009-05-22 14:50:54 -040010087 return rc;
10088}
10089
10090/**
10091 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
10092 * @pdev: pointer to PCI device
10093 *
10094 * This routine is to be registered to the kernel's PCI subsystem. When an
10095 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
10096 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
10097 * remove routine, which will perform all the necessary cleanup for the
10098 * device to be removed from the PCI subsystem properly.
10099 **/
10100static void __devexit
10101lpfc_pci_remove_one(struct pci_dev *pdev)
10102{
10103 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10104 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10105
10106 switch (phba->pci_dev_grp) {
10107 case LPFC_PCI_DEV_LP:
10108 lpfc_pci_remove_one_s3(pdev);
10109 break;
James Smartda0436e2009-05-22 14:51:39 -040010110 case LPFC_PCI_DEV_OC:
10111 lpfc_pci_remove_one_s4(pdev);
10112 break;
James Smart3772a992009-05-22 14:50:54 -040010113 default:
10114 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10115 "1424 Invalid PCI device group: 0x%x\n",
10116 phba->pci_dev_grp);
10117 break;
10118 }
10119 return;
10120}
10121
10122/**
10123 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
10124 * @pdev: pointer to PCI device
10125 * @msg: power management message
10126 *
10127 * This routine is to be registered to the kernel's PCI subsystem to support
10128 * system Power Management (PM). When PM invokes this method, it dispatches
10129 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
10130 * suspend the device.
10131 *
10132 * Return code
10133 * 0 - driver suspended the device
10134 * Error otherwise
10135 **/
10136static int
10137lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
10138{
10139 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10140 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10141 int rc = -ENODEV;
10142
10143 switch (phba->pci_dev_grp) {
10144 case LPFC_PCI_DEV_LP:
10145 rc = lpfc_pci_suspend_one_s3(pdev, msg);
10146 break;
James Smartda0436e2009-05-22 14:51:39 -040010147 case LPFC_PCI_DEV_OC:
10148 rc = lpfc_pci_suspend_one_s4(pdev, msg);
10149 break;
James Smart3772a992009-05-22 14:50:54 -040010150 default:
10151 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10152 "1425 Invalid PCI device group: 0x%x\n",
10153 phba->pci_dev_grp);
10154 break;
10155 }
10156 return rc;
10157}
10158
10159/**
10160 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
10161 * @pdev: pointer to PCI device
10162 *
10163 * This routine is to be registered to the kernel's PCI subsystem to support
10164 * system Power Management (PM). When PM invokes this method, it dispatches
10165 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
10166 * resume the device.
10167 *
10168 * Return code
10169 * 0 - driver suspended the device
10170 * Error otherwise
10171 **/
10172static int
10173lpfc_pci_resume_one(struct pci_dev *pdev)
10174{
10175 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10176 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10177 int rc = -ENODEV;
10178
10179 switch (phba->pci_dev_grp) {
10180 case LPFC_PCI_DEV_LP:
10181 rc = lpfc_pci_resume_one_s3(pdev);
10182 break;
James Smartda0436e2009-05-22 14:51:39 -040010183 case LPFC_PCI_DEV_OC:
10184 rc = lpfc_pci_resume_one_s4(pdev);
10185 break;
James Smart3772a992009-05-22 14:50:54 -040010186 default:
10187 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10188 "1426 Invalid PCI device group: 0x%x\n",
10189 phba->pci_dev_grp);
10190 break;
10191 }
10192 return rc;
10193}
10194
10195/**
10196 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
10197 * @pdev: pointer to PCI device.
10198 * @state: the current PCI connection state.
10199 *
10200 * This routine is registered to the PCI subsystem for error handling. This
10201 * function is called by the PCI subsystem after a PCI bus error affecting
10202 * this device has been detected. When this routine is invoked, it dispatches
10203 * the action to the proper SLI-3 or SLI-4 device error detected handling
10204 * routine, which will perform the proper error detected operation.
10205 *
10206 * Return codes
10207 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10208 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10209 **/
10210static pci_ers_result_t
10211lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
10212{
10213 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10214 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10215 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
10216
10217 switch (phba->pci_dev_grp) {
10218 case LPFC_PCI_DEV_LP:
10219 rc = lpfc_io_error_detected_s3(pdev, state);
10220 break;
James Smartda0436e2009-05-22 14:51:39 -040010221 case LPFC_PCI_DEV_OC:
10222 rc = lpfc_io_error_detected_s4(pdev, state);
10223 break;
James Smart3772a992009-05-22 14:50:54 -040010224 default:
10225 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10226 "1427 Invalid PCI device group: 0x%x\n",
10227 phba->pci_dev_grp);
10228 break;
10229 }
10230 return rc;
10231}
10232
10233/**
10234 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
10235 * @pdev: pointer to PCI device.
10236 *
10237 * This routine is registered to the PCI subsystem for error handling. This
10238 * function is called after PCI bus has been reset to restart the PCI card
10239 * from scratch, as if from a cold-boot. When this routine is invoked, it
10240 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
10241 * routine, which will perform the proper device reset.
10242 *
10243 * Return codes
10244 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10245 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10246 **/
10247static pci_ers_result_t
10248lpfc_io_slot_reset(struct pci_dev *pdev)
10249{
10250 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10251 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10252 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
10253
10254 switch (phba->pci_dev_grp) {
10255 case LPFC_PCI_DEV_LP:
10256 rc = lpfc_io_slot_reset_s3(pdev);
10257 break;
James Smartda0436e2009-05-22 14:51:39 -040010258 case LPFC_PCI_DEV_OC:
10259 rc = lpfc_io_slot_reset_s4(pdev);
10260 break;
James Smart3772a992009-05-22 14:50:54 -040010261 default:
10262 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10263 "1428 Invalid PCI device group: 0x%x\n",
10264 phba->pci_dev_grp);
10265 break;
10266 }
10267 return rc;
10268}
10269
10270/**
10271 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
10272 * @pdev: pointer to PCI device
10273 *
10274 * This routine is registered to the PCI subsystem for error handling. It
10275 * is called when kernel error recovery tells the lpfc driver that it is
10276 * OK to resume normal PCI operation after PCI bus error recovery. When
10277 * this routine is invoked, it dispatches the action to the proper SLI-3
10278 * or SLI-4 device io_resume routine, which will resume the device operation.
10279 **/
10280static void
10281lpfc_io_resume(struct pci_dev *pdev)
10282{
10283 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10284 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10285
10286 switch (phba->pci_dev_grp) {
10287 case LPFC_PCI_DEV_LP:
10288 lpfc_io_resume_s3(pdev);
10289 break;
James Smartda0436e2009-05-22 14:51:39 -040010290 case LPFC_PCI_DEV_OC:
10291 lpfc_io_resume_s4(pdev);
10292 break;
James Smart3772a992009-05-22 14:50:54 -040010293 default:
10294 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10295 "1429 Invalid PCI device group: 0x%x\n",
10296 phba->pci_dev_grp);
10297 break;
10298 }
10299 return;
10300}
10301
James Smart3ef6d242012-01-18 16:23:48 -050010302/**
10303 * lpfc_mgmt_open - method called when 'lpfcmgmt' is opened from userspace
10304 * @inode: pointer to the inode representing the lpfcmgmt device
10305 * @filep: pointer to the file representing the open lpfcmgmt device
10306 *
10307 * This routine puts a reference count on the lpfc module whenever the
10308 * character device is opened
10309 **/
10310static int
10311lpfc_mgmt_open(struct inode *inode, struct file *filep)
10312{
10313 try_module_get(THIS_MODULE);
10314 return 0;
10315}
10316
10317/**
10318 * lpfc_mgmt_release - method called when 'lpfcmgmt' is closed in userspace
10319 * @inode: pointer to the inode representing the lpfcmgmt device
10320 * @filep: pointer to the file representing the open lpfcmgmt device
10321 *
10322 * This routine removes a reference count from the lpfc module when the
10323 * character device is closed
10324 **/
10325static int
10326lpfc_mgmt_release(struct inode *inode, struct file *filep)
10327{
10328 module_put(THIS_MODULE);
10329 return 0;
10330}
10331
dea31012005-04-17 16:05:31 -050010332static struct pci_device_id lpfc_id_table[] = {
10333 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
10334 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -040010335 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
10336 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050010337 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
10338 PCI_ANY_ID, PCI_ANY_ID, },
10339 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
10340 PCI_ANY_ID, PCI_ANY_ID, },
10341 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
10342 PCI_ANY_ID, PCI_ANY_ID, },
10343 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
10344 PCI_ANY_ID, PCI_ANY_ID, },
10345 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
10346 PCI_ANY_ID, PCI_ANY_ID, },
10347 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
10348 PCI_ANY_ID, PCI_ANY_ID, },
10349 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
10350 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050010351 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
10352 PCI_ANY_ID, PCI_ANY_ID, },
10353 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
10354 PCI_ANY_ID, PCI_ANY_ID, },
10355 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
10356 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050010357 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
10358 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050010359 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
10360 PCI_ANY_ID, PCI_ANY_ID, },
10361 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
10362 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050010363 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
10364 PCI_ANY_ID, PCI_ANY_ID, },
10365 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
10366 PCI_ANY_ID, PCI_ANY_ID, },
10367 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
10368 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -040010369 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
10370 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050010371 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
10372 PCI_ANY_ID, PCI_ANY_ID, },
10373 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
10374 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050010375 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
10376 PCI_ANY_ID, PCI_ANY_ID, },
10377 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
10378 PCI_ANY_ID, PCI_ANY_ID, },
10379 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
10380 PCI_ANY_ID, PCI_ANY_ID, },
10381 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
10382 PCI_ANY_ID, PCI_ANY_ID, },
10383 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
10384 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050010385 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
10386 PCI_ANY_ID, PCI_ANY_ID, },
10387 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
10388 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -040010389 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
10390 PCI_ANY_ID, PCI_ANY_ID, },
10391 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
10392 PCI_ANY_ID, PCI_ANY_ID, },
10393 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
10394 PCI_ANY_ID, PCI_ANY_ID, },
10395 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
10396 PCI_ANY_ID, PCI_ANY_ID, },
10397 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
10398 PCI_ANY_ID, PCI_ANY_ID, },
10399 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
10400 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -040010401 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
10402 PCI_ANY_ID, PCI_ANY_ID, },
10403 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
10404 PCI_ANY_ID, PCI_ANY_ID, },
10405 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
10406 PCI_ANY_ID, PCI_ANY_ID, },
James Smart3772a992009-05-22 14:50:54 -040010407 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
10408 PCI_ANY_ID, PCI_ANY_ID, },
James Smarta747c9c2009-11-18 15:41:10 -050010409 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT,
10410 PCI_ANY_ID, PCI_ANY_ID, },
10411 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON,
James Smart6669f9b2009-10-02 15:16:45 -040010412 PCI_ANY_ID, PCI_ANY_ID, },
James Smart98fc5dd2010-06-07 15:24:29 -040010413 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS,
10414 PCI_ANY_ID, PCI_ANY_ID, },
James Smart085c6472010-11-20 23:11:37 -050010415 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC,
10416 PCI_ANY_ID, PCI_ANY_ID, },
10417 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE,
10418 PCI_ANY_ID, PCI_ANY_ID, },
James Smartc0c11512011-05-24 11:41:34 -040010419 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF,
10420 PCI_ANY_ID, PCI_ANY_ID, },
10421 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF,
10422 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050010423 { 0 }
10424};
10425
10426MODULE_DEVICE_TABLE(pci, lpfc_id_table);
10427
Linas Vepstas8d63f372007-02-14 14:28:36 -060010428static struct pci_error_handlers lpfc_err_handler = {
10429 .error_detected = lpfc_io_error_detected,
10430 .slot_reset = lpfc_io_slot_reset,
10431 .resume = lpfc_io_resume,
10432};
10433
dea31012005-04-17 16:05:31 -050010434static struct pci_driver lpfc_driver = {
10435 .name = LPFC_DRIVER_NAME,
10436 .id_table = lpfc_id_table,
10437 .probe = lpfc_pci_probe_one,
10438 .remove = __devexit_p(lpfc_pci_remove_one),
James Smart3a55b532008-12-04 22:38:54 -050010439 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040010440 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050010441 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050010442};
10443
James Smart3ef6d242012-01-18 16:23:48 -050010444static const struct file_operations lpfc_mgmt_fop = {
10445 .open = lpfc_mgmt_open,
10446 .release = lpfc_mgmt_release,
10447};
10448
10449static struct miscdevice lpfc_mgmt_dev = {
10450 .minor = MISC_DYNAMIC_MINOR,
10451 .name = "lpfcmgmt",
10452 .fops = &lpfc_mgmt_fop,
10453};
10454
James Smarte59058c2008-08-24 21:49:00 -040010455/**
James Smart3621a712009-04-06 18:47:14 -040010456 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040010457 *
10458 * This routine is to be invoked when the lpfc module is loaded into the
10459 * kernel. The special kernel macro module_init() is used to indicate the
10460 * role of this routine to the kernel as lpfc module entry point.
10461 *
10462 * Return codes
10463 * 0 - successful
10464 * -ENOMEM - FC attach transport failed
10465 * all others - failed
10466 */
dea31012005-04-17 16:05:31 -050010467static int __init
10468lpfc_init(void)
10469{
10470 int error = 0;
10471
10472 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010473 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050010474
James Smart3ef6d242012-01-18 16:23:48 -050010475 error = misc_register(&lpfc_mgmt_dev);
10476 if (error)
10477 printk(KERN_ERR "Could not register lpfcmgmt device, "
10478 "misc_register returned with status %d", error);
10479
James Smart7ee5d432007-10-27 13:37:17 -040010480 if (lpfc_enable_npiv) {
10481 lpfc_transport_functions.vport_create = lpfc_vport_create;
10482 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
10483 }
dea31012005-04-17 16:05:31 -050010484 lpfc_transport_template =
10485 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040010486 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050010487 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040010488 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -040010489 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -040010490 fc_attach_transport(&lpfc_vport_transport_functions);
10491 if (lpfc_vport_transport_template == NULL) {
10492 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040010493 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -040010494 }
James Smart7ee5d432007-10-27 13:37:17 -040010495 }
dea31012005-04-17 16:05:31 -050010496 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050010497 if (error) {
dea31012005-04-17 16:05:31 -050010498 fc_release_transport(lpfc_transport_template);
James Smartd7c255b2008-08-24 21:50:00 -040010499 if (lpfc_enable_npiv)
10500 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050010501 }
dea31012005-04-17 16:05:31 -050010502
10503 return error;
10504}
10505
James Smarte59058c2008-08-24 21:49:00 -040010506/**
James Smart3621a712009-04-06 18:47:14 -040010507 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040010508 *
10509 * This routine is invoked when the lpfc module is removed from the kernel.
10510 * The special kernel macro module_exit() is used to indicate the role of
10511 * this routine to the kernel as lpfc module exit point.
10512 */
dea31012005-04-17 16:05:31 -050010513static void __exit
10514lpfc_exit(void)
10515{
James Smart3ef6d242012-01-18 16:23:48 -050010516 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050010517 pci_unregister_driver(&lpfc_driver);
10518 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040010519 if (lpfc_enable_npiv)
10520 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050010521 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040010522 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
10523 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050010524 (1L << _dump_buf_data_order), _dump_buf_data);
10525 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
10526 }
10527
10528 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040010529 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
10530 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050010531 (1L << _dump_buf_dif_order), _dump_buf_dif);
10532 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
10533 }
dea31012005-04-17 16:05:31 -050010534}
10535
10536module_init(lpfc_init);
10537module_exit(lpfc_exit);
10538MODULE_LICENSE("GPL");
10539MODULE_DESCRIPTION(LPFC_MODULE_DESC);
10540MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
10541MODULE_VERSION("0:" LPFC_DRIVER_VERSION);