blob: f31a3682751215889d16ede9ba81f66fb31507ab [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 Smart92c13f22013-05-31 17:05:45 -04004 * Copyright (C) 2004-2013 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/delay.h>
24#include <linux/dma-mapping.h>
25#include <linux/idr.h>
26#include <linux/interrupt.h>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040027#include <linux/module.h>
dea31012005-04-17 16:05:31 -050028#include <linux/kthread.h>
29#include <linux/pci.h>
30#include <linux/spinlock.h>
James Smart92d7f7b2007-06-17 19:56:38 -050031#include <linux/ctype.h>
James Smart0d878412009-10-02 15:16:56 -040032#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
James Smart52d52442011-05-24 11:42:45 -040034#include <linux/firmware.h>
James Smart3ef6d242012-01-18 16:23:48 -050035#include <linux/miscdevice.h>
James Smart7bb03bb2013-04-17 20:19:16 -040036#include <linux/percpu.h>
dea31012005-04-17 16:05:31 -050037
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040038#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050039#include <scsi/scsi_device.h>
40#include <scsi/scsi_host.h>
41#include <scsi/scsi_transport_fc.h>
42
James Smartda0436e2009-05-22 14:51:39 -040043#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050044#include "lpfc_hw.h"
45#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040046#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040047#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050048#include "lpfc_disc.h"
49#include "lpfc_scsi.h"
50#include "lpfc.h"
51#include "lpfc_logmsg.h"
52#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050053#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050054#include "lpfc_version.h"
55
James Smart81301a92008-12-04 22:39:46 -050056char *_dump_buf_data;
57unsigned long _dump_buf_data_order;
58char *_dump_buf_dif;
59unsigned long _dump_buf_dif_order;
60spinlock_t _dump_buf_lock;
61
James Smart7bb03bb2013-04-17 20:19:16 -040062/* Used when mapping IRQ vectors in a driver centric manner */
James Smartb246de12013-05-31 17:03:07 -040063uint16_t *lpfc_used_cpu;
64uint32_t lpfc_present_cpu;
James Smart7bb03bb2013-04-17 20:19:16 -040065
dea31012005-04-17 16:05:31 -050066static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
67static int lpfc_post_rcv_buf(struct lpfc_hba *);
James Smart5350d872011-10-10 21:33:49 -040068static int lpfc_sli4_queue_verify(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040069static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
70static int lpfc_setup_endian_order(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040071static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040072static void lpfc_free_els_sgl_list(struct lpfc_hba *);
73static void lpfc_init_sgl_list(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040074static int lpfc_init_active_sgl_array(struct lpfc_hba *);
75static void lpfc_free_active_sgl(struct lpfc_hba *);
76static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
77static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
78static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
79static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
80static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
James Smart618a5232012-06-12 13:54:36 -040081static void lpfc_sli4_disable_intr(struct lpfc_hba *);
82static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
James Smart1ba981f2014-02-20 09:56:45 -050083static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
dea31012005-04-17 16:05:31 -050084
85static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050086static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -050087static DEFINE_IDR(lpfc_hba_index);
88
James Smarte59058c2008-08-24 21:49:00 -040089/**
James Smart3621a712009-04-06 18:47:14 -040090 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
James Smarte59058c2008-08-24 21:49:00 -040091 * @phba: pointer to lpfc hba data structure.
92 *
93 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
94 * mailbox command. It retrieves the revision information from the HBA and
95 * collects the Vital Product Data (VPD) about the HBA for preparing the
96 * configuration of the HBA.
97 *
98 * Return codes:
99 * 0 - success.
100 * -ERESTART - requests the SLI layer to reset the HBA and try again.
101 * Any other value - indicates an error.
102 **/
dea31012005-04-17 16:05:31 -0500103int
James Smart2e0fef82007-06-17 19:56:36 -0500104lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500105{
106 lpfc_vpd_t *vp = &phba->vpd;
107 int i = 0, rc;
108 LPFC_MBOXQ_t *pmb;
109 MAILBOX_t *mb;
110 char *lpfc_vpd_data = NULL;
111 uint16_t offset = 0;
112 static char licensed[56] =
113 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -0400114 static int init_key = 1;
dea31012005-04-17 16:05:31 -0500115
116 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
117 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500118 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500119 return -ENOMEM;
120 }
121
James Smart04c68492009-05-22 14:52:52 -0400122 mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -0500123 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -0500124
125 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -0400126 if (init_key) {
127 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -0500128
James Smart65a29c12006-07-06 15:50:50 -0400129 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
130 *ptext = cpu_to_be32(*ptext);
131 init_key = 0;
132 }
dea31012005-04-17 16:05:31 -0500133
134 lpfc_read_nv(phba, pmb);
135 memset((char*)mb->un.varRDnvp.rsvd3, 0,
136 sizeof (mb->un.varRDnvp.rsvd3));
137 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
138 sizeof (licensed));
139
140 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
141
142 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500143 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400144 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500145 "error, mbxCmd x%x READ_NVPARM, "
146 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500147 mb->mbxCommand, mb->mbxStatus);
148 mempool_free(pmb, phba->mbox_mem_pool);
149 return -ERESTART;
150 }
151 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500152 sizeof(phba->wwnn));
153 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
154 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500155 }
156
James Smart92d7f7b2007-06-17 19:56:38 -0500157 phba->sli3_options = 0x0;
158
dea31012005-04-17 16:05:31 -0500159 /* Setup and issue mailbox READ REV command */
160 lpfc_read_rev(phba, pmb);
161 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
162 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500163 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400164 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500165 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500166 mb->mbxCommand, mb->mbxStatus);
167 mempool_free( pmb, phba->mbox_mem_pool);
168 return -ERESTART;
169 }
170
James Smart92d7f7b2007-06-17 19:56:38 -0500171
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500172 /*
173 * The value of rr must be 1 since the driver set the cv field to 1.
174 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500175 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500176 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500177 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500178 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400179 "0440 Adapter failed to init, READ_REV has "
180 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500181 mempool_free(pmb, phba->mbox_mem_pool);
182 return -ERESTART;
dea31012005-04-17 16:05:31 -0500183 }
184
James Smart495a7142008-06-14 22:52:59 -0400185 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
186 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500187 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400188 }
James Smarted957682007-06-17 19:56:37 -0500189
dea31012005-04-17 16:05:31 -0500190 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500191 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500192 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500193 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
194 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
195 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
196 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500197 vp->rev.biuRev = mb->un.varRdRev.biuRev;
198 vp->rev.smRev = mb->un.varRdRev.smRev;
199 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
200 vp->rev.endecRev = mb->un.varRdRev.endecRev;
201 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
202 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
203 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
204 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
205 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
206 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
207
James Smart92d7f7b2007-06-17 19:56:38 -0500208 /* If the sli feature level is less then 9, we must
209 * tear down all RPIs and VPIs on link down if NPIV
210 * is enabled.
211 */
212 if (vp->rev.feaLevelHigh < 9)
213 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
214
dea31012005-04-17 16:05:31 -0500215 if (lpfc_is_LC_HBA(phba->pcidev->device))
216 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
217 sizeof (phba->RandomData));
218
dea31012005-04-17 16:05:31 -0500219 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500220 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
221 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400222 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500223 do {
James Smarta0c87cb2009-07-19 10:01:10 -0400224 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
dea31012005-04-17 16:05:31 -0500225 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
226
227 if (rc != MBX_SUCCESS) {
228 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400229 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500230 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500231 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500232 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500233 }
James Smart04c68492009-05-22 14:52:52 -0400234 /* dump mem may return a zero when finished or we got a
235 * mailbox error, either way we are done.
236 */
237 if (mb->un.varDmp.word_cnt == 0)
238 break;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500239 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
240 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400241 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
242 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500243 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500244 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500245 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
246 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500247
248 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500249out_free_mbox:
250 mempool_free(pmb, phba->mbox_mem_pool);
251 return 0;
252}
253
James Smarte59058c2008-08-24 21:49:00 -0400254/**
James Smart3621a712009-04-06 18:47:14 -0400255 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
James Smarte59058c2008-08-24 21:49:00 -0400256 * @phba: pointer to lpfc hba data structure.
257 * @pmboxq: pointer to the driver internal queue element for mailbox command.
258 *
259 * This is the completion handler for driver's configuring asynchronous event
260 * mailbox command to the device. If the mailbox command returns successfully,
261 * it will set internal async event support flag to 1; otherwise, it will
262 * set internal async event support flag to 0.
263 **/
James Smart57127f12007-10-27 13:37:05 -0400264static void
265lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
266{
James Smart04c68492009-05-22 14:52:52 -0400267 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
James Smart57127f12007-10-27 13:37:05 -0400268 phba->temp_sensor_support = 1;
269 else
270 phba->temp_sensor_support = 0;
271 mempool_free(pmboxq, phba->mbox_mem_pool);
272 return;
273}
274
James Smarte59058c2008-08-24 21:49:00 -0400275/**
James Smart3621a712009-04-06 18:47:14 -0400276 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
James Smart97207482008-12-04 22:39:19 -0500277 * @phba: pointer to lpfc hba data structure.
278 * @pmboxq: pointer to the driver internal queue element for mailbox command.
279 *
280 * This is the completion handler for dump mailbox command for getting
281 * wake up parameters. When this command complete, the response contain
282 * Option rom version of the HBA. This function translate the version number
283 * into a human readable string and store it in OptionROMVersion.
284 **/
285static void
286lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
287{
288 struct prog_id *prg;
289 uint32_t prog_id_word;
290 char dist = ' ';
291 /* character array used for decoding dist type. */
292 char dist_char[] = "nabx";
293
James Smart04c68492009-05-22 14:52:52 -0400294 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
James Smart9f1e1b52008-12-04 22:39:40 -0500295 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500296 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500297 }
James Smart97207482008-12-04 22:39:19 -0500298
299 prg = (struct prog_id *) &prog_id_word;
300
301 /* word 7 contain option rom version */
James Smart04c68492009-05-22 14:52:52 -0400302 prog_id_word = pmboxq->u.mb.un.varWords[7];
James Smart97207482008-12-04 22:39:19 -0500303
304 /* Decode the Option rom version word to a readable string */
305 if (prg->dist < 4)
306 dist = dist_char[prg->dist];
307
308 if ((prg->dist == 3) && (prg->num == 0))
309 sprintf(phba->OptionROMVersion, "%d.%d%d",
310 prg->ver, prg->rev, prg->lev);
311 else
312 sprintf(phba->OptionROMVersion, "%d.%d%d%c%d",
313 prg->ver, prg->rev, prg->lev,
314 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500315 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500316 return;
317}
318
319/**
James Smart05580562011-05-24 11:40:48 -0400320 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
321 * cfg_soft_wwnn, cfg_soft_wwpn
322 * @vport: pointer to lpfc vport data structure.
323 *
324 *
325 * Return codes
326 * None.
327 **/
328void
329lpfc_update_vport_wwn(struct lpfc_vport *vport)
330{
331 /* If the soft name exists then update it using the service params */
332 if (vport->phba->cfg_soft_wwnn)
333 u64_to_wwn(vport->phba->cfg_soft_wwnn,
334 vport->fc_sparam.nodeName.u.wwn);
335 if (vport->phba->cfg_soft_wwpn)
336 u64_to_wwn(vport->phba->cfg_soft_wwpn,
337 vport->fc_sparam.portName.u.wwn);
338
339 /*
340 * If the name is empty or there exists a soft name
341 * then copy the service params name, otherwise use the fc name
342 */
343 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
344 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
345 sizeof(struct lpfc_name));
346 else
347 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
348 sizeof(struct lpfc_name));
349
350 if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn)
351 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
352 sizeof(struct lpfc_name));
353 else
354 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
355 sizeof(struct lpfc_name));
356}
357
358/**
James Smart3621a712009-04-06 18:47:14 -0400359 * lpfc_config_port_post - Perform lpfc initialization after config port
James Smarte59058c2008-08-24 21:49:00 -0400360 * @phba: pointer to lpfc hba data structure.
361 *
362 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
363 * command call. It performs all internal resource and state setups on the
364 * port: post IOCB buffers, enable appropriate host interrupt attentions,
365 * ELS ring timers, etc.
366 *
367 * Return codes
368 * 0 - success.
369 * Any other value - error.
370 **/
dea31012005-04-17 16:05:31 -0500371int
James Smart2e0fef82007-06-17 19:56:36 -0500372lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500373{
James Smart2e0fef82007-06-17 19:56:36 -0500374 struct lpfc_vport *vport = phba->pport;
James Smarta257bf92009-04-06 18:48:10 -0400375 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500376 LPFC_MBOXQ_t *pmb;
377 MAILBOX_t *mb;
378 struct lpfc_dmabuf *mp;
379 struct lpfc_sli *psli = &phba->sli;
380 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500381 int i, j;
382 int rc;
dea31012005-04-17 16:05:31 -0500383
James Smart7af67052007-10-27 13:38:11 -0400384 spin_lock_irq(&phba->hbalock);
385 /*
386 * If the Config port completed correctly the HBA is not
387 * over heated any more.
388 */
389 if (phba->over_temp_state == HBA_OVER_TEMP)
390 phba->over_temp_state = HBA_NORMAL_TEMP;
391 spin_unlock_irq(&phba->hbalock);
392
dea31012005-04-17 16:05:31 -0500393 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
394 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500395 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500396 return -ENOMEM;
397 }
James Smart04c68492009-05-22 14:52:52 -0400398 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500399
dea31012005-04-17 16:05:31 -0500400 /* Get login parameters for NID. */
James Smart9f1177a2010-02-26 14:12:57 -0500401 rc = lpfc_read_sparam(phba, pmb, 0);
402 if (rc) {
403 mempool_free(pmb, phba->mbox_mem_pool);
404 return -ENOMEM;
405 }
406
James Smarted957682007-06-17 19:56:37 -0500407 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500408 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500409 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400410 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500411 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500412 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500413 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500414 mp = (struct lpfc_dmabuf *) pmb->context1;
James Smart9f1177a2010-02-26 14:12:57 -0500415 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500416 lpfc_mbuf_free(phba, mp->virt, mp->phys);
417 kfree(mp);
418 return -EIO;
419 }
420
421 mp = (struct lpfc_dmabuf *) pmb->context1;
422
James Smart2e0fef82007-06-17 19:56:36 -0500423 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500424 lpfc_mbuf_free(phba, mp->virt, mp->phys);
425 kfree(mp);
426 pmb->context1 = NULL;
James Smart05580562011-05-24 11:40:48 -0400427 lpfc_update_vport_wwn(vport);
James Smarta257bf92009-04-06 18:48:10 -0400428
429 /* Update the fc_host data structures with new wwn. */
430 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
431 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart21e9a0a2009-05-22 14:53:21 -0400432 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smarta257bf92009-04-06 18:48:10 -0400433
dea31012005-04-17 16:05:31 -0500434 /* If no serial number in VPD data, use low 6 bytes of WWNN */
435 /* This should be consolidated into parse_vpd ? - mr */
436 if (phba->SerialNumber[0] == 0) {
437 uint8_t *outptr;
438
James Smart2e0fef82007-06-17 19:56:36 -0500439 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500440 for (i = 0; i < 12; i++) {
441 status = *outptr++;
442 j = ((status & 0xf0) >> 4);
443 if (j <= 9)
444 phba->SerialNumber[i] =
445 (char)((uint8_t) 0x30 + (uint8_t) j);
446 else
447 phba->SerialNumber[i] =
448 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
449 i++;
450 j = (status & 0xf);
451 if (j <= 9)
452 phba->SerialNumber[i] =
453 (char)((uint8_t) 0x30 + (uint8_t) j);
454 else
455 phba->SerialNumber[i] =
456 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
457 }
458 }
459
dea31012005-04-17 16:05:31 -0500460 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500461 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500462 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500463 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400464 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500465 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500466 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500467 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500468 mempool_free( pmb, phba->mbox_mem_pool);
469 return -EIO;
470 }
471
James Smarta0c87cb2009-07-19 10:01:10 -0400472 /* Check if the port is disabled */
473 lpfc_sli_read_link_ste(phba);
474
dea31012005-04-17 16:05:31 -0500475 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -0400476 i = (mb->un.varRdConfig.max_xri + 1);
477 if (phba->cfg_hba_queue_depth > i) {
478 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
479 "3359 HBA queue depth changed from %d to %d\n",
480 phba->cfg_hba_queue_depth, i);
481 phba->cfg_hba_queue_depth = i;
482 }
483
484 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
485 i = (mb->un.varRdConfig.max_xri >> 3);
486 if (phba->pport->cfg_lun_queue_depth > i) {
487 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
488 "3360 LUN queue depth changed from %d to %d\n",
489 phba->pport->cfg_lun_queue_depth, i);
490 phba->pport->cfg_lun_queue_depth = i;
491 }
dea31012005-04-17 16:05:31 -0500492
493 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500494
495 /* Get the default values for Model Name and Description */
496 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
497
James Smart2e0fef82007-06-17 19:56:36 -0500498 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500499
James Smart0b727fe2007-10-27 13:37:25 -0400500 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smart7e56aa22012-08-03 12:35:34 -0400501 if (psli->ring[psli->extra_ring].sli.sli3.cmdringaddr)
James Smarta4bc3372006-12-02 13:34:16 -0500502 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
James Smart7e56aa22012-08-03 12:35:34 -0400503 if (psli->ring[psli->fcp_ring].sli.sli3.cmdringaddr)
dea31012005-04-17 16:05:31 -0500504 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
James Smart7e56aa22012-08-03 12:35:34 -0400505 if (psli->ring[psli->next_ring].sli.sli3.cmdringaddr)
dea31012005-04-17 16:05:31 -0500506 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
507
508 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500509 if (phba->sli_rev != 3)
510 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500511
James Smart93996272008-08-24 21:50:30 -0400512 /*
513 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
514 */
515 if (phba->intr_type == MSIX) {
516 rc = lpfc_config_msi(phba, pmb);
517 if (rc) {
518 mempool_free(pmb, phba->mbox_mem_pool);
519 return -EIO;
520 }
521 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
522 if (rc != MBX_SUCCESS) {
523 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
524 "0352 Config MSI mailbox command "
525 "failed, mbxCmd x%x, mbxStatus x%x\n",
James Smart04c68492009-05-22 14:52:52 -0400526 pmb->u.mb.mbxCommand,
527 pmb->u.mb.mbxStatus);
James Smart93996272008-08-24 21:50:30 -0400528 mempool_free(pmb, phba->mbox_mem_pool);
529 return -EIO;
530 }
531 }
532
James Smart04c68492009-05-22 14:52:52 -0400533 spin_lock_irq(&phba->hbalock);
James Smart93996272008-08-24 21:50:30 -0400534 /* Initialize ERATT handling flag */
535 phba->hba_flag &= ~HBA_ERATT_HANDLED;
536
dea31012005-04-17 16:05:31 -0500537 /* Enable appropriate host interrupts */
James Smart9940b972011-03-11 16:06:12 -0500538 if (lpfc_readl(phba->HCregaddr, &status)) {
539 spin_unlock_irq(&phba->hbalock);
540 return -EIO;
541 }
dea31012005-04-17 16:05:31 -0500542 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
543 if (psli->num_rings > 0)
544 status |= HC_R0INT_ENA;
545 if (psli->num_rings > 1)
546 status |= HC_R1INT_ENA;
547 if (psli->num_rings > 2)
548 status |= HC_R2INT_ENA;
549 if (psli->num_rings > 3)
550 status |= HC_R3INT_ENA;
551
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500552 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
553 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400554 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500555
dea31012005-04-17 16:05:31 -0500556 writel(status, phba->HCregaddr);
557 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500558 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500559
James Smart93996272008-08-24 21:50:30 -0400560 /* Set up ring-0 (ELS) timer */
561 timeout = phba->fc_ratov * 2;
James Smart256ec0d2013-04-17 20:14:58 -0400562 mod_timer(&vport->els_tmofunc,
563 jiffies + msecs_to_jiffies(1000 * timeout));
James Smart93996272008-08-24 21:50:30 -0400564 /* Set up heart beat (HB) timer */
James Smart256ec0d2013-04-17 20:14:58 -0400565 mod_timer(&phba->hb_tmofunc,
566 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -0500567 phba->hb_outstanding = 0;
568 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400569 /* Set up error attention (ERATT) polling timer */
James Smart256ec0d2013-04-17 20:14:58 -0400570 mod_timer(&phba->eratt_poll,
571 jiffies + msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL));
dea31012005-04-17 16:05:31 -0500572
James Smarta0c87cb2009-07-19 10:01:10 -0400573 if (phba->hba_flag & LINK_DISABLED) {
574 lpfc_printf_log(phba,
575 KERN_ERR, LOG_INIT,
576 "2598 Adapter Link is disabled.\n");
577 lpfc_down_link(phba, pmb);
578 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
579 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
580 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
581 lpfc_printf_log(phba,
582 KERN_ERR, LOG_INIT,
583 "2599 Adapter failed to issue DOWN_LINK"
584 " mbox command rc 0x%x\n", rc);
585
586 mempool_free(pmb, phba->mbox_mem_pool);
587 return -EIO;
588 }
James Smarte40a02c2010-02-26 14:13:54 -0500589 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
James Smart026abb82011-12-13 13:20:45 -0500590 mempool_free(pmb, phba->mbox_mem_pool);
591 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
592 if (rc)
593 return rc;
dea31012005-04-17 16:05:31 -0500594 }
595 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400596 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500597 if (!pmb) {
598 phba->link_state = LPFC_HBA_ERROR;
599 return -ENOMEM;
600 }
601
James Smart57127f12007-10-27 13:37:05 -0400602 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
603 pmb->mbox_cmpl = lpfc_config_async_cmpl;
604 pmb->vport = phba->pport;
605 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500606
James Smart57127f12007-10-27 13:37:05 -0400607 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
608 lpfc_printf_log(phba,
609 KERN_ERR,
610 LOG_INIT,
611 "0456 Adapter failed to issue "
James Smarte4e74272009-07-19 10:01:38 -0400612 "ASYNCEVT_ENABLE mbox status x%x\n",
James Smart57127f12007-10-27 13:37:05 -0400613 rc);
614 mempool_free(pmb, phba->mbox_mem_pool);
615 }
James Smart97207482008-12-04 22:39:19 -0500616
617 /* Get Option rom version */
618 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500619 if (!pmb) {
620 phba->link_state = LPFC_HBA_ERROR;
621 return -ENOMEM;
622 }
623
James Smart97207482008-12-04 22:39:19 -0500624 lpfc_dump_wakeup_param(phba, pmb);
625 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
626 pmb->vport = phba->pport;
627 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
628
629 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
630 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
James Smarte4e74272009-07-19 10:01:38 -0400631 "to get Option ROM version status x%x\n", rc);
James Smart97207482008-12-04 22:39:19 -0500632 mempool_free(pmb, phba->mbox_mem_pool);
633 }
634
James Smartd7c255b2008-08-24 21:50:00 -0400635 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400636}
637
James Smarte59058c2008-08-24 21:49:00 -0400638/**
James Smart84d1b002010-02-12 14:42:33 -0500639 * lpfc_hba_init_link - Initialize the FC link
640 * @phba: pointer to lpfc hba data structure.
James Smart6e7288d2010-06-07 15:23:35 -0400641 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500642 *
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
James Smart6e7288d2010-06-07 15:23:35 -0400653lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500654{
James Smart1b511972011-12-13 13:23:09 -0500655 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
656}
657
658/**
659 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
660 * @phba: pointer to lpfc hba data structure.
661 * @fc_topology: desired fc topology.
662 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
663 *
664 * This routine will issue the INIT_LINK mailbox command call.
665 * It is available to other drivers through the lpfc_hba data
666 * structure for use as a delayed link up mechanism with the
667 * module parameter lpfc_suppress_link_up.
668 *
669 * Return code
670 * 0 - success
671 * Any other value - error
672 **/
673int
674lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
675 uint32_t flag)
676{
James Smart84d1b002010-02-12 14:42:33 -0500677 struct lpfc_vport *vport = phba->pport;
678 LPFC_MBOXQ_t *pmb;
679 MAILBOX_t *mb;
680 int rc;
681
682 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
683 if (!pmb) {
684 phba->link_state = LPFC_HBA_ERROR;
685 return -ENOMEM;
686 }
687 mb = &pmb->u.mb;
688 pmb->vport = vport;
689
James Smart026abb82011-12-13 13:20:45 -0500690 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
691 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
692 !(phba->lmt & LMT_1Gb)) ||
693 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
694 !(phba->lmt & LMT_2Gb)) ||
695 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
696 !(phba->lmt & LMT_4Gb)) ||
697 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
698 !(phba->lmt & LMT_8Gb)) ||
699 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
700 !(phba->lmt & LMT_10Gb)) ||
701 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
702 !(phba->lmt & LMT_16Gb))) {
703 /* Reset link speed to auto */
704 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
705 "1302 Invalid speed for this board:%d "
706 "Reset link speed to auto.\n",
707 phba->cfg_link_speed);
708 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
709 }
James Smart1b511972011-12-13 13:23:09 -0500710 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
James Smart84d1b002010-02-12 14:42:33 -0500711 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart1b511972011-12-13 13:23:09 -0500712 if (phba->sli_rev < LPFC_SLI_REV4)
713 lpfc_set_loopback_flag(phba);
James Smart6e7288d2010-06-07 15:23:35 -0400714 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart76a95d72010-11-20 23:11:48 -0500715 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
James Smart84d1b002010-02-12 14:42:33 -0500716 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
717 "0498 Adapter failed to init, mbxCmd x%x "
718 "INIT_LINK, mbxStatus x%x\n",
719 mb->mbxCommand, mb->mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -0500720 if (phba->sli_rev <= LPFC_SLI_REV3) {
721 /* Clear all interrupt enable conditions */
722 writel(0, phba->HCregaddr);
723 readl(phba->HCregaddr); /* flush */
724 /* Clear all pending interrupts */
725 writel(0xffffffff, phba->HAregaddr);
726 readl(phba->HAregaddr); /* flush */
727 }
James Smart84d1b002010-02-12 14:42:33 -0500728 phba->link_state = LPFC_HBA_ERROR;
James Smart6e7288d2010-06-07 15:23:35 -0400729 if (rc != MBX_BUSY || flag == MBX_POLL)
James Smart84d1b002010-02-12 14:42:33 -0500730 mempool_free(pmb, phba->mbox_mem_pool);
731 return -EIO;
732 }
James Smarte40a02c2010-02-26 14:13:54 -0500733 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
James Smart6e7288d2010-06-07 15:23:35 -0400734 if (flag == MBX_POLL)
735 mempool_free(pmb, phba->mbox_mem_pool);
James Smart84d1b002010-02-12 14:42:33 -0500736
737 return 0;
738}
739
740/**
741 * lpfc_hba_down_link - this routine downs the FC link
James Smart6e7288d2010-06-07 15:23:35 -0400742 * @phba: pointer to lpfc hba data structure.
743 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500744 *
745 * This routine will issue the DOWN_LINK mailbox command call.
746 * It is available to other drivers through the lpfc_hba data
747 * structure for use to stop the link.
748 *
749 * Return code
750 * 0 - success
751 * Any other value - error
752 **/
753int
James Smart6e7288d2010-06-07 15:23:35 -0400754lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500755{
756 LPFC_MBOXQ_t *pmb;
757 int rc;
758
759 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
760 if (!pmb) {
761 phba->link_state = LPFC_HBA_ERROR;
762 return -ENOMEM;
763 }
764
765 lpfc_printf_log(phba,
766 KERN_ERR, LOG_INIT,
767 "0491 Adapter Link is disabled.\n");
768 lpfc_down_link(phba, pmb);
769 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart6e7288d2010-06-07 15:23:35 -0400770 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart84d1b002010-02-12 14:42:33 -0500771 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
772 lpfc_printf_log(phba,
773 KERN_ERR, LOG_INIT,
774 "2522 Adapter failed to issue DOWN_LINK"
775 " mbox command rc 0x%x\n", rc);
776
777 mempool_free(pmb, phba->mbox_mem_pool);
778 return -EIO;
779 }
James Smart6e7288d2010-06-07 15:23:35 -0400780 if (flag == MBX_POLL)
781 mempool_free(pmb, phba->mbox_mem_pool);
782
James Smart84d1b002010-02-12 14:42:33 -0500783 return 0;
784}
785
786/**
James Smart3621a712009-04-06 18:47:14 -0400787 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400788 * @phba: pointer to lpfc HBA data structure.
789 *
790 * This routine will do LPFC uninitialization before the HBA is reset when
791 * bringing down the SLI Layer.
792 *
793 * Return codes
794 * 0 - success.
795 * Any other value - error.
796 **/
dea31012005-04-17 16:05:31 -0500797int
James Smart2e0fef82007-06-17 19:56:36 -0500798lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500799{
James Smart1b32f6a2008-02-08 18:49:39 -0500800 struct lpfc_vport **vports;
801 int i;
James Smart3772a992009-05-22 14:50:54 -0400802
803 if (phba->sli_rev <= LPFC_SLI_REV3) {
804 /* Disable interrupts */
805 writel(0, phba->HCregaddr);
806 readl(phba->HCregaddr); /* flush */
807 }
dea31012005-04-17 16:05:31 -0500808
James Smart1b32f6a2008-02-08 18:49:39 -0500809 if (phba->pport->load_flag & FC_UNLOADING)
810 lpfc_cleanup_discovery_resources(phba->pport);
811 else {
812 vports = lpfc_create_vport_work_array(phba);
813 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -0400814 for (i = 0; i <= phba->max_vports &&
815 vports[i] != NULL; i++)
James Smart1b32f6a2008-02-08 18:49:39 -0500816 lpfc_cleanup_discovery_resources(vports[i]);
817 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500818 }
819 return 0;
dea31012005-04-17 16:05:31 -0500820}
821
James Smarte59058c2008-08-24 21:49:00 -0400822/**
James Smart3772a992009-05-22 14:50:54 -0400823 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400824 * @phba: pointer to lpfc HBA data structure.
825 *
826 * This routine will do uninitialization after the HBA is reset when bring
827 * down the SLI Layer.
828 *
829 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200830 * 0 - success.
James Smarte59058c2008-08-24 21:49:00 -0400831 * Any other value - error.
832 **/
James Smart3772a992009-05-22 14:50:54 -0400833static int
834lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500835{
836 struct lpfc_sli *psli = &phba->sli;
837 struct lpfc_sli_ring *pring;
838 struct lpfc_dmabuf *mp, *next_mp;
James Smart09372822008-01-11 01:52:54 -0500839 LIST_HEAD(completions);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500840 int i;
841
James Smart92d7f7b2007-06-17 19:56:38 -0500842 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
843 lpfc_sli_hbqbuf_free_all(phba);
844 else {
845 /* Cleanup preposted buffers on the ELS ring */
846 pring = &psli->ring[LPFC_ELS_RING];
847 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
848 list_del(&mp->list);
849 pring->postbufq_cnt--;
850 lpfc_mbuf_free(phba, mp->virt, mp->phys);
851 kfree(mp);
852 }
Jamie Wellnitz41415862006-02-28 19:25:27 -0500853 }
854
James Smart09372822008-01-11 01:52:54 -0500855 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500856 for (i = 0; i < psli->num_rings; i++) {
857 pring = &psli->ring[i];
James Smart09372822008-01-11 01:52:54 -0500858
859 /* At this point in time the HBA is either reset or DOA. Either
860 * way, nothing should be on txcmplq as it will NEVER complete.
861 */
862 list_splice_init(&pring->txcmplq, &completions);
James Smart09372822008-01-11 01:52:54 -0500863 spin_unlock_irq(&phba->hbalock);
864
James Smarta257bf92009-04-06 18:48:10 -0400865 /* Cancel all the IOCBs from the completions list */
866 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
867 IOERR_SLI_ABORTED);
James Smart09372822008-01-11 01:52:54 -0500868
Jamie Wellnitz41415862006-02-28 19:25:27 -0500869 lpfc_sli_abort_iocb_ring(phba, pring);
James Smart09372822008-01-11 01:52:54 -0500870 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500871 }
James Smart09372822008-01-11 01:52:54 -0500872 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500873
874 return 0;
875}
James Smart5af5eee2010-10-22 11:06:38 -0400876
James Smartda0436e2009-05-22 14:51:39 -0400877/**
878 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
879 * @phba: pointer to lpfc HBA data structure.
880 *
881 * This routine will do uninitialization after the HBA is reset when bring
882 * down the SLI Layer.
883 *
884 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200885 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -0400886 * Any other value - error.
887 **/
888static int
889lpfc_hba_down_post_s4(struct lpfc_hba *phba)
890{
891 struct lpfc_scsi_buf *psb, *psb_next;
892 LIST_HEAD(aborts);
893 int ret;
894 unsigned long iflag = 0;
James Smart0f65ff62010-02-26 14:14:23 -0500895 struct lpfc_sglq *sglq_entry = NULL;
896
James Smartda0436e2009-05-22 14:51:39 -0400897 ret = lpfc_hba_down_post_s3(phba);
898 if (ret)
899 return ret;
900 /* At this point in time the HBA is either reset or DOA. Either
901 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
902 * on the lpfc_sgl_list so that it can either be freed if the
903 * driver is unloading or reposted if the driver is restarting
904 * the port.
905 */
906 spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */
907 /* scsl_buf_list */
908 /* abts_sgl_list_lock required because worker thread uses this
909 * list.
910 */
911 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -0500912 list_for_each_entry(sglq_entry,
913 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
914 sglq_entry->state = SGL_FREED;
915
James Smartda0436e2009-05-22 14:51:39 -0400916 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
917 &phba->sli4_hba.lpfc_sgl_list);
918 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
919 /* abts_scsi_buf_list_lock required because worker thread uses this
920 * list.
921 */
922 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
923 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
924 &aborts);
925 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
926 spin_unlock_irq(&phba->hbalock);
927
928 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
929 psb->pCmd = NULL;
930 psb->status = IOSTAT_SUCCESS;
931 }
James Smarta40fc5f2013-04-17 20:17:40 -0400932 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
933 list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
934 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
James Smartda0436e2009-05-22 14:51:39 -0400935 return 0;
936}
937
938/**
939 * lpfc_hba_down_post - Wrapper func for hba down post routine
940 * @phba: pointer to lpfc HBA data structure.
941 *
942 * This routine wraps the actual SLI3 or SLI4 routine for performing
943 * uninitialization after the HBA is reset when bring down the SLI Layer.
944 *
945 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200946 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -0400947 * Any other value - error.
948 **/
949int
950lpfc_hba_down_post(struct lpfc_hba *phba)
951{
952 return (*phba->lpfc_hba_down_post)(phba);
953}
Jamie Wellnitz41415862006-02-28 19:25:27 -0500954
James Smarte59058c2008-08-24 21:49:00 -0400955/**
James Smart3621a712009-04-06 18:47:14 -0400956 * lpfc_hb_timeout - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -0400957 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
958 *
959 * This is the HBA-timer timeout handler registered to the lpfc driver. When
960 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
961 * work-port-events bitmap and the worker thread is notified. This timeout
962 * event will be used by the worker thread to invoke the actual timeout
963 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
964 * be performed in the timeout handler and the HBA timeout event bit shall
965 * be cleared by the worker thread after it has taken the event bitmap out.
966 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +0100967static void
James Smart858c9f62007-06-17 19:56:39 -0500968lpfc_hb_timeout(unsigned long ptr)
969{
970 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -0400971 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -0500972 unsigned long iflag;
973
974 phba = (struct lpfc_hba *)ptr;
James Smart93996272008-08-24 21:50:30 -0400975
976 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -0500977 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -0400978 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
979 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -0500980 phba->pport->work_port_events |= WORKER_HB_TMO;
981 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
982
James Smart93996272008-08-24 21:50:30 -0400983 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -0400984 if (!tmo_posted)
985 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -0500986 return;
987}
988
James Smarte59058c2008-08-24 21:49:00 -0400989/**
James Smart19ca7602010-11-20 23:11:55 -0500990 * lpfc_rrq_timeout - The RRQ-timer timeout handler
991 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
992 *
993 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
994 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
995 * work-port-events bitmap and the worker thread is notified. This timeout
996 * event will be used by the worker thread to invoke the actual timeout
997 * handler routine, lpfc_rrq_handler. Any periodical operations will
998 * be performed in the timeout handler and the RRQ timeout event bit shall
999 * be cleared by the worker thread after it has taken the event bitmap out.
1000 **/
1001static void
1002lpfc_rrq_timeout(unsigned long ptr)
1003{
1004 struct lpfc_hba *phba;
James Smart19ca7602010-11-20 23:11:55 -05001005 unsigned long iflag;
1006
1007 phba = (struct lpfc_hba *)ptr;
1008 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart1151e3e2011-02-16 12:39:35 -05001009 phba->hba_flag |= HBA_RRQ_ACTIVE;
James Smart19ca7602010-11-20 23:11:55 -05001010 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
James Smart1151e3e2011-02-16 12:39:35 -05001011 lpfc_worker_wake_up(phba);
James Smart19ca7602010-11-20 23:11:55 -05001012}
1013
1014/**
James Smart3621a712009-04-06 18:47:14 -04001015 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -04001016 * @phba: pointer to lpfc hba data structure.
1017 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1018 *
1019 * This is the callback function to the lpfc heart-beat mailbox command.
1020 * If configured, the lpfc driver issues the heart-beat mailbox command to
1021 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1022 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1023 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1024 * heart-beat outstanding state. Once the mailbox command comes back and
1025 * no error conditions detected, the heart-beat mailbox command timer is
1026 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1027 * state is cleared for the next heart-beat. If the timer expired with the
1028 * heart-beat outstanding state set, the driver will put the HBA offline.
1029 **/
James Smart858c9f62007-06-17 19:56:39 -05001030static void
1031lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1032{
1033 unsigned long drvr_flag;
1034
1035 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1036 phba->hb_outstanding = 0;
1037 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1038
James Smart93996272008-08-24 21:50:30 -04001039 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -05001040 mempool_free(pmboxq, phba->mbox_mem_pool);
1041 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1042 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -04001043 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -05001044 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001045 jiffies +
1046 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001047 return;
1048}
1049
James Smarte59058c2008-08-24 21:49:00 -04001050/**
James Smart3621a712009-04-06 18:47:14 -04001051 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001052 * @phba: pointer to lpfc hba data structure.
1053 *
1054 * This is the actual HBA-timer timeout handler to be invoked by the worker
1055 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1056 * handler performs any periodic operations needed for the device. If such
1057 * periodic event has already been attended to either in the interrupt handler
1058 * or by processing slow-ring or fast-ring events within the HBA-timer
1059 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1060 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1061 * is configured and there is no heart-beat mailbox command outstanding, a
1062 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1063 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1064 * to offline.
1065 **/
James Smart858c9f62007-06-17 19:56:39 -05001066void
1067lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1068{
James Smart45ed1192009-10-02 15:17:02 -04001069 struct lpfc_vport **vports;
James Smart858c9f62007-06-17 19:56:39 -05001070 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -05001071 struct lpfc_dmabuf *buf_ptr;
James Smart45ed1192009-10-02 15:17:02 -04001072 int retval, i;
James Smart858c9f62007-06-17 19:56:39 -05001073 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -05001074 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -05001075
James Smart45ed1192009-10-02 15:17:02 -04001076 vports = lpfc_create_vport_work_array(phba);
1077 if (vports != NULL)
1078 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
1079 lpfc_rcv_seq_check_edtov(vports[i]);
1080 lpfc_destroy_vport_work_array(phba, vports);
1081
James Smart858c9f62007-06-17 19:56:39 -05001082 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -04001083 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -05001084 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1085 return;
1086
1087 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -05001088
James Smart256ec0d2013-04-17 20:14:58 -04001089 if (time_after(phba->last_completion_time +
1090 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1091 jiffies)) {
James Smart858c9f62007-06-17 19:56:39 -05001092 spin_unlock_irq(&phba->pport->work_port_lock);
1093 if (!phba->hb_outstanding)
1094 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001095 jiffies +
1096 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001097 else
1098 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001099 jiffies +
1100 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001101 return;
1102 }
1103 spin_unlock_irq(&phba->pport->work_port_lock);
1104
James Smart0ff10d42008-01-11 01:52:36 -05001105 if (phba->elsbuf_cnt &&
1106 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1107 spin_lock_irq(&phba->hbalock);
1108 list_splice_init(&phba->elsbuf, &completions);
1109 phba->elsbuf_cnt = 0;
1110 phba->elsbuf_prev_cnt = 0;
1111 spin_unlock_irq(&phba->hbalock);
1112
1113 while (!list_empty(&completions)) {
1114 list_remove_head(&completions, buf_ptr,
1115 struct lpfc_dmabuf, list);
1116 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1117 kfree(buf_ptr);
1118 }
1119 }
1120 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1121
James Smart858c9f62007-06-17 19:56:39 -05001122 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -05001123 if (phba->cfg_enable_hba_heartbeat) {
1124 if (!phba->hb_outstanding) {
James Smartbc739052010-08-04 16:11:18 -04001125 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1126 (list_empty(&psli->mboxq))) {
1127 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1128 GFP_KERNEL);
1129 if (!pmboxq) {
1130 mod_timer(&phba->hb_tmofunc,
1131 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001132 msecs_to_jiffies(1000 *
1133 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001134 return;
1135 }
James Smart13815c82008-01-11 01:52:48 -05001136
James Smartbc739052010-08-04 16:11:18 -04001137 lpfc_heart_beat(phba, pmboxq);
1138 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1139 pmboxq->vport = phba->pport;
1140 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1141 MBX_NOWAIT);
James Smart13815c82008-01-11 01:52:48 -05001142
James Smartbc739052010-08-04 16:11:18 -04001143 if (retval != MBX_BUSY &&
1144 retval != MBX_SUCCESS) {
1145 mempool_free(pmboxq,
1146 phba->mbox_mem_pool);
1147 mod_timer(&phba->hb_tmofunc,
1148 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001149 msecs_to_jiffies(1000 *
1150 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001151 return;
1152 }
1153 phba->skipped_hb = 0;
1154 phba->hb_outstanding = 1;
1155 } else if (time_before_eq(phba->last_completion_time,
1156 phba->skipped_hb)) {
1157 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1158 "2857 Last completion time not "
1159 " updated in %d ms\n",
1160 jiffies_to_msecs(jiffies
1161 - phba->last_completion_time));
1162 } else
1163 phba->skipped_hb = jiffies;
1164
James Smart858c9f62007-06-17 19:56:39 -05001165 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001166 jiffies +
1167 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001168 return;
James Smart13815c82008-01-11 01:52:48 -05001169 } else {
1170 /*
1171 * If heart beat timeout called with hb_outstanding set
James Smartdcf2a4e2010-09-29 11:18:53 -04001172 * we need to give the hb mailbox cmd a chance to
1173 * complete or TMO.
James Smart13815c82008-01-11 01:52:48 -05001174 */
James Smartdcf2a4e2010-09-29 11:18:53 -04001175 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1176 "0459 Adapter heartbeat still out"
1177 "standing:last compl time was %d ms.\n",
1178 jiffies_to_msecs(jiffies
1179 - phba->last_completion_time));
1180 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001181 jiffies +
1182 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001183 }
James Smart858c9f62007-06-17 19:56:39 -05001184 }
1185}
1186
James Smarte59058c2008-08-24 21:49:00 -04001187/**
James Smart3621a712009-04-06 18:47:14 -04001188 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -04001189 * @phba: pointer to lpfc hba data structure.
1190 *
1191 * This routine is called to bring the HBA offline when HBA hardware error
1192 * other than Port Error 6 has been detected.
1193 **/
James Smart09372822008-01-11 01:52:54 -05001194static void
1195lpfc_offline_eratt(struct lpfc_hba *phba)
1196{
1197 struct lpfc_sli *psli = &phba->sli;
1198
1199 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001200 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -05001201 spin_unlock_irq(&phba->hbalock);
James Smart618a5232012-06-12 13:54:36 -04001202 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart09372822008-01-11 01:52:54 -05001203
1204 lpfc_offline(phba);
1205 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001206 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001207 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001208 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001209 lpfc_hba_down_post(phba);
1210 lpfc_sli_brdready(phba, HS_MBRDY);
1211 lpfc_unblock_mgmt_io(phba);
1212 phba->link_state = LPFC_HBA_ERROR;
1213 return;
1214}
1215
James Smarte59058c2008-08-24 21:49:00 -04001216/**
James Smartda0436e2009-05-22 14:51:39 -04001217 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1218 * @phba: pointer to lpfc hba data structure.
1219 *
1220 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1221 * other than Port Error 6 has been detected.
1222 **/
James Smarta88dbb62013-04-17 20:18:39 -04001223void
James Smartda0436e2009-05-22 14:51:39 -04001224lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1225{
James Smart618a5232012-06-12 13:54:36 -04001226 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smartda0436e2009-05-22 14:51:39 -04001227 lpfc_offline(phba);
1228 lpfc_sli4_brdreset(phba);
1229 lpfc_hba_down_post(phba);
1230 lpfc_sli4_post_status_check(phba);
1231 lpfc_unblock_mgmt_io(phba);
1232 phba->link_state = LPFC_HBA_ERROR;
1233}
1234
1235/**
James Smarta257bf92009-04-06 18:48:10 -04001236 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1237 * @phba: pointer to lpfc hba data structure.
1238 *
1239 * This routine is invoked to handle the deferred HBA hardware error
1240 * conditions. This type of error is indicated by HBA by setting ER1
1241 * and another ER bit in the host status register. The driver will
1242 * wait until the ER1 bit clears before handling the error condition.
1243 **/
1244static void
1245lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1246{
1247 uint32_t old_host_status = phba->work_hs;
1248 struct lpfc_sli_ring *pring;
1249 struct lpfc_sli *psli = &phba->sli;
1250
James Smartf4b4c682009-05-22 14:53:12 -04001251 /* If the pci channel is offline, ignore possible errors,
1252 * since we cannot communicate with the pci card anyway.
1253 */
1254 if (pci_channel_offline(phba->pcidev)) {
1255 spin_lock_irq(&phba->hbalock);
1256 phba->hba_flag &= ~DEFER_ERATT;
1257 spin_unlock_irq(&phba->hbalock);
1258 return;
1259 }
1260
James Smarta257bf92009-04-06 18:48:10 -04001261 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1262 "0479 Deferred Adapter Hardware Error "
1263 "Data: x%x x%x x%x\n",
1264 phba->work_hs,
1265 phba->work_status[0], phba->work_status[1]);
1266
1267 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001268 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001269 spin_unlock_irq(&phba->hbalock);
1270
1271
1272 /*
1273 * Firmware stops when it triggred erratt. That could cause the I/Os
1274 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1275 * SCSI layer retry it after re-establishing link.
1276 */
1277 pring = &psli->ring[psli->fcp_ring];
1278 lpfc_sli_abort_iocb_ring(phba, pring);
1279
1280 /*
1281 * There was a firmware error. Take the hba offline and then
1282 * attempt to restart it.
1283 */
James Smart618a5232012-06-12 13:54:36 -04001284 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smarta257bf92009-04-06 18:48:10 -04001285 lpfc_offline(phba);
1286
1287 /* Wait for the ER1 bit to clear.*/
1288 while (phba->work_hs & HS_FFER1) {
1289 msleep(100);
James Smart9940b972011-03-11 16:06:12 -05001290 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1291 phba->work_hs = UNPLUG_ERR ;
1292 break;
1293 }
James Smarta257bf92009-04-06 18:48:10 -04001294 /* If driver is unloading let the worker thread continue */
1295 if (phba->pport->load_flag & FC_UNLOADING) {
1296 phba->work_hs = 0;
1297 break;
1298 }
1299 }
1300
1301 /*
1302 * This is to ptrotect against a race condition in which
1303 * first write to the host attention register clear the
1304 * host status register.
1305 */
1306 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1307 phba->work_hs = old_host_status & ~HS_FFER1;
1308
James Smart3772a992009-05-22 14:50:54 -04001309 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001310 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001311 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001312 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1313 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1314}
1315
James Smart3772a992009-05-22 14:50:54 -04001316static void
1317lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1318{
1319 struct lpfc_board_event_header board_event;
1320 struct Scsi_Host *shost;
1321
1322 board_event.event_type = FC_REG_BOARD_EVENT;
1323 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1324 shost = lpfc_shost_from_vport(phba->pport);
1325 fc_host_post_vendor_event(shost, fc_get_event_number(),
1326 sizeof(board_event),
1327 (char *) &board_event,
1328 LPFC_NL_VENDOR_ID);
1329}
1330
James Smarta257bf92009-04-06 18:48:10 -04001331/**
James Smart3772a992009-05-22 14:50:54 -04001332 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001333 * @phba: pointer to lpfc hba data structure.
1334 *
1335 * This routine is invoked to handle the following HBA hardware error
1336 * conditions:
1337 * 1 - HBA error attention interrupt
1338 * 2 - DMA ring index out of range
1339 * 3 - Mailbox command came back as unknown
1340 **/
James Smart3772a992009-05-22 14:50:54 -04001341static void
1342lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001343{
James Smart2e0fef82007-06-17 19:56:36 -05001344 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001345 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001346 struct lpfc_sli_ring *pring;
James Smartd2873e42006-08-18 17:46:43 -04001347 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001348 unsigned long temperature;
1349 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001350 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001351
Linas Vepstas8d63f372007-02-14 14:28:36 -06001352 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001353 * since we cannot communicate with the pci card anyway.
1354 */
1355 if (pci_channel_offline(phba->pcidev)) {
1356 spin_lock_irq(&phba->hbalock);
1357 phba->hba_flag &= ~DEFER_ERATT;
1358 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001359 return;
James Smart3772a992009-05-22 14:50:54 -04001360 }
1361
James Smart13815c82008-01-11 01:52:48 -05001362 /* If resets are disabled then leave the HBA alone and return */
1363 if (!phba->cfg_enable_hba_reset)
1364 return;
dea31012005-04-17 16:05:31 -05001365
James Smartea2151b2008-09-07 11:52:10 -04001366 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001367 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001368
James Smarta257bf92009-04-06 18:48:10 -04001369 if (phba->hba_flag & DEFER_ERATT)
1370 lpfc_handle_deferred_eratt(phba);
1371
James Smartdcf2a4e2010-09-29 11:18:53 -04001372 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1373 if (phba->work_hs & HS_FFER6)
1374 /* Re-establishing Link */
1375 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1376 "1301 Re-establishing Link "
1377 "Data: x%x x%x x%x\n",
1378 phba->work_hs, phba->work_status[0],
1379 phba->work_status[1]);
1380 if (phba->work_hs & HS_FFER8)
1381 /* Device Zeroization */
1382 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1383 "2861 Host Authentication device "
1384 "zeroization Data:x%x x%x x%x\n",
1385 phba->work_hs, phba->work_status[0],
1386 phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001387
James Smart92d7f7b2007-06-17 19:56:38 -05001388 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001389 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001390 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001391
1392 /*
1393 * Firmware stops when it triggled erratt with HS_FFER6.
1394 * That could cause the I/Os dropped by the firmware.
1395 * Error iocb (I/O) on txcmplq and let the SCSI layer
1396 * retry it after re-establishing link.
1397 */
1398 pring = &psli->ring[psli->fcp_ring];
1399 lpfc_sli_abort_iocb_ring(phba, pring);
1400
dea31012005-04-17 16:05:31 -05001401 /*
1402 * There was a firmware error. Take the hba offline and then
1403 * attempt to restart it.
1404 */
James Smart618a5232012-06-12 13:54:36 -04001405 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
dea31012005-04-17 16:05:31 -05001406 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001407 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001408 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001409 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001410 return;
1411 }
James Smart46fa3112007-04-25 09:51:45 -04001412 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001413 } else if (phba->work_hs & HS_CRIT_TEMP) {
1414 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1415 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1416 temp_event_data.event_code = LPFC_CRIT_TEMP;
1417 temp_event_data.data = (uint32_t)temperature;
1418
1419 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001420 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001421 "(%ld), taking this port offline "
1422 "Data: x%x x%x x%x\n",
1423 temperature, phba->work_hs,
1424 phba->work_status[0], phba->work_status[1]);
1425
1426 shost = lpfc_shost_from_vport(phba->pport);
1427 fc_host_post_vendor_event(shost, fc_get_event_number(),
1428 sizeof(temp_event_data),
1429 (char *) &temp_event_data,
1430 SCSI_NL_VID_TYPE_PCI
1431 | PCI_VENDOR_ID_EMULEX);
1432
James Smart7af67052007-10-27 13:38:11 -04001433 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001434 phba->over_temp_state = HBA_OVER_TEMP;
1435 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001436 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001437
dea31012005-04-17 16:05:31 -05001438 } else {
1439 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001440 * failure is a value other than FFER6. Do not call the offline
1441 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001442 */
1443 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001444 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001445 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001446 phba->work_hs,
dea31012005-04-17 16:05:31 -05001447 phba->work_status[0], phba->work_status[1]);
1448
James Smartd2873e42006-08-18 17:46:43 -04001449 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001450 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001451 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001452 sizeof(event_data), (char *) &event_data,
1453 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1454
James Smart09372822008-01-11 01:52:54 -05001455 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001456 }
James Smart93996272008-08-24 21:50:30 -04001457 return;
dea31012005-04-17 16:05:31 -05001458}
1459
James Smarte59058c2008-08-24 21:49:00 -04001460/**
James Smart618a5232012-06-12 13:54:36 -04001461 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1462 * @phba: pointer to lpfc hba data structure.
1463 * @mbx_action: flag for mailbox shutdown action.
1464 *
1465 * This routine is invoked to perform an SLI4 port PCI function reset in
1466 * response to port status register polling attention. It waits for port
1467 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1468 * During this process, interrupt vectors are freed and later requested
1469 * for handling possible port resource change.
1470 **/
1471static int
1472lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action)
1473{
1474 int rc;
1475 uint32_t intr_mode;
1476
1477 /*
1478 * On error status condition, driver need to wait for port
1479 * ready before performing reset.
1480 */
1481 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1482 if (!rc) {
1483 /* need reset: attempt for port recovery */
1484 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1485 "2887 Reset Needed: Attempting Port "
1486 "Recovery...\n");
1487 lpfc_offline_prep(phba, mbx_action);
1488 lpfc_offline(phba);
1489 /* release interrupt for possible resource change */
1490 lpfc_sli4_disable_intr(phba);
1491 lpfc_sli_brdrestart(phba);
1492 /* request and enable interrupt */
1493 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1494 if (intr_mode == LPFC_INTR_ERROR) {
1495 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1496 "3175 Failed to enable interrupt\n");
1497 return -EIO;
1498 } else {
1499 phba->intr_mode = intr_mode;
1500 }
1501 rc = lpfc_online(phba);
1502 if (rc == 0)
1503 lpfc_unblock_mgmt_io(phba);
1504 }
1505 return rc;
1506}
1507
1508/**
James Smartda0436e2009-05-22 14:51:39 -04001509 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1510 * @phba: pointer to lpfc hba data structure.
1511 *
1512 * This routine is invoked to handle the SLI4 HBA hardware error attention
1513 * conditions.
1514 **/
1515static void
1516lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1517{
1518 struct lpfc_vport *vport = phba->pport;
1519 uint32_t event_data;
1520 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001521 uint32_t if_type;
James Smart2e90f4b2011-12-13 13:22:37 -05001522 struct lpfc_register portstat_reg = {0};
1523 uint32_t reg_err1, reg_err2;
1524 uint32_t uerrlo_reg, uemasklo_reg;
1525 uint32_t pci_rd_rc1, pci_rd_rc2;
James Smart73d91e52011-10-10 21:32:10 -04001526 int rc;
James Smartda0436e2009-05-22 14:51:39 -04001527
1528 /* If the pci channel is offline, ignore possible errors, since
1529 * we cannot communicate with the pci card anyway.
1530 */
1531 if (pci_channel_offline(phba->pcidev))
1532 return;
1533 /* If resets are disabled then leave the HBA alone and return */
1534 if (!phba->cfg_enable_hba_reset)
1535 return;
1536
James Smart2fcee4b2010-12-15 17:57:46 -05001537 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1538 switch (if_type) {
1539 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart2e90f4b2011-12-13 13:22:37 -05001540 pci_rd_rc1 = lpfc_readl(
1541 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1542 &uerrlo_reg);
1543 pci_rd_rc2 = lpfc_readl(
1544 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1545 &uemasklo_reg);
1546 /* consider PCI bus read error as pci_channel_offline */
1547 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1548 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001549 lpfc_sli4_offline_eratt(phba);
1550 break;
1551 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2e90f4b2011-12-13 13:22:37 -05001552 pci_rd_rc1 = lpfc_readl(
1553 phba->sli4_hba.u.if_type2.STATUSregaddr,
1554 &portstat_reg.word0);
1555 /* consider PCI bus read error as pci_channel_offline */
James Smart6b5151f2012-01-18 16:24:06 -05001556 if (pci_rd_rc1 == -EIO) {
1557 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1558 "3151 PCI bus read access failure: x%x\n",
1559 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
James Smart2e90f4b2011-12-13 13:22:37 -05001560 return;
James Smart6b5151f2012-01-18 16:24:06 -05001561 }
James Smart2e90f4b2011-12-13 13:22:37 -05001562 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1563 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
James Smart2fcee4b2010-12-15 17:57:46 -05001564 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
1565 /* TODO: Register for Overtemp async events. */
1566 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1567 "2889 Port Overtemperature event, "
James Smart026abb82011-12-13 13:20:45 -05001568 "taking port offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05001569 spin_lock_irq(&phba->hbalock);
1570 phba->over_temp_state = HBA_OVER_TEMP;
1571 spin_unlock_irq(&phba->hbalock);
1572 lpfc_sli4_offline_eratt(phba);
James Smart2e90f4b2011-12-13 13:22:37 -05001573 break;
James Smart2fcee4b2010-12-15 17:57:46 -05001574 }
James Smart2e90f4b2011-12-13 13:22:37 -05001575 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1576 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART)
1577 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1578 "3143 Port Down: Firmware Restarted\n");
1579 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1580 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1581 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1582 "3144 Port Down: Debug Dump\n");
1583 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1584 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1585 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1586 "3145 Port Down: Provisioning\n");
James Smart618a5232012-06-12 13:54:36 -04001587
1588 /* Check port status register for function reset */
1589 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT);
1590 if (rc == 0) {
1591 /* don't report event on forced debug dump */
1592 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1593 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1594 return;
1595 else
1596 break;
James Smart2fcee4b2010-12-15 17:57:46 -05001597 }
James Smart618a5232012-06-12 13:54:36 -04001598 /* fall through for not able to recover */
James Smart6b5151f2012-01-18 16:24:06 -05001599 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1600 "3152 Unrecoverable error, bring the port "
1601 "offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05001602 lpfc_sli4_offline_eratt(phba);
1603 break;
1604 case LPFC_SLI_INTF_IF_TYPE_1:
1605 default:
1606 break;
1607 }
James Smart2e90f4b2011-12-13 13:22:37 -05001608 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1609 "3123 Report dump event to upper layer\n");
1610 /* Send an internal error event to mgmt application */
1611 lpfc_board_errevt_to_mgmt(phba);
1612
1613 event_data = FC_REG_DUMP_EVENT;
1614 shost = lpfc_shost_from_vport(vport);
1615 fc_host_post_vendor_event(shost, fc_get_event_number(),
1616 sizeof(event_data), (char *) &event_data,
1617 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
James Smartda0436e2009-05-22 14:51:39 -04001618}
1619
1620/**
1621 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1622 * @phba: pointer to lpfc HBA data structure.
1623 *
1624 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1625 * routine from the API jump table function pointer from the lpfc_hba struct.
1626 *
1627 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001628 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001629 * Any other value - error.
1630 **/
1631void
1632lpfc_handle_eratt(struct lpfc_hba *phba)
1633{
1634 (*phba->lpfc_handle_eratt)(phba);
1635}
1636
1637/**
James Smart3621a712009-04-06 18:47:14 -04001638 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04001639 * @phba: pointer to lpfc hba data structure.
1640 *
1641 * This routine is invoked from the worker thread to handle a HBA host
1642 * attention link event.
1643 **/
dea31012005-04-17 16:05:31 -05001644void
James Smart2e0fef82007-06-17 19:56:36 -05001645lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001646{
James Smart2e0fef82007-06-17 19:56:36 -05001647 struct lpfc_vport *vport = phba->pport;
1648 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001649 LPFC_MBOXQ_t *pmb;
1650 volatile uint32_t control;
1651 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05001652 int rc = 0;
dea31012005-04-17 16:05:31 -05001653
1654 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001655 if (!pmb) {
1656 rc = 1;
dea31012005-04-17 16:05:31 -05001657 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05001658 }
dea31012005-04-17 16:05:31 -05001659
1660 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001661 if (!mp) {
1662 rc = 2;
dea31012005-04-17 16:05:31 -05001663 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05001664 }
dea31012005-04-17 16:05:31 -05001665
1666 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05001667 if (!mp->virt) {
1668 rc = 3;
dea31012005-04-17 16:05:31 -05001669 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05001670 }
dea31012005-04-17 16:05:31 -05001671
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001672 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04001673 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05001674
1675 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05001676 lpfc_read_topology(phba, pmb, mp);
1677 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05001678 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04001679 /* Block ELS IOCBs until we have processed this mbox command */
1680 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04001681 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05001682 if (rc == MBX_NOT_FINISHED) {
1683 rc = 4;
James Smart14691152006-12-02 13:34:28 -05001684 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05001685 }
dea31012005-04-17 16:05:31 -05001686
1687 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05001688 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001689 writel(HA_LATT, phba->HAregaddr);
1690 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001691 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001692
1693 return;
1694
James Smart14691152006-12-02 13:34:28 -05001695lpfc_handle_latt_free_mbuf:
James Smart0d2b6b82008-06-14 22:52:47 -04001696 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05001697 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05001698lpfc_handle_latt_free_mp:
1699 kfree(mp);
1700lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04001701 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001702lpfc_handle_latt_err_exit:
1703 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001704 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001705 psli->sli_flag |= LPFC_PROCESS_LA;
1706 control = readl(phba->HCregaddr);
1707 control |= HC_LAINT_ENA;
1708 writel(control, phba->HCregaddr);
1709 readl(phba->HCregaddr); /* flush */
1710
1711 /* Clear Link Attention in HA REG */
1712 writel(HA_LATT, phba->HAregaddr);
1713 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001714 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001715 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001716 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001717
James Smart09372822008-01-11 01:52:54 -05001718 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1719 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05001720
1721 return;
1722}
1723
James Smarte59058c2008-08-24 21:49:00 -04001724/**
James Smart3621a712009-04-06 18:47:14 -04001725 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04001726 * @phba: pointer to lpfc hba data structure.
1727 * @vpd: pointer to the vital product data.
1728 * @len: length of the vital product data in bytes.
1729 *
1730 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1731 * an array of characters. In this routine, the ModelName, ProgramType, and
1732 * ModelDesc, etc. fields of the phba data structure will be populated.
1733 *
1734 * Return codes
1735 * 0 - pointer to the VPD passed in is NULL
1736 * 1 - success
1737 **/
James Smart3772a992009-05-22 14:50:54 -04001738int
James Smart2e0fef82007-06-17 19:56:36 -05001739lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05001740{
1741 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05001742 int Length;
dea31012005-04-17 16:05:31 -05001743 int i, j;
1744 int finished = 0;
1745 int index = 0;
1746
1747 if (!vpd)
1748 return 0;
1749
1750 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05001751 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001752 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001753 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
1754 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001755 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05001756 switch (vpd[index]) {
1757 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001758 case 0x91:
dea31012005-04-17 16:05:31 -05001759 index += 1;
1760 lenlo = vpd[index];
1761 index += 1;
1762 lenhi = vpd[index];
1763 index += 1;
1764 i = ((((unsigned short)lenhi) << 8) + lenlo);
1765 index += i;
1766 break;
1767 case 0x90:
1768 index += 1;
1769 lenlo = vpd[index];
1770 index += 1;
1771 lenhi = vpd[index];
1772 index += 1;
1773 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001774 if (Length > len - index)
1775 Length = len - index;
dea31012005-04-17 16:05:31 -05001776 while (Length > 0) {
1777 /* Look for Serial Number */
1778 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
1779 index += 2;
1780 i = vpd[index];
1781 index += 1;
1782 j = 0;
1783 Length -= (3+i);
1784 while(i--) {
1785 phba->SerialNumber[j++] = vpd[index++];
1786 if (j == 31)
1787 break;
1788 }
1789 phba->SerialNumber[j] = 0;
1790 continue;
1791 }
1792 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
1793 phba->vpd_flag |= VPD_MODEL_DESC;
1794 index += 2;
1795 i = vpd[index];
1796 index += 1;
1797 j = 0;
1798 Length -= (3+i);
1799 while(i--) {
1800 phba->ModelDesc[j++] = vpd[index++];
1801 if (j == 255)
1802 break;
1803 }
1804 phba->ModelDesc[j] = 0;
1805 continue;
1806 }
1807 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
1808 phba->vpd_flag |= VPD_MODEL_NAME;
1809 index += 2;
1810 i = vpd[index];
1811 index += 1;
1812 j = 0;
1813 Length -= (3+i);
1814 while(i--) {
1815 phba->ModelName[j++] = vpd[index++];
1816 if (j == 79)
1817 break;
1818 }
1819 phba->ModelName[j] = 0;
1820 continue;
1821 }
1822 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
1823 phba->vpd_flag |= VPD_PROGRAM_TYPE;
1824 index += 2;
1825 i = vpd[index];
1826 index += 1;
1827 j = 0;
1828 Length -= (3+i);
1829 while(i--) {
1830 phba->ProgramType[j++] = vpd[index++];
1831 if (j == 255)
1832 break;
1833 }
1834 phba->ProgramType[j] = 0;
1835 continue;
1836 }
1837 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1838 phba->vpd_flag |= VPD_PORT;
1839 index += 2;
1840 i = vpd[index];
1841 index += 1;
1842 j = 0;
1843 Length -= (3+i);
1844 while(i--) {
James Smartcd1c8302011-10-10 21:33:25 -04001845 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1846 (phba->sli4_hba.pport_name_sta ==
1847 LPFC_SLI4_PPNAME_GET)) {
1848 j++;
1849 index++;
1850 } else
1851 phba->Port[j++] = vpd[index++];
1852 if (j == 19)
1853 break;
dea31012005-04-17 16:05:31 -05001854 }
James Smartcd1c8302011-10-10 21:33:25 -04001855 if ((phba->sli_rev != LPFC_SLI_REV4) ||
1856 (phba->sli4_hba.pport_name_sta ==
1857 LPFC_SLI4_PPNAME_NON))
1858 phba->Port[j] = 0;
dea31012005-04-17 16:05:31 -05001859 continue;
1860 }
1861 else {
1862 index += 2;
1863 i = vpd[index];
1864 index += 1;
1865 index += i;
1866 Length -= (3 + i);
1867 }
1868 }
1869 finished = 0;
1870 break;
1871 case 0x78:
1872 finished = 1;
1873 break;
1874 default:
1875 index ++;
1876 break;
1877 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001878 }
dea31012005-04-17 16:05:31 -05001879
1880 return(1);
1881}
1882
James Smarte59058c2008-08-24 21:49:00 -04001883/**
James Smart3621a712009-04-06 18:47:14 -04001884 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04001885 * @phba: pointer to lpfc hba data structure.
1886 * @mdp: pointer to the data structure to hold the derived model name.
1887 * @descp: pointer to the data structure to hold the derived description.
1888 *
1889 * This routine retrieves HBA's description based on its registered PCI device
1890 * ID. The @descp passed into this function points to an array of 256 chars. It
1891 * shall be returned with the model name, maximum speed, and the host bus type.
1892 * The @mdp passed into this function points to an array of 80 chars. When the
1893 * function returns, the @mdp will be filled with the model name.
1894 **/
dea31012005-04-17 16:05:31 -05001895static void
James Smart2e0fef82007-06-17 19:56:36 -05001896lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05001897{
1898 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05001899 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001900 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04001901 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04001902 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001903 struct {
James Smarta747c9c2009-11-18 15:41:10 -05001904 char *name;
1905 char *bus;
1906 char *function;
1907 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001908
1909 if (mdp && mdp[0] != '\0'
1910 && descp && descp[0] != '\0')
1911 return;
1912
James Smartc0c11512011-05-24 11:41:34 -04001913 if (phba->lmt & LMT_16Gb)
1914 max_speed = 16;
1915 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001916 max_speed = 10;
1917 else if (phba->lmt & LMT_8Gb)
1918 max_speed = 8;
1919 else if (phba->lmt & LMT_4Gb)
1920 max_speed = 4;
1921 else if (phba->lmt & LMT_2Gb)
1922 max_speed = 2;
James Smart4169d862012-09-29 11:32:09 -04001923 else if (phba->lmt & LMT_1Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001924 max_speed = 1;
James Smart4169d862012-09-29 11:32:09 -04001925 else
1926 max_speed = 0;
dea31012005-04-17 16:05:31 -05001927
1928 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05001929
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001930 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001931 case PCI_DEVICE_ID_FIREFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001932 m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001933 break;
dea31012005-04-17 16:05:31 -05001934 case PCI_DEVICE_ID_SUPERFLY:
1935 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smarta747c9c2009-11-18 15:41:10 -05001936 m = (typeof(m)){"LP7000", "PCI",
1937 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001938 else
James Smarta747c9c2009-11-18 15:41:10 -05001939 m = (typeof(m)){"LP7000E", "PCI",
1940 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001941 break;
1942 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001943 m = (typeof(m)){"LP8000", "PCI",
1944 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001945 break;
1946 case PCI_DEVICE_ID_CENTAUR:
1947 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smarta747c9c2009-11-18 15:41:10 -05001948 m = (typeof(m)){"LP9002", "PCI",
1949 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001950 else
James Smarta747c9c2009-11-18 15:41:10 -05001951 m = (typeof(m)){"LP9000", "PCI",
1952 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001953 break;
1954 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001955 m = (typeof(m)){"LP952", "PCI",
1956 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001957 break;
1958 case PCI_DEVICE_ID_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05001959 m = (typeof(m)){"LP9802", "PCI-X",
1960 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001961 break;
1962 case PCI_DEVICE_ID_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05001963 m = (typeof(m)){"LP10000", "PCI-X",
1964 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001965 break;
1966 case PCI_DEVICE_ID_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05001967 m = (typeof(m)){"LPX1000", "PCI-X",
1968 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001969 break;
1970 case PCI_DEVICE_ID_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001971 m = (typeof(m)){"LP982", "PCI-X",
1972 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001973 break;
1974 case PCI_DEVICE_ID_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001975 m = (typeof(m)){"LP1050", "PCI-X",
1976 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001977 break;
1978 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05001979 m = (typeof(m)){"LP11000", "PCI-X2",
1980 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001981 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001982 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001983 m = (typeof(m)){"LP11000-SP", "PCI-X2",
1984 "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001985 break;
1986 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001987 m = (typeof(m)){"LP11002-SP", "PCI-X2",
1988 "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001989 break;
1990 case PCI_DEVICE_ID_NEPTUNE:
James Smarta747c9c2009-11-18 15:41:10 -05001991 m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001992 break;
1993 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001994 m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001995 break;
1996 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001997 m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001998 break;
dea31012005-04-17 16:05:31 -05001999 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05002000 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002001 break;
2002 case PCI_DEVICE_ID_BSMB:
James Smarta747c9c2009-11-18 15:41:10 -05002003 m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002004 break;
2005 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05002006 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002007 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002008 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002009 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002010 break;
2011 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002012 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04002013 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002014 break;
dea31012005-04-17 16:05:31 -05002015 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05002016 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002017 break;
2018 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05002019 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002020 break;
2021 case PCI_DEVICE_ID_LP101:
James Smarta747c9c2009-11-18 15:41:10 -05002022 m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002023 break;
2024 case PCI_DEVICE_ID_LP10000S:
James Smarta747c9c2009-11-18 15:41:10 -05002025 m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002026 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002027 case PCI_DEVICE_ID_LP11000S:
James Smarta747c9c2009-11-18 15:41:10 -05002028 m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05002029 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002030 case PCI_DEVICE_ID_LPE11000S:
James Smarta747c9c2009-11-18 15:41:10 -05002031 m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002032 break;
James Smartb87eab32007-04-25 09:53:28 -04002033 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05002034 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002035 break;
2036 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05002037 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002038 break;
2039 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05002040 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002041 break;
2042 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002043 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002044 break;
2045 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002046 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002047 break;
2048 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05002049 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002050 break;
James Smart84774a42008-08-24 21:50:06 -04002051 case PCI_DEVICE_ID_HORNET:
James Smarta747c9c2009-11-18 15:41:10 -05002052 m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002053 GE = 1;
2054 break;
2055 case PCI_DEVICE_ID_PROTEUS_VF:
James Smarta747c9c2009-11-18 15:41:10 -05002056 m = (typeof(m)){"LPev12000", "PCIe IOV",
2057 "Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002058 break;
2059 case PCI_DEVICE_ID_PROTEUS_PF:
James Smarta747c9c2009-11-18 15:41:10 -05002060 m = (typeof(m)){"LPev12000", "PCIe IOV",
2061 "Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002062 break;
2063 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05002064 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
2065 "Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002066 break;
James Smartda0436e2009-05-22 14:51:39 -04002067 case PCI_DEVICE_ID_TIGERSHARK:
2068 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002069 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04002070 break;
James Smarta747c9c2009-11-18 15:41:10 -05002071 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04002072 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002073 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2074 break;
2075 case PCI_DEVICE_ID_FALCON:
2076 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2077 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04002078 break;
James Smart98fc5dd2010-06-07 15:24:29 -04002079 case PCI_DEVICE_ID_BALIUS:
2080 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
2081 "Fibre Channel Adapter"};
2082 break;
James Smart085c6472010-11-20 23:11:37 -05002083 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04002084 case PCI_DEVICE_ID_LANCER_FC_VF:
2085 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05002086 break;
2087 case PCI_DEVICE_ID_LANCER_FCOE:
James Smartc0c11512011-05-24 11:41:34 -04002088 case PCI_DEVICE_ID_LANCER_FCOE_VF:
James Smart085c6472010-11-20 23:11:37 -05002089 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04002090 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05002091 break;
James Smartf8cafd32012-08-03 12:42:51 -04002092 case PCI_DEVICE_ID_SKYHAWK:
2093 case PCI_DEVICE_ID_SKYHAWK_VF:
2094 oneConnect = 1;
2095 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2096 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002097 default:
James Smarta747c9c2009-11-18 15:41:10 -05002098 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002099 break;
dea31012005-04-17 16:05:31 -05002100 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002101
2102 if (mdp && mdp[0] == '\0')
2103 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04002104 /*
2105 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04002106 * and we put the port number on the end
2107 */
2108 if (descp && descp[0] == '\0') {
2109 if (oneConnect)
2110 snprintf(descp, 255,
James Smart4169d862012-09-29 11:32:09 -04002111 "Emulex OneConnect %s, %s Initiator %s",
James Smarta747c9c2009-11-18 15:41:10 -05002112 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04002113 phba->Port);
James Smart4169d862012-09-29 11:32:09 -04002114 else if (max_speed == 0)
2115 snprintf(descp, 255,
2116 "Emulex %s %s %s ",
2117 m.name, m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002118 else
2119 snprintf(descp, 255,
2120 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05002121 m.name, max_speed, (GE) ? "GE" : "Gb",
2122 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002123 }
dea31012005-04-17 16:05:31 -05002124}
2125
James Smarte59058c2008-08-24 21:49:00 -04002126/**
James Smart3621a712009-04-06 18:47:14 -04002127 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04002128 * @phba: pointer to lpfc hba data structure.
2129 * @pring: pointer to a IOCB ring.
2130 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2131 *
2132 * This routine posts a given number of IOCBs with the associated DMA buffer
2133 * descriptors specified by the cnt argument to the given IOCB ring.
2134 *
2135 * Return codes
2136 * The number of IOCBs NOT able to be posted to the IOCB ring.
2137 **/
dea31012005-04-17 16:05:31 -05002138int
James Smart495a7142008-06-14 22:52:59 -04002139lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002140{
2141 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002142 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002143 struct lpfc_dmabuf *mp1, *mp2;
2144
2145 cnt += pring->missbufcnt;
2146
2147 /* While there are buffers to post */
2148 while (cnt > 0) {
2149 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002150 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002151 if (iocb == NULL) {
2152 pring->missbufcnt = cnt;
2153 return cnt;
2154 }
dea31012005-04-17 16:05:31 -05002155 icmd = &iocb->iocb;
2156
2157 /* 2 buffers can be posted per command */
2158 /* Allocate buffer to post */
2159 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2160 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002161 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2162 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002163 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002164 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002165 pring->missbufcnt = cnt;
2166 return cnt;
2167 }
2168
2169 INIT_LIST_HEAD(&mp1->list);
2170 /* Allocate buffer to post */
2171 if (cnt > 1) {
2172 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2173 if (mp2)
2174 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2175 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002176 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002177 kfree(mp2);
dea31012005-04-17 16:05:31 -05002178 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2179 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002180 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002181 pring->missbufcnt = cnt;
2182 return cnt;
2183 }
2184
2185 INIT_LIST_HEAD(&mp2->list);
2186 } else {
2187 mp2 = NULL;
2188 }
2189
2190 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2191 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2192 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2193 icmd->ulpBdeCount = 1;
2194 cnt--;
2195 if (mp2) {
2196 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2197 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2198 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2199 cnt--;
2200 icmd->ulpBdeCount = 2;
2201 }
2202
2203 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2204 icmd->ulpLe = 1;
2205
James Smart3772a992009-05-22 14:50:54 -04002206 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2207 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002208 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2209 kfree(mp1);
2210 cnt++;
2211 if (mp2) {
2212 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2213 kfree(mp2);
2214 cnt++;
2215 }
James Bottomley604a3e32005-10-29 10:28:33 -05002216 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002217 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002218 return cnt;
2219 }
dea31012005-04-17 16:05:31 -05002220 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002221 if (mp2)
dea31012005-04-17 16:05:31 -05002222 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002223 }
2224 pring->missbufcnt = 0;
2225 return 0;
2226}
2227
James Smarte59058c2008-08-24 21:49:00 -04002228/**
James Smart3621a712009-04-06 18:47:14 -04002229 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002230 * @phba: pointer to lpfc hba data structure.
2231 *
2232 * This routine posts initial receive IOCB buffers to the ELS ring. The
2233 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2234 * set to 64 IOCBs.
2235 *
2236 * Return codes
2237 * 0 - success (currently always success)
2238 **/
dea31012005-04-17 16:05:31 -05002239static int
James Smart2e0fef82007-06-17 19:56:36 -05002240lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002241{
2242 struct lpfc_sli *psli = &phba->sli;
2243
2244 /* Ring 0, ELS / CT buffers */
James Smart495a7142008-06-14 22:52:59 -04002245 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002246 /* Ring 2 - FCP no buffers needed */
2247
2248 return 0;
2249}
2250
2251#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2252
James Smarte59058c2008-08-24 21:49:00 -04002253/**
James Smart3621a712009-04-06 18:47:14 -04002254 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002255 * @HashResultPointer: pointer to an array as hash table.
2256 *
2257 * This routine sets up the initial values to the array of hash table entries
2258 * for the LC HBAs.
2259 **/
dea31012005-04-17 16:05:31 -05002260static void
2261lpfc_sha_init(uint32_t * HashResultPointer)
2262{
2263 HashResultPointer[0] = 0x67452301;
2264 HashResultPointer[1] = 0xEFCDAB89;
2265 HashResultPointer[2] = 0x98BADCFE;
2266 HashResultPointer[3] = 0x10325476;
2267 HashResultPointer[4] = 0xC3D2E1F0;
2268}
2269
James Smarte59058c2008-08-24 21:49:00 -04002270/**
James Smart3621a712009-04-06 18:47:14 -04002271 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002272 * @HashResultPointer: pointer to an initial/result hash table.
2273 * @HashWorkingPointer: pointer to an working hash table.
2274 *
2275 * This routine iterates an initial hash table pointed by @HashResultPointer
2276 * with the values from the working hash table pointeed by @HashWorkingPointer.
2277 * The results are putting back to the initial hash table, returned through
2278 * the @HashResultPointer as the result hash table.
2279 **/
dea31012005-04-17 16:05:31 -05002280static void
2281lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2282{
2283 int t;
2284 uint32_t TEMP;
2285 uint32_t A, B, C, D, E;
2286 t = 16;
2287 do {
2288 HashWorkingPointer[t] =
2289 S(1,
2290 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2291 8] ^
2292 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2293 } while (++t <= 79);
2294 t = 0;
2295 A = HashResultPointer[0];
2296 B = HashResultPointer[1];
2297 C = HashResultPointer[2];
2298 D = HashResultPointer[3];
2299 E = HashResultPointer[4];
2300
2301 do {
2302 if (t < 20) {
2303 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2304 } else if (t < 40) {
2305 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2306 } else if (t < 60) {
2307 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2308 } else {
2309 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2310 }
2311 TEMP += S(5, A) + E + HashWorkingPointer[t];
2312 E = D;
2313 D = C;
2314 C = S(30, B);
2315 B = A;
2316 A = TEMP;
2317 } while (++t <= 79);
2318
2319 HashResultPointer[0] += A;
2320 HashResultPointer[1] += B;
2321 HashResultPointer[2] += C;
2322 HashResultPointer[3] += D;
2323 HashResultPointer[4] += E;
2324
2325}
2326
James Smarte59058c2008-08-24 21:49:00 -04002327/**
James Smart3621a712009-04-06 18:47:14 -04002328 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002329 * @RandomChallenge: pointer to the entry of host challenge random number array.
2330 * @HashWorking: pointer to the entry of the working hash array.
2331 *
2332 * This routine calculates the working hash array referred by @HashWorking
2333 * from the challenge random numbers associated with the host, referred by
2334 * @RandomChallenge. The result is put into the entry of the working hash
2335 * array and returned by reference through @HashWorking.
2336 **/
dea31012005-04-17 16:05:31 -05002337static void
2338lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2339{
2340 *HashWorking = (*RandomChallenge ^ *HashWorking);
2341}
2342
James Smarte59058c2008-08-24 21:49:00 -04002343/**
James Smart3621a712009-04-06 18:47:14 -04002344 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002345 * @phba: pointer to lpfc hba data structure.
2346 * @hbainit: pointer to an array of unsigned 32-bit integers.
2347 *
2348 * This routine performs the special handling for LC HBA initialization.
2349 **/
dea31012005-04-17 16:05:31 -05002350void
2351lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2352{
2353 int t;
2354 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002355 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002356
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002357 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002358 if (!HashWorking)
2359 return;
2360
dea31012005-04-17 16:05:31 -05002361 HashWorking[0] = HashWorking[78] = *pwwnn++;
2362 HashWorking[1] = HashWorking[79] = *pwwnn;
2363
2364 for (t = 0; t < 7; t++)
2365 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2366
2367 lpfc_sha_init(hbainit);
2368 lpfc_sha_iterate(hbainit, HashWorking);
2369 kfree(HashWorking);
2370}
2371
James Smarte59058c2008-08-24 21:49:00 -04002372/**
James Smart3621a712009-04-06 18:47:14 -04002373 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002374 * @vport: pointer to a virtual N_Port data structure.
2375 *
2376 * This routine performs the necessary cleanups before deleting the @vport.
2377 * It invokes the discovery state machine to perform necessary state
2378 * transitions and to release the ndlps associated with the @vport. Note,
2379 * the physical port is treated as @vport 0.
2380 **/
James Smart87af33f2007-10-27 13:37:43 -04002381void
James Smart2e0fef82007-06-17 19:56:36 -05002382lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002383{
James Smart87af33f2007-10-27 13:37:43 -04002384 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002385 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002386 int i = 0;
dea31012005-04-17 16:05:31 -05002387
James Smart87af33f2007-10-27 13:37:43 -04002388 if (phba->link_state > LPFC_LINK_DOWN)
2389 lpfc_port_link_failure(vport);
2390
2391 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002392 if (!NLP_CHK_NODE_ACT(ndlp)) {
2393 ndlp = lpfc_enable_node(vport, ndlp,
2394 NLP_STE_UNUSED_NODE);
2395 if (!ndlp)
2396 continue;
2397 spin_lock_irq(&phba->ndlp_lock);
2398 NLP_SET_FREE_REQ(ndlp);
2399 spin_unlock_irq(&phba->ndlp_lock);
2400 /* Trigger the release of the ndlp memory */
2401 lpfc_nlp_put(ndlp);
2402 continue;
2403 }
2404 spin_lock_irq(&phba->ndlp_lock);
2405 if (NLP_CHK_FREE_REQ(ndlp)) {
2406 /* The ndlp should not be in memory free mode already */
2407 spin_unlock_irq(&phba->ndlp_lock);
2408 continue;
2409 } else
2410 /* Indicate request for freeing ndlp memory */
2411 NLP_SET_FREE_REQ(ndlp);
2412 spin_unlock_irq(&phba->ndlp_lock);
2413
James Smart58da1ff2008-04-07 10:15:56 -04002414 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2415 ndlp->nlp_DID == Fabric_DID) {
2416 /* Just free up ndlp with Fabric_DID for vports */
2417 lpfc_nlp_put(ndlp);
2418 continue;
2419 }
2420
James Smarteff4a012012-01-18 16:25:25 -05002421 /* take care of nodes in unused state before the state
2422 * machine taking action.
2423 */
2424 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2425 lpfc_nlp_put(ndlp);
2426 continue;
2427 }
2428
James Smart87af33f2007-10-27 13:37:43 -04002429 if (ndlp->nlp_type & NLP_FABRIC)
2430 lpfc_disc_state_machine(vport, ndlp, NULL,
2431 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002432
James Smart87af33f2007-10-27 13:37:43 -04002433 lpfc_disc_state_machine(vport, ndlp, NULL,
2434 NLP_EVT_DEVICE_RM);
2435 }
2436
James Smarta8adb832007-10-27 13:37:53 -04002437 /* At this point, ALL ndlp's should be gone
2438 * because of the previous NLP_EVT_DEVICE_RM.
2439 * Lets wait for this to happen, if needed.
2440 */
James Smart87af33f2007-10-27 13:37:43 -04002441 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002442 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04002443 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04002444 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002445 list_for_each_entry_safe(ndlp, next_ndlp,
2446 &vport->fc_nodes, nlp_listp) {
2447 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2448 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04002449 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05002450 "usgmap:x%x refcnt:%d\n",
2451 ndlp->nlp_DID, (void *)ndlp,
2452 ndlp->nlp_usg_map,
2453 atomic_read(
2454 &ndlp->kref.refcount));
2455 }
James Smarta8adb832007-10-27 13:37:53 -04002456 break;
James Smart87af33f2007-10-27 13:37:43 -04002457 }
James Smarta8adb832007-10-27 13:37:53 -04002458
2459 /* Wait for any activity on ndlps to settle */
2460 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002461 }
James Smart1151e3e2011-02-16 12:39:35 -05002462 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002463}
2464
James Smarte59058c2008-08-24 21:49:00 -04002465/**
James Smart3621a712009-04-06 18:47:14 -04002466 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002467 * @vport: pointer to a virtual N_Port data structure.
2468 *
2469 * This routine stops all the timers associated with a @vport. This function
2470 * is invoked before disabling or deleting a @vport. Note that the physical
2471 * port is treated as @vport 0.
2472 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002473void
2474lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002475{
James Smart92d7f7b2007-06-17 19:56:38 -05002476 del_timer_sync(&vport->els_tmofunc);
2477 del_timer_sync(&vport->fc_fdmitmo);
James Smart92494142011-02-16 12:39:44 -05002478 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002479 lpfc_can_disctmo(vport);
2480 return;
dea31012005-04-17 16:05:31 -05002481}
2482
James Smarte59058c2008-08-24 21:49:00 -04002483/**
James Smartecfd03c2010-02-12 14:41:27 -05002484 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2485 * @phba: pointer to lpfc hba data structure.
2486 *
2487 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2488 * caller of this routine should already hold the host lock.
2489 **/
2490void
2491__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2492{
James Smart5ac6b302010-10-22 11:05:36 -04002493 /* Clear pending FCF rediscovery wait flag */
2494 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2495
James Smartecfd03c2010-02-12 14:41:27 -05002496 /* Now, try to stop the timer */
2497 del_timer(&phba->fcf.redisc_wait);
2498}
2499
2500/**
2501 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2502 * @phba: pointer to lpfc hba data structure.
2503 *
2504 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2505 * checks whether the FCF rediscovery wait timer is pending with the host
2506 * lock held before proceeding with disabling the timer and clearing the
2507 * wait timer pendig flag.
2508 **/
2509void
2510lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2511{
2512 spin_lock_irq(&phba->hbalock);
2513 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2514 /* FCF rediscovery timer already fired or stopped */
2515 spin_unlock_irq(&phba->hbalock);
2516 return;
2517 }
2518 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002519 /* Clear failover in progress flags */
2520 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002521 spin_unlock_irq(&phba->hbalock);
2522}
2523
2524/**
James Smart3772a992009-05-22 14:50:54 -04002525 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002526 * @phba: pointer to lpfc hba data structure.
2527 *
2528 * This routine stops all the timers associated with a HBA. This function is
2529 * invoked before either putting a HBA offline or unloading the driver.
2530 **/
James Smart3772a992009-05-22 14:50:54 -04002531void
2532lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002533{
James Smart51ef4c22007-08-02 11:10:31 -04002534 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05002535 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002536 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002537 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002538 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002539 if (phba->sli_rev == LPFC_SLI_REV4) {
2540 del_timer_sync(&phba->rrq_tmr);
2541 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2542 }
James Smart3772a992009-05-22 14:50:54 -04002543 phba->hb_outstanding = 0;
2544
2545 switch (phba->pci_dev_grp) {
2546 case LPFC_PCI_DEV_LP:
2547 /* Stop any LightPulse device specific driver timers */
2548 del_timer_sync(&phba->fcp_poll_timer);
2549 break;
2550 case LPFC_PCI_DEV_OC:
2551 /* Stop any OneConnect device sepcific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002552 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002553 break;
2554 default:
2555 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2556 "0297 Invalid device group (x%x)\n",
2557 phba->pci_dev_grp);
2558 break;
2559 }
James Smart2e0fef82007-06-17 19:56:36 -05002560 return;
dea31012005-04-17 16:05:31 -05002561}
2562
James Smarte59058c2008-08-24 21:49:00 -04002563/**
James Smart3621a712009-04-06 18:47:14 -04002564 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002565 * @phba: pointer to lpfc hba data structure.
2566 *
2567 * This routine marks a HBA's management interface as blocked. Once the HBA's
2568 * management interface is marked as blocked, all the user space access to
2569 * the HBA, whether they are from sysfs interface or libdfc interface will
2570 * all be blocked. The HBA is set to block the management interface when the
2571 * driver prepares the HBA interface for online or offline.
2572 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01002573static void
James Smart618a5232012-06-12 13:54:36 -04002574lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
Adrian Bunka6ababd2007-11-05 18:07:33 +01002575{
2576 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04002577 uint8_t actcmd = MBX_HEARTBEAT;
2578 unsigned long timeout;
2579
Adrian Bunka6ababd2007-11-05 18:07:33 +01002580 spin_lock_irqsave(&phba->hbalock, iflag);
2581 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart618a5232012-06-12 13:54:36 -04002582 spin_unlock_irqrestore(&phba->hbalock, iflag);
2583 if (mbx_action == LPFC_MBX_NO_WAIT)
2584 return;
2585 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2586 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002587 if (phba->sli.mbox_active) {
James Smart6e7288d2010-06-07 15:23:35 -04002588 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
James Smarta183a152011-10-10 21:32:43 -04002589 /* Determine how long we might wait for the active mailbox
2590 * command to be gracefully completed by firmware.
2591 */
2592 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
2593 phba->sli.mbox_active) * 1000) + jiffies;
2594 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002595 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002596
James Smart6e7288d2010-06-07 15:23:35 -04002597 /* Wait for the outstnading mailbox command to complete */
2598 while (phba->sli.mbox_active) {
2599 /* Check active mailbox complete status every 2ms */
2600 msleep(2);
2601 if (time_after(jiffies, timeout)) {
2602 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2603 "2813 Mgmt IO is Blocked %x "
2604 "- mbox cmd %x still active\n",
2605 phba->sli.sli_flag, actcmd);
2606 break;
2607 }
2608 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002609}
2610
James Smarte59058c2008-08-24 21:49:00 -04002611/**
James Smart6b5151f2012-01-18 16:24:06 -05002612 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
2613 * @phba: pointer to lpfc hba data structure.
2614 *
2615 * Allocate RPIs for all active remote nodes. This is needed whenever
2616 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
2617 * is to fixup the temporary rpi assignments.
2618 **/
2619void
2620lpfc_sli4_node_prep(struct lpfc_hba *phba)
2621{
2622 struct lpfc_nodelist *ndlp, *next_ndlp;
2623 struct lpfc_vport **vports;
2624 int i;
2625
2626 if (phba->sli_rev != LPFC_SLI_REV4)
2627 return;
2628
2629 vports = lpfc_create_vport_work_array(phba);
2630 if (vports != NULL) {
2631 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2632 if (vports[i]->load_flag & FC_UNLOADING)
2633 continue;
2634
2635 list_for_each_entry_safe(ndlp, next_ndlp,
2636 &vports[i]->fc_nodes,
2637 nlp_listp) {
2638 if (NLP_CHK_NODE_ACT(ndlp))
2639 ndlp->nlp_rpi =
2640 lpfc_sli4_alloc_rpi(phba);
2641 }
2642 }
2643 }
2644 lpfc_destroy_vport_work_array(phba, vports);
2645}
2646
2647/**
James Smart3621a712009-04-06 18:47:14 -04002648 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04002649 * @phba: pointer to lpfc hba data structure.
2650 *
2651 * This routine initializes the HBA and brings a HBA online. During this
2652 * process, the management interface is blocked to prevent user space access
2653 * to the HBA interfering with the driver initialization.
2654 *
2655 * Return codes
2656 * 0 - successful
2657 * 1 - failed
2658 **/
dea31012005-04-17 16:05:31 -05002659int
James Smart2e0fef82007-06-17 19:56:36 -05002660lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002661{
Julia Lawall372bd282008-12-16 16:15:08 +01002662 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04002663 struct lpfc_vport **vports;
2664 int i;
James Smart16a3a202013-04-17 20:14:38 -04002665 bool vpis_cleared = false;
James Smart2e0fef82007-06-17 19:56:36 -05002666
dea31012005-04-17 16:05:31 -05002667 if (!phba)
2668 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01002669 vport = phba->pport;
dea31012005-04-17 16:05:31 -05002670
James Smart2e0fef82007-06-17 19:56:36 -05002671 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05002672 return 0;
2673
James Smarted957682007-06-17 19:56:37 -05002674 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002675 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05002676
James Smart618a5232012-06-12 13:54:36 -04002677 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05002678
James Smart46fa3112007-04-25 09:51:45 -04002679 if (!lpfc_sli_queue_setup(phba)) {
2680 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002681 return 1;
James Smart46fa3112007-04-25 09:51:45 -04002682 }
2683
James Smartda0436e2009-05-22 14:51:39 -04002684 if (phba->sli_rev == LPFC_SLI_REV4) {
2685 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
2686 lpfc_unblock_mgmt_io(phba);
2687 return 1;
2688 }
James Smart16a3a202013-04-17 20:14:38 -04002689 spin_lock_irq(&phba->hbalock);
2690 if (!phba->sli4_hba.max_cfg_param.vpi_used)
2691 vpis_cleared = true;
2692 spin_unlock_irq(&phba->hbalock);
James Smartda0436e2009-05-22 14:51:39 -04002693 } else {
2694 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
2695 lpfc_unblock_mgmt_io(phba);
2696 return 1;
2697 }
James Smart46fa3112007-04-25 09:51:45 -04002698 }
dea31012005-04-17 16:05:31 -05002699
James Smart549e55c2007-08-02 11:09:51 -04002700 vports = lpfc_create_vport_work_array(phba);
2701 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002702 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002703 struct Scsi_Host *shost;
2704 shost = lpfc_shost_from_vport(vports[i]);
2705 spin_lock_irq(shost->host_lock);
2706 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
2707 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2708 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart16a3a202013-04-17 20:14:38 -04002709 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart1c6834a2009-07-19 10:01:26 -04002710 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart16a3a202013-04-17 20:14:38 -04002711 if ((vpis_cleared) &&
2712 (vports[i]->port_type !=
2713 LPFC_PHYSICAL_PORT))
2714 vports[i]->vpi = 0;
2715 }
James Smart549e55c2007-08-02 11:09:51 -04002716 spin_unlock_irq(shost->host_lock);
2717 }
James Smart09372822008-01-11 01:52:54 -05002718 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002719
James Smart46fa3112007-04-25 09:51:45 -04002720 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002721 return 0;
2722}
2723
James Smarte59058c2008-08-24 21:49:00 -04002724/**
James Smart3621a712009-04-06 18:47:14 -04002725 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04002726 * @phba: pointer to lpfc hba data structure.
2727 *
2728 * This routine marks a HBA's management interface as not blocked. Once the
2729 * HBA's management interface is marked as not blocked, all the user space
2730 * access to the HBA, whether they are from sysfs interface or libdfc
2731 * interface will be allowed. The HBA is set to block the management interface
2732 * when the driver prepares the HBA interface for online or offline and then
2733 * set to unblock the management interface afterwards.
2734 **/
James Smart46fa3112007-04-25 09:51:45 -04002735void
James Smart46fa3112007-04-25 09:51:45 -04002736lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
2737{
2738 unsigned long iflag;
2739
James Smart2e0fef82007-06-17 19:56:36 -05002740 spin_lock_irqsave(&phba->hbalock, iflag);
2741 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
2742 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04002743}
2744
James Smarte59058c2008-08-24 21:49:00 -04002745/**
James Smart3621a712009-04-06 18:47:14 -04002746 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04002747 * @phba: pointer to lpfc hba data structure.
2748 *
2749 * This routine is invoked to prepare a HBA to be brought offline. It performs
2750 * unregistration login to all the nodes on all vports and flushes the mailbox
2751 * queue to make it ready to be brought offline.
2752 **/
James Smart46fa3112007-04-25 09:51:45 -04002753void
James Smart618a5232012-06-12 13:54:36 -04002754lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04002755{
James Smart2e0fef82007-06-17 19:56:36 -05002756 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04002757 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04002758 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05002759 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04002760 int i;
dea31012005-04-17 16:05:31 -05002761
James Smart2e0fef82007-06-17 19:56:36 -05002762 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002763 return;
dea31012005-04-17 16:05:31 -05002764
James Smart618a5232012-06-12 13:54:36 -04002765 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05002766
2767 lpfc_linkdown(phba);
2768
James Smart87af33f2007-10-27 13:37:43 -04002769 /* Issue an unreg_login to all nodes on all vports */
2770 vports = lpfc_create_vport_work_array(phba);
2771 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04002772 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04002773 if (vports[i]->load_flag & FC_UNLOADING)
2774 continue;
James Smart72100cc2010-02-12 14:43:01 -05002775 shost = lpfc_shost_from_vport(vports[i]);
2776 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05002777 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002778 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2779 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05002780 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05002781
James Smart87af33f2007-10-27 13:37:43 -04002782 shost = lpfc_shost_from_vport(vports[i]);
2783 list_for_each_entry_safe(ndlp, next_ndlp,
2784 &vports[i]->fc_nodes,
2785 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002786 if (!NLP_CHK_NODE_ACT(ndlp))
2787 continue;
James Smart87af33f2007-10-27 13:37:43 -04002788 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2789 continue;
2790 if (ndlp->nlp_type & NLP_FABRIC) {
2791 lpfc_disc_state_machine(vports[i], ndlp,
2792 NULL, NLP_EVT_DEVICE_RECOVERY);
2793 lpfc_disc_state_machine(vports[i], ndlp,
2794 NULL, NLP_EVT_DEVICE_RM);
2795 }
2796 spin_lock_irq(shost->host_lock);
2797 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart401ee0c2012-03-01 22:35:34 -05002798 spin_unlock_irq(shost->host_lock);
James Smart6b5151f2012-01-18 16:24:06 -05002799 /*
2800 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05002801 * RPI. Get a new RPI when the adapter port
2802 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05002803 */
2804 if (phba->sli_rev == LPFC_SLI_REV4)
2805 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04002806 lpfc_unreg_rpi(vports[i], ndlp);
2807 }
2808 }
2809 }
James Smart09372822008-01-11 01:52:54 -05002810 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002811
James Smart618a5232012-06-12 13:54:36 -04002812 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
James Smart46fa3112007-04-25 09:51:45 -04002813}
2814
James Smarte59058c2008-08-24 21:49:00 -04002815/**
James Smart3621a712009-04-06 18:47:14 -04002816 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04002817 * @phba: pointer to lpfc hba data structure.
2818 *
2819 * This routine actually brings a HBA offline. It stops all the timers
2820 * associated with the HBA, brings down the SLI layer, and eventually
2821 * marks the HBA as in offline state for the upper layer protocol.
2822 **/
James Smart46fa3112007-04-25 09:51:45 -04002823void
James Smart2e0fef82007-06-17 19:56:36 -05002824lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04002825{
James Smart549e55c2007-08-02 11:09:51 -04002826 struct Scsi_Host *shost;
2827 struct lpfc_vport **vports;
2828 int i;
James Smart46fa3112007-04-25 09:51:45 -04002829
James Smart549e55c2007-08-02 11:09:51 -04002830 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002831 return;
James Smart688a8862006-07-06 15:49:56 -04002832
James Smartda0436e2009-05-22 14:51:39 -04002833 /* stop port and all timers associated with this hba */
2834 lpfc_stop_port(phba);
James Smart51ef4c22007-08-02 11:10:31 -04002835 vports = lpfc_create_vport_work_array(phba);
2836 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002837 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04002838 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05002839 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05002840 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002841 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05002842 /* Bring down the SLI Layer and cleanup. The HBA is offline
2843 now. */
2844 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002845 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04002846 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05002847 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04002848 vports = lpfc_create_vport_work_array(phba);
2849 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002850 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002851 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04002852 spin_lock_irq(shost->host_lock);
2853 vports[i]->work_port_events = 0;
2854 vports[i]->fc_flag |= FC_OFFLINE_MODE;
2855 spin_unlock_irq(shost->host_lock);
2856 }
James Smart09372822008-01-11 01:52:54 -05002857 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002858}
2859
James Smarte59058c2008-08-24 21:49:00 -04002860/**
James Smart3621a712009-04-06 18:47:14 -04002861 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04002862 * @phba: pointer to lpfc hba data structure.
2863 *
2864 * This routine is to free all the SCSI buffers and IOCBs from the driver
2865 * list back to kernel. It is called from lpfc_pci_remove_one to free
2866 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04002867 **/
James Smart8a9d2e82012-05-09 21:16:12 -04002868static void
James Smart2e0fef82007-06-17 19:56:36 -05002869lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002870{
2871 struct lpfc_scsi_buf *sb, *sb_next;
2872 struct lpfc_iocbq *io, *io_next;
2873
James Smart2e0fef82007-06-17 19:56:36 -05002874 spin_lock_irq(&phba->hbalock);
James Smarta40fc5f2013-04-17 20:17:40 -04002875
dea31012005-04-17 16:05:31 -05002876 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smarta40fc5f2013-04-17 20:17:40 -04002877
2878 spin_lock(&phba->scsi_buf_list_put_lock);
2879 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
2880 list) {
dea31012005-04-17 16:05:31 -05002881 list_del(&sb->list);
2882 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05002883 sb->dma_handle);
dea31012005-04-17 16:05:31 -05002884 kfree(sb);
2885 phba->total_scsi_bufs--;
2886 }
James Smarta40fc5f2013-04-17 20:17:40 -04002887 spin_unlock(&phba->scsi_buf_list_put_lock);
2888
2889 spin_lock(&phba->scsi_buf_list_get_lock);
2890 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
2891 list) {
2892 list_del(&sb->list);
2893 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
2894 sb->dma_handle);
2895 kfree(sb);
2896 phba->total_scsi_bufs--;
2897 }
2898 spin_unlock(&phba->scsi_buf_list_get_lock);
dea31012005-04-17 16:05:31 -05002899
2900 /* Release all the lpfc_iocbq entries maintained by this host. */
2901 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
2902 list_del(&io->list);
2903 kfree(io);
2904 phba->total_iocbq_bufs--;
2905 }
James Smart6d368e52011-05-24 11:44:12 -04002906
James Smart2e0fef82007-06-17 19:56:36 -05002907 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04002908}
2909
2910/**
2911 * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping
2912 * @phba: pointer to lpfc hba data structure.
2913 *
2914 * This routine first calculates the sizes of the current els and allocated
2915 * scsi sgl lists, and then goes through all sgls to updates the physical
2916 * XRIs assigned due to port function reset. During port initialization, the
2917 * current els and allocated scsi sgl lists are 0s.
2918 *
2919 * Return codes
2920 * 0 - successful (for now, it always returns 0)
2921 **/
2922int
2923lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba)
2924{
2925 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
2926 struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL;
2927 uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt;
2928 LIST_HEAD(els_sgl_list);
2929 LIST_HEAD(scsi_sgl_list);
2930 int rc;
2931
2932 /*
2933 * update on pci function's els xri-sgl list
2934 */
2935 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
2936 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
2937 /* els xri-sgl expanded */
2938 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
2939 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2940 "3157 ELS xri-sgl count increased from "
2941 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
2942 els_xri_cnt);
2943 /* allocate the additional els sgls */
2944 for (i = 0; i < xri_cnt; i++) {
2945 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
2946 GFP_KERNEL);
2947 if (sglq_entry == NULL) {
2948 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2949 "2562 Failure to allocate an "
2950 "ELS sgl entry:%d\n", i);
2951 rc = -ENOMEM;
2952 goto out_free_mem;
2953 }
2954 sglq_entry->buff_type = GEN_BUFF_TYPE;
2955 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
2956 &sglq_entry->phys);
2957 if (sglq_entry->virt == NULL) {
2958 kfree(sglq_entry);
2959 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2960 "2563 Failure to allocate an "
2961 "ELS mbuf:%d\n", i);
2962 rc = -ENOMEM;
2963 goto out_free_mem;
2964 }
2965 sglq_entry->sgl = sglq_entry->virt;
2966 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
2967 sglq_entry->state = SGL_FREED;
2968 list_add_tail(&sglq_entry->list, &els_sgl_list);
2969 }
James Smart38c20672013-03-01 16:37:44 -05002970 spin_lock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04002971 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
James Smart38c20672013-03-01 16:37:44 -05002972 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04002973 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
2974 /* els xri-sgl shrinked */
2975 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
2976 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2977 "3158 ELS xri-sgl count decreased from "
2978 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
2979 els_xri_cnt);
2980 spin_lock_irq(&phba->hbalock);
2981 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list);
2982 spin_unlock_irq(&phba->hbalock);
2983 /* release extra els sgls from list */
2984 for (i = 0; i < xri_cnt; i++) {
2985 list_remove_head(&els_sgl_list,
2986 sglq_entry, struct lpfc_sglq, list);
2987 if (sglq_entry) {
2988 lpfc_mbuf_free(phba, sglq_entry->virt,
2989 sglq_entry->phys);
2990 kfree(sglq_entry);
2991 }
2992 }
2993 spin_lock_irq(&phba->hbalock);
2994 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
2995 spin_unlock_irq(&phba->hbalock);
2996 } else
2997 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2998 "3163 ELS xri-sgl count unchanged: %d\n",
2999 els_xri_cnt);
3000 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3001
3002 /* update xris to els sgls on the list */
3003 sglq_entry = NULL;
3004 sglq_entry_next = NULL;
3005 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3006 &phba->sli4_hba.lpfc_sgl_list, list) {
3007 lxri = lpfc_sli4_next_xritag(phba);
3008 if (lxri == NO_XRI) {
3009 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3010 "2400 Failed to allocate xri for "
3011 "ELS sgl\n");
3012 rc = -ENOMEM;
3013 goto out_free_mem;
3014 }
3015 sglq_entry->sli4_lxritag = lxri;
3016 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3017 }
3018
3019 /*
3020 * update on pci function's allocated scsi xri-sgl list
3021 */
3022 phba->total_scsi_bufs = 0;
3023
3024 /* maximum number of xris available for scsi buffers */
3025 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3026 els_xri_cnt;
3027
3028 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3029 "2401 Current allocated SCSI xri-sgl count:%d, "
3030 "maximum SCSI xri count:%d\n",
3031 phba->sli4_hba.scsi_xri_cnt,
3032 phba->sli4_hba.scsi_xri_max);
3033
James Smarta40fc5f2013-04-17 20:17:40 -04003034 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003035 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003036 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3037 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
James Smart164cecd2013-09-06 12:22:38 -04003038 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003039 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003040
3041 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3042 /* max scsi xri shrinked below the allocated scsi buffers */
3043 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3044 phba->sli4_hba.scsi_xri_max;
3045 /* release the extra allocated scsi buffers */
3046 for (i = 0; i < scsi_xri_cnt; i++) {
3047 list_remove_head(&scsi_sgl_list, psb,
3048 struct lpfc_scsi_buf, list);
3049 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, psb->data,
3050 psb->dma_handle);
3051 kfree(psb);
3052 }
James Smarta40fc5f2013-04-17 20:17:40 -04003053 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003054 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
James Smarta40fc5f2013-04-17 20:17:40 -04003055 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003056 }
3057
3058 /* update xris associated to remaining allocated scsi buffers */
3059 psb = NULL;
3060 psb_next = NULL;
3061 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3062 lxri = lpfc_sli4_next_xritag(phba);
3063 if (lxri == NO_XRI) {
3064 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3065 "2560 Failed to allocate xri for "
3066 "scsi buffer\n");
3067 rc = -ENOMEM;
3068 goto out_free_mem;
3069 }
3070 psb->cur_iocbq.sli4_lxritag = lxri;
3071 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3072 }
James Smarta40fc5f2013-04-17 20:17:40 -04003073 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003074 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003075 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3076 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
James Smart164cecd2013-09-06 12:22:38 -04003077 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003078 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003079
dea31012005-04-17 16:05:31 -05003080 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003081
3082out_free_mem:
3083 lpfc_free_els_sgl_list(phba);
3084 lpfc_scsi_free(phba);
3085 return rc;
dea31012005-04-17 16:05:31 -05003086}
3087
James Smarte59058c2008-08-24 21:49:00 -04003088/**
James Smart3621a712009-04-06 18:47:14 -04003089 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04003090 * @phba: pointer to lpfc hba data structure.
3091 * @instance: a unique integer ID to this FC port.
3092 * @dev: pointer to the device data structure.
3093 *
3094 * This routine creates a FC port for the upper layer protocol. The FC port
3095 * can be created on top of either a physical port or a virtual port provided
3096 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3097 * and associates the FC port created before adding the shost into the SCSI
3098 * layer.
3099 *
3100 * Return codes
3101 * @vport - pointer to the virtual N_Port data structure.
3102 * NULL - port create failed.
3103 **/
James Smart2e0fef82007-06-17 19:56:36 -05003104struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04003105lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04003106{
James Smart2e0fef82007-06-17 19:56:36 -05003107 struct lpfc_vport *vport;
3108 struct Scsi_Host *shost;
3109 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04003110
James Smart3de2a652007-08-02 11:09:59 -04003111 if (dev != &phba->pcidev->dev)
3112 shost = scsi_host_alloc(&lpfc_vport_template,
3113 sizeof(struct lpfc_vport));
3114 else
3115 shost = scsi_host_alloc(&lpfc_template,
3116 sizeof(struct lpfc_vport));
James Smart2e0fef82007-06-17 19:56:36 -05003117 if (!shost)
3118 goto out;
James Smart47a86172007-04-25 09:53:22 -04003119
James Smart2e0fef82007-06-17 19:56:36 -05003120 vport = (struct lpfc_vport *) shost->hostdata;
3121 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05003122 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05003123 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05003124 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04003125
James Smart3de2a652007-08-02 11:09:59 -04003126 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05003127 shost->unique_id = instance;
3128 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04003129 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05003130 shost->this_id = -1;
3131 shost->max_cmd_len = 16;
James Smartda0436e2009-05-22 14:51:39 -04003132 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05003133 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04003134 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smartda0436e2009-05-22 14:51:39 -04003135 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
3136 }
James Smart81301a92008-12-04 22:39:46 -05003137
James Smart47a86172007-04-25 09:53:22 -04003138 /*
James Smart2e0fef82007-06-17 19:56:36 -05003139 * Set initial can_queue value since 0 is no longer supported and
3140 * scsi_add_host will fail. This will be adjusted later based on the
3141 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04003142 */
James Smart2e0fef82007-06-17 19:56:36 -05003143 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04003144 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05003145 shost->transportt = lpfc_vport_transport_template;
3146 vport->port_type = LPFC_NPIV_PORT;
3147 } else {
3148 shost->transportt = lpfc_transport_template;
3149 vport->port_type = LPFC_PHYSICAL_PORT;
3150 }
James Smart47a86172007-04-25 09:53:22 -04003151
James Smart2e0fef82007-06-17 19:56:36 -05003152 /* Initialize all internally managed lists. */
3153 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04003154 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05003155 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04003156
James Smart2e0fef82007-06-17 19:56:36 -05003157 init_timer(&vport->fc_disctmo);
3158 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003159 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04003160
James Smart2e0fef82007-06-17 19:56:36 -05003161 init_timer(&vport->fc_fdmitmo);
3162 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
James Smart92d7f7b2007-06-17 19:56:38 -05003163 vport->fc_fdmitmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04003164
James Smart2e0fef82007-06-17 19:56:36 -05003165 init_timer(&vport->els_tmofunc);
3166 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003167 vport->els_tmofunc.data = (unsigned long)vport;
James Smart92494142011-02-16 12:39:44 -05003168
3169 init_timer(&vport->delayed_disc_tmo);
3170 vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
3171 vport->delayed_disc_tmo.data = (unsigned long)vport;
3172
James Bottomleyd139b9b2009-11-05 13:33:12 -06003173 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05003174 if (error)
3175 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04003176
James Smart549e55c2007-08-02 11:09:51 -04003177 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003178 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04003179 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003180 return vport;
James Smart47a86172007-04-25 09:53:22 -04003181
James Smart2e0fef82007-06-17 19:56:36 -05003182out_put_shost:
3183 scsi_host_put(shost);
3184out:
3185 return NULL;
James Smart47a86172007-04-25 09:53:22 -04003186}
3187
James Smarte59058c2008-08-24 21:49:00 -04003188/**
James Smart3621a712009-04-06 18:47:14 -04003189 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04003190 * @vport: pointer to an lpfc virtual N_Port data structure.
3191 *
3192 * This routine destroys a FC port from the upper layer protocol. All the
3193 * resources associated with the port are released.
3194 **/
James Smart2e0fef82007-06-17 19:56:36 -05003195void
3196destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04003197{
James Smart92d7f7b2007-06-17 19:56:38 -05003198 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3199 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003200
James Smart858c9f62007-06-17 19:56:39 -05003201 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05003202 fc_remove_host(shost);
3203 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04003204
James Smart92d7f7b2007-06-17 19:56:38 -05003205 spin_lock_irq(&phba->hbalock);
3206 list_del_init(&vport->listentry);
3207 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04003208
James Smart92d7f7b2007-06-17 19:56:38 -05003209 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04003210 return;
James Smart47a86172007-04-25 09:53:22 -04003211}
3212
James Smarte59058c2008-08-24 21:49:00 -04003213/**
James Smart3621a712009-04-06 18:47:14 -04003214 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04003215 *
3216 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3217 * uses the kernel idr facility to perform the task.
3218 *
3219 * Return codes:
3220 * instance - a unique integer ID allocated as the new instance.
3221 * -1 - lpfc get instance failed.
3222 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003223int
3224lpfc_get_instance(void)
3225{
Tejun Heoab516032013-02-27 17:04:44 -08003226 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003227
Tejun Heoab516032013-02-27 17:04:44 -08003228 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
3229 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003230}
3231
James Smarte59058c2008-08-24 21:49:00 -04003232/**
James Smart3621a712009-04-06 18:47:14 -04003233 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04003234 * @shost: pointer to SCSI host data structure.
3235 * @time: elapsed time of the scan in jiffies.
3236 *
3237 * This routine is called by the SCSI layer with a SCSI host to determine
3238 * whether the scan host is finished.
3239 *
3240 * Note: there is no scan_start function as adapter initialization will have
3241 * asynchronously kicked off the link initialization.
3242 *
3243 * Return codes
3244 * 0 - SCSI host scan is not over yet.
3245 * 1 - SCSI host scan is over.
3246 **/
James Smart47a86172007-04-25 09:53:22 -04003247int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
3248{
James Smart2e0fef82007-06-17 19:56:36 -05003249 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3250 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05003251 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04003252
James Smart858c9f62007-06-17 19:56:39 -05003253 spin_lock_irq(shost->host_lock);
3254
James Smart51ef4c22007-08-02 11:10:31 -04003255 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05003256 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003257 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05003258 }
James Smart256ec0d2013-04-17 20:14:58 -04003259 if (time >= msecs_to_jiffies(30 * 1000)) {
James Smart2e0fef82007-06-17 19:56:36 -05003260 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003261 "0461 Scanning longer than 30 "
3262 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003263 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003264 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003265 }
James Smart256ec0d2013-04-17 20:14:58 -04003266 if (time >= msecs_to_jiffies(15 * 1000) &&
3267 phba->link_state <= LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05003268 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003269 "0465 Link down longer than 15 "
3270 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003271 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05003272 goto finished;
James Smart47a86172007-04-25 09:53:22 -04003273 }
3274
James Smart2e0fef82007-06-17 19:56:36 -05003275 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05003276 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003277 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05003278 goto finished;
James Smart256ec0d2013-04-17 20:14:58 -04003279 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
James Smart858c9f62007-06-17 19:56:39 -05003280 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003281 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05003282 goto finished;
3283
3284 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003285
3286finished:
James Smart858c9f62007-06-17 19:56:39 -05003287 spin_unlock_irq(shost->host_lock);
3288 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003289}
3290
James Smarte59058c2008-08-24 21:49:00 -04003291/**
James Smart3621a712009-04-06 18:47:14 -04003292 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04003293 * @shost: pointer to SCSI host data structure.
3294 *
3295 * This routine initializes a given SCSI host attributes on a FC port. The
3296 * SCSI host can be either on top of a physical port or a virtual port.
3297 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003298void lpfc_host_attrib_init(struct Scsi_Host *shost)
3299{
3300 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3301 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003302 /*
James Smart2e0fef82007-06-17 19:56:36 -05003303 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04003304 */
3305
James Smart2e0fef82007-06-17 19:56:36 -05003306 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
3307 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04003308 fc_host_supported_classes(shost) = FC_COS_CLASS3;
3309
3310 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003311 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003312 fc_host_supported_fc4s(shost)[2] = 1;
3313 fc_host_supported_fc4s(shost)[7] = 1;
3314
James Smart92d7f7b2007-06-17 19:56:38 -05003315 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
3316 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04003317
3318 fc_host_supported_speeds(shost) = 0;
James Smart88a2cfb2011-07-22 18:36:33 -04003319 if (phba->lmt & LMT_16Gb)
3320 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
James Smart47a86172007-04-25 09:53:22 -04003321 if (phba->lmt & LMT_10Gb)
3322 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04003323 if (phba->lmt & LMT_8Gb)
3324 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04003325 if (phba->lmt & LMT_4Gb)
3326 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
3327 if (phba->lmt & LMT_2Gb)
3328 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
3329 if (phba->lmt & LMT_1Gb)
3330 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
3331
3332 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05003333 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
3334 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04003335
Mike Christie0af5d702010-09-15 16:52:31 -05003336 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
3337
James Smart47a86172007-04-25 09:53:22 -04003338 /* This value is also unchanging */
3339 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003340 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003341 fc_host_active_fc4s(shost)[2] = 1;
3342 fc_host_active_fc4s(shost)[7] = 1;
3343
James Smart92d7f7b2007-06-17 19:56:38 -05003344 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04003345 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04003346 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04003347 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04003348}
dea31012005-04-17 16:05:31 -05003349
James Smarte59058c2008-08-24 21:49:00 -04003350/**
James Smartda0436e2009-05-22 14:51:39 -04003351 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04003352 * @phba: pointer to lpfc hba data structure.
3353 *
James Smartda0436e2009-05-22 14:51:39 -04003354 * This routine is invoked to stop an SLI3 device port, it stops the device
3355 * from generating interrupts and stops the device driver's timers for the
3356 * device.
James Smarte59058c2008-08-24 21:49:00 -04003357 **/
James Smartdb2378e2008-02-08 18:49:51 -05003358static void
James Smartda0436e2009-05-22 14:51:39 -04003359lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05003360{
James Smartda0436e2009-05-22 14:51:39 -04003361 /* Clear all interrupt enable conditions */
3362 writel(0, phba->HCregaddr);
3363 readl(phba->HCregaddr); /* flush */
3364 /* Clear all pending interrupts */
3365 writel(0xffffffff, phba->HAregaddr);
3366 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04003367
James Smartda0436e2009-05-22 14:51:39 -04003368 /* Reset some HBA SLI setup states */
3369 lpfc_stop_hba_timers(phba);
3370 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05003371}
3372
James Smarte59058c2008-08-24 21:49:00 -04003373/**
James Smartda0436e2009-05-22 14:51:39 -04003374 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05003375 * @phba: pointer to lpfc hba data structure.
3376 *
James Smartda0436e2009-05-22 14:51:39 -04003377 * This routine is invoked to stop an SLI4 device port, it stops the device
3378 * from generating interrupts and stops the device driver's timers for the
3379 * device.
3380 **/
3381static void
3382lpfc_stop_port_s4(struct lpfc_hba *phba)
3383{
3384 /* Reset some HBA SLI4 setup states */
3385 lpfc_stop_hba_timers(phba);
3386 phba->pport->work_port_events = 0;
3387 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04003388}
3389
3390/**
3391 * lpfc_stop_port - Wrapper function for stopping hba port
3392 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05003393 *
James Smartda0436e2009-05-22 14:51:39 -04003394 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3395 * the API jump table function pointer from the lpfc_hba struct.
3396 **/
3397void
3398lpfc_stop_port(struct lpfc_hba *phba)
3399{
3400 phba->lpfc_stop_port(phba);
3401}
3402
3403/**
James Smartecfd03c2010-02-12 14:41:27 -05003404 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3405 * @phba: Pointer to hba for which this call is being executed.
3406 *
3407 * This routine starts the timer waiting for the FCF rediscovery to complete.
3408 **/
3409void
3410lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
3411{
3412 unsigned long fcf_redisc_wait_tmo =
3413 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
3414 /* Start fcf rediscovery wait period timer */
3415 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
3416 spin_lock_irq(&phba->hbalock);
3417 /* Allow action to new fcf asynchronous event */
3418 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
3419 /* Mark the FCF rediscovery pending state */
3420 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
3421 spin_unlock_irq(&phba->hbalock);
3422}
3423
3424/**
3425 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
3426 * @ptr: Map to lpfc_hba data structure pointer.
3427 *
3428 * This routine is invoked when waiting for FCF table rediscover has been
3429 * timed out. If new FCF record(s) has (have) been discovered during the
3430 * wait period, a new FCF event shall be added to the FCOE async event
3431 * list, and then worker thread shall be waked up for processing from the
3432 * worker thread context.
3433 **/
3434void
3435lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
3436{
3437 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
3438
3439 /* Don't send FCF rediscovery event if timer cancelled */
3440 spin_lock_irq(&phba->hbalock);
3441 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
3442 spin_unlock_irq(&phba->hbalock);
3443 return;
3444 }
3445 /* Clear FCF rediscovery timer pending flag */
3446 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
3447 /* FCF rediscovery event to worker thread */
3448 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
3449 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003450 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04003451 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05003452 /* wake up worker thread */
3453 lpfc_worker_wake_up(phba);
3454}
3455
3456/**
James Smartda0436e2009-05-22 14:51:39 -04003457 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
3458 * @phba: pointer to lpfc hba data structure.
3459 * @acqe_link: pointer to the async link completion queue entry.
3460 *
3461 * This routine is to parse the SLI4 link-attention link fault code and
3462 * translate it into the base driver's read link attention mailbox command
3463 * status.
3464 *
3465 * Return: Link-attention status in terms of base driver's coding.
3466 **/
3467static uint16_t
3468lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
3469 struct lpfc_acqe_link *acqe_link)
3470{
3471 uint16_t latt_fault;
3472
3473 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
3474 case LPFC_ASYNC_LINK_FAULT_NONE:
3475 case LPFC_ASYNC_LINK_FAULT_LOCAL:
3476 case LPFC_ASYNC_LINK_FAULT_REMOTE:
3477 latt_fault = 0;
3478 break;
3479 default:
3480 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3481 "0398 Invalid link fault code: x%x\n",
3482 bf_get(lpfc_acqe_link_fault, acqe_link));
3483 latt_fault = MBXERR_ERROR;
3484 break;
3485 }
3486 return latt_fault;
3487}
3488
3489/**
3490 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
3491 * @phba: pointer to lpfc hba data structure.
3492 * @acqe_link: pointer to the async link completion queue entry.
3493 *
3494 * This routine is to parse the SLI4 link attention type and translate it
3495 * into the base driver's link attention type coding.
3496 *
3497 * Return: Link attention type in terms of base driver's coding.
3498 **/
3499static uint8_t
3500lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
3501 struct lpfc_acqe_link *acqe_link)
3502{
3503 uint8_t att_type;
3504
3505 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
3506 case LPFC_ASYNC_LINK_STATUS_DOWN:
3507 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05003508 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04003509 break;
3510 case LPFC_ASYNC_LINK_STATUS_UP:
3511 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05003512 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003513 break;
3514 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05003515 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04003516 break;
3517 default:
3518 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3519 "0399 Invalid link attention type: x%x\n",
3520 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003521 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003522 break;
3523 }
3524 return att_type;
3525}
3526
3527/**
3528 * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
3529 * @phba: pointer to lpfc hba data structure.
3530 * @acqe_link: pointer to the async link completion queue entry.
3531 *
3532 * This routine is to parse the SLI4 link-attention link speed and translate
3533 * it into the base driver's link-attention link speed coding.
3534 *
3535 * Return: Link-attention link speed in terms of base driver's coding.
3536 **/
3537static uint8_t
3538lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba,
3539 struct lpfc_acqe_link *acqe_link)
3540{
3541 uint8_t link_speed;
3542
3543 switch (bf_get(lpfc_acqe_link_speed, acqe_link)) {
3544 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smartda0436e2009-05-22 14:51:39 -04003545 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smartda0436e2009-05-22 14:51:39 -04003546 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart76a95d72010-11-20 23:11:48 -05003547 link_speed = LPFC_LINK_SPEED_UNKNOWN;
James Smartda0436e2009-05-22 14:51:39 -04003548 break;
3549 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart76a95d72010-11-20 23:11:48 -05003550 link_speed = LPFC_LINK_SPEED_1GHZ;
James Smartda0436e2009-05-22 14:51:39 -04003551 break;
3552 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart76a95d72010-11-20 23:11:48 -05003553 link_speed = LPFC_LINK_SPEED_10GHZ;
James Smartda0436e2009-05-22 14:51:39 -04003554 break;
3555 default:
3556 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3557 "0483 Invalid link-attention link speed: x%x\n",
3558 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003559 link_speed = LPFC_LINK_SPEED_UNKNOWN;
James Smartda0436e2009-05-22 14:51:39 -04003560 break;
3561 }
3562 return link_speed;
3563}
3564
3565/**
James Smart8b68cd52012-09-29 11:32:37 -04003566 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
3567 * @phba: pointer to lpfc hba data structure.
3568 *
3569 * This routine is to get an SLI3 FC port's link speed in Mbps.
3570 *
3571 * Return: link speed in terms of Mbps.
3572 **/
3573uint32_t
3574lpfc_sli_port_speed_get(struct lpfc_hba *phba)
3575{
3576 uint32_t link_speed;
3577
3578 if (!lpfc_is_link_up(phba))
3579 return 0;
3580
3581 switch (phba->fc_linkspeed) {
3582 case LPFC_LINK_SPEED_1GHZ:
3583 link_speed = 1000;
3584 break;
3585 case LPFC_LINK_SPEED_2GHZ:
3586 link_speed = 2000;
3587 break;
3588 case LPFC_LINK_SPEED_4GHZ:
3589 link_speed = 4000;
3590 break;
3591 case LPFC_LINK_SPEED_8GHZ:
3592 link_speed = 8000;
3593 break;
3594 case LPFC_LINK_SPEED_10GHZ:
3595 link_speed = 10000;
3596 break;
3597 case LPFC_LINK_SPEED_16GHZ:
3598 link_speed = 16000;
3599 break;
3600 default:
3601 link_speed = 0;
3602 }
3603 return link_speed;
3604}
3605
3606/**
3607 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
3608 * @phba: pointer to lpfc hba data structure.
3609 * @evt_code: asynchronous event code.
3610 * @speed_code: asynchronous event link speed code.
3611 *
3612 * This routine is to parse the giving SLI4 async event link speed code into
3613 * value of Mbps for the link speed.
3614 *
3615 * Return: link speed in terms of Mbps.
3616 **/
3617static uint32_t
3618lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
3619 uint8_t speed_code)
3620{
3621 uint32_t port_speed;
3622
3623 switch (evt_code) {
3624 case LPFC_TRAILER_CODE_LINK:
3625 switch (speed_code) {
3626 case LPFC_EVT_CODE_LINK_NO_LINK:
3627 port_speed = 0;
3628 break;
3629 case LPFC_EVT_CODE_LINK_10_MBIT:
3630 port_speed = 10;
3631 break;
3632 case LPFC_EVT_CODE_LINK_100_MBIT:
3633 port_speed = 100;
3634 break;
3635 case LPFC_EVT_CODE_LINK_1_GBIT:
3636 port_speed = 1000;
3637 break;
3638 case LPFC_EVT_CODE_LINK_10_GBIT:
3639 port_speed = 10000;
3640 break;
3641 default:
3642 port_speed = 0;
3643 }
3644 break;
3645 case LPFC_TRAILER_CODE_FC:
3646 switch (speed_code) {
3647 case LPFC_EVT_CODE_FC_NO_LINK:
3648 port_speed = 0;
3649 break;
3650 case LPFC_EVT_CODE_FC_1_GBAUD:
3651 port_speed = 1000;
3652 break;
3653 case LPFC_EVT_CODE_FC_2_GBAUD:
3654 port_speed = 2000;
3655 break;
3656 case LPFC_EVT_CODE_FC_4_GBAUD:
3657 port_speed = 4000;
3658 break;
3659 case LPFC_EVT_CODE_FC_8_GBAUD:
3660 port_speed = 8000;
3661 break;
3662 case LPFC_EVT_CODE_FC_10_GBAUD:
3663 port_speed = 10000;
3664 break;
3665 case LPFC_EVT_CODE_FC_16_GBAUD:
3666 port_speed = 16000;
3667 break;
3668 default:
3669 port_speed = 0;
3670 }
3671 break;
3672 default:
3673 port_speed = 0;
3674 }
3675 return port_speed;
3676}
3677
3678/**
James Smart70f3c072010-12-15 17:57:33 -05003679 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04003680 * @phba: pointer to lpfc hba data structure.
3681 * @acqe_link: pointer to the async link completion queue entry.
3682 *
James Smart70f3c072010-12-15 17:57:33 -05003683 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04003684 **/
3685static void
3686lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
3687 struct lpfc_acqe_link *acqe_link)
3688{
3689 struct lpfc_dmabuf *mp;
3690 LPFC_MBOXQ_t *pmb;
3691 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05003692 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04003693 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05003694 int rc;
James Smartda0436e2009-05-22 14:51:39 -04003695
3696 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05003697 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04003698 return;
James Smart32b97932009-07-19 10:01:21 -04003699 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04003700 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3701 if (!pmb) {
3702 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3703 "0395 The mboxq allocation failed\n");
3704 return;
3705 }
3706 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3707 if (!mp) {
3708 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3709 "0396 The lpfc_dmabuf allocation failed\n");
3710 goto out_free_pmb;
3711 }
3712 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
3713 if (!mp->virt) {
3714 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3715 "0397 The mbuf allocation failed\n");
3716 goto out_free_dmabuf;
3717 }
3718
3719 /* Cleanup any outstanding ELS commands */
3720 lpfc_els_flush_all_cmd(phba);
3721
3722 /* Block ELS IOCBs until we have done process link event */
3723 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
3724
3725 /* Update link event statistics */
3726 phba->sli.slistat.link_event++;
3727
James Smart76a95d72010-11-20 23:11:48 -05003728 /* Create lpfc_handle_latt mailbox command from link ACQE */
3729 lpfc_read_topology(phba, pmb, mp);
3730 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04003731 pmb->vport = phba->pport;
3732
James Smartda0436e2009-05-22 14:51:39 -04003733 /* Keep the link status for extra SLI4 state machine reference */
3734 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04003735 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
3736 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04003737 phba->sli4_hba.link_state.duplex =
3738 bf_get(lpfc_acqe_link_duplex, acqe_link);
3739 phba->sli4_hba.link_state.status =
3740 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05003741 phba->sli4_hba.link_state.type =
3742 bf_get(lpfc_acqe_link_type, acqe_link);
3743 phba->sli4_hba.link_state.number =
3744 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04003745 phba->sli4_hba.link_state.fault =
3746 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05003747 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04003748 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
3749
James Smart70f3c072010-12-15 17:57:33 -05003750 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04003751 "2900 Async FC/FCoE Link event - Speed:%dGBit "
3752 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
3753 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05003754 phba->sli4_hba.link_state.speed,
3755 phba->sli4_hba.link_state.topology,
3756 phba->sli4_hba.link_state.status,
3757 phba->sli4_hba.link_state.type,
3758 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04003759 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05003760 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05003761 /*
3762 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
3763 * topology info. Note: Optional for non FC-AL ports.
3764 */
3765 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3766 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3767 if (rc == MBX_NOT_FINISHED)
3768 goto out_free_dmabuf;
3769 return;
3770 }
3771 /*
3772 * For FCoE Mode: fill in all the topology information we need and call
3773 * the READ_TOPOLOGY completion routine to continue without actually
3774 * sending the READ_TOPOLOGY mailbox command to the port.
3775 */
3776 /* Parse and translate status field */
3777 mb = &pmb->u.mb;
3778 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
3779
3780 /* Parse and translate link attention fields */
3781 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3782 la->eventTag = acqe_link->event_tag;
3783 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
3784 bf_set(lpfc_mbx_read_top_link_spd, la,
3785 lpfc_sli4_parse_latt_link_speed(phba, acqe_link));
3786
3787 /* Fake the the following irrelvant fields */
3788 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
3789 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
3790 bf_set(lpfc_mbx_read_top_il, la, 0);
3791 bf_set(lpfc_mbx_read_top_pb, la, 0);
3792 bf_set(lpfc_mbx_read_top_fa, la, 0);
3793 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04003794
3795 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05003796 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04003797
3798 return;
3799
3800out_free_dmabuf:
3801 kfree(mp);
3802out_free_pmb:
3803 mempool_free(pmb, phba->mbox_mem_pool);
3804}
3805
3806/**
James Smart70f3c072010-12-15 17:57:33 -05003807 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
3808 * @phba: pointer to lpfc hba data structure.
3809 * @acqe_fc: pointer to the async fc completion queue entry.
3810 *
3811 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
3812 * that the event was received and then issue a read_topology mailbox command so
3813 * that the rest of the driver will treat it the same as SLI3.
3814 **/
3815static void
3816lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
3817{
3818 struct lpfc_dmabuf *mp;
3819 LPFC_MBOXQ_t *pmb;
3820 int rc;
3821
3822 if (bf_get(lpfc_trailer_type, acqe_fc) !=
3823 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
3824 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3825 "2895 Non FC link Event detected.(%d)\n",
3826 bf_get(lpfc_trailer_type, acqe_fc));
3827 return;
3828 }
3829 /* Keep the link status for extra SLI4 state machine reference */
3830 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04003831 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
3832 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05003833 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
3834 phba->sli4_hba.link_state.topology =
3835 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
3836 phba->sli4_hba.link_state.status =
3837 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
3838 phba->sli4_hba.link_state.type =
3839 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
3840 phba->sli4_hba.link_state.number =
3841 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
3842 phba->sli4_hba.link_state.fault =
3843 bf_get(lpfc_acqe_link_fault, acqe_fc);
3844 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04003845 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart70f3c072010-12-15 17:57:33 -05003846 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3847 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
3848 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
3849 "%dMbps Fault:%d\n",
3850 phba->sli4_hba.link_state.speed,
3851 phba->sli4_hba.link_state.topology,
3852 phba->sli4_hba.link_state.status,
3853 phba->sli4_hba.link_state.type,
3854 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04003855 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05003856 phba->sli4_hba.link_state.fault);
3857 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3858 if (!pmb) {
3859 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3860 "2897 The mboxq allocation failed\n");
3861 return;
3862 }
3863 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3864 if (!mp) {
3865 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3866 "2898 The lpfc_dmabuf allocation failed\n");
3867 goto out_free_pmb;
3868 }
3869 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
3870 if (!mp->virt) {
3871 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3872 "2899 The mbuf allocation failed\n");
3873 goto out_free_dmabuf;
3874 }
3875
3876 /* Cleanup any outstanding ELS commands */
3877 lpfc_els_flush_all_cmd(phba);
3878
3879 /* Block ELS IOCBs until we have done process link event */
3880 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
3881
3882 /* Update link event statistics */
3883 phba->sli.slistat.link_event++;
3884
3885 /* Create lpfc_handle_latt mailbox command from link ACQE */
3886 lpfc_read_topology(phba, pmb, mp);
3887 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
3888 pmb->vport = phba->pport;
3889
3890 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3891 if (rc == MBX_NOT_FINISHED)
3892 goto out_free_dmabuf;
3893 return;
3894
3895out_free_dmabuf:
3896 kfree(mp);
3897out_free_pmb:
3898 mempool_free(pmb, phba->mbox_mem_pool);
3899}
3900
3901/**
3902 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
3903 * @phba: pointer to lpfc hba data structure.
3904 * @acqe_fc: pointer to the async SLI completion queue entry.
3905 *
3906 * This routine is to handle the SLI4 asynchronous SLI events.
3907 **/
3908static void
3909lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
3910{
James Smart4b8bae02012-06-12 13:55:07 -04003911 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04003912 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04003913 uint8_t status;
3914 struct lpfc_acqe_misconfigured_event *misconfigured;
3915
3916 /* special case misconfigured event as it contains data for all ports */
3917 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3918 LPFC_SLI_INTF_IF_TYPE_2) ||
3919 (bf_get(lpfc_trailer_type, acqe_sli) !=
3920 LPFC_SLI_EVENT_TYPE_MISCONFIGURED)) {
3921 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3922 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
3923 "x%08x SLI Event Type:%d\n",
3924 acqe_sli->event_data1, acqe_sli->event_data2,
3925 bf_get(lpfc_trailer_type, acqe_sli));
3926 return;
3927 }
3928
3929 port_name = phba->Port[0];
3930 if (port_name == 0x00)
3931 port_name = '?'; /* get port name is empty */
3932
3933 misconfigured = (struct lpfc_acqe_misconfigured_event *)
3934 &acqe_sli->event_data1;
3935
3936 /* fetch the status for this port */
3937 switch (phba->sli4_hba.lnk_info.lnk_no) {
3938 case LPFC_LINK_NUMBER_0:
3939 status = bf_get(lpfc_sli_misconfigured_port0,
3940 &misconfigured->theEvent);
3941 break;
3942 case LPFC_LINK_NUMBER_1:
3943 status = bf_get(lpfc_sli_misconfigured_port1,
3944 &misconfigured->theEvent);
3945 break;
3946 case LPFC_LINK_NUMBER_2:
3947 status = bf_get(lpfc_sli_misconfigured_port2,
3948 &misconfigured->theEvent);
3949 break;
3950 case LPFC_LINK_NUMBER_3:
3951 status = bf_get(lpfc_sli_misconfigured_port3,
3952 &misconfigured->theEvent);
3953 break;
3954 default:
3955 status = ~LPFC_SLI_EVENT_STATUS_VALID;
3956 break;
3957 }
3958
3959 switch (status) {
3960 case LPFC_SLI_EVENT_STATUS_VALID:
3961 return; /* no message if the sfp is okay */
3962 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
James Smart292098b2012-09-29 11:31:41 -04003963 sprintf(message, "Optics faulted/incorrectly installed/not " \
3964 "installed - Reseat optics, if issue not "
3965 "resolved, replace.");
James Smart4b8bae02012-06-12 13:55:07 -04003966 break;
3967 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
3968 sprintf(message,
James Smart292098b2012-09-29 11:31:41 -04003969 "Optics of two types installed - Remove one optic or " \
3970 "install matching pair of optics.");
James Smart4b8bae02012-06-12 13:55:07 -04003971 break;
3972 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
James Smart292098b2012-09-29 11:31:41 -04003973 sprintf(message, "Incompatible optics - Replace with " \
3974 "compatible optics for card to function.");
James Smart4b8bae02012-06-12 13:55:07 -04003975 break;
3976 default:
3977 /* firmware is reporting a status we don't know about */
3978 sprintf(message, "Unknown event status x%02x", status);
3979 break;
3980 }
3981
3982 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3983 "3176 Misconfigured Physical Port - "
3984 "Port Name %c %s\n", port_name, message);
James Smart70f3c072010-12-15 17:57:33 -05003985}
3986
3987/**
James Smartfc2b9892010-02-26 14:15:29 -05003988 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
3989 * @vport: pointer to vport data structure.
3990 *
3991 * This routine is to perform Clear Virtual Link (CVL) on a vport in
3992 * response to a CVL event.
3993 *
3994 * Return the pointer to the ndlp with the vport if successful, otherwise
3995 * return NULL.
3996 **/
3997static struct lpfc_nodelist *
3998lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
3999{
4000 struct lpfc_nodelist *ndlp;
4001 struct Scsi_Host *shost;
4002 struct lpfc_hba *phba;
4003
4004 if (!vport)
4005 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05004006 phba = vport->phba;
4007 if (!phba)
4008 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04004009 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4010 if (!ndlp) {
4011 /* Cannot find existing Fabric ndlp, so allocate a new one */
4012 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4013 if (!ndlp)
4014 return 0;
4015 lpfc_nlp_init(vport, ndlp, Fabric_DID);
4016 /* Set the node type */
4017 ndlp->nlp_type |= NLP_FABRIC;
4018 /* Put ndlp onto node list */
4019 lpfc_enqueue_node(vport, ndlp);
4020 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4021 /* re-setup ndlp without removing from node list */
4022 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4023 if (!ndlp)
4024 return 0;
4025 }
James Smart63e801c2010-11-20 23:14:19 -05004026 if ((phba->pport->port_state < LPFC_FLOGI) &&
4027 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004028 return NULL;
4029 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05004030 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
4031 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004032 return NULL;
4033 shost = lpfc_shost_from_vport(vport);
4034 if (!shost)
4035 return NULL;
4036 lpfc_linkdown_port(vport);
4037 lpfc_cleanup_pending_mbox(vport);
4038 spin_lock_irq(shost->host_lock);
4039 vport->fc_flag |= FC_VPORT_CVL_RCVD;
4040 spin_unlock_irq(shost->host_lock);
4041
4042 return ndlp;
4043}
4044
4045/**
4046 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4047 * @vport: pointer to lpfc hba data structure.
4048 *
4049 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4050 * response to a FCF dead event.
4051 **/
4052static void
4053lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
4054{
4055 struct lpfc_vport **vports;
4056 int i;
4057
4058 vports = lpfc_create_vport_work_array(phba);
4059 if (vports)
4060 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4061 lpfc_sli4_perform_vport_cvl(vports[i]);
4062 lpfc_destroy_vport_work_array(phba, vports);
4063}
4064
4065/**
James Smart76a95d72010-11-20 23:11:48 -05004066 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04004067 * @phba: pointer to lpfc hba data structure.
4068 * @acqe_link: pointer to the async fcoe completion queue entry.
4069 *
4070 * This routine is to handle the SLI4 asynchronous fcoe event.
4071 **/
4072static void
James Smart76a95d72010-11-20 23:11:48 -05004073lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05004074 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04004075{
James Smart70f3c072010-12-15 17:57:33 -05004076 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004077 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04004078 struct lpfc_vport *vport;
4079 struct lpfc_nodelist *ndlp;
4080 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05004081 int active_vlink_present;
4082 struct lpfc_vport **vports;
4083 int i;
James Smartda0436e2009-05-22 14:51:39 -04004084
James Smart70f3c072010-12-15 17:57:33 -05004085 phba->fc_eventTag = acqe_fip->event_tag;
4086 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004087 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05004088 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
4089 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
4090 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04004091 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4092 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004093 "2546 New FCF event, evt_tag:x%x, "
4094 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004095 acqe_fip->event_tag,
4096 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04004097 else
4098 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
4099 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004100 "2788 FCF param modified event, "
4101 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004102 acqe_fip->event_tag,
4103 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04004104 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004105 /*
4106 * During period of FCF discovery, read the FCF
4107 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04004108 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05004109 */
4110 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4111 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004112 "2779 Read FCF (x%x) for updating "
4113 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05004114 acqe_fip->index);
4115 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004116 }
James Smart38b92ef2010-08-04 16:11:39 -04004117
4118 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04004119 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04004120 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04004121 spin_unlock_irq(&phba->hbalock);
4122 break;
4123 }
4124 /* If fast FCF failover rescan event is pending, do nothing */
4125 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
4126 spin_unlock_irq(&phba->hbalock);
4127 break;
4128 }
4129
James Smartc2b97122013-05-31 17:05:36 -04004130 /* If the FCF has been in discovered state, do nothing. */
4131 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
James Smart3804dc82010-07-14 15:31:37 -04004132 spin_unlock_irq(&phba->hbalock);
4133 break;
4134 }
4135 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04004136
James Smart0c9ab6f2010-02-26 14:15:57 -05004137 /* Otherwise, scan the entire FCF table and re-discover SAN */
4138 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004139 "2770 Start FCF table scan per async FCF "
4140 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004141 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004142 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
4143 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04004144 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004145 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4146 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04004147 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04004148 break;
4149
James Smart70f3c072010-12-15 17:57:33 -05004150 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04004151 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04004152 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004153 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
4154 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004155 break;
4156
James Smart70f3c072010-12-15 17:57:33 -05004157 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05004158 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004159 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004160 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05004161 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04004162 /*
4163 * If we are in the middle of FCF failover process, clear
4164 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04004165 */
James Smartfc2b9892010-02-26 14:15:29 -05004166 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004167 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05004168 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004169 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05004170 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004171 break;
4172 }
James Smart38b92ef2010-08-04 16:11:39 -04004173 spin_unlock_irq(&phba->hbalock);
4174
4175 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05004176 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04004177 break;
4178
4179 /*
4180 * Otherwise, request the port to rediscover the entire FCF
4181 * table for a fast recovery from case that the current FCF
4182 * is no longer valid as we are not in the middle of FCF
4183 * failover process already.
4184 */
James Smartc2b97122013-05-31 17:05:36 -04004185 spin_lock_irq(&phba->hbalock);
4186 /* Mark the fast failover process in progress */
4187 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
4188 spin_unlock_irq(&phba->hbalock);
4189
4190 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
4191 "2771 Start FCF fast failover process due to "
4192 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
4193 "\n", acqe_fip->event_tag, acqe_fip->index);
4194 rc = lpfc_sli4_redisc_fcf_table(phba);
4195 if (rc) {
4196 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4197 LOG_DISCOVERY,
4198 "2772 Issue FCF rediscover mabilbox "
4199 "command failed, fail through to FCF "
4200 "dead event\n");
4201 spin_lock_irq(&phba->hbalock);
4202 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
4203 spin_unlock_irq(&phba->hbalock);
4204 /*
4205 * Last resort will fail over by treating this
4206 * as a link down to FCF registration.
4207 */
4208 lpfc_sli4_fcf_dead_failthrough(phba);
4209 } else {
4210 /* Reset FCF roundrobin bmask for new discovery */
4211 lpfc_sli4_clear_fcf_rr_bmask(phba);
4212 /*
4213 * Handling fast FCF failover to a DEAD FCF event is
4214 * considered equalivant to receiving CVL to all vports.
4215 */
4216 lpfc_sli4_perform_all_vport_cvl(phba);
4217 }
James Smartda0436e2009-05-22 14:51:39 -04004218 break;
James Smart70f3c072010-12-15 17:57:33 -05004219 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05004220 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004221 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04004222 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05004223 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04004224
James Smart6669f9b2009-10-02 15:16:45 -04004225 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04004226 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004227 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004228 if (!ndlp)
4229 break;
James Smart695a8142010-01-26 23:08:03 -05004230 active_vlink_present = 0;
4231
4232 vports = lpfc_create_vport_work_array(phba);
4233 if (vports) {
4234 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
4235 i++) {
4236 if ((!(vports[i]->fc_flag &
4237 FC_VPORT_CVL_RCVD)) &&
4238 (vports[i]->port_state > LPFC_FDISC)) {
4239 active_vlink_present = 1;
4240 break;
4241 }
4242 }
4243 lpfc_destroy_vport_work_array(phba, vports);
4244 }
4245
4246 if (active_vlink_present) {
4247 /*
4248 * If there are other active VLinks present,
4249 * re-instantiate the Vlink using FDISC.
4250 */
James Smart256ec0d2013-04-17 20:14:58 -04004251 mod_timer(&ndlp->nlp_delayfunc,
4252 jiffies + msecs_to_jiffies(1000));
James Smartfc2b9892010-02-26 14:15:29 -05004253 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004254 spin_lock_irq(shost->host_lock);
4255 ndlp->nlp_flag |= NLP_DELAY_TMO;
4256 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05004257 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
4258 vport->port_state = LPFC_FDISC;
4259 } else {
James Smartecfd03c2010-02-12 14:41:27 -05004260 /*
4261 * Otherwise, we request port to rediscover
4262 * the entire FCF table for a fast recovery
4263 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05004264 * is no longer valid if we are not already
4265 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05004266 */
James Smartfc2b9892010-02-26 14:15:29 -05004267 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004268 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05004269 spin_unlock_irq(&phba->hbalock);
4270 break;
4271 }
4272 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05004273 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004274 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004275 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4276 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004277 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05004278 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05004279 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05004280 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004281 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4282 LOG_DISCOVERY,
4283 "2774 Issue FCF rediscover "
4284 "mabilbox command failed, "
4285 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05004286 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004287 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004288 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05004289 /*
4290 * Last resort will be re-try on the
4291 * the current registered FCF entry.
4292 */
4293 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04004294 } else
4295 /*
4296 * Reset FCF roundrobin bmask for new
4297 * discovery.
4298 */
James Smart7d791df2011-07-22 18:37:52 -04004299 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04004300 }
4301 break;
James Smartda0436e2009-05-22 14:51:39 -04004302 default:
4303 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4304 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05004305 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004306 break;
4307 }
4308}
4309
4310/**
4311 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
4312 * @phba: pointer to lpfc hba data structure.
4313 * @acqe_link: pointer to the async dcbx completion queue entry.
4314 *
4315 * This routine is to handle the SLI4 asynchronous dcbx event.
4316 **/
4317static void
4318lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
4319 struct lpfc_acqe_dcbx *acqe_dcbx)
4320{
James Smart4d9ab992009-10-02 15:16:39 -04004321 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004322 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4323 "0290 The SLI4 DCBX asynchronous event is not "
4324 "handled yet\n");
4325}
4326
4327/**
James Smartb19a0612010-04-06 14:48:51 -04004328 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
4329 * @phba: pointer to lpfc hba data structure.
4330 * @acqe_link: pointer to the async grp5 completion queue entry.
4331 *
4332 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
4333 * is an asynchronous notified of a logical link speed change. The Port
4334 * reports the logical link speed in units of 10Mbps.
4335 **/
4336static void
4337lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
4338 struct lpfc_acqe_grp5 *acqe_grp5)
4339{
4340 uint16_t prev_ll_spd;
4341
4342 phba->fc_eventTag = acqe_grp5->event_tag;
4343 phba->fcoe_eventtag = acqe_grp5->event_tag;
4344 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
4345 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004346 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04004347 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4348 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04004349 "from %dMbps to %dMbps\n", prev_ll_spd,
4350 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04004351}
4352
4353/**
James Smartda0436e2009-05-22 14:51:39 -04004354 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
4355 * @phba: pointer to lpfc hba data structure.
4356 *
4357 * This routine is invoked by the worker thread to process all the pending
4358 * SLI4 asynchronous events.
4359 **/
4360void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
4361{
4362 struct lpfc_cq_event *cq_event;
4363
4364 /* First, declare the async event has been handled */
4365 spin_lock_irq(&phba->hbalock);
4366 phba->hba_flag &= ~ASYNC_EVENT;
4367 spin_unlock_irq(&phba->hbalock);
4368 /* Now, handle all the async events */
4369 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
4370 /* Get the first event from the head of the event queue */
4371 spin_lock_irq(&phba->hbalock);
4372 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
4373 cq_event, struct lpfc_cq_event, list);
4374 spin_unlock_irq(&phba->hbalock);
4375 /* Process the asynchronous event */
4376 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
4377 case LPFC_TRAILER_CODE_LINK:
4378 lpfc_sli4_async_link_evt(phba,
4379 &cq_event->cqe.acqe_link);
4380 break;
4381 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05004382 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004383 break;
4384 case LPFC_TRAILER_CODE_DCBX:
4385 lpfc_sli4_async_dcbx_evt(phba,
4386 &cq_event->cqe.acqe_dcbx);
4387 break;
James Smartb19a0612010-04-06 14:48:51 -04004388 case LPFC_TRAILER_CODE_GRP5:
4389 lpfc_sli4_async_grp5_evt(phba,
4390 &cq_event->cqe.acqe_grp5);
4391 break;
James Smart70f3c072010-12-15 17:57:33 -05004392 case LPFC_TRAILER_CODE_FC:
4393 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
4394 break;
4395 case LPFC_TRAILER_CODE_SLI:
4396 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
4397 break;
James Smartda0436e2009-05-22 14:51:39 -04004398 default:
4399 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4400 "1804 Invalid asynchrous event code: "
4401 "x%x\n", bf_get(lpfc_trailer_code,
4402 &cq_event->cqe.mcqe_cmpl));
4403 break;
4404 }
4405 /* Free the completion event processed to the free pool */
4406 lpfc_sli4_cq_event_release(phba, cq_event);
4407 }
4408}
4409
4410/**
James Smartecfd03c2010-02-12 14:41:27 -05004411 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
4412 * @phba: pointer to lpfc hba data structure.
4413 *
4414 * This routine is invoked by the worker thread to process FCF table
4415 * rediscovery pending completion event.
4416 **/
4417void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
4418{
4419 int rc;
4420
4421 spin_lock_irq(&phba->hbalock);
4422 /* Clear FCF rediscovery timeout event */
4423 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
4424 /* Clear driver fast failover FCF record flag */
4425 phba->fcf.failover_rec.flag = 0;
4426 /* Set state for FCF fast failover */
4427 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
4428 spin_unlock_irq(&phba->hbalock);
4429
4430 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05004431 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004432 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05004433 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05004434 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004435 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4436 "2747 Issue FCF scan read FCF mailbox "
4437 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05004438}
4439
4440/**
James Smartda0436e2009-05-22 14:51:39 -04004441 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
4442 * @phba: pointer to lpfc hba data structure.
4443 * @dev_grp: The HBA PCI-Device group number.
4444 *
4445 * This routine is invoked to set up the per HBA PCI-Device group function
4446 * API jump table entries.
4447 *
4448 * Return: 0 if success, otherwise -ENODEV
4449 **/
4450int
4451lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05004452{
4453 int rc;
4454
James Smartda0436e2009-05-22 14:51:39 -04004455 /* Set up lpfc PCI-device group */
4456 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05004457
James Smartda0436e2009-05-22 14:51:39 -04004458 /* The LPFC_PCI_DEV_OC uses SLI4 */
4459 if (dev_grp == LPFC_PCI_DEV_OC)
4460 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05004461
James Smartda0436e2009-05-22 14:51:39 -04004462 /* Set up device INIT API function jump table */
4463 rc = lpfc_init_api_table_setup(phba, dev_grp);
4464 if (rc)
4465 return -ENODEV;
4466 /* Set up SCSI API function jump table */
4467 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
4468 if (rc)
4469 return -ENODEV;
4470 /* Set up SLI API function jump table */
4471 rc = lpfc_sli_api_table_setup(phba, dev_grp);
4472 if (rc)
4473 return -ENODEV;
4474 /* Set up MBOX API function jump table */
4475 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
4476 if (rc)
4477 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05004478
James Smartda0436e2009-05-22 14:51:39 -04004479 return 0;
James Smart5b75da22008-12-04 22:39:35 -05004480}
4481
4482/**
James Smart3621a712009-04-06 18:47:14 -04004483 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05004484 * @phba: pointer to lpfc hba data structure.
4485 * @intr_mode: active interrupt mode adopted.
4486 *
4487 * This routine it invoked to log the currently used active interrupt mode
4488 * to the device.
James Smart3772a992009-05-22 14:50:54 -04004489 **/
4490static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05004491{
4492 switch (intr_mode) {
4493 case 0:
4494 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4495 "0470 Enable INTx interrupt mode.\n");
4496 break;
4497 case 1:
4498 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4499 "0481 Enabled MSI interrupt mode.\n");
4500 break;
4501 case 2:
4502 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4503 "0480 Enabled MSI-X interrupt mode.\n");
4504 break;
4505 default:
4506 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4507 "0482 Illegal interrupt mode.\n");
4508 break;
4509 }
4510 return;
4511}
4512
James Smart5b75da22008-12-04 22:39:35 -05004513/**
James Smart3772a992009-05-22 14:50:54 -04004514 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05004515 * @phba: pointer to lpfc hba data structure.
4516 *
James Smart3772a992009-05-22 14:50:54 -04004517 * This routine is invoked to enable the PCI device that is common to all
4518 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05004519 *
4520 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004521 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004522 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05004523 **/
James Smart3772a992009-05-22 14:50:54 -04004524static int
4525lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05004526{
James Smart3772a992009-05-22 14:50:54 -04004527 struct pci_dev *pdev;
James Smart079b5c92011-08-21 21:48:49 -04004528 int bars = 0;
James Smart5b75da22008-12-04 22:39:35 -05004529
James Smart3772a992009-05-22 14:50:54 -04004530 /* Obtain PCI device reference */
4531 if (!phba->pcidev)
4532 goto out_error;
4533 else
4534 pdev = phba->pcidev;
4535 /* Select PCI BARs */
4536 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4537 /* Enable PCI device */
4538 if (pci_enable_device_mem(pdev))
4539 goto out_error;
4540 /* Request PCI resource for the device */
4541 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
4542 goto out_disable_device;
4543 /* Set up device as PCI master and save state for EEH */
4544 pci_set_master(pdev);
4545 pci_try_set_mwi(pdev);
4546 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05004547
James Smart05580562011-05-24 11:40:48 -04004548 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
Jon Mason453193e2013-09-11 15:38:13 -07004549 if (pci_is_pcie(pdev))
James Smart05580562011-05-24 11:40:48 -04004550 pdev->needs_freset = 1;
4551
James Smart3772a992009-05-22 14:50:54 -04004552 return 0;
James Smart5b75da22008-12-04 22:39:35 -05004553
James Smart3772a992009-05-22 14:50:54 -04004554out_disable_device:
4555 pci_disable_device(pdev);
4556out_error:
James Smart079b5c92011-08-21 21:48:49 -04004557 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4558 "1401 Failed to enable pci device, bars:x%x\n", bars);
James Smart3772a992009-05-22 14:50:54 -04004559 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05004560}
4561
4562/**
James Smart3772a992009-05-22 14:50:54 -04004563 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05004564 * @phba: pointer to lpfc hba data structure.
4565 *
James Smart3772a992009-05-22 14:50:54 -04004566 * This routine is invoked to disable the PCI device that is common to all
4567 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05004568 **/
4569static void
James Smart3772a992009-05-22 14:50:54 -04004570lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05004571{
James Smart3772a992009-05-22 14:50:54 -04004572 struct pci_dev *pdev;
4573 int bars;
James Smart5b75da22008-12-04 22:39:35 -05004574
James Smart3772a992009-05-22 14:50:54 -04004575 /* Obtain PCI device reference */
4576 if (!phba->pcidev)
4577 return;
4578 else
4579 pdev = phba->pcidev;
4580 /* Select PCI BARs */
4581 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4582 /* Release PCI resource and disable PCI device */
4583 pci_release_selected_regions(pdev, bars);
4584 pci_disable_device(pdev);
James Smart5b75da22008-12-04 22:39:35 -05004585
4586 return;
4587}
4588
4589/**
James Smart3772a992009-05-22 14:50:54 -04004590 * lpfc_reset_hba - Reset a hba
4591 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04004592 *
James Smart3772a992009-05-22 14:50:54 -04004593 * This routine is invoked to reset a hba device. It brings the HBA
4594 * offline, performs a board restart, and then brings the board back
4595 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
4596 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04004597 **/
James Smart3772a992009-05-22 14:50:54 -04004598void
4599lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05004600{
James Smart3772a992009-05-22 14:50:54 -04004601 /* If resets are disabled then set error state and return. */
4602 if (!phba->cfg_enable_hba_reset) {
4603 phba->link_state = LPFC_HBA_ERROR;
4604 return;
4605 }
James Smart618a5232012-06-12 13:54:36 -04004606 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3772a992009-05-22 14:50:54 -04004607 lpfc_offline(phba);
4608 lpfc_sli_brdrestart(phba);
4609 lpfc_online(phba);
4610 lpfc_unblock_mgmt_io(phba);
4611}
dea31012005-04-17 16:05:31 -05004612
James Smart3772a992009-05-22 14:50:54 -04004613/**
James Smart0a96e972011-07-22 18:37:28 -04004614 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
4615 * @phba: pointer to lpfc hba data structure.
4616 *
4617 * This function enables the PCI SR-IOV virtual functions to a physical
4618 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4619 * enable the number of virtual functions to the physical function. As
4620 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4621 * API call does not considered as an error condition for most of the device.
4622 **/
4623uint16_t
4624lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
4625{
4626 struct pci_dev *pdev = phba->pcidev;
4627 uint16_t nr_virtfn;
4628 int pos;
4629
James Smart0a96e972011-07-22 18:37:28 -04004630 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4631 if (pos == 0)
4632 return 0;
4633
4634 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
4635 return nr_virtfn;
4636}
4637
4638/**
James Smart912e3ac2011-05-24 11:42:11 -04004639 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
4640 * @phba: pointer to lpfc hba data structure.
4641 * @nr_vfn: number of virtual functions to be enabled.
4642 *
4643 * This function enables the PCI SR-IOV virtual functions to a physical
4644 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4645 * enable the number of virtual functions to the physical function. As
4646 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4647 * API call does not considered as an error condition for most of the device.
4648 **/
4649int
4650lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
4651{
4652 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04004653 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04004654 int rc;
4655
James Smart0a96e972011-07-22 18:37:28 -04004656 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
4657 if (nr_vfn > max_nr_vfn) {
4658 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4659 "3057 Requested vfs (%d) greater than "
4660 "supported vfs (%d)", nr_vfn, max_nr_vfn);
4661 return -EINVAL;
4662 }
4663
James Smart912e3ac2011-05-24 11:42:11 -04004664 rc = pci_enable_sriov(pdev, nr_vfn);
4665 if (rc) {
4666 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4667 "2806 Failed to enable sriov on this device "
4668 "with vfn number nr_vf:%d, rc:%d\n",
4669 nr_vfn, rc);
4670 } else
4671 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4672 "2807 Successful enable sriov on this device "
4673 "with vfn number nr_vf:%d\n", nr_vfn);
4674 return rc;
4675}
4676
4677/**
James Smart3772a992009-05-22 14:50:54 -04004678 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
4679 * @phba: pointer to lpfc hba data structure.
4680 *
4681 * This routine is invoked to set up the driver internal resources specific to
4682 * support the SLI-3 HBA device it attached to.
4683 *
4684 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004685 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004686 * other values - error
4687 **/
4688static int
4689lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
4690{
4691 struct lpfc_sli *psli;
James Smart912e3ac2011-05-24 11:42:11 -04004692 int rc;
dea31012005-04-17 16:05:31 -05004693
James Smart3772a992009-05-22 14:50:54 -04004694 /*
4695 * Initialize timers used by driver
4696 */
dea31012005-04-17 16:05:31 -05004697
James Smart3772a992009-05-22 14:50:54 -04004698 /* Heartbeat timer */
4699 init_timer(&phba->hb_tmofunc);
4700 phba->hb_tmofunc.function = lpfc_hb_timeout;
4701 phba->hb_tmofunc.data = (unsigned long)phba;
4702
4703 psli = &phba->sli;
4704 /* MBOX heartbeat timer */
4705 init_timer(&psli->mbox_tmo);
4706 psli->mbox_tmo.function = lpfc_mbox_timeout;
4707 psli->mbox_tmo.data = (unsigned long) phba;
4708 /* FCP polling mode timer */
4709 init_timer(&phba->fcp_poll_timer);
4710 phba->fcp_poll_timer.function = lpfc_poll_timeout;
4711 phba->fcp_poll_timer.data = (unsigned long) phba;
4712 /* Fabric block timer */
4713 init_timer(&phba->fabric_block_timer);
4714 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
4715 phba->fabric_block_timer.data = (unsigned long) phba;
4716 /* EA polling mode timer */
4717 init_timer(&phba->eratt_poll);
4718 phba->eratt_poll.function = lpfc_poll_eratt;
4719 phba->eratt_poll.data = (unsigned long) phba;
4720
4721 /* Host attention work mask setup */
4722 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
4723 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
4724
4725 /* Get all the module params for configuring this host */
4726 lpfc_get_cfgparam(phba);
James Smart49198b32010-04-06 15:04:33 -04004727 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
4728 phba->menlo_flag |= HBA_MENLO_SUPPORT;
4729 /* check for menlo minimum sg count */
4730 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
4731 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
4732 }
4733
James Smart2a76a282012-08-03 12:35:54 -04004734 if (!phba->sli.ring)
4735 phba->sli.ring = (struct lpfc_sli_ring *)
4736 kzalloc(LPFC_SLI3_MAX_RING *
4737 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
4738 if (!phba->sli.ring)
4739 return -ENOMEM;
4740
James Smart3772a992009-05-22 14:50:54 -04004741 /*
James Smart96f70772013-04-17 20:16:15 -04004742 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smart3772a992009-05-22 14:50:54 -04004743 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart3772a992009-05-22 14:50:54 -04004744 */
James Smart3772a992009-05-22 14:50:54 -04004745
James Smart96f70772013-04-17 20:16:15 -04004746 /* Initialize the host templates the configured values. */
James Smart3772a992009-05-22 14:50:54 -04004747 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4748 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4749
James Smart96f70772013-04-17 20:16:15 -04004750 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
4751 if (phba->cfg_enable_bg) {
4752 /*
4753 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
4754 * the FCP rsp, and a BDE for each. Sice we have no control
4755 * over how many protection data segments the SCSI Layer
4756 * will hand us (ie: there could be one for every block
4757 * in the IO), we just allocate enough BDEs to accomidate
4758 * our max amount and we need to limit lpfc_sg_seg_cnt to
4759 * minimize the risk of running out.
4760 */
4761 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
4762 sizeof(struct fcp_rsp) +
4763 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
4764
4765 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
4766 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
4767
4768 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
4769 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
4770 } else {
4771 /*
4772 * The scsi_buf for a regular I/O will hold the FCP cmnd,
4773 * the FCP rsp, a BDE for each, and a BDE for up to
4774 * cfg_sg_seg_cnt data segments.
4775 */
4776 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
4777 sizeof(struct fcp_rsp) +
4778 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
4779
4780 /* Total BDEs in BPL for scsi_sg_list */
4781 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
4782 }
4783
4784 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
4785 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
4786 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
4787 phba->cfg_total_seg_cnt);
4788
James Smart3772a992009-05-22 14:50:54 -04004789 phba->max_vpi = LPFC_MAX_VPI;
4790 /* This will be set to correct value after config_port mbox */
4791 phba->max_vports = 0;
4792
4793 /*
4794 * Initialize the SLI Layer to run with lpfc HBAs.
4795 */
4796 lpfc_sli_setup(phba);
4797 lpfc_sli_queue_setup(phba);
4798
4799 /* Allocate device driver memory */
4800 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
4801 return -ENOMEM;
4802
James Smart912e3ac2011-05-24 11:42:11 -04004803 /*
4804 * Enable sr-iov virtual functions if supported and configured
4805 * through the module parameter.
4806 */
4807 if (phba->cfg_sriov_nr_virtfn > 0) {
4808 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
4809 phba->cfg_sriov_nr_virtfn);
4810 if (rc) {
4811 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4812 "2808 Requested number of SR-IOV "
4813 "virtual functions (%d) is not "
4814 "supported\n",
4815 phba->cfg_sriov_nr_virtfn);
4816 phba->cfg_sriov_nr_virtfn = 0;
4817 }
4818 }
4819
James Smart3772a992009-05-22 14:50:54 -04004820 return 0;
4821}
4822
4823/**
4824 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
4825 * @phba: pointer to lpfc hba data structure.
4826 *
4827 * This routine is invoked to unset the driver internal resources set up
4828 * specific for supporting the SLI-3 HBA device it attached to.
4829 **/
4830static void
4831lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
4832{
4833 /* Free device driver memory allocated */
4834 lpfc_mem_free_all(phba);
4835
4836 return;
4837}
4838
4839/**
James Smartda0436e2009-05-22 14:51:39 -04004840 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
4841 * @phba: pointer to lpfc hba data structure.
4842 *
4843 * This routine is invoked to set up the driver internal resources specific to
4844 * support the SLI-4 HBA device it attached to.
4845 *
4846 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004847 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04004848 * other values - error
4849 **/
4850static int
4851lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
4852{
James Smart7bb03bb2013-04-17 20:19:16 -04004853 struct lpfc_vector_map_info *cpup;
James Smartda0436e2009-05-22 14:51:39 -04004854 struct lpfc_sli *psli;
James Smart28baac72010-02-12 14:42:03 -05004855 LPFC_MBOXQ_t *mboxq;
James Smart96f70772013-04-17 20:16:15 -04004856 int rc, i, hbq_count, max_buf_size;
James Smart28baac72010-02-12 14:42:03 -05004857 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
4858 struct lpfc_mqe *mqe;
James Smart09294d42013-04-17 20:16:05 -04004859 int longs;
James Smart1ba981f2014-02-20 09:56:45 -05004860 int fof_vectors = 0;
James Smartda0436e2009-05-22 14:51:39 -04004861
James Smart716d3bc2013-09-06 12:18:28 -04004862 /* Get all the module params for configuring this host */
4863 lpfc_get_cfgparam(phba);
4864
James Smartda0436e2009-05-22 14:51:39 -04004865 /* Before proceed, wait for POST done and device ready */
4866 rc = lpfc_sli4_post_status_check(phba);
4867 if (rc)
4868 return -ENODEV;
4869
4870 /*
4871 * Initialize timers used by driver
4872 */
4873
4874 /* Heartbeat timer */
4875 init_timer(&phba->hb_tmofunc);
4876 phba->hb_tmofunc.function = lpfc_hb_timeout;
4877 phba->hb_tmofunc.data = (unsigned long)phba;
James Smart19ca7602010-11-20 23:11:55 -05004878 init_timer(&phba->rrq_tmr);
4879 phba->rrq_tmr.function = lpfc_rrq_timeout;
4880 phba->rrq_tmr.data = (unsigned long)phba;
James Smartda0436e2009-05-22 14:51:39 -04004881
4882 psli = &phba->sli;
4883 /* MBOX heartbeat timer */
4884 init_timer(&psli->mbox_tmo);
4885 psli->mbox_tmo.function = lpfc_mbox_timeout;
4886 psli->mbox_tmo.data = (unsigned long) phba;
4887 /* Fabric block timer */
4888 init_timer(&phba->fabric_block_timer);
4889 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
4890 phba->fabric_block_timer.data = (unsigned long) phba;
4891 /* EA polling mode timer */
4892 init_timer(&phba->eratt_poll);
4893 phba->eratt_poll.function = lpfc_poll_eratt;
4894 phba->eratt_poll.data = (unsigned long) phba;
James Smartecfd03c2010-02-12 14:41:27 -05004895 /* FCF rediscover timer */
4896 init_timer(&phba->fcf.redisc_wait);
4897 phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
4898 phba->fcf.redisc_wait.data = (unsigned long)phba;
4899
James Smartda0436e2009-05-22 14:51:39 -04004900 /*
James Smart7ad20aa2011-05-24 11:44:28 -04004901 * Control structure for handling external multi-buffer mailbox
4902 * command pass-through.
4903 */
4904 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
4905 sizeof(struct lpfc_mbox_ext_buf_ctx));
4906 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
4907
James Smartda0436e2009-05-22 14:51:39 -04004908 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04004909
James Smartda0436e2009-05-22 14:51:39 -04004910 /* This will be set to correct value after the read_config mbox */
4911 phba->max_vports = 0;
4912
4913 /* Program the default value of vlan_id and fc_map */
4914 phba->valid_vlan = 0;
4915 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
4916 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
4917 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
4918
4919 /*
James Smart2a76a282012-08-03 12:35:54 -04004920 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
4921 * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple.
4922 */
4923 if (!phba->sli.ring)
4924 phba->sli.ring = kzalloc(
James Smart67d12732012-08-03 12:36:13 -04004925 (LPFC_SLI3_MAX_RING + phba->cfg_fcp_io_channel) *
James Smart2a76a282012-08-03 12:35:54 -04004926 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
4927 if (!phba->sli.ring)
4928 return -ENOMEM;
James Smart085c6472010-11-20 23:11:37 -05004929
James Smart09294d42013-04-17 20:16:05 -04004930 /*
4931 * It doesn't matter what family our adapter is in, we are
4932 * limited to 2 Pages, 512 SGEs, for our SGL.
4933 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
4934 */
4935 max_buf_size = (2 * SLI4_PAGE_SIZE);
4936 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2)
4937 phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2;
James Smart09294d42013-04-17 20:16:05 -04004938
James Smartda0436e2009-05-22 14:51:39 -04004939 /*
James Smart96f70772013-04-17 20:16:15 -04004940 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smartda0436e2009-05-22 14:51:39 -04004941 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart28baac72010-02-12 14:42:03 -05004942 */
James Smart085c6472010-11-20 23:11:37 -05004943
James Smart96f70772013-04-17 20:16:15 -04004944 if (phba->cfg_enable_bg) {
4945 /*
4946 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
4947 * the FCP rsp, and a SGE for each. Sice we have no control
4948 * over how many protection data segments the SCSI Layer
4949 * will hand us (ie: there could be one for every block
4950 * in the IO), we just allocate enough SGEs to accomidate
4951 * our max amount and we need to limit lpfc_sg_seg_cnt to
4952 * minimize the risk of running out.
4953 */
4954 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
4955 sizeof(struct fcp_rsp) + max_buf_size;
4956
4957 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
4958 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
4959
4960 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
4961 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
4962 } else {
4963 /*
4964 * The scsi_buf for a regular I/O will hold the FCP cmnd,
4965 * the FCP rsp, a SGE for each, and a SGE for up to
4966 * cfg_sg_seg_cnt data segments.
4967 */
4968 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
4969 sizeof(struct fcp_rsp) +
4970 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge));
4971
4972 /* Total SGEs for scsi_sg_list */
4973 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
4974 /*
4975 * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only need
4976 * to post 1 page for the SGL.
4977 */
James Smart085c6472010-11-20 23:11:37 -05004978 }
James Smartacd68592012-01-18 16:25:09 -05004979
James Smart96f70772013-04-17 20:16:15 -04004980 /* Initialize the host templates with the updated values. */
4981 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4982 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4983
4984 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
4985 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
4986 else
4987 phba->cfg_sg_dma_buf_size =
4988 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
4989
4990 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
4991 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
4992 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
4993 phba->cfg_total_seg_cnt);
James Smartda0436e2009-05-22 14:51:39 -04004994
4995 /* Initialize buffer queue management fields */
4996 hbq_count = lpfc_sli_hbq_count();
4997 for (i = 0; i < hbq_count; ++i)
4998 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
4999 INIT_LIST_HEAD(&phba->rb_pend_list);
5000 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
5001 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
5002
5003 /*
5004 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
5005 */
5006 /* Initialize the Abort scsi buffer list used by driver */
5007 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
5008 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
5009 /* This abort list used by worker thread */
5010 spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
5011
5012 /*
James Smart6d368e52011-05-24 11:44:12 -04005013 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04005014 */
5015
5016 /* Driver internel slow-path CQ Event pool */
5017 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
5018 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04005019 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04005020 /* Asynchronous event CQ Event work queue list */
5021 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
5022 /* Fast-path XRI aborted CQ Event work queue list */
5023 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
5024 /* Slow-path XRI aborted CQ Event work queue list */
5025 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
5026 /* Receive queue CQ Event work queue list */
5027 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
5028
James Smart6d368e52011-05-24 11:44:12 -04005029 /* Initialize extent block lists. */
5030 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
5031 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
5032 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
5033 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
5034
James Smartda0436e2009-05-22 14:51:39 -04005035 /* Initialize the driver internal SLI layer lists. */
5036 lpfc_sli_setup(phba);
5037 lpfc_sli_queue_setup(phba);
5038
5039 /* Allocate device driver memory */
5040 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
5041 if (rc)
5042 return -ENOMEM;
5043
James Smart2fcee4b2010-12-15 17:57:46 -05005044 /* IF Type 2 ports get initialized now. */
5045 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5046 LPFC_SLI_INTF_IF_TYPE_2) {
5047 rc = lpfc_pci_function_reset(phba);
5048 if (unlikely(rc))
5049 return -ENODEV;
5050 }
5051
James Smartda0436e2009-05-22 14:51:39 -04005052 /* Create the bootstrap mailbox command */
5053 rc = lpfc_create_bootstrap_mbox(phba);
5054 if (unlikely(rc))
5055 goto out_free_mem;
5056
5057 /* Set up the host's endian order with the device. */
5058 rc = lpfc_setup_endian_order(phba);
5059 if (unlikely(rc))
5060 goto out_free_bsmbx;
5061
5062 /* Set up the hba's configuration parameters. */
5063 rc = lpfc_sli4_read_config(phba);
5064 if (unlikely(rc))
5065 goto out_free_bsmbx;
James Smartcff261f2013-12-17 20:29:47 -05005066 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
5067 if (unlikely(rc))
5068 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005069
James Smart2fcee4b2010-12-15 17:57:46 -05005070 /* IF Type 0 ports get initialized now. */
5071 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5072 LPFC_SLI_INTF_IF_TYPE_0) {
5073 rc = lpfc_pci_function_reset(phba);
5074 if (unlikely(rc))
5075 goto out_free_bsmbx;
5076 }
James Smartda0436e2009-05-22 14:51:39 -04005077
James Smartcb5172e2010-03-15 11:25:07 -04005078 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
5079 GFP_KERNEL);
5080 if (!mboxq) {
5081 rc = -ENOMEM;
5082 goto out_free_bsmbx;
5083 }
5084
James Smartfedd3b72011-02-16 12:39:24 -05005085 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04005086 lpfc_supported_pages(mboxq);
5087 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05005088 if (!rc) {
5089 mqe = &mboxq->u.mqe;
5090 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
5091 LPFC_MAX_SUPPORTED_PAGES);
5092 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
5093 switch (pn_page[i]) {
5094 case LPFC_SLI4_PARAMETERS:
5095 phba->sli4_hba.pc_sli4_params.supported = 1;
5096 break;
5097 default:
5098 break;
5099 }
5100 }
5101 /* Read the port's SLI4 Parameters capabilities if supported. */
5102 if (phba->sli4_hba.pc_sli4_params.supported)
5103 rc = lpfc_pc_sli4_params_get(phba, mboxq);
5104 if (rc) {
5105 mempool_free(mboxq, phba->mbox_mem_pool);
5106 rc = -EIO;
5107 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04005108 }
5109 }
James Smartfedd3b72011-02-16 12:39:24 -05005110 /*
5111 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04005112 * If this call fails, it isn't critical unless the SLI4 parameters come
5113 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05005114 */
James Smart6d368e52011-05-24 11:44:12 -04005115 rc = lpfc_get_sli4_parameters(phba, mboxq);
5116 if (rc) {
5117 if (phba->sli4_hba.extents_in_use &&
5118 phba->sli4_hba.rpi_hdrs_in_use) {
5119 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5120 "2999 Unsupported SLI4 Parameters "
5121 "Extents and RPI headers enabled.\n");
5122 goto out_free_bsmbx;
5123 }
5124 }
James Smartcb5172e2010-03-15 11:25:07 -04005125 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -05005126
5127 /* Verify OAS is supported */
5128 lpfc_sli4_oas_verify(phba);
5129 if (phba->cfg_fof)
5130 fof_vectors = 1;
5131
James Smart5350d872011-10-10 21:33:49 -04005132 /* Verify all the SLI4 queues */
5133 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04005134 if (rc)
5135 goto out_free_bsmbx;
5136
5137 /* Create driver internal CQE event pool */
5138 rc = lpfc_sli4_cq_event_pool_create(phba);
5139 if (rc)
James Smart5350d872011-10-10 21:33:49 -04005140 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005141
James Smart8a9d2e82012-05-09 21:16:12 -04005142 /* Initialize sgl lists per host */
5143 lpfc_init_sgl_list(phba);
5144
5145 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04005146 rc = lpfc_init_active_sgl_array(phba);
5147 if (rc) {
5148 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5149 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04005150 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04005151 }
James Smartda0436e2009-05-22 14:51:39 -04005152 rc = lpfc_sli4_init_rpi_hdrs(phba);
5153 if (rc) {
5154 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5155 "1432 Failed to initialize rpi headers.\n");
5156 goto out_free_active_sgl;
5157 }
5158
James Smarta93ff372010-10-22 11:06:08 -04005159 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05005160 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
5161 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
5162 GFP_KERNEL);
5163 if (!phba->fcf.fcf_rr_bmask) {
5164 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5165 "2759 Failed allocate memory for FCF round "
5166 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04005167 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05005168 goto out_remove_rpi_hdrs;
5169 }
5170
James Smart67d12732012-08-03 12:36:13 -04005171 phba->sli4_hba.fcp_eq_hdl =
5172 kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
James Smart1ba981f2014-02-20 09:56:45 -05005173 (fof_vectors + phba->cfg_fcp_io_channel)),
5174 GFP_KERNEL);
James Smart67d12732012-08-03 12:36:13 -04005175 if (!phba->sli4_hba.fcp_eq_hdl) {
5176 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5177 "2572 Failed allocate memory for "
5178 "fast-path per-EQ handle array\n");
5179 rc = -ENOMEM;
5180 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04005181 }
5182
5183 phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
James Smart1ba981f2014-02-20 09:56:45 -05005184 (fof_vectors +
5185 phba->cfg_fcp_io_channel)), GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04005186 if (!phba->sli4_hba.msix_entries) {
5187 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5188 "2573 Failed allocate memory for msi-x "
5189 "interrupt vector entries\n");
James Smart05580562011-05-24 11:40:48 -04005190 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04005191 goto out_free_fcp_eq_hdl;
5192 }
5193
James Smart7bb03bb2013-04-17 20:19:16 -04005194 phba->sli4_hba.cpu_map = kzalloc((sizeof(struct lpfc_vector_map_info) *
5195 phba->sli4_hba.num_present_cpu),
5196 GFP_KERNEL);
5197 if (!phba->sli4_hba.cpu_map) {
5198 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5199 "3327 Failed allocate memory for msi-x "
5200 "interrupt vector mapping\n");
5201 rc = -ENOMEM;
5202 goto out_free_msix;
5203 }
James Smartb246de12013-05-31 17:03:07 -04005204 if (lpfc_used_cpu == NULL) {
5205 lpfc_used_cpu = kzalloc((sizeof(uint16_t) * lpfc_present_cpu),
5206 GFP_KERNEL);
5207 if (!lpfc_used_cpu) {
5208 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5209 "3335 Failed allocate memory for msi-x "
5210 "interrupt vector mapping\n");
5211 kfree(phba->sli4_hba.cpu_map);
5212 rc = -ENOMEM;
5213 goto out_free_msix;
5214 }
5215 for (i = 0; i < lpfc_present_cpu; i++)
5216 lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
5217 }
5218
James Smart7bb03bb2013-04-17 20:19:16 -04005219 /* Initialize io channels for round robin */
5220 cpup = phba->sli4_hba.cpu_map;
5221 rc = 0;
5222 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
5223 cpup->channel_id = rc;
5224 rc++;
5225 if (rc >= phba->cfg_fcp_io_channel)
5226 rc = 0;
5227 }
5228
James Smart912e3ac2011-05-24 11:42:11 -04005229 /*
5230 * Enable sr-iov virtual functions if supported and configured
5231 * through the module parameter.
5232 */
5233 if (phba->cfg_sriov_nr_virtfn > 0) {
5234 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5235 phba->cfg_sriov_nr_virtfn);
5236 if (rc) {
5237 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5238 "3020 Requested number of SR-IOV "
5239 "virtual functions (%d) is not "
5240 "supported\n",
5241 phba->cfg_sriov_nr_virtfn);
5242 phba->cfg_sriov_nr_virtfn = 0;
5243 }
5244 }
5245
James Smart5248a742011-07-22 18:37:06 -04005246 return 0;
James Smartda0436e2009-05-22 14:51:39 -04005247
James Smart7bb03bb2013-04-17 20:19:16 -04005248out_free_msix:
5249 kfree(phba->sli4_hba.msix_entries);
James Smartda0436e2009-05-22 14:51:39 -04005250out_free_fcp_eq_hdl:
5251 kfree(phba->sli4_hba.fcp_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05005252out_free_fcf_rr_bmask:
5253 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04005254out_remove_rpi_hdrs:
5255 lpfc_sli4_remove_rpi_hdrs(phba);
5256out_free_active_sgl:
5257 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04005258out_destroy_cq_event_pool:
5259 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04005260out_free_bsmbx:
5261 lpfc_destroy_bootstrap_mbox(phba);
5262out_free_mem:
5263 lpfc_mem_free(phba);
5264 return rc;
5265}
5266
5267/**
5268 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
5269 * @phba: pointer to lpfc hba data structure.
5270 *
5271 * This routine is invoked to unset the driver internal resources set up
5272 * specific for supporting the SLI-4 HBA device it attached to.
5273 **/
5274static void
5275lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
5276{
5277 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
5278
James Smart7bb03bb2013-04-17 20:19:16 -04005279 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
5280 kfree(phba->sli4_hba.cpu_map);
5281 phba->sli4_hba.num_present_cpu = 0;
5282 phba->sli4_hba.num_online_cpu = 0;
James Smart76fd07a2014-02-20 09:57:18 -05005283 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04005284
James Smartda0436e2009-05-22 14:51:39 -04005285 /* Free memory allocated for msi-x interrupt vector entries */
5286 kfree(phba->sli4_hba.msix_entries);
5287
5288 /* Free memory allocated for fast-path work queue handles */
5289 kfree(phba->sli4_hba.fcp_eq_hdl);
5290
5291 /* Free the allocated rpi headers. */
5292 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04005293 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04005294
James Smart0c9ab6f2010-02-26 14:15:57 -05005295 /* Free eligible FCF index bmask */
5296 kfree(phba->fcf.fcf_rr_bmask);
5297
James Smartda0436e2009-05-22 14:51:39 -04005298 /* Free the ELS sgl list */
5299 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04005300 lpfc_free_els_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04005301
James Smartda0436e2009-05-22 14:51:39 -04005302 /* Free the completion queue EQ event pool */
5303 lpfc_sli4_cq_event_release_all(phba);
5304 lpfc_sli4_cq_event_pool_destroy(phba);
5305
James Smart6d368e52011-05-24 11:44:12 -04005306 /* Release resource identifiers. */
5307 lpfc_sli4_dealloc_resource_identifiers(phba);
5308
James Smartda0436e2009-05-22 14:51:39 -04005309 /* Free the bsmbx region. */
5310 lpfc_destroy_bootstrap_mbox(phba);
5311
5312 /* Free the SLI Layer memory with SLI4 HBAs */
5313 lpfc_mem_free_all(phba);
5314
5315 /* Free the current connect table */
5316 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04005317 &phba->fcf_conn_rec_list, list) {
5318 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04005319 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04005320 }
James Smartda0436e2009-05-22 14:51:39 -04005321
5322 return;
5323}
5324
5325/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005326 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04005327 * @phba: The hba struct for which this call is being executed.
5328 * @dev_grp: The HBA PCI-Device group number.
5329 *
5330 * This routine sets up the device INIT interface API function jump table
5331 * in @phba struct.
5332 *
5333 * Returns: 0 - success, -ENODEV - failure.
5334 **/
5335int
5336lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5337{
James Smart84d1b002010-02-12 14:42:33 -05005338 phba->lpfc_hba_init_link = lpfc_hba_init_link;
5339 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05005340 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04005341 switch (dev_grp) {
5342 case LPFC_PCI_DEV_LP:
5343 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
5344 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
5345 phba->lpfc_stop_port = lpfc_stop_port_s3;
5346 break;
James Smartda0436e2009-05-22 14:51:39 -04005347 case LPFC_PCI_DEV_OC:
5348 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
5349 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
5350 phba->lpfc_stop_port = lpfc_stop_port_s4;
5351 break;
James Smart3772a992009-05-22 14:50:54 -04005352 default:
5353 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5354 "1431 Invalid HBA PCI-device group: 0x%x\n",
5355 dev_grp);
5356 return -ENODEV;
5357 break;
5358 }
5359 return 0;
5360}
5361
5362/**
5363 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
5364 * @phba: pointer to lpfc hba data structure.
5365 *
5366 * This routine is invoked to set up the driver internal resources before the
5367 * device specific resource setup to support the HBA device it attached to.
5368 *
5369 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005370 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005371 * other values - error
5372 **/
5373static int
5374lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
5375{
5376 /*
5377 * Driver resources common to all SLI revisions
5378 */
James Smartea2151b2008-09-07 11:52:10 -04005379 atomic_set(&phba->fast_event_count, 0);
James Smart2e0fef82007-06-17 19:56:36 -05005380 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005381
James Smarte47c9092008-02-08 18:49:26 -05005382 /* Initialize ndlp management spinlock */
5383 spin_lock_init(&phba->ndlp_lock);
5384
James Smart2e0fef82007-06-17 19:56:36 -05005385 INIT_LIST_HEAD(&phba->port_list);
James Smart3772a992009-05-22 14:50:54 -04005386 INIT_LIST_HEAD(&phba->work_list);
James Smart84774a42008-08-24 21:50:06 -04005387 init_waitqueue_head(&phba->wait_4_mlo_m_q);
dea31012005-04-17 16:05:31 -05005388
James Smart3772a992009-05-22 14:50:54 -04005389 /* Initialize the wait queue head for the kernel thread */
5390 init_waitqueue_head(&phba->work_waitq);
James Smart858c9f62007-06-17 19:56:39 -05005391
James Smart3772a992009-05-22 14:50:54 -04005392 /* Initialize the scsi buffer list used by driver for scsi IO */
James Smarta40fc5f2013-04-17 20:17:40 -04005393 spin_lock_init(&phba->scsi_buf_list_get_lock);
5394 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5395 spin_lock_init(&phba->scsi_buf_list_put_lock);
5396 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
dea31012005-04-17 16:05:31 -05005397
James Smart3772a992009-05-22 14:50:54 -04005398 /* Initialize the fabric iocb list */
5399 INIT_LIST_HEAD(&phba->fabric_iocb_list);
dea31012005-04-17 16:05:31 -05005400
James Smart3772a992009-05-22 14:50:54 -04005401 /* Initialize list to save ELS buffers */
5402 INIT_LIST_HEAD(&phba->elsbuf);
dea31012005-04-17 16:05:31 -05005403
James Smart3772a992009-05-22 14:50:54 -04005404 /* Initialize FCF connection rec list */
5405 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
dea31012005-04-17 16:05:31 -05005406
James Smart1ba981f2014-02-20 09:56:45 -05005407 /* Initialize OAS configuration list */
5408 spin_lock_init(&phba->devicelock);
5409 INIT_LIST_HEAD(&phba->luns);
5410
James Smart3772a992009-05-22 14:50:54 -04005411 return 0;
5412}
dea31012005-04-17 16:05:31 -05005413
James Smart3772a992009-05-22 14:50:54 -04005414/**
5415 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
5416 * @phba: pointer to lpfc hba data structure.
5417 *
5418 * This routine is invoked to set up the driver internal resources after the
5419 * device specific resource setup to support the HBA device it attached to.
5420 *
5421 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005422 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005423 * other values - error
5424 **/
5425static int
5426lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
5427{
5428 int error;
5429
5430 /* Startup the kernel thread for this host adapter. */
5431 phba->worker_thread = kthread_run(lpfc_do_work, phba,
5432 "lpfc_worker_%d", phba->brd_no);
5433 if (IS_ERR(phba->worker_thread)) {
5434 error = PTR_ERR(phba->worker_thread);
5435 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005436 }
5437
James Smart3772a992009-05-22 14:50:54 -04005438 return 0;
5439}
5440
5441/**
5442 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
5443 * @phba: pointer to lpfc hba data structure.
5444 *
5445 * This routine is invoked to unset the driver internal resources set up after
5446 * the device specific resource setup for supporting the HBA device it
5447 * attached to.
5448 **/
5449static void
5450lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
5451{
5452 /* Stop kernel worker thread */
5453 kthread_stop(phba->worker_thread);
5454}
5455
5456/**
5457 * lpfc_free_iocb_list - Free iocb list.
5458 * @phba: pointer to lpfc hba data structure.
5459 *
5460 * This routine is invoked to free the driver's IOCB list and memory.
5461 **/
5462static void
5463lpfc_free_iocb_list(struct lpfc_hba *phba)
5464{
5465 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
5466
5467 spin_lock_irq(&phba->hbalock);
5468 list_for_each_entry_safe(iocbq_entry, iocbq_next,
5469 &phba->lpfc_iocb_list, list) {
5470 list_del(&iocbq_entry->list);
5471 kfree(iocbq_entry);
5472 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005473 }
James Smart3772a992009-05-22 14:50:54 -04005474 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005475
James Smart3772a992009-05-22 14:50:54 -04005476 return;
5477}
dea31012005-04-17 16:05:31 -05005478
James Smart3772a992009-05-22 14:50:54 -04005479/**
5480 * lpfc_init_iocb_list - Allocate and initialize iocb list.
5481 * @phba: pointer to lpfc hba data structure.
5482 *
5483 * This routine is invoked to allocate and initizlize the driver's IOCB
5484 * list and set up the IOCB tag array accordingly.
5485 *
5486 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005487 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005488 * other values - error
5489 **/
5490static int
5491lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
5492{
5493 struct lpfc_iocbq *iocbq_entry = NULL;
5494 uint16_t iotag;
5495 int i;
dea31012005-04-17 16:05:31 -05005496
5497 /* Initialize and populate the iocb list per host. */
5498 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04005499 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07005500 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05005501 if (iocbq_entry == NULL) {
5502 printk(KERN_ERR "%s: only allocated %d iocbs of "
5503 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07005504 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05005505 goto out_free_iocbq;
5506 }
5507
James Bottomley604a3e32005-10-29 10:28:33 -05005508 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
5509 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04005510 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05005511 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04005512 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05005513 goto out_free_iocbq;
5514 }
James Smart6d368e52011-05-24 11:44:12 -04005515 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04005516 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05005517
5518 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005519 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
5520 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05005521 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005522 }
5523
James Smart3772a992009-05-22 14:50:54 -04005524 return 0;
5525
5526out_free_iocbq:
5527 lpfc_free_iocb_list(phba);
5528
5529 return -ENOMEM;
5530}
5531
5532/**
James Smart8a9d2e82012-05-09 21:16:12 -04005533 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04005534 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04005535 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04005536 *
James Smart8a9d2e82012-05-09 21:16:12 -04005537 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04005538 **/
James Smart8a9d2e82012-05-09 21:16:12 -04005539void
5540lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04005541{
5542 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04005543
5544 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
5545 list_del(&sglq_entry->list);
5546 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
5547 kfree(sglq_entry);
5548 }
5549}
5550
5551/**
5552 * lpfc_free_els_sgl_list - Free els sgl list.
5553 * @phba: pointer to lpfc hba data structure.
5554 *
5555 * This routine is invoked to free the driver's els sgl list and memory.
5556 **/
5557static void
5558lpfc_free_els_sgl_list(struct lpfc_hba *phba)
5559{
James Smartda0436e2009-05-22 14:51:39 -04005560 LIST_HEAD(sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04005561
James Smart8a9d2e82012-05-09 21:16:12 -04005562 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04005563 spin_lock_irq(&phba->hbalock);
5564 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
5565 spin_unlock_irq(&phba->hbalock);
5566
James Smart8a9d2e82012-05-09 21:16:12 -04005567 /* Now free the sgl list */
5568 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04005569}
5570
5571/**
5572 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
5573 * @phba: pointer to lpfc hba data structure.
5574 *
5575 * This routine is invoked to allocate the driver's active sgl memory.
5576 * This array will hold the sglq_entry's for active IOs.
5577 **/
5578static int
5579lpfc_init_active_sgl_array(struct lpfc_hba *phba)
5580{
5581 int size;
5582 size = sizeof(struct lpfc_sglq *);
5583 size *= phba->sli4_hba.max_cfg_param.max_xri;
5584
5585 phba->sli4_hba.lpfc_sglq_active_list =
5586 kzalloc(size, GFP_KERNEL);
5587 if (!phba->sli4_hba.lpfc_sglq_active_list)
5588 return -ENOMEM;
5589 return 0;
5590}
5591
5592/**
5593 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
5594 * @phba: pointer to lpfc hba data structure.
5595 *
5596 * This routine is invoked to walk through the array of active sglq entries
5597 * and free all of the resources.
5598 * This is just a place holder for now.
5599 **/
5600static void
5601lpfc_free_active_sgl(struct lpfc_hba *phba)
5602{
5603 kfree(phba->sli4_hba.lpfc_sglq_active_list);
5604}
5605
5606/**
5607 * lpfc_init_sgl_list - Allocate and initialize sgl list.
5608 * @phba: pointer to lpfc hba data structure.
5609 *
5610 * This routine is invoked to allocate and initizlize the driver's sgl
5611 * list and set up the sgl xritag tag array accordingly.
5612 *
James Smartda0436e2009-05-22 14:51:39 -04005613 **/
James Smart8a9d2e82012-05-09 21:16:12 -04005614static void
James Smartda0436e2009-05-22 14:51:39 -04005615lpfc_init_sgl_list(struct lpfc_hba *phba)
5616{
James Smartda0436e2009-05-22 14:51:39 -04005617 /* Initialize and populate the sglq list per host/VF. */
5618 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
5619 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
5620
James Smart8a9d2e82012-05-09 21:16:12 -04005621 /* els xri-sgl book keeping */
5622 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04005623
James Smart8a9d2e82012-05-09 21:16:12 -04005624 /* scsi xri-buffer book keeping */
James Smartda0436e2009-05-22 14:51:39 -04005625 phba->sli4_hba.scsi_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04005626}
5627
5628/**
5629 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
5630 * @phba: pointer to lpfc hba data structure.
5631 *
5632 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04005633 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04005634 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04005635 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
5636 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04005637 *
5638 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005639 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04005640 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04005641 **/
5642int
5643lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
5644{
5645 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04005646 struct lpfc_rpi_hdr *rpi_hdr;
5647
5648 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05005649 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04005650 return rc;
James Smart6d368e52011-05-24 11:44:12 -04005651 if (phba->sli4_hba.extents_in_use)
5652 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04005653
5654 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
5655 if (!rpi_hdr) {
5656 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5657 "0391 Error during rpi post operation\n");
5658 lpfc_sli4_remove_rpis(phba);
5659 rc = -ENODEV;
5660 }
5661
5662 return rc;
5663}
5664
5665/**
5666 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
5667 * @phba: pointer to lpfc hba data structure.
5668 *
5669 * This routine is invoked to allocate a single 4KB memory region to
5670 * support rpis and stores them in the phba. This single region
5671 * provides support for up to 64 rpis. The region is used globally
5672 * by the device.
5673 *
5674 * Returns:
5675 * A valid rpi hdr on success.
5676 * A NULL pointer on any failure.
5677 **/
5678struct lpfc_rpi_hdr *
5679lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
5680{
5681 uint16_t rpi_limit, curr_rpi_range;
5682 struct lpfc_dmabuf *dmabuf;
5683 struct lpfc_rpi_hdr *rpi_hdr;
James Smart9589b0622011-04-16 11:03:17 -04005684 uint32_t rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04005685
James Smart6d368e52011-05-24 11:44:12 -04005686 /*
5687 * If the SLI4 port supports extents, posting the rpi header isn't
5688 * required. Set the expected maximum count and let the actual value
5689 * get set when extents are fully allocated.
5690 */
5691 if (!phba->sli4_hba.rpi_hdrs_in_use)
5692 return NULL;
5693 if (phba->sli4_hba.extents_in_use)
5694 return NULL;
5695
5696 /* The limit on the logical index is just the max_rpi count. */
James Smartda0436e2009-05-22 14:51:39 -04005697 rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
James Smart6d368e52011-05-24 11:44:12 -04005698 phba->sli4_hba.max_cfg_param.max_rpi - 1;
James Smartda0436e2009-05-22 14:51:39 -04005699
5700 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04005701 /*
5702 * Establish the starting RPI in this header block. The starting
5703 * rpi is normalized to a zero base because the physical rpi is
5704 * port based.
5705 */
James Smart97f2ecf2012-03-01 22:35:23 -05005706 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04005707 spin_unlock_irq(&phba->hbalock);
5708
5709 /*
5710 * The port has a limited number of rpis. The increment here
5711 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
5712 * and to allow the full max_rpi range per port.
5713 */
5714 if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
James Smart9589b0622011-04-16 11:03:17 -04005715 rpi_count = rpi_limit - curr_rpi_range;
5716 else
5717 rpi_count = LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04005718
James Smart6d368e52011-05-24 11:44:12 -04005719 if (!rpi_count)
5720 return NULL;
James Smartda0436e2009-05-22 14:51:39 -04005721 /*
5722 * First allocate the protocol header region for the port. The
5723 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
5724 */
5725 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5726 if (!dmabuf)
5727 return NULL;
5728
5729 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
5730 LPFC_HDR_TEMPLATE_SIZE,
5731 &dmabuf->phys,
5732 GFP_KERNEL);
5733 if (!dmabuf->virt) {
5734 rpi_hdr = NULL;
5735 goto err_free_dmabuf;
5736 }
5737
5738 memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE);
5739 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
5740 rpi_hdr = NULL;
5741 goto err_free_coherent;
5742 }
5743
5744 /* Save the rpi header data for cleanup later. */
5745 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
5746 if (!rpi_hdr)
5747 goto err_free_coherent;
5748
5749 rpi_hdr->dmabuf = dmabuf;
5750 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
5751 rpi_hdr->page_count = 1;
5752 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04005753
5754 /* The rpi_hdr stores the logical index only. */
5755 rpi_hdr->start_rpi = curr_rpi_range;
James Smartda0436e2009-05-22 14:51:39 -04005756 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
5757
5758 /*
James Smart6d368e52011-05-24 11:44:12 -04005759 * The next_rpi stores the next logical module-64 rpi value used
5760 * to post physical rpis in subsequent rpi postings.
James Smartda0436e2009-05-22 14:51:39 -04005761 */
James Smart9589b0622011-04-16 11:03:17 -04005762 phba->sli4_hba.next_rpi += rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04005763 spin_unlock_irq(&phba->hbalock);
5764 return rpi_hdr;
5765
5766 err_free_coherent:
5767 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
5768 dmabuf->virt, dmabuf->phys);
5769 err_free_dmabuf:
5770 kfree(dmabuf);
5771 return NULL;
5772}
5773
5774/**
5775 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
5776 * @phba: pointer to lpfc hba data structure.
5777 *
5778 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04005779 * to support rpis for SLI4 ports not supporting extents. This routine
5780 * presumes the caller has released all rpis consumed by fabric or port
5781 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04005782 **/
5783void
5784lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
5785{
5786 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
5787
James Smart6d368e52011-05-24 11:44:12 -04005788 if (!phba->sli4_hba.rpi_hdrs_in_use)
5789 goto exit;
5790
James Smartda0436e2009-05-22 14:51:39 -04005791 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
5792 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
5793 list_del(&rpi_hdr->list);
5794 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
5795 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
5796 kfree(rpi_hdr->dmabuf);
5797 kfree(rpi_hdr);
5798 }
James Smart6d368e52011-05-24 11:44:12 -04005799 exit:
5800 /* There are no rpis available to the port now. */
5801 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04005802}
5803
5804/**
James Smart3772a992009-05-22 14:50:54 -04005805 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
5806 * @pdev: pointer to pci device data structure.
5807 *
5808 * This routine is invoked to allocate the driver hba data structure for an
5809 * HBA device. If the allocation is successful, the phba reference to the
5810 * PCI device data structure is set.
5811 *
5812 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005813 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04005814 * NULL - error
5815 **/
5816static struct lpfc_hba *
5817lpfc_hba_alloc(struct pci_dev *pdev)
5818{
5819 struct lpfc_hba *phba;
5820
5821 /* Allocate memory for HBA structure */
5822 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
5823 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02005824 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04005825 return NULL;
5826 }
5827
5828 /* Set reference to PCI device in HBA structure */
5829 phba->pcidev = pdev;
5830
5831 /* Assign an unused board number */
5832 phba->brd_no = lpfc_get_instance();
5833 if (phba->brd_no < 0) {
5834 kfree(phba);
5835 return NULL;
5836 }
5837
James Smart4fede782010-01-26 23:08:55 -05005838 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04005839 INIT_LIST_HEAD(&phba->ct_ev_waiters);
5840
James Smart3772a992009-05-22 14:50:54 -04005841 return phba;
5842}
5843
5844/**
5845 * lpfc_hba_free - Free driver hba data structure with a device.
5846 * @phba: pointer to lpfc hba data structure.
5847 *
5848 * This routine is invoked to free the driver hba data structure with an
5849 * HBA device.
5850 **/
5851static void
5852lpfc_hba_free(struct lpfc_hba *phba)
5853{
5854 /* Release the driver assigned board number */
5855 idr_remove(&lpfc_hba_index, phba->brd_no);
5856
James Smart2a76a282012-08-03 12:35:54 -04005857 /* Free memory allocated with sli rings */
5858 kfree(phba->sli.ring);
5859 phba->sli.ring = NULL;
5860
James Smart3772a992009-05-22 14:50:54 -04005861 kfree(phba);
5862 return;
5863}
5864
5865/**
5866 * lpfc_create_shost - Create hba physical port with associated scsi host.
5867 * @phba: pointer to lpfc hba data structure.
5868 *
5869 * This routine is invoked to create HBA physical port and associate a SCSI
5870 * host with it.
5871 *
5872 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005873 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005874 * other values - error
5875 **/
5876static int
5877lpfc_create_shost(struct lpfc_hba *phba)
5878{
5879 struct lpfc_vport *vport;
5880 struct Scsi_Host *shost;
5881
5882 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05005883 phba->fc_edtov = FF_DEF_EDTOV;
5884 phba->fc_ratov = FF_DEF_RATOV;
5885 phba->fc_altov = FF_DEF_ALTOV;
5886 phba->fc_arbtov = FF_DEF_ARBTOV;
5887
James Smartd7c47992010-06-08 18:31:54 -04005888 atomic_set(&phba->sdev_cnt, 0);
James Smart3de2a652007-08-02 11:09:59 -04005889 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05005890 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04005891 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05005892
5893 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05005894 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05005895 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04005896 /* Put reference to SCSI host to driver's device private data */
5897 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05005898
James Smart3772a992009-05-22 14:50:54 -04005899 return 0;
5900}
dea31012005-04-17 16:05:31 -05005901
James Smart3772a992009-05-22 14:50:54 -04005902/**
5903 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
5904 * @phba: pointer to lpfc hba data structure.
5905 *
5906 * This routine is invoked to destroy HBA physical port and the associated
5907 * SCSI host.
5908 **/
5909static void
5910lpfc_destroy_shost(struct lpfc_hba *phba)
5911{
5912 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04005913
James Smart3772a992009-05-22 14:50:54 -04005914 /* Destroy physical port that associated with the SCSI host */
5915 destroy_port(vport);
5916
5917 return;
5918}
5919
5920/**
5921 * lpfc_setup_bg - Setup Block guard structures and debug areas.
5922 * @phba: pointer to lpfc hba data structure.
5923 * @shost: the shost to be used to detect Block guard settings.
5924 *
5925 * This routine sets up the local Block guard protocol settings for @shost.
5926 * This routine also allocates memory for debugging bg buffers.
5927 **/
5928static void
5929lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
5930{
James Smartbbeb79b2012-06-12 13:54:27 -04005931 uint32_t old_mask;
5932 uint32_t old_guard;
5933
James Smart3772a992009-05-22 14:50:54 -04005934 int pagecnt = 10;
5935 if (lpfc_prot_mask && lpfc_prot_guard) {
5936 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5937 "1478 Registering BlockGuard with the "
5938 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04005939
5940 old_mask = lpfc_prot_mask;
5941 old_guard = lpfc_prot_guard;
5942
5943 /* Only allow supported values */
5944 lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
5945 SHOST_DIX_TYPE0_PROTECTION |
5946 SHOST_DIX_TYPE1_PROTECTION);
5947 lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC);
5948
5949 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
5950 if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
5951 lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
5952
5953 if (lpfc_prot_mask && lpfc_prot_guard) {
5954 if ((old_mask != lpfc_prot_mask) ||
5955 (old_guard != lpfc_prot_guard))
5956 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5957 "1475 Registering BlockGuard with the "
5958 "SCSI layer: mask %d guard %d\n",
5959 lpfc_prot_mask, lpfc_prot_guard);
5960
5961 scsi_host_set_prot(shost, lpfc_prot_mask);
5962 scsi_host_set_guard(shost, lpfc_prot_guard);
5963 } else
5964 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5965 "1479 Not Registering BlockGuard with the SCSI "
5966 "layer, Bad protection parameters: %d %d\n",
5967 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04005968 }
James Smartbbeb79b2012-06-12 13:54:27 -04005969
James Smart81301a92008-12-04 22:39:46 -05005970 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05005971 while (pagecnt) {
5972 spin_lock_init(&_dump_buf_lock);
5973 _dump_buf_data =
5974 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
5975 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04005976 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5977 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04005978 "_dump_buf_data at 0x%p\n",
5979 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05005980 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04005981 memset(_dump_buf_data, 0,
5982 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05005983 break;
James Smart3772a992009-05-22 14:50:54 -04005984 } else
James Smart81301a92008-12-04 22:39:46 -05005985 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05005986 }
James Smart81301a92008-12-04 22:39:46 -05005987 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04005988 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5989 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04005990 "memory for hexdump\n");
5991 } else
James Smart6a9c52c2009-10-02 15:16:51 -04005992 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5993 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05005994 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05005995 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05005996 while (pagecnt) {
5997 _dump_buf_dif =
5998 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
5999 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04006000 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6001 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04006002 "_dump_buf_dif at 0x%p\n",
6003 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05006004 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04006005 memset(_dump_buf_dif, 0,
6006 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05006007 break;
James Smart3772a992009-05-22 14:50:54 -04006008 } else
James Smart81301a92008-12-04 22:39:46 -05006009 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05006010 }
James Smart81301a92008-12-04 22:39:46 -05006011 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04006012 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6013 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04006014 "memory for hexdump\n");
6015 } else
James Smart6a9c52c2009-10-02 15:16:51 -04006016 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6017 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04006018 _dump_buf_dif);
6019}
6020
6021/**
6022 * lpfc_post_init_setup - Perform necessary device post initialization setup.
6023 * @phba: pointer to lpfc hba data structure.
6024 *
6025 * This routine is invoked to perform all the necessary post initialization
6026 * setup for the device.
6027 **/
6028static void
6029lpfc_post_init_setup(struct lpfc_hba *phba)
6030{
6031 struct Scsi_Host *shost;
6032 struct lpfc_adapter_event_header adapter_event;
6033
6034 /* Get the default values for Model Name and Description */
6035 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
6036
6037 /*
6038 * hba setup may have changed the hba_queue_depth so we need to
6039 * adjust the value of can_queue.
6040 */
6041 shost = pci_get_drvdata(phba->pcidev);
6042 shost->can_queue = phba->cfg_hba_queue_depth - 10;
6043 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
6044 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05006045
6046 lpfc_host_attrib_init(shost);
6047
James Smart2e0fef82007-06-17 19:56:36 -05006048 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
6049 spin_lock_irq(shost->host_lock);
6050 lpfc_poll_start_timer(phba);
6051 spin_unlock_irq(shost->host_lock);
6052 }
James Smart8f6d98d2006-08-01 07:34:00 -04006053
James Smart93996272008-08-24 21:50:30 -04006054 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6055 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04006056 /* Send board arrival event to upper layer */
6057 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
6058 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
6059 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04006060 sizeof(adapter_event),
6061 (char *) &adapter_event,
6062 LPFC_NL_VENDOR_ID);
6063 return;
6064}
6065
6066/**
6067 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
6068 * @phba: pointer to lpfc hba data structure.
6069 *
6070 * This routine is invoked to set up the PCI device memory space for device
6071 * with SLI-3 interface spec.
6072 *
6073 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006074 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006075 * other values - error
6076 **/
6077static int
6078lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
6079{
6080 struct pci_dev *pdev;
6081 unsigned long bar0map_len, bar2map_len;
6082 int i, hbq_count;
6083 void *ptr;
6084 int error = -ENODEV;
6085
6086 /* Obtain PCI device reference */
6087 if (!phba->pcidev)
6088 return error;
6089 else
6090 pdev = phba->pcidev;
6091
6092 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05006093 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
6094 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
6095 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
6096 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smart3772a992009-05-22 14:50:54 -04006097 return error;
Michael Reed8e685972009-09-18 12:02:05 -05006098 }
6099 }
James Smart3772a992009-05-22 14:50:54 -04006100
6101 /* Get the bus address of Bar0 and Bar2 and the number of bytes
6102 * required by each mapping.
6103 */
6104 phba->pci_bar0_map = pci_resource_start(pdev, 0);
6105 bar0map_len = pci_resource_len(pdev, 0);
6106
6107 phba->pci_bar2_map = pci_resource_start(pdev, 2);
6108 bar2map_len = pci_resource_len(pdev, 2);
6109
6110 /* Map HBA SLIM to a kernel virtual address. */
6111 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
6112 if (!phba->slim_memmap_p) {
6113 dev_printk(KERN_ERR, &pdev->dev,
6114 "ioremap failed for SLIM memory.\n");
6115 goto out;
6116 }
6117
6118 /* Map HBA Control Registers to a kernel virtual address. */
6119 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
6120 if (!phba->ctrl_regs_memmap_p) {
6121 dev_printk(KERN_ERR, &pdev->dev,
6122 "ioremap failed for HBA control registers.\n");
6123 goto out_iounmap_slim;
6124 }
6125
6126 /* Allocate memory for SLI-2 structures */
6127 phba->slim2p.virt = dma_alloc_coherent(&pdev->dev,
6128 SLI2_SLIM_SIZE,
6129 &phba->slim2p.phys,
6130 GFP_KERNEL);
6131 if (!phba->slim2p.virt)
6132 goto out_iounmap;
6133
6134 memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
6135 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04006136 phba->mbox_ext = (phba->slim2p.virt +
6137 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04006138 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
6139 phba->IOCBs = (phba->slim2p.virt +
6140 offsetof(struct lpfc_sli2_slim, IOCBs));
6141
6142 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
6143 lpfc_sli_hbq_size(),
6144 &phba->hbqslimp.phys,
6145 GFP_KERNEL);
6146 if (!phba->hbqslimp.virt)
6147 goto out_free_slim;
6148
6149 hbq_count = lpfc_sli_hbq_count();
6150 ptr = phba->hbqslimp.virt;
6151 for (i = 0; i < hbq_count; ++i) {
6152 phba->hbqs[i].hbq_virt = ptr;
6153 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
6154 ptr += (lpfc_hbq_defs[i]->entry_count *
6155 sizeof(struct lpfc_hbq_entry));
6156 }
6157 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
6158 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
6159
6160 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
6161
6162 INIT_LIST_HEAD(&phba->rb_pend_list);
6163
6164 phba->MBslimaddr = phba->slim_memmap_p;
6165 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
6166 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
6167 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
6168 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04006169
dea31012005-04-17 16:05:31 -05006170 return 0;
6171
dea31012005-04-17 16:05:31 -05006172out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04006173 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6174 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05006175out_iounmap:
6176 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006177out_iounmap_slim:
dea31012005-04-17 16:05:31 -05006178 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05006179out:
6180 return error;
6181}
6182
James Smarte59058c2008-08-24 21:49:00 -04006183/**
James Smart3772a992009-05-22 14:50:54 -04006184 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
6185 * @phba: pointer to lpfc hba data structure.
6186 *
6187 * This routine is invoked to unset the PCI device memory space for device
6188 * with SLI-3 interface spec.
6189 **/
6190static void
6191lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
6192{
6193 struct pci_dev *pdev;
6194
6195 /* Obtain PCI device reference */
6196 if (!phba->pcidev)
6197 return;
6198 else
6199 pdev = phba->pcidev;
6200
6201 /* Free coherent DMA memory allocated */
6202 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
6203 phba->hbqslimp.virt, phba->hbqslimp.phys);
6204 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6205 phba->slim2p.virt, phba->slim2p.phys);
6206
6207 /* I/O memory unmap */
6208 iounmap(phba->ctrl_regs_memmap_p);
6209 iounmap(phba->slim_memmap_p);
6210
6211 return;
6212}
6213
6214/**
James Smartda0436e2009-05-22 14:51:39 -04006215 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
6216 * @phba: pointer to lpfc hba data structure.
6217 *
6218 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
6219 * done and check status.
6220 *
6221 * Return 0 if successful, otherwise -ENODEV.
6222 **/
6223int
6224lpfc_sli4_post_status_check(struct lpfc_hba *phba)
6225{
James Smart2fcee4b2010-12-15 17:57:46 -05006226 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
6227 struct lpfc_register reg_data;
6228 int i, port_error = 0;
6229 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04006230
James Smart9940b972011-03-11 16:06:12 -05006231 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
6232 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05006233 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04006234 return -ENODEV;
6235
James Smartda0436e2009-05-22 14:51:39 -04006236 /* Wait up to 30 seconds for the SLI Port POST done and ready */
6237 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05006238 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
6239 &portsmphr_reg.word0) ||
6240 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006241 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04006242 port_error = -ENODEV;
6243 break;
6244 }
James Smart2fcee4b2010-12-15 17:57:46 -05006245 if (LPFC_POST_STAGE_PORT_READY ==
6246 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04006247 break;
James Smartda0436e2009-05-22 14:51:39 -04006248 msleep(10);
6249 }
6250
James Smart2fcee4b2010-12-15 17:57:46 -05006251 /*
6252 * If there was a port error during POST, then don't proceed with
6253 * other register reads as the data may not be valid. Just exit.
6254 */
6255 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04006256 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006257 "1408 Port Failed POST - portsmphr=0x%x, "
6258 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
6259 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
6260 portsmphr_reg.word0,
6261 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
6262 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
6263 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
6264 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
6265 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
6266 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
6267 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
6268 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
6269 } else {
James Smart28baac72010-02-12 14:42:03 -05006270 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006271 "2534 Device Info: SLIFamily=0x%x, "
6272 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
6273 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05006274 bf_get(lpfc_sli_intf_sli_family,
6275 &phba->sli4_hba.sli_intf),
6276 bf_get(lpfc_sli_intf_slirev,
6277 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006278 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05006279 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006280 bf_get(lpfc_sli_intf_sli_hint1,
6281 &phba->sli4_hba.sli_intf),
6282 bf_get(lpfc_sli_intf_sli_hint2,
6283 &phba->sli4_hba.sli_intf),
6284 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05006285 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05006286 /*
6287 * Check for other Port errors during the initialization
6288 * process. Fail the load if the port did not come up
6289 * correctly.
6290 */
6291 if_type = bf_get(lpfc_sli_intf_if_type,
6292 &phba->sli4_hba.sli_intf);
6293 switch (if_type) {
6294 case LPFC_SLI_INTF_IF_TYPE_0:
6295 phba->sli4_hba.ue_mask_lo =
6296 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
6297 phba->sli4_hba.ue_mask_hi =
6298 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
6299 uerrlo_reg.word0 =
6300 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
6301 uerrhi_reg.word0 =
6302 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
6303 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
6304 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
6305 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6306 "1422 Unrecoverable Error "
6307 "Detected during POST "
6308 "uerr_lo_reg=0x%x, "
6309 "uerr_hi_reg=0x%x, "
6310 "ue_mask_lo_reg=0x%x, "
6311 "ue_mask_hi_reg=0x%x\n",
6312 uerrlo_reg.word0,
6313 uerrhi_reg.word0,
6314 phba->sli4_hba.ue_mask_lo,
6315 phba->sli4_hba.ue_mask_hi);
6316 port_error = -ENODEV;
6317 }
6318 break;
6319 case LPFC_SLI_INTF_IF_TYPE_2:
6320 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05006321 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
6322 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04006323 (bf_get(lpfc_sliport_status_err, &reg_data) &&
6324 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006325 phba->work_status[0] =
6326 readl(phba->sli4_hba.u.if_type2.
6327 ERR1regaddr);
6328 phba->work_status[1] =
6329 readl(phba->sli4_hba.u.if_type2.
6330 ERR2regaddr);
6331 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05006332 "2888 Unrecoverable port error "
6333 "following POST: port status reg "
6334 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05006335 "error 1=0x%x, error 2=0x%x\n",
6336 reg_data.word0,
6337 portsmphr_reg.word0,
6338 phba->work_status[0],
6339 phba->work_status[1]);
6340 port_error = -ENODEV;
6341 }
6342 break;
6343 case LPFC_SLI_INTF_IF_TYPE_1:
6344 default:
6345 break;
6346 }
James Smart28baac72010-02-12 14:42:03 -05006347 }
James Smartda0436e2009-05-22 14:51:39 -04006348 return port_error;
6349}
6350
6351/**
6352 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
6353 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05006354 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04006355 *
6356 * This routine is invoked to set up SLI4 BAR0 PCI config space register
6357 * memory map.
6358 **/
6359static void
James Smart2fcee4b2010-12-15 17:57:46 -05006360lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04006361{
James Smart2fcee4b2010-12-15 17:57:46 -05006362 switch (if_type) {
6363 case LPFC_SLI_INTF_IF_TYPE_0:
6364 phba->sli4_hba.u.if_type0.UERRLOregaddr =
6365 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
6366 phba->sli4_hba.u.if_type0.UERRHIregaddr =
6367 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
6368 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
6369 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
6370 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
6371 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
6372 phba->sli4_hba.SLIINTFregaddr =
6373 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6374 break;
6375 case LPFC_SLI_INTF_IF_TYPE_2:
6376 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006377 phba->sli4_hba.conf_regs_memmap_p +
6378 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006379 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006380 phba->sli4_hba.conf_regs_memmap_p +
6381 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006382 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006383 phba->sli4_hba.conf_regs_memmap_p +
6384 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006385 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006386 phba->sli4_hba.conf_regs_memmap_p +
6387 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006388 phba->sli4_hba.SLIINTFregaddr =
6389 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6390 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006391 phba->sli4_hba.conf_regs_memmap_p +
6392 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006393 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006394 phba->sli4_hba.conf_regs_memmap_p +
6395 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006396 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006397 phba->sli4_hba.conf_regs_memmap_p +
6398 LPFC_ULP0_WQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006399 phba->sli4_hba.EQCQDBregaddr =
6400 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
6401 phba->sli4_hba.MQDBregaddr =
6402 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
6403 phba->sli4_hba.BMBXregaddr =
6404 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
6405 break;
6406 case LPFC_SLI_INTF_IF_TYPE_1:
6407 default:
6408 dev_printk(KERN_ERR, &phba->pcidev->dev,
6409 "FATAL - unsupported SLI4 interface type - %d\n",
6410 if_type);
6411 break;
6412 }
James Smartda0436e2009-05-22 14:51:39 -04006413}
6414
6415/**
6416 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
6417 * @phba: pointer to lpfc hba data structure.
6418 *
6419 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
6420 * memory map.
6421 **/
6422static void
6423lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
6424{
James Smart2fcee4b2010-12-15 17:57:46 -05006425 phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
6426 LPFC_SLIPORT_IF0_SMPHR;
James Smartda0436e2009-05-22 14:51:39 -04006427 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006428 LPFC_HST_ISR0;
James Smartda0436e2009-05-22 14:51:39 -04006429 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006430 LPFC_HST_IMR0;
James Smartda0436e2009-05-22 14:51:39 -04006431 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006432 LPFC_HST_ISCR0;
James Smartda0436e2009-05-22 14:51:39 -04006433}
6434
6435/**
6436 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
6437 * @phba: pointer to lpfc hba data structure.
6438 * @vf: virtual function number
6439 *
6440 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
6441 * based on the given viftual function number, @vf.
6442 *
6443 * Return 0 if successful, otherwise -ENODEV.
6444 **/
6445static int
6446lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
6447{
6448 if (vf > LPFC_VIR_FUNC_MAX)
6449 return -ENODEV;
6450
6451 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05006452 vf * LPFC_VFR_PAGE_SIZE +
6453 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04006454 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05006455 vf * LPFC_VFR_PAGE_SIZE +
6456 LPFC_ULP0_WQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04006457 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6458 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
6459 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6460 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
6461 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6462 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
6463 return 0;
6464}
6465
6466/**
6467 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
6468 * @phba: pointer to lpfc hba data structure.
6469 *
6470 * This routine is invoked to create the bootstrap mailbox
6471 * region consistent with the SLI-4 interface spec. This
6472 * routine allocates all memory necessary to communicate
6473 * mailbox commands to the port and sets up all alignment
6474 * needs. No locks are expected to be held when calling
6475 * this routine.
6476 *
6477 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006478 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04006479 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04006480 **/
6481static int
6482lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
6483{
6484 uint32_t bmbx_size;
6485 struct lpfc_dmabuf *dmabuf;
6486 struct dma_address *dma_address;
6487 uint32_t pa_addr;
6488 uint64_t phys_addr;
6489
6490 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6491 if (!dmabuf)
6492 return -ENOMEM;
6493
6494 /*
6495 * The bootstrap mailbox region is comprised of 2 parts
6496 * plus an alignment restriction of 16 bytes.
6497 */
6498 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
6499 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
6500 bmbx_size,
6501 &dmabuf->phys,
6502 GFP_KERNEL);
6503 if (!dmabuf->virt) {
6504 kfree(dmabuf);
6505 return -ENOMEM;
6506 }
6507 memset(dmabuf->virt, 0, bmbx_size);
6508
6509 /*
6510 * Initialize the bootstrap mailbox pointers now so that the register
6511 * operations are simple later. The mailbox dma address is required
6512 * to be 16-byte aligned. Also align the virtual memory as each
6513 * maibox is copied into the bmbx mailbox region before issuing the
6514 * command to the port.
6515 */
6516 phba->sli4_hba.bmbx.dmabuf = dmabuf;
6517 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
6518
6519 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
6520 LPFC_ALIGN_16_BYTE);
6521 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
6522 LPFC_ALIGN_16_BYTE);
6523
6524 /*
6525 * Set the high and low physical addresses now. The SLI4 alignment
6526 * requirement is 16 bytes and the mailbox is posted to the port
6527 * as two 30-bit addresses. The other data is a bit marking whether
6528 * the 30-bit address is the high or low address.
6529 * Upcast bmbx aphys to 64bits so shift instruction compiles
6530 * clean on 32 bit machines.
6531 */
6532 dma_address = &phba->sli4_hba.bmbx.dma_address;
6533 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
6534 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
6535 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
6536 LPFC_BMBX_BIT1_ADDR_HI);
6537
6538 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
6539 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
6540 LPFC_BMBX_BIT1_ADDR_LO);
6541 return 0;
6542}
6543
6544/**
6545 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
6546 * @phba: pointer to lpfc hba data structure.
6547 *
6548 * This routine is invoked to teardown the bootstrap mailbox
6549 * region and release all host resources. This routine requires
6550 * the caller to ensure all mailbox commands recovered, no
6551 * additional mailbox comands are sent, and interrupts are disabled
6552 * before calling this routine.
6553 *
6554 **/
6555static void
6556lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
6557{
6558 dma_free_coherent(&phba->pcidev->dev,
6559 phba->sli4_hba.bmbx.bmbx_size,
6560 phba->sli4_hba.bmbx.dmabuf->virt,
6561 phba->sli4_hba.bmbx.dmabuf->phys);
6562
6563 kfree(phba->sli4_hba.bmbx.dmabuf);
6564 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
6565}
6566
6567/**
6568 * lpfc_sli4_read_config - Get the config parameters.
6569 * @phba: pointer to lpfc hba data structure.
6570 *
6571 * This routine is invoked to read the configuration parameters from the HBA.
6572 * The configuration parameters are used to set the base and maximum values
6573 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
6574 * allocation for the port.
6575 *
6576 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006577 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006578 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006579 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006580 **/
James Smartff78d8f2011-12-13 13:21:35 -05006581int
James Smartda0436e2009-05-22 14:51:39 -04006582lpfc_sli4_read_config(struct lpfc_hba *phba)
6583{
6584 LPFC_MBOXQ_t *pmb;
6585 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04006586 union lpfc_sli4_cfg_shdr *shdr;
6587 uint32_t shdr_status, shdr_add_status;
6588 struct lpfc_mbx_get_func_cfg *get_func_cfg;
6589 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04006590 char *pdesc_0;
James Smart912e3ac2011-05-24 11:42:11 -04006591 uint32_t desc_count;
James Smart8aa134a2012-08-14 14:25:29 -04006592 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04006593
6594 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6595 if (!pmb) {
6596 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6597 "2011 Unable to allocate memory for issuing "
6598 "SLI_CONFIG_SPECIAL mailbox command\n");
6599 return -ENOMEM;
6600 }
6601
6602 lpfc_read_config(phba, pmb);
6603
6604 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
6605 if (rc != MBX_SUCCESS) {
6606 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6607 "2012 Mailbox failed , mbxCmd x%x "
6608 "READ_CONFIG, mbxStatus x%x\n",
6609 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6610 bf_get(lpfc_mqe_status, &pmb->u.mqe));
6611 rc = -EIO;
6612 } else {
6613 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05006614 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
6615 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
6616 phba->sli4_hba.lnk_info.lnk_tp =
6617 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
6618 phba->sli4_hba.lnk_info.lnk_no =
6619 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
6620 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6621 "3081 lnk_type:%d, lnk_numb:%d\n",
6622 phba->sli4_hba.lnk_info.lnk_tp,
6623 phba->sli4_hba.lnk_info.lnk_no);
6624 } else
6625 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6626 "3082 Mailbox (x%x) returned ldv:x0\n",
6627 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart6d368e52011-05-24 11:44:12 -04006628 phba->sli4_hba.extents_in_use =
6629 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04006630 phba->sli4_hba.max_cfg_param.max_xri =
6631 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
6632 phba->sli4_hba.max_cfg_param.xri_base =
6633 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
6634 phba->sli4_hba.max_cfg_param.max_vpi =
6635 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
6636 phba->sli4_hba.max_cfg_param.vpi_base =
6637 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
6638 phba->sli4_hba.max_cfg_param.max_rpi =
6639 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
6640 phba->sli4_hba.max_cfg_param.rpi_base =
6641 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
6642 phba->sli4_hba.max_cfg_param.max_vfi =
6643 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
6644 phba->sli4_hba.max_cfg_param.vfi_base =
6645 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
6646 phba->sli4_hba.max_cfg_param.max_fcfi =
6647 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04006648 phba->sli4_hba.max_cfg_param.max_eq =
6649 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
6650 phba->sli4_hba.max_cfg_param.max_rq =
6651 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
6652 phba->sli4_hba.max_cfg_param.max_wq =
6653 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
6654 phba->sli4_hba.max_cfg_param.max_cq =
6655 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
6656 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
6657 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
6658 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
6659 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05006660 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
6661 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04006662 phba->max_vports = phba->max_vpi;
6663 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04006664 "2003 cfg params Extents? %d "
6665 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04006666 "VPI(B:%d M:%d) "
6667 "VFI(B:%d M:%d) "
6668 "RPI(B:%d M:%d) "
James Smart6d368e52011-05-24 11:44:12 -04006669 "FCFI(Count:%d)\n",
6670 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04006671 phba->sli4_hba.max_cfg_param.xri_base,
6672 phba->sli4_hba.max_cfg_param.max_xri,
6673 phba->sli4_hba.max_cfg_param.vpi_base,
6674 phba->sli4_hba.max_cfg_param.max_vpi,
6675 phba->sli4_hba.max_cfg_param.vfi_base,
6676 phba->sli4_hba.max_cfg_param.max_vfi,
6677 phba->sli4_hba.max_cfg_param.rpi_base,
6678 phba->sli4_hba.max_cfg_param.max_rpi,
James Smartda0436e2009-05-22 14:51:39 -04006679 phba->sli4_hba.max_cfg_param.max_fcfi);
6680 }
James Smart912e3ac2011-05-24 11:42:11 -04006681
6682 if (rc)
6683 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04006684
6685 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -04006686 length = phba->sli4_hba.max_cfg_param.max_xri -
6687 lpfc_sli4_get_els_iocb_cnt(phba);
6688 if (phba->cfg_hba_queue_depth > length) {
6689 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6690 "3361 HBA queue depth changed from %d to %d\n",
6691 phba->cfg_hba_queue_depth, length);
6692 phba->cfg_hba_queue_depth = length;
6693 }
James Smart912e3ac2011-05-24 11:42:11 -04006694
6695 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
6696 LPFC_SLI_INTF_IF_TYPE_2)
6697 goto read_cfg_out;
6698
6699 /* get the pf# and vf# for SLI4 if_type 2 port */
6700 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
6701 sizeof(struct lpfc_sli4_cfg_mhdr));
6702 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
6703 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
6704 length, LPFC_SLI4_MBX_EMBED);
6705
James Smart8aa134a2012-08-14 14:25:29 -04006706 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04006707 shdr = (union lpfc_sli4_cfg_shdr *)
6708 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
6709 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6710 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04006711 if (rc2 || shdr_status || shdr_add_status) {
James Smart912e3ac2011-05-24 11:42:11 -04006712 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6713 "3026 Mailbox failed , mbxCmd x%x "
6714 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
6715 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6716 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04006717 goto read_cfg_out;
6718 }
6719
6720 /* search for fc_fcoe resrouce descriptor */
6721 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
6722 desc_count = get_func_cfg->func_cfg.rsrc_desc_count;
6723
James Smart8aa134a2012-08-14 14:25:29 -04006724 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
6725 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
6726 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
6727 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
6728 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
6729 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
6730 goto read_cfg_out;
6731
James Smart912e3ac2011-05-24 11:42:11 -04006732 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04006733 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04006734 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04006735 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04006736 phba->sli4_hba.iov.pf_number =
6737 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
6738 phba->sli4_hba.iov.vf_number =
6739 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
6740 break;
6741 }
6742 }
6743
6744 if (i < LPFC_RSRC_DESC_MAX_NUM)
6745 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6746 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
6747 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
6748 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04006749 else
James Smart912e3ac2011-05-24 11:42:11 -04006750 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6751 "3028 GET_FUNCTION_CONFIG: failed to find "
6752 "Resrouce Descriptor:x%x\n",
6753 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04006754
6755read_cfg_out:
6756 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04006757 return rc;
6758}
6759
6760/**
James Smart2fcee4b2010-12-15 17:57:46 -05006761 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04006762 * @phba: pointer to lpfc hba data structure.
6763 *
James Smart2fcee4b2010-12-15 17:57:46 -05006764 * This routine is invoked to setup the port-side endian order when
6765 * the port if_type is 0. This routine has no function for other
6766 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04006767 *
6768 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006769 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006770 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006771 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006772 **/
6773static int
6774lpfc_setup_endian_order(struct lpfc_hba *phba)
6775{
6776 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05006777 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04006778 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
6779 HOST_ENDIAN_HIGH_WORD1};
6780
James Smart2fcee4b2010-12-15 17:57:46 -05006781 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
6782 switch (if_type) {
6783 case LPFC_SLI_INTF_IF_TYPE_0:
6784 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
6785 GFP_KERNEL);
6786 if (!mboxq) {
6787 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6788 "0492 Unable to allocate memory for "
6789 "issuing SLI_CONFIG_SPECIAL mailbox "
6790 "command\n");
6791 return -ENOMEM;
6792 }
James Smartda0436e2009-05-22 14:51:39 -04006793
James Smart2fcee4b2010-12-15 17:57:46 -05006794 /*
6795 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
6796 * two words to contain special data values and no other data.
6797 */
6798 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
6799 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
6800 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6801 if (rc != MBX_SUCCESS) {
6802 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6803 "0493 SLI_CONFIG_SPECIAL mailbox "
6804 "failed with status x%x\n",
6805 rc);
6806 rc = -EIO;
6807 }
6808 mempool_free(mboxq, phba->mbox_mem_pool);
6809 break;
6810 case LPFC_SLI_INTF_IF_TYPE_2:
6811 case LPFC_SLI_INTF_IF_TYPE_1:
6812 default:
6813 break;
James Smartda0436e2009-05-22 14:51:39 -04006814 }
James Smartda0436e2009-05-22 14:51:39 -04006815 return rc;
6816}
6817
6818/**
James Smart5350d872011-10-10 21:33:49 -04006819 * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts
James Smartda0436e2009-05-22 14:51:39 -04006820 * @phba: pointer to lpfc hba data structure.
6821 *
James Smart5350d872011-10-10 21:33:49 -04006822 * This routine is invoked to check the user settable queue counts for EQs and
6823 * CQs. after this routine is called the counts will be set to valid values that
6824 * adhere to the constraints of the system's interrupt vectors and the port's
6825 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04006826 *
6827 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006828 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006829 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04006830 **/
6831static int
James Smart5350d872011-10-10 21:33:49 -04006832lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04006833{
James Smart67d12732012-08-03 12:36:13 -04006834 int cfg_fcp_io_channel;
James Smart90695ee2012-08-14 14:25:36 -04006835 uint32_t cpu;
6836 uint32_t i = 0;
James Smart1ba981f2014-02-20 09:56:45 -05006837 int fof_vectors = phba->cfg_fof ? 1 : 0;
James Smartda0436e2009-05-22 14:51:39 -04006838
6839 /*
James Smart67d12732012-08-03 12:36:13 -04006840 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04006841 * device parameters
6842 */
6843
James Smart67d12732012-08-03 12:36:13 -04006844 /* Sanity check on HBA EQ parameters */
6845 cfg_fcp_io_channel = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04006846
James Smart7bb03bb2013-04-17 20:19:16 -04006847 /* It doesn't make sense to have more io channels then online CPUs */
6848 for_each_present_cpu(cpu) {
6849 if (cpu_online(cpu))
6850 i++;
James Smart90695ee2012-08-14 14:25:36 -04006851 }
James Smart7bb03bb2013-04-17 20:19:16 -04006852 phba->sli4_hba.num_online_cpu = i;
James Smartb246de12013-05-31 17:03:07 -04006853 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
James Smart76fd07a2014-02-20 09:57:18 -05006854 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04006855
James Smart90695ee2012-08-14 14:25:36 -04006856 if (i < cfg_fcp_io_channel) {
James Smart82c3e9b2012-09-29 11:29:50 -04006857 lpfc_printf_log(phba,
6858 KERN_ERR, LOG_INIT,
James Smart90695ee2012-08-14 14:25:36 -04006859 "3188 Reducing IO channels to match number of "
James Smart7bb03bb2013-04-17 20:19:16 -04006860 "online CPUs: from %d to %d\n",
6861 cfg_fcp_io_channel, i);
James Smart90695ee2012-08-14 14:25:36 -04006862 cfg_fcp_io_channel = i;
6863 }
6864
James Smart1ba981f2014-02-20 09:56:45 -05006865 if (cfg_fcp_io_channel + fof_vectors >
James Smart67d12732012-08-03 12:36:13 -04006866 phba->sli4_hba.max_cfg_param.max_eq) {
James Smart82c3e9b2012-09-29 11:29:50 -04006867 if (phba->sli4_hba.max_cfg_param.max_eq <
6868 LPFC_FCP_IO_CHAN_MIN) {
James Smartda0436e2009-05-22 14:51:39 -04006869 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6870 "2574 Not enough EQs (%d) from the "
6871 "pci function for supporting FCP "
6872 "EQs (%d)\n",
6873 phba->sli4_hba.max_cfg_param.max_eq,
James Smart67d12732012-08-03 12:36:13 -04006874 phba->cfg_fcp_io_channel);
James Smartda0436e2009-05-22 14:51:39 -04006875 goto out_error;
6876 }
James Smart82c3e9b2012-09-29 11:29:50 -04006877 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6878 "2575 Reducing IO channels to match number of "
6879 "available EQs: from %d to %d\n",
6880 cfg_fcp_io_channel,
6881 phba->sli4_hba.max_cfg_param.max_eq);
James Smart1ba981f2014-02-20 09:56:45 -05006882 cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq -
6883 fof_vectors;
James Smartda0436e2009-05-22 14:51:39 -04006884 }
James Smart67d12732012-08-03 12:36:13 -04006885
James Smartda0436e2009-05-22 14:51:39 -04006886 /* The actual number of FCP event queues adopted */
James Smart67d12732012-08-03 12:36:13 -04006887 phba->cfg_fcp_io_channel = cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04006888
James Smartda0436e2009-05-22 14:51:39 -04006889 /* Get EQ depth from module parameter, fake the default for now */
6890 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
6891 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
6892
James Smart5350d872011-10-10 21:33:49 -04006893 /* Get CQ depth from module parameter, fake the default for now */
6894 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
6895 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
6896
6897 return 0;
6898out_error:
6899 return -ENOMEM;
6900}
6901
6902/**
6903 * lpfc_sli4_queue_create - Create all the SLI4 queues
6904 * @phba: pointer to lpfc hba data structure.
6905 *
6906 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
6907 * operation. For each SLI4 queue type, the parameters such as queue entry
6908 * count (queue depth) shall be taken from the module parameter. For now,
6909 * we just use some constant number as place holder.
6910 *
6911 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07006912 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04006913 * -ENOMEM - No availble memory
6914 * -EIO - The mailbox failed to complete successfully.
6915 **/
6916int
6917lpfc_sli4_queue_create(struct lpfc_hba *phba)
6918{
6919 struct lpfc_queue *qdesc;
James Smart67d12732012-08-03 12:36:13 -04006920 int idx;
James Smart5350d872011-10-10 21:33:49 -04006921
6922 /*
James Smart67d12732012-08-03 12:36:13 -04006923 * Create HBA Record arrays.
James Smart5350d872011-10-10 21:33:49 -04006924 */
James Smart67d12732012-08-03 12:36:13 -04006925 if (!phba->cfg_fcp_io_channel)
6926 return -ERANGE;
James Smart5350d872011-10-10 21:33:49 -04006927
James Smart67d12732012-08-03 12:36:13 -04006928 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
6929 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
6930 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
6931 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
6932 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
6933 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
6934
6935 phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) *
6936 phba->cfg_fcp_io_channel), GFP_KERNEL);
6937 if (!phba->sli4_hba.hba_eq) {
James Smartda0436e2009-05-22 14:51:39 -04006938 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04006939 "2576 Failed allocate memory for "
6940 "fast-path EQ record array\n");
James Smartda0436e2009-05-22 14:51:39 -04006941 goto out_error;
6942 }
James Smart67d12732012-08-03 12:36:13 -04006943
6944 phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
6945 phba->cfg_fcp_io_channel), GFP_KERNEL);
6946 if (!phba->sli4_hba.fcp_cq) {
6947 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6948 "2577 Failed allocate memory for fast-path "
6949 "CQ record array\n");
6950 goto out_error;
6951 }
6952
6953 phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
6954 phba->cfg_fcp_io_channel), GFP_KERNEL);
6955 if (!phba->sli4_hba.fcp_wq) {
6956 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6957 "2578 Failed allocate memory for fast-path "
6958 "WQ record array\n");
6959 goto out_error;
6960 }
James Smartda0436e2009-05-22 14:51:39 -04006961
James Smart5350d872011-10-10 21:33:49 -04006962 /*
James Smart67d12732012-08-03 12:36:13 -04006963 * Since the first EQ can have multiple CQs associated with it,
6964 * this array is used to quickly see if we have a FCP fast-path
6965 * CQ match.
James Smart5350d872011-10-10 21:33:49 -04006966 */
James Smart67d12732012-08-03 12:36:13 -04006967 phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) *
6968 phba->cfg_fcp_io_channel), GFP_KERNEL);
6969 if (!phba->sli4_hba.fcp_cq_map) {
6970 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6971 "2545 Failed allocate memory for fast-path "
6972 "CQ map\n");
6973 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04006974 }
James Smart67d12732012-08-03 12:36:13 -04006975
6976 /*
6977 * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies
6978 * how many EQs to create.
6979 */
6980 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
6981
6982 /* Create EQs */
James Smartda0436e2009-05-22 14:51:39 -04006983 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
6984 phba->sli4_hba.eq_ecount);
6985 if (!qdesc) {
6986 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04006987 "0497 Failed allocate EQ (%d)\n", idx);
6988 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04006989 }
James Smart67d12732012-08-03 12:36:13 -04006990 phba->sli4_hba.hba_eq[idx] = qdesc;
6991
6992 /* Create Fast Path FCP CQs */
6993 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
6994 phba->sli4_hba.cq_ecount);
6995 if (!qdesc) {
6996 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6997 "0499 Failed allocate fast-path FCP "
6998 "CQ (%d)\n", idx);
6999 goto out_error;
7000 }
7001 phba->sli4_hba.fcp_cq[idx] = qdesc;
7002
7003 /* Create Fast Path FCP WQs */
7004 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
7005 phba->sli4_hba.wq_ecount);
7006 if (!qdesc) {
7007 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7008 "0503 Failed allocate fast-path FCP "
7009 "WQ (%d)\n", idx);
7010 goto out_error;
7011 }
7012 phba->sli4_hba.fcp_wq[idx] = qdesc;
James Smartda0436e2009-05-22 14:51:39 -04007013 }
7014
James Smart67d12732012-08-03 12:36:13 -04007015
James Smartda0436e2009-05-22 14:51:39 -04007016 /*
James Smart67d12732012-08-03 12:36:13 -04007017 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04007018 */
7019
James Smartda0436e2009-05-22 14:51:39 -04007020 /* Create slow-path Mailbox Command Complete Queue */
7021 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7022 phba->sli4_hba.cq_ecount);
7023 if (!qdesc) {
7024 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7025 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04007026 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007027 }
7028 phba->sli4_hba.mbx_cq = qdesc;
7029
7030 /* Create slow-path ELS Complete Queue */
7031 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7032 phba->sli4_hba.cq_ecount);
7033 if (!qdesc) {
7034 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7035 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -04007036 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007037 }
7038 phba->sli4_hba.els_cq = qdesc;
7039
James Smartda0436e2009-05-22 14:51:39 -04007040
James Smart5350d872011-10-10 21:33:49 -04007041 /*
James Smart67d12732012-08-03 12:36:13 -04007042 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04007043 */
James Smartda0436e2009-05-22 14:51:39 -04007044
7045 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04007046
7047 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
7048 phba->sli4_hba.mq_ecount);
7049 if (!qdesc) {
7050 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7051 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04007052 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007053 }
7054 phba->sli4_hba.mbx_wq = qdesc;
7055
7056 /*
James Smart67d12732012-08-03 12:36:13 -04007057 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04007058 */
James Smartda0436e2009-05-22 14:51:39 -04007059
7060 /* Create slow-path ELS Work Queue */
7061 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
7062 phba->sli4_hba.wq_ecount);
7063 if (!qdesc) {
7064 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7065 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04007066 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007067 }
7068 phba->sli4_hba.els_wq = qdesc;
7069
James Smartda0436e2009-05-22 14:51:39 -04007070 /*
7071 * Create Receive Queue (RQ)
7072 */
James Smartda0436e2009-05-22 14:51:39 -04007073
7074 /* Create Receive Queue for header */
7075 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
7076 phba->sli4_hba.rq_ecount);
7077 if (!qdesc) {
7078 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7079 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04007080 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007081 }
7082 phba->sli4_hba.hdr_rq = qdesc;
7083
7084 /* Create Receive Queue for data */
7085 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
7086 phba->sli4_hba.rq_ecount);
7087 if (!qdesc) {
7088 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7089 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04007090 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007091 }
7092 phba->sli4_hba.dat_rq = qdesc;
7093
James Smart1ba981f2014-02-20 09:56:45 -05007094 /* Create the Queues needed for Flash Optimized Fabric operations */
7095 if (phba->cfg_fof)
7096 lpfc_fof_queue_create(phba);
James Smartda0436e2009-05-22 14:51:39 -04007097 return 0;
7098
James Smartda0436e2009-05-22 14:51:39 -04007099out_error:
James Smart67d12732012-08-03 12:36:13 -04007100 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04007101 return -ENOMEM;
7102}
7103
7104/**
7105 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
7106 * @phba: pointer to lpfc hba data structure.
7107 *
7108 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
7109 * operation.
7110 *
7111 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007112 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007113 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007114 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007115 **/
James Smart5350d872011-10-10 21:33:49 -04007116void
James Smartda0436e2009-05-22 14:51:39 -04007117lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
7118{
James Smart67d12732012-08-03 12:36:13 -04007119 int idx;
7120
James Smart1ba981f2014-02-20 09:56:45 -05007121 if (phba->cfg_fof)
7122 lpfc_fof_queue_destroy(phba);
7123
James Smart67d12732012-08-03 12:36:13 -04007124 if (phba->sli4_hba.hba_eq != NULL) {
7125 /* Release HBA event queue */
7126 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7127 if (phba->sli4_hba.hba_eq[idx] != NULL) {
7128 lpfc_sli4_queue_free(
7129 phba->sli4_hba.hba_eq[idx]);
7130 phba->sli4_hba.hba_eq[idx] = NULL;
7131 }
7132 }
7133 kfree(phba->sli4_hba.hba_eq);
7134 phba->sli4_hba.hba_eq = NULL;
7135 }
7136
7137 if (phba->sli4_hba.fcp_cq != NULL) {
7138 /* Release FCP completion queue */
7139 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7140 if (phba->sli4_hba.fcp_cq[idx] != NULL) {
7141 lpfc_sli4_queue_free(
7142 phba->sli4_hba.fcp_cq[idx]);
7143 phba->sli4_hba.fcp_cq[idx] = NULL;
7144 }
7145 }
7146 kfree(phba->sli4_hba.fcp_cq);
7147 phba->sli4_hba.fcp_cq = NULL;
7148 }
7149
7150 if (phba->sli4_hba.fcp_wq != NULL) {
7151 /* Release FCP work queue */
7152 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7153 if (phba->sli4_hba.fcp_wq[idx] != NULL) {
7154 lpfc_sli4_queue_free(
7155 phba->sli4_hba.fcp_wq[idx]);
7156 phba->sli4_hba.fcp_wq[idx] = NULL;
7157 }
7158 }
7159 kfree(phba->sli4_hba.fcp_wq);
7160 phba->sli4_hba.fcp_wq = NULL;
7161 }
7162
7163 /* Release FCP CQ mapping array */
7164 if (phba->sli4_hba.fcp_cq_map != NULL) {
7165 kfree(phba->sli4_hba.fcp_cq_map);
7166 phba->sli4_hba.fcp_cq_map = NULL;
7167 }
James Smartda0436e2009-05-22 14:51:39 -04007168
7169 /* Release mailbox command work queue */
James Smart67d12732012-08-03 12:36:13 -04007170 if (phba->sli4_hba.mbx_wq != NULL) {
7171 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
7172 phba->sli4_hba.mbx_wq = NULL;
7173 }
James Smartda0436e2009-05-22 14:51:39 -04007174
7175 /* Release ELS work queue */
James Smart67d12732012-08-03 12:36:13 -04007176 if (phba->sli4_hba.els_wq != NULL) {
7177 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
7178 phba->sli4_hba.els_wq = NULL;
7179 }
James Smartda0436e2009-05-22 14:51:39 -04007180
7181 /* Release unsolicited receive queue */
James Smart67d12732012-08-03 12:36:13 -04007182 if (phba->sli4_hba.hdr_rq != NULL) {
7183 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
7184 phba->sli4_hba.hdr_rq = NULL;
7185 }
7186 if (phba->sli4_hba.dat_rq != NULL) {
7187 lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
7188 phba->sli4_hba.dat_rq = NULL;
7189 }
James Smartda0436e2009-05-22 14:51:39 -04007190
James Smartda0436e2009-05-22 14:51:39 -04007191 /* Release ELS complete queue */
James Smart67d12732012-08-03 12:36:13 -04007192 if (phba->sli4_hba.els_cq != NULL) {
7193 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
7194 phba->sli4_hba.els_cq = NULL;
7195 }
James Smartda0436e2009-05-22 14:51:39 -04007196
7197 /* Release mailbox command complete queue */
James Smart67d12732012-08-03 12:36:13 -04007198 if (phba->sli4_hba.mbx_cq != NULL) {
7199 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
7200 phba->sli4_hba.mbx_cq = NULL;
7201 }
James Smartda0436e2009-05-22 14:51:39 -04007202
7203 return;
7204}
7205
7206/**
7207 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
7208 * @phba: pointer to lpfc hba data structure.
7209 *
7210 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
7211 * operation.
7212 *
7213 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007214 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007215 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007216 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007217 **/
7218int
7219lpfc_sli4_queue_setup(struct lpfc_hba *phba)
7220{
James Smart2a76a282012-08-03 12:35:54 -04007221 struct lpfc_sli *psli = &phba->sli;
7222 struct lpfc_sli_ring *pring;
James Smartda0436e2009-05-22 14:51:39 -04007223 int rc = -ENOMEM;
7224 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
7225 int fcp_cq_index = 0;
James Smart962bc512013-01-03 15:44:00 -05007226 uint32_t shdr_status, shdr_add_status;
7227 union lpfc_sli4_cfg_shdr *shdr;
7228 LPFC_MBOXQ_t *mboxq;
7229 uint32_t length;
7230
7231 /* Check for dual-ULP support */
7232 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7233 if (!mboxq) {
7234 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7235 "3249 Unable to allocate memory for "
7236 "QUERY_FW_CFG mailbox command\n");
7237 return -ENOMEM;
7238 }
7239 length = (sizeof(struct lpfc_mbx_query_fw_config) -
7240 sizeof(struct lpfc_sli4_cfg_mhdr));
7241 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
7242 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
7243 length, LPFC_SLI4_MBX_EMBED);
7244
7245 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7246
7247 shdr = (union lpfc_sli4_cfg_shdr *)
7248 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
7249 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7250 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7251 if (shdr_status || shdr_add_status || rc) {
7252 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7253 "3250 QUERY_FW_CFG mailbox failed with status "
7254 "x%x add_status x%x, mbx status x%x\n",
7255 shdr_status, shdr_add_status, rc);
7256 if (rc != MBX_TIMEOUT)
7257 mempool_free(mboxq, phba->mbox_mem_pool);
7258 rc = -ENXIO;
7259 goto out_error;
7260 }
7261
7262 phba->sli4_hba.fw_func_mode =
7263 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
7264 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
7265 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
7266 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7267 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
7268 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
7269 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
7270
7271 if (rc != MBX_TIMEOUT)
7272 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04007273
7274 /*
James Smart67d12732012-08-03 12:36:13 -04007275 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04007276 */
7277
James Smart67d12732012-08-03 12:36:13 -04007278 /* Set up HBA event queue */
7279 if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) {
James Smart2e90f4b2011-12-13 13:22:37 -05007280 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7281 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007282 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007283 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05007284 }
James Smart67d12732012-08-03 12:36:13 -04007285 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
7286 if (!phba->sli4_hba.hba_eq[fcp_eqidx]) {
James Smartda0436e2009-05-22 14:51:39 -04007287 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7288 "0522 Fast-path EQ (%d) not "
7289 "allocated\n", fcp_eqidx);
James Smart1b511972011-12-13 13:23:09 -05007290 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007291 goto out_destroy_hba_eq;
James Smartda0436e2009-05-22 14:51:39 -04007292 }
James Smart67d12732012-08-03 12:36:13 -04007293 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx],
James Smartbf8dae82012-08-03 12:36:24 -04007294 (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel));
James Smartda0436e2009-05-22 14:51:39 -04007295 if (rc) {
7296 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7297 "0523 Failed setup of fast-path EQ "
7298 "(%d), rc = 0x%x\n", fcp_eqidx, rc);
James Smart67d12732012-08-03 12:36:13 -04007299 goto out_destroy_hba_eq;
James Smartda0436e2009-05-22 14:51:39 -04007300 }
7301 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007302 "2584 HBA EQ setup: "
James Smartda0436e2009-05-22 14:51:39 -04007303 "queue[%d]-id=%d\n", fcp_eqidx,
James Smart67d12732012-08-03 12:36:13 -04007304 phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007305 }
7306
James Smart67d12732012-08-03 12:36:13 -04007307 /* Set up fast-path FCP Response Complete Queue */
7308 if (!phba->sli4_hba.fcp_cq) {
7309 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7310 "3148 Fast-path FCP CQ array not "
7311 "allocated\n");
7312 rc = -ENOMEM;
7313 goto out_destroy_hba_eq;
7314 }
7315
7316 for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) {
7317 if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
7318 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7319 "0526 Fast-path FCP CQ (%d) not "
7320 "allocated\n", fcp_cqidx);
7321 rc = -ENOMEM;
7322 goto out_destroy_fcp_cq;
7323 }
7324 rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
7325 phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP);
7326 if (rc) {
7327 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7328 "0527 Failed setup of fast-path FCP "
7329 "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc);
7330 goto out_destroy_fcp_cq;
7331 }
7332
7333 /* Setup fcp_cq_map for fast lookup */
7334 phba->sli4_hba.fcp_cq_map[fcp_cqidx] =
7335 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id;
7336
7337 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7338 "2588 FCP CQ setup: cq[%d]-id=%d, "
7339 "parent seq[%d]-id=%d\n",
7340 fcp_cqidx,
7341 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
7342 fcp_cqidx,
7343 phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id);
7344 }
7345
7346 /* Set up fast-path FCP Work Queue */
7347 if (!phba->sli4_hba.fcp_wq) {
7348 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7349 "3149 Fast-path FCP WQ array not "
7350 "allocated\n");
7351 rc = -ENOMEM;
7352 goto out_destroy_fcp_cq;
7353 }
7354
7355 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) {
7356 if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
7357 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7358 "0534 Fast-path FCP WQ (%d) not "
7359 "allocated\n", fcp_wqidx);
7360 rc = -ENOMEM;
7361 goto out_destroy_fcp_wq;
7362 }
7363 rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
7364 phba->sli4_hba.fcp_cq[fcp_wqidx],
7365 LPFC_FCP);
7366 if (rc) {
7367 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7368 "0535 Failed setup of fast-path FCP "
7369 "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc);
7370 goto out_destroy_fcp_wq;
7371 }
7372
7373 /* Bind this WQ to the next FCP ring */
7374 pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx];
7375 pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx];
7376 phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring;
7377
7378 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7379 "2591 FCP WQ setup: wq[%d]-id=%d, "
7380 "parent cq[%d]-id=%d\n",
7381 fcp_wqidx,
7382 phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
7383 fcp_cq_index,
7384 phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id);
7385 }
James Smartda0436e2009-05-22 14:51:39 -04007386 /*
7387 * Set up Complete Queues (CQs)
7388 */
7389
7390 /* Set up slow-path MBOX Complete Queue as the first CQ */
7391 if (!phba->sli4_hba.mbx_cq) {
7392 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7393 "0528 Mailbox CQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007394 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007395 goto out_destroy_fcp_wq;
James Smartda0436e2009-05-22 14:51:39 -04007396 }
James Smart67d12732012-08-03 12:36:13 -04007397 rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq,
7398 phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04007399 if (rc) {
7400 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7401 "0529 Failed setup of slow-path mailbox CQ: "
7402 "rc = 0x%x\n", rc);
James Smart67d12732012-08-03 12:36:13 -04007403 goto out_destroy_fcp_wq;
James Smartda0436e2009-05-22 14:51:39 -04007404 }
7405 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7406 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
7407 phba->sli4_hba.mbx_cq->queue_id,
James Smart67d12732012-08-03 12:36:13 -04007408 phba->sli4_hba.hba_eq[0]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007409
7410 /* Set up slow-path ELS Complete Queue */
7411 if (!phba->sli4_hba.els_cq) {
7412 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7413 "0530 ELS CQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007414 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007415 goto out_destroy_mbx_cq;
7416 }
James Smart67d12732012-08-03 12:36:13 -04007417 rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq,
7418 phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04007419 if (rc) {
7420 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7421 "0531 Failed setup of slow-path ELS CQ: "
7422 "rc = 0x%x\n", rc);
7423 goto out_destroy_mbx_cq;
7424 }
7425 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7426 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
7427 phba->sli4_hba.els_cq->queue_id,
James Smart67d12732012-08-03 12:36:13 -04007428 phba->sli4_hba.hba_eq[0]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007429
7430 /*
7431 * Set up all the Work Queues (WQs)
7432 */
7433
7434 /* Set up Mailbox Command Queue */
7435 if (!phba->sli4_hba.mbx_wq) {
7436 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7437 "0538 Slow-path MQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007438 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007439 goto out_destroy_els_cq;
James Smartda0436e2009-05-22 14:51:39 -04007440 }
7441 rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
7442 phba->sli4_hba.mbx_cq, LPFC_MBOX);
7443 if (rc) {
7444 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7445 "0539 Failed setup of slow-path MQ: "
7446 "rc = 0x%x\n", rc);
James Smart67d12732012-08-03 12:36:13 -04007447 goto out_destroy_els_cq;
James Smartda0436e2009-05-22 14:51:39 -04007448 }
7449 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7450 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
7451 phba->sli4_hba.mbx_wq->queue_id,
7452 phba->sli4_hba.mbx_cq->queue_id);
7453
7454 /* Set up slow-path ELS Work Queue */
7455 if (!phba->sli4_hba.els_wq) {
7456 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7457 "0536 Slow-path ELS WQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007458 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007459 goto out_destroy_mbx_wq;
7460 }
7461 rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
7462 phba->sli4_hba.els_cq, LPFC_ELS);
7463 if (rc) {
7464 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7465 "0537 Failed setup of slow-path ELS WQ: "
7466 "rc = 0x%x\n", rc);
7467 goto out_destroy_mbx_wq;
7468 }
James Smart2a76a282012-08-03 12:35:54 -04007469
7470 /* Bind this WQ to the ELS ring */
7471 pring = &psli->ring[LPFC_ELS_RING];
7472 pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq;
7473 phba->sli4_hba.els_cq->pring = pring;
7474
James Smartda0436e2009-05-22 14:51:39 -04007475 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7476 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
7477 phba->sli4_hba.els_wq->queue_id,
7478 phba->sli4_hba.els_cq->queue_id);
7479
James Smartda0436e2009-05-22 14:51:39 -04007480 /*
7481 * Create Receive Queue (RQ)
7482 */
7483 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
7484 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7485 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007486 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007487 goto out_destroy_els_wq;
James Smartda0436e2009-05-22 14:51:39 -04007488 }
James Smart73d91e52011-10-10 21:32:10 -04007489
7490 lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
7491 lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
7492
James Smartda0436e2009-05-22 14:51:39 -04007493 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04007494 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04007495 if (rc) {
7496 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7497 "0541 Failed setup of Receive Queue: "
7498 "rc = 0x%x\n", rc);
7499 goto out_destroy_fcp_wq;
7500 }
James Smart73d91e52011-10-10 21:32:10 -04007501
James Smartda0436e2009-05-22 14:51:39 -04007502 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7503 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
7504 "parent cq-id=%d\n",
7505 phba->sli4_hba.hdr_rq->queue_id,
7506 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04007507 phba->sli4_hba.els_cq->queue_id);
James Smart1ba981f2014-02-20 09:56:45 -05007508
7509 if (phba->cfg_fof) {
7510 rc = lpfc_fof_queue_setup(phba);
7511 if (rc) {
7512 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7513 "0549 Failed setup of FOF Queues: "
7514 "rc = 0x%x\n", rc);
7515 goto out_destroy_els_rq;
7516 }
7517 }
James Smartda0436e2009-05-22 14:51:39 -04007518 return 0;
7519
James Smart1ba981f2014-02-20 09:56:45 -05007520out_destroy_els_rq:
7521 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
James Smart2e90f4b2011-12-13 13:22:37 -05007522out_destroy_els_wq:
James Smartda0436e2009-05-22 14:51:39 -04007523 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7524out_destroy_mbx_wq:
7525 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
James Smart2e90f4b2011-12-13 13:22:37 -05007526out_destroy_els_cq:
James Smartda0436e2009-05-22 14:51:39 -04007527 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
7528out_destroy_mbx_cq:
7529 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
James Smart67d12732012-08-03 12:36:13 -04007530out_destroy_fcp_wq:
7531 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
7532 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
7533out_destroy_fcp_cq:
7534 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
7535 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
7536out_destroy_hba_eq:
James Smartda0436e2009-05-22 14:51:39 -04007537 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
James Smart67d12732012-08-03 12:36:13 -04007538 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]);
James Smartda0436e2009-05-22 14:51:39 -04007539out_error:
7540 return rc;
7541}
7542
7543/**
7544 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
7545 * @phba: pointer to lpfc hba data structure.
7546 *
7547 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
7548 * operation.
7549 *
7550 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007551 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007552 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007553 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007554 **/
7555void
7556lpfc_sli4_queue_unset(struct lpfc_hba *phba)
7557{
7558 int fcp_qidx;
7559
James Smart1ba981f2014-02-20 09:56:45 -05007560 /* Unset the queues created for Flash Optimized Fabric operations */
7561 if (phba->cfg_fof)
7562 lpfc_fof_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04007563 /* Unset mailbox command work queue */
7564 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
7565 /* Unset ELS work queue */
7566 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7567 /* Unset unsolicited receive queue */
7568 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
7569 /* Unset FCP work queue */
James Smart67d12732012-08-03 12:36:13 -04007570 if (phba->sli4_hba.fcp_wq) {
7571 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
7572 fcp_qidx++)
7573 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
7574 }
James Smartda0436e2009-05-22 14:51:39 -04007575 /* Unset mailbox command complete queue */
7576 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
7577 /* Unset ELS complete queue */
7578 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
James Smartda0436e2009-05-22 14:51:39 -04007579 /* Unset FCP response complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05007580 if (phba->sli4_hba.fcp_cq) {
James Smart67d12732012-08-03 12:36:13 -04007581 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
7582 fcp_qidx++)
James Smart2e90f4b2011-12-13 13:22:37 -05007583 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
James Smart2e90f4b2011-12-13 13:22:37 -05007584 }
James Smartda0436e2009-05-22 14:51:39 -04007585 /* Unset fast-path event queue */
James Smart67d12732012-08-03 12:36:13 -04007586 if (phba->sli4_hba.hba_eq) {
7587 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
James Smart2e90f4b2011-12-13 13:22:37 -05007588 fcp_qidx++)
James Smart67d12732012-08-03 12:36:13 -04007589 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_qidx]);
James Smart2e90f4b2011-12-13 13:22:37 -05007590 }
James Smartda0436e2009-05-22 14:51:39 -04007591}
7592
7593/**
7594 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
7595 * @phba: pointer to lpfc hba data structure.
7596 *
7597 * This routine is invoked to allocate and set up a pool of completion queue
7598 * events. The body of the completion queue event is a completion queue entry
7599 * CQE. For now, this pool is used for the interrupt service routine to queue
7600 * the following HBA completion queue events for the worker thread to process:
7601 * - Mailbox asynchronous events
7602 * - Receive queue completion unsolicited events
7603 * Later, this can be used for all the slow-path events.
7604 *
7605 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007606 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007607 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007608 **/
7609static int
7610lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
7611{
7612 struct lpfc_cq_event *cq_event;
7613 int i;
7614
7615 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
7616 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
7617 if (!cq_event)
7618 goto out_pool_create_fail;
7619 list_add_tail(&cq_event->list,
7620 &phba->sli4_hba.sp_cqe_event_pool);
7621 }
7622 return 0;
7623
7624out_pool_create_fail:
7625 lpfc_sli4_cq_event_pool_destroy(phba);
7626 return -ENOMEM;
7627}
7628
7629/**
7630 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
7631 * @phba: pointer to lpfc hba data structure.
7632 *
7633 * This routine is invoked to free the pool of completion queue events at
7634 * driver unload time. Note that, it is the responsibility of the driver
7635 * cleanup routine to free all the outstanding completion-queue events
7636 * allocated from this pool back into the pool before invoking this routine
7637 * to destroy the pool.
7638 **/
7639static void
7640lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
7641{
7642 struct lpfc_cq_event *cq_event, *next_cq_event;
7643
7644 list_for_each_entry_safe(cq_event, next_cq_event,
7645 &phba->sli4_hba.sp_cqe_event_pool, list) {
7646 list_del(&cq_event->list);
7647 kfree(cq_event);
7648 }
7649}
7650
7651/**
7652 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7653 * @phba: pointer to lpfc hba data structure.
7654 *
7655 * This routine is the lock free version of the API invoked to allocate a
7656 * completion-queue event from the free pool.
7657 *
7658 * Return: Pointer to the newly allocated completion-queue event if successful
7659 * NULL otherwise.
7660 **/
7661struct lpfc_cq_event *
7662__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
7663{
7664 struct lpfc_cq_event *cq_event = NULL;
7665
7666 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
7667 struct lpfc_cq_event, list);
7668 return cq_event;
7669}
7670
7671/**
7672 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7673 * @phba: pointer to lpfc hba data structure.
7674 *
7675 * This routine is the lock version of the API invoked to allocate a
7676 * completion-queue event from the free pool.
7677 *
7678 * Return: Pointer to the newly allocated completion-queue event if successful
7679 * NULL otherwise.
7680 **/
7681struct lpfc_cq_event *
7682lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
7683{
7684 struct lpfc_cq_event *cq_event;
7685 unsigned long iflags;
7686
7687 spin_lock_irqsave(&phba->hbalock, iflags);
7688 cq_event = __lpfc_sli4_cq_event_alloc(phba);
7689 spin_unlock_irqrestore(&phba->hbalock, iflags);
7690 return cq_event;
7691}
7692
7693/**
7694 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7695 * @phba: pointer to lpfc hba data structure.
7696 * @cq_event: pointer to the completion queue event to be freed.
7697 *
7698 * This routine is the lock free version of the API invoked to release a
7699 * completion-queue event back into the free pool.
7700 **/
7701void
7702__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
7703 struct lpfc_cq_event *cq_event)
7704{
7705 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
7706}
7707
7708/**
7709 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7710 * @phba: pointer to lpfc hba data structure.
7711 * @cq_event: pointer to the completion queue event to be freed.
7712 *
7713 * This routine is the lock version of the API invoked to release a
7714 * completion-queue event back into the free pool.
7715 **/
7716void
7717lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
7718 struct lpfc_cq_event *cq_event)
7719{
7720 unsigned long iflags;
7721 spin_lock_irqsave(&phba->hbalock, iflags);
7722 __lpfc_sli4_cq_event_release(phba, cq_event);
7723 spin_unlock_irqrestore(&phba->hbalock, iflags);
7724}
7725
7726/**
7727 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
7728 * @phba: pointer to lpfc hba data structure.
7729 *
7730 * This routine is to free all the pending completion-queue events to the
7731 * back into the free pool for device reset.
7732 **/
7733static void
7734lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
7735{
7736 LIST_HEAD(cqelist);
7737 struct lpfc_cq_event *cqe;
7738 unsigned long iflags;
7739
7740 /* Retrieve all the pending WCQEs from pending WCQE lists */
7741 spin_lock_irqsave(&phba->hbalock, iflags);
7742 /* Pending FCP XRI abort events */
7743 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
7744 &cqelist);
7745 /* Pending ELS XRI abort events */
7746 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
7747 &cqelist);
7748 /* Pending asynnc events */
7749 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
7750 &cqelist);
7751 spin_unlock_irqrestore(&phba->hbalock, iflags);
7752
7753 while (!list_empty(&cqelist)) {
7754 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
7755 lpfc_sli4_cq_event_release(phba, cqe);
7756 }
7757}
7758
7759/**
7760 * lpfc_pci_function_reset - Reset pci function.
7761 * @phba: pointer to lpfc hba data structure.
7762 *
7763 * This routine is invoked to request a PCI function reset. It will destroys
7764 * all resources assigned to the PCI function which originates this request.
7765 *
7766 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007767 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007768 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007769 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007770 **/
7771int
7772lpfc_pci_function_reset(struct lpfc_hba *phba)
7773{
7774 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05007775 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04007776 uint32_t shdr_status, shdr_add_status;
James Smart2fcee4b2010-12-15 17:57:46 -05007777 uint32_t rdy_chk, num_resets = 0, reset_again = 0;
James Smartda0436e2009-05-22 14:51:39 -04007778 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05007779 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -05007780 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -04007781
James Smart2fcee4b2010-12-15 17:57:46 -05007782 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7783 switch (if_type) {
7784 case LPFC_SLI_INTF_IF_TYPE_0:
7785 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7786 GFP_KERNEL);
7787 if (!mboxq) {
7788 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7789 "0494 Unable to allocate memory for "
7790 "issuing SLI_FUNCTION_RESET mailbox "
7791 "command\n");
7792 return -ENOMEM;
7793 }
7794
7795 /* Setup PCI function reset mailbox-ioctl command */
7796 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
7797 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
7798 LPFC_SLI4_MBX_EMBED);
7799 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7800 shdr = (union lpfc_sli4_cfg_shdr *)
7801 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
7802 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7803 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
7804 &shdr->response);
7805 if (rc != MBX_TIMEOUT)
7806 mempool_free(mboxq, phba->mbox_mem_pool);
7807 if (shdr_status || shdr_add_status || rc) {
7808 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7809 "0495 SLI_FUNCTION_RESET mailbox "
7810 "failed with status x%x add_status x%x,"
7811 " mbx status x%x\n",
7812 shdr_status, shdr_add_status, rc);
7813 rc = -ENXIO;
7814 }
7815 break;
7816 case LPFC_SLI_INTF_IF_TYPE_2:
7817 for (num_resets = 0;
7818 num_resets < MAX_IF_TYPE_2_RESETS;
7819 num_resets++) {
7820 reg_data.word0 = 0;
7821 bf_set(lpfc_sliport_ctrl_end, &reg_data,
7822 LPFC_SLIPORT_LITTLE_ENDIAN);
7823 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
7824 LPFC_SLIPORT_INIT_PORT);
7825 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
7826 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -05007827 /* flush */
James Smart2b81f942012-03-01 22:37:18 -05007828 pci_read_config_word(phba->pcidev,
7829 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -05007830 /*
7831 * Poll the Port Status Register and wait for RDY for
7832 * up to 10 seconds. If the port doesn't respond, treat
7833 * it as an error. If the port responds with RN, start
7834 * the loop again.
7835 */
7836 for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) {
James Smart73d91e52011-10-10 21:32:10 -04007837 msleep(10);
James Smart9940b972011-03-11 16:06:12 -05007838 if (lpfc_readl(phba->sli4_hba.u.if_type2.
7839 STATUSregaddr, &reg_data.word0)) {
7840 rc = -ENODEV;
James Smart73d91e52011-10-10 21:32:10 -04007841 goto out;
James Smart9940b972011-03-11 16:06:12 -05007842 }
James Smart6b5151f2012-01-18 16:24:06 -05007843 if (bf_get(lpfc_sliport_status_rn, &reg_data))
7844 reset_again++;
James Smart2fcee4b2010-12-15 17:57:46 -05007845 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
7846 break;
James Smart2fcee4b2010-12-15 17:57:46 -05007847 }
7848
7849 /*
7850 * If the port responds to the init request with
7851 * reset needed, delay for a bit and restart the loop.
7852 */
James Smart6b5151f2012-01-18 16:24:06 -05007853 if (reset_again && (rdy_chk < 1000)) {
James Smart2fcee4b2010-12-15 17:57:46 -05007854 msleep(10);
7855 reset_again = 0;
7856 continue;
7857 }
7858
7859 /* Detect any port errors. */
James Smart2fcee4b2010-12-15 17:57:46 -05007860 if ((bf_get(lpfc_sliport_status_err, &reg_data)) ||
7861 (rdy_chk >= 1000)) {
7862 phba->work_status[0] = readl(
7863 phba->sli4_hba.u.if_type2.ERR1regaddr);
7864 phba->work_status[1] = readl(
7865 phba->sli4_hba.u.if_type2.ERR2regaddr);
7866 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05007867 "2890 Port error detected during port "
James Smart8a9d2e82012-05-09 21:16:12 -04007868 "reset(%d): wait_tmo:%d ms, "
7869 "port status reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05007870 "error 1=0x%x, error 2=0x%x\n",
James Smart8a9d2e82012-05-09 21:16:12 -04007871 num_resets, rdy_chk*10,
7872 reg_data.word0,
James Smart2fcee4b2010-12-15 17:57:46 -05007873 phba->work_status[0],
7874 phba->work_status[1]);
7875 rc = -ENODEV;
7876 }
7877
7878 /*
7879 * Terminate the outer loop provided the Port indicated
7880 * ready within 10 seconds.
7881 */
7882 if (rdy_chk < 1000)
7883 break;
7884 }
James Smart05580562011-05-24 11:40:48 -04007885 /* delay driver action following IF_TYPE_2 function reset */
7886 msleep(100);
James Smart2fcee4b2010-12-15 17:57:46 -05007887 break;
7888 case LPFC_SLI_INTF_IF_TYPE_1:
7889 default:
7890 break;
James Smartda0436e2009-05-22 14:51:39 -04007891 }
7892
James Smart73d91e52011-10-10 21:32:10 -04007893out:
James Smart2fcee4b2010-12-15 17:57:46 -05007894 /* Catch the not-ready port failure after a port reset. */
James Smart229adb02013-04-17 20:16:51 -04007895 if (num_resets >= MAX_IF_TYPE_2_RESETS) {
7896 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7897 "3317 HBA not functional: IP Reset Failed "
7898 "after (%d) retries, try: "
7899 "echo fw_reset > board_mode\n", num_resets);
James Smart2fcee4b2010-12-15 17:57:46 -05007900 rc = -ENODEV;
James Smart229adb02013-04-17 20:16:51 -04007901 }
James Smart2fcee4b2010-12-15 17:57:46 -05007902
James Smartda0436e2009-05-22 14:51:39 -04007903 return rc;
7904}
7905
7906/**
James Smartda0436e2009-05-22 14:51:39 -04007907 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
7908 * @phba: pointer to lpfc hba data structure.
7909 *
7910 * This routine is invoked to set up the PCI device memory space for device
7911 * with SLI-4 interface spec.
7912 *
7913 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007914 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04007915 * other values - error
7916 **/
7917static int
7918lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
7919{
7920 struct pci_dev *pdev;
7921 unsigned long bar0map_len, bar1map_len, bar2map_len;
7922 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05007923 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04007924
7925 /* Obtain PCI device reference */
7926 if (!phba->pcidev)
7927 return error;
7928 else
7929 pdev = phba->pcidev;
7930
7931 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05007932 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
7933 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
7934 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
7935 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smartda0436e2009-05-22 14:51:39 -04007936 return error;
Michael Reed8e685972009-09-18 12:02:05 -05007937 }
7938 }
James Smartda0436e2009-05-22 14:51:39 -04007939
James Smart2fcee4b2010-12-15 17:57:46 -05007940 /*
7941 * The BARs and register set definitions and offset locations are
7942 * dependent on the if_type.
7943 */
7944 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
7945 &phba->sli4_hba.sli_intf.word0)) {
7946 return error;
7947 }
7948
7949 /* There is no SLI3 failback for SLI4 devices. */
7950 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
7951 LPFC_SLI_INTF_VALID) {
7952 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7953 "2894 SLI_INTF reg contents invalid "
7954 "sli_intf reg 0x%x\n",
7955 phba->sli4_hba.sli_intf.word0);
7956 return error;
7957 }
7958
7959 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7960 /*
7961 * Get the bus address of SLI4 device Bar regions and the
7962 * number of bytes required by each mapping. The mapping of the
7963 * particular PCI BARs regions is dependent on the type of
7964 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04007965 */
James Smartf5ca6f22013-09-06 12:21:09 -04007966 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
7967 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
7968 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
James Smart2fcee4b2010-12-15 17:57:46 -05007969
7970 /*
7971 * Map SLI4 PCI Config Space Register base to a kernel virtual
7972 * addr
7973 */
7974 phba->sli4_hba.conf_regs_memmap_p =
7975 ioremap(phba->pci_bar0_map, bar0map_len);
7976 if (!phba->sli4_hba.conf_regs_memmap_p) {
7977 dev_printk(KERN_ERR, &pdev->dev,
7978 "ioremap failed for SLI4 PCI config "
7979 "registers.\n");
7980 goto out;
7981 }
James Smartf5ca6f22013-09-06 12:21:09 -04007982 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05007983 /* Set up BAR0 PCI config space register memory map */
7984 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05007985 } else {
7986 phba->pci_bar0_map = pci_resource_start(pdev, 1);
7987 bar0map_len = pci_resource_len(pdev, 1);
James Smart2fcee4b2010-12-15 17:57:46 -05007988 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
7989 dev_printk(KERN_ERR, &pdev->dev,
7990 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
7991 goto out;
7992 }
7993 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04007994 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05007995 if (!phba->sli4_hba.conf_regs_memmap_p) {
7996 dev_printk(KERN_ERR, &pdev->dev,
7997 "ioremap failed for SLI4 PCI config "
7998 "registers.\n");
7999 goto out;
8000 }
8001 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04008002 }
8003
James Smartc31098c2011-04-16 11:03:33 -04008004 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04008005 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
James Smart2fcee4b2010-12-15 17:57:46 -05008006 /*
8007 * Map SLI4 if type 0 HBA Control Register base to a kernel
8008 * virtual address and setup the registers.
8009 */
James Smartf5ca6f22013-09-06 12:21:09 -04008010 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
8011 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
James Smart2fcee4b2010-12-15 17:57:46 -05008012 phba->sli4_hba.ctrl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008013 ioremap(phba->pci_bar1_map, bar1map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008014 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
8015 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04008016 "ioremap failed for SLI4 HBA control registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008017 goto out_iounmap_conf;
8018 }
James Smartf5ca6f22013-09-06 12:21:09 -04008019 phba->pci_bar2_memmap_p = phba->sli4_hba.ctrl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008020 lpfc_sli4_bar1_register_memmap(phba);
James Smartda0436e2009-05-22 14:51:39 -04008021 }
8022
James Smartc31098c2011-04-16 11:03:33 -04008023 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04008024 (pci_resource_start(pdev, PCI_64BIT_BAR4))) {
James Smart2fcee4b2010-12-15 17:57:46 -05008025 /*
8026 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
8027 * virtual address and setup the registers.
8028 */
James Smartf5ca6f22013-09-06 12:21:09 -04008029 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
8030 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
James Smart2fcee4b2010-12-15 17:57:46 -05008031 phba->sli4_hba.drbl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008032 ioremap(phba->pci_bar2_map, bar2map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008033 if (!phba->sli4_hba.drbl_regs_memmap_p) {
8034 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04008035 "ioremap failed for SLI4 HBA doorbell registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008036 goto out_iounmap_ctrl;
8037 }
James Smartf5ca6f22013-09-06 12:21:09 -04008038 phba->pci_bar4_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008039 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
8040 if (error)
8041 goto out_iounmap_all;
James Smartda0436e2009-05-22 14:51:39 -04008042 }
8043
James Smartda0436e2009-05-22 14:51:39 -04008044 return 0;
8045
8046out_iounmap_all:
8047 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
8048out_iounmap_ctrl:
8049 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
8050out_iounmap_conf:
8051 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8052out:
8053 return error;
8054}
8055
8056/**
8057 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
8058 * @phba: pointer to lpfc hba data structure.
8059 *
8060 * This routine is invoked to unset the PCI device memory space for device
8061 * with SLI-4 interface spec.
8062 **/
8063static void
8064lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
8065{
James Smart2e90f4b2011-12-13 13:22:37 -05008066 uint32_t if_type;
8067 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -04008068
James Smart2e90f4b2011-12-13 13:22:37 -05008069 switch (if_type) {
8070 case LPFC_SLI_INTF_IF_TYPE_0:
8071 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
8072 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
8073 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8074 break;
8075 case LPFC_SLI_INTF_IF_TYPE_2:
8076 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8077 break;
8078 case LPFC_SLI_INTF_IF_TYPE_1:
8079 default:
8080 dev_printk(KERN_ERR, &phba->pcidev->dev,
8081 "FATAL - unsupported SLI4 interface type - %d\n",
8082 if_type);
8083 break;
8084 }
James Smartda0436e2009-05-22 14:51:39 -04008085}
8086
8087/**
James Smart3772a992009-05-22 14:50:54 -04008088 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
8089 * @phba: pointer to lpfc hba data structure.
8090 *
8091 * This routine is invoked to enable the MSI-X interrupt vectors to device
8092 * with SLI-3 interface specs. The kernel function pci_enable_msix() is
8093 * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
8094 * invoked, enables either all or nothing, depending on the current
8095 * availability of PCI vector resources. The device driver is responsible
8096 * for calling the individual request_irq() to register each MSI-X vector
8097 * with a interrupt handler, which is done in this function. Note that
8098 * later when device is unloading, the driver should always call free_irq()
8099 * on all MSI-X vectors it has done request_irq() on before calling
8100 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
8101 * will be left with MSI-X enabled and leaks its vectors.
8102 *
8103 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008104 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008105 * other values - error
8106 **/
8107static int
8108lpfc_sli_enable_msix(struct lpfc_hba *phba)
8109{
8110 int rc, i;
8111 LPFC_MBOXQ_t *pmb;
8112
8113 /* Set up MSI-X multi-message vectors */
8114 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8115 phba->msix_entries[i].entry = i;
8116
8117 /* Configure MSI-X capability structure */
8118 rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
8119 ARRAY_SIZE(phba->msix_entries));
8120 if (rc) {
8121 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8122 "0420 PCI enable MSI-X failed (%d)\n", rc);
8123 goto msi_fail_out;
8124 }
8125 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8126 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8127 "0477 MSI-X entry[%d]: vector=x%x "
8128 "message=%d\n", i,
8129 phba->msix_entries[i].vector,
8130 phba->msix_entries[i].entry);
8131 /*
8132 * Assign MSI-X vectors to interrupt handlers
8133 */
8134
8135 /* vector-0 is associated to slow-path handler */
8136 rc = request_irq(phba->msix_entries[0].vector,
8137 &lpfc_sli_sp_intr_handler, IRQF_SHARED,
8138 LPFC_SP_DRIVER_HANDLER_NAME, phba);
8139 if (rc) {
8140 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8141 "0421 MSI-X slow-path request_irq failed "
8142 "(%d)\n", rc);
8143 goto msi_fail_out;
8144 }
8145
8146 /* vector-1 is associated to fast-path handler */
8147 rc = request_irq(phba->msix_entries[1].vector,
8148 &lpfc_sli_fp_intr_handler, IRQF_SHARED,
8149 LPFC_FP_DRIVER_HANDLER_NAME, phba);
8150
8151 if (rc) {
8152 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8153 "0429 MSI-X fast-path request_irq failed "
8154 "(%d)\n", rc);
8155 goto irq_fail_out;
8156 }
8157
8158 /*
8159 * Configure HBA MSI-X attention conditions to messages
8160 */
8161 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8162
8163 if (!pmb) {
8164 rc = -ENOMEM;
8165 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8166 "0474 Unable to allocate memory for issuing "
8167 "MBOX_CONFIG_MSI command\n");
8168 goto mem_fail_out;
8169 }
8170 rc = lpfc_config_msi(phba, pmb);
8171 if (rc)
8172 goto mbx_fail_out;
8173 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
8174 if (rc != MBX_SUCCESS) {
8175 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
8176 "0351 Config MSI mailbox command failed, "
8177 "mbxCmd x%x, mbxStatus x%x\n",
8178 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
8179 goto mbx_fail_out;
8180 }
8181
8182 /* Free memory allocated for mailbox command */
8183 mempool_free(pmb, phba->mbox_mem_pool);
8184 return rc;
8185
8186mbx_fail_out:
8187 /* Free memory allocated for mailbox command */
8188 mempool_free(pmb, phba->mbox_mem_pool);
8189
8190mem_fail_out:
8191 /* free the irq already requested */
8192 free_irq(phba->msix_entries[1].vector, phba);
8193
8194irq_fail_out:
8195 /* free the irq already requested */
8196 free_irq(phba->msix_entries[0].vector, phba);
8197
8198msi_fail_out:
8199 /* Unconfigure MSI-X capability structure */
8200 pci_disable_msix(phba->pcidev);
8201 return rc;
8202}
8203
8204/**
8205 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
8206 * @phba: pointer to lpfc hba data structure.
8207 *
8208 * This routine is invoked to release the MSI-X vectors and then disable the
8209 * MSI-X interrupt mode to device with SLI-3 interface spec.
8210 **/
8211static void
8212lpfc_sli_disable_msix(struct lpfc_hba *phba)
8213{
8214 int i;
8215
8216 /* Free up MSI-X multi-message vectors */
8217 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8218 free_irq(phba->msix_entries[i].vector, phba);
8219 /* Disable MSI-X */
8220 pci_disable_msix(phba->pcidev);
8221
8222 return;
8223}
8224
8225/**
8226 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
8227 * @phba: pointer to lpfc hba data structure.
8228 *
8229 * This routine is invoked to enable the MSI interrupt mode to device with
8230 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
8231 * enable the MSI vector. The device driver is responsible for calling the
8232 * request_irq() to register MSI vector with a interrupt the handler, which
8233 * is done in this function.
8234 *
8235 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008236 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008237 * other values - error
8238 */
8239static int
8240lpfc_sli_enable_msi(struct lpfc_hba *phba)
8241{
8242 int rc;
8243
8244 rc = pci_enable_msi(phba->pcidev);
8245 if (!rc)
8246 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8247 "0462 PCI enable MSI mode success.\n");
8248 else {
8249 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8250 "0471 PCI enable MSI mode failed (%d)\n", rc);
8251 return rc;
8252 }
8253
8254 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
8255 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8256 if (rc) {
8257 pci_disable_msi(phba->pcidev);
8258 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8259 "0478 MSI request_irq failed (%d)\n", rc);
8260 }
8261 return rc;
8262}
8263
8264/**
8265 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
8266 * @phba: pointer to lpfc hba data structure.
8267 *
8268 * This routine is invoked to disable the MSI interrupt mode to device with
8269 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
8270 * done request_irq() on before calling pci_disable_msi(). Failure to do so
8271 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
8272 * its vector.
8273 */
8274static void
8275lpfc_sli_disable_msi(struct lpfc_hba *phba)
8276{
8277 free_irq(phba->pcidev->irq, phba);
8278 pci_disable_msi(phba->pcidev);
8279 return;
8280}
8281
8282/**
8283 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
8284 * @phba: pointer to lpfc hba data structure.
8285 *
8286 * This routine is invoked to enable device interrupt and associate driver's
8287 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
8288 * spec. Depends on the interrupt mode configured to the driver, the driver
8289 * will try to fallback from the configured interrupt mode to an interrupt
8290 * mode which is supported by the platform, kernel, and device in the order
8291 * of:
8292 * MSI-X -> MSI -> IRQ.
8293 *
8294 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008295 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008296 * other values - error
8297 **/
8298static uint32_t
8299lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
8300{
8301 uint32_t intr_mode = LPFC_INTR_ERROR;
8302 int retval;
8303
8304 if (cfg_mode == 2) {
8305 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
8306 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
8307 if (!retval) {
8308 /* Now, try to enable MSI-X interrupt mode */
8309 retval = lpfc_sli_enable_msix(phba);
8310 if (!retval) {
8311 /* Indicate initialization to MSI-X mode */
8312 phba->intr_type = MSIX;
8313 intr_mode = 2;
8314 }
8315 }
8316 }
8317
8318 /* Fallback to MSI if MSI-X initialization failed */
8319 if (cfg_mode >= 1 && phba->intr_type == NONE) {
8320 retval = lpfc_sli_enable_msi(phba);
8321 if (!retval) {
8322 /* Indicate initialization to MSI mode */
8323 phba->intr_type = MSI;
8324 intr_mode = 1;
8325 }
8326 }
8327
8328 /* Fallback to INTx if both MSI-X/MSI initalization failed */
8329 if (phba->intr_type == NONE) {
8330 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
8331 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8332 if (!retval) {
8333 /* Indicate initialization to INTx mode */
8334 phba->intr_type = INTx;
8335 intr_mode = 0;
8336 }
8337 }
8338 return intr_mode;
8339}
8340
8341/**
8342 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
8343 * @phba: pointer to lpfc hba data structure.
8344 *
8345 * This routine is invoked to disable device interrupt and disassociate the
8346 * driver's interrupt handler(s) from interrupt vector(s) to device with
8347 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
8348 * release the interrupt vector(s) for the message signaled interrupt.
8349 **/
8350static void
8351lpfc_sli_disable_intr(struct lpfc_hba *phba)
8352{
8353 /* Disable the currently initialized interrupt mode */
8354 if (phba->intr_type == MSIX)
8355 lpfc_sli_disable_msix(phba);
8356 else if (phba->intr_type == MSI)
8357 lpfc_sli_disable_msi(phba);
8358 else if (phba->intr_type == INTx)
8359 free_irq(phba->pcidev->irq, phba);
8360
8361 /* Reset interrupt management states */
8362 phba->intr_type = NONE;
8363 phba->sli.slistat.sli_intr = 0;
8364
8365 return;
8366}
8367
8368/**
James Smart7bb03bb2013-04-17 20:19:16 -04008369 * lpfc_find_next_cpu - Find next available CPU that matches the phys_id
8370 * @phba: pointer to lpfc hba data structure.
8371 *
8372 * Find next available CPU to use for IRQ to CPU affinity.
8373 */
8374static int
8375lpfc_find_next_cpu(struct lpfc_hba *phba, uint32_t phys_id)
8376{
8377 struct lpfc_vector_map_info *cpup;
8378 int cpu;
8379
8380 cpup = phba->sli4_hba.cpu_map;
8381 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8382 /* CPU must be online */
8383 if (cpu_online(cpu)) {
8384 if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
8385 (lpfc_used_cpu[cpu] == LPFC_VECTOR_MAP_EMPTY) &&
8386 (cpup->phys_id == phys_id)) {
8387 return cpu;
8388 }
8389 }
8390 cpup++;
8391 }
8392
8393 /*
8394 * If we get here, we have used ALL CPUs for the specific
8395 * phys_id. Now we need to clear out lpfc_used_cpu and start
8396 * reusing CPUs.
8397 */
8398
8399 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8400 if (lpfc_used_cpu[cpu] == phys_id)
8401 lpfc_used_cpu[cpu] = LPFC_VECTOR_MAP_EMPTY;
8402 }
8403
8404 cpup = phba->sli4_hba.cpu_map;
8405 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8406 /* CPU must be online */
8407 if (cpu_online(cpu)) {
8408 if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
8409 (cpup->phys_id == phys_id)) {
8410 return cpu;
8411 }
8412 }
8413 cpup++;
8414 }
8415 return LPFC_VECTOR_MAP_EMPTY;
8416}
8417
8418/**
8419 * lpfc_sli4_set_affinity - Set affinity for HBA IRQ vectors
8420 * @phba: pointer to lpfc hba data structure.
8421 * @vectors: number of HBA vectors
8422 *
8423 * Affinitize MSIX IRQ vectors to CPUs. Try to equally spread vector
8424 * affinization across multple physical CPUs (numa nodes).
8425 * In addition, this routine will assign an IO channel for each CPU
8426 * to use when issuing I/Os.
8427 */
8428static int
8429lpfc_sli4_set_affinity(struct lpfc_hba *phba, int vectors)
8430{
8431 int i, idx, saved_chann, used_chann, cpu, phys_id;
James Smartec2087a2013-09-06 12:20:36 -04008432 int max_phys_id, min_phys_id;
8433 int num_io_channel, first_cpu, chan;
James Smart7bb03bb2013-04-17 20:19:16 -04008434 struct lpfc_vector_map_info *cpup;
8435#ifdef CONFIG_X86
8436 struct cpuinfo_x86 *cpuinfo;
8437#endif
8438 struct cpumask *mask;
8439 uint8_t chann[LPFC_FCP_IO_CHAN_MAX+1];
8440
8441 /* If there is no mapping, just return */
8442 if (!phba->cfg_fcp_cpu_map)
8443 return 1;
8444
8445 /* Init cpu_map array */
8446 memset(phba->sli4_hba.cpu_map, 0xff,
8447 (sizeof(struct lpfc_vector_map_info) *
8448 phba->sli4_hba.num_present_cpu));
8449
8450 max_phys_id = 0;
James Smartec2087a2013-09-06 12:20:36 -04008451 min_phys_id = 0xff;
James Smart7bb03bb2013-04-17 20:19:16 -04008452 phys_id = 0;
8453 num_io_channel = 0;
8454 first_cpu = LPFC_VECTOR_MAP_EMPTY;
8455
8456 /* Update CPU map with physical id and core id of each CPU */
8457 cpup = phba->sli4_hba.cpu_map;
8458 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8459#ifdef CONFIG_X86
8460 cpuinfo = &cpu_data(cpu);
8461 cpup->phys_id = cpuinfo->phys_proc_id;
8462 cpup->core_id = cpuinfo->cpu_core_id;
8463#else
8464 /* No distinction between CPUs for other platforms */
8465 cpup->phys_id = 0;
8466 cpup->core_id = 0;
8467#endif
8468
8469 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8470 "3328 CPU physid %d coreid %d\n",
8471 cpup->phys_id, cpup->core_id);
8472
8473 if (cpup->phys_id > max_phys_id)
8474 max_phys_id = cpup->phys_id;
James Smartec2087a2013-09-06 12:20:36 -04008475 if (cpup->phys_id < min_phys_id)
8476 min_phys_id = cpup->phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008477 cpup++;
8478 }
8479
James Smartec2087a2013-09-06 12:20:36 -04008480 phys_id = min_phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008481 /* Now associate the HBA vectors with specific CPUs */
8482 for (idx = 0; idx < vectors; idx++) {
8483 cpup = phba->sli4_hba.cpu_map;
8484 cpu = lpfc_find_next_cpu(phba, phys_id);
8485 if (cpu == LPFC_VECTOR_MAP_EMPTY) {
8486
8487 /* Try for all phys_id's */
8488 for (i = 1; i < max_phys_id; i++) {
8489 phys_id++;
8490 if (phys_id > max_phys_id)
James Smartec2087a2013-09-06 12:20:36 -04008491 phys_id = min_phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008492 cpu = lpfc_find_next_cpu(phba, phys_id);
8493 if (cpu == LPFC_VECTOR_MAP_EMPTY)
8494 continue;
8495 goto found;
8496 }
8497
James Smartec2087a2013-09-06 12:20:36 -04008498 /* Use round robin for scheduling */
8499 phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_ROUND_ROBIN;
8500 chan = 0;
8501 cpup = phba->sli4_hba.cpu_map;
8502 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
8503 cpup->channel_id = chan;
8504 cpup++;
8505 chan++;
8506 if (chan >= phba->cfg_fcp_io_channel)
8507 chan = 0;
8508 }
8509
James Smart7bb03bb2013-04-17 20:19:16 -04008510 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8511 "3329 Cannot set affinity:"
8512 "Error mapping vector %d (%d)\n",
8513 idx, vectors);
8514 return 0;
8515 }
8516found:
8517 cpup += cpu;
8518 if (phba->cfg_fcp_cpu_map == LPFC_DRIVER_CPU_MAP)
8519 lpfc_used_cpu[cpu] = phys_id;
8520
8521 /* Associate vector with selected CPU */
8522 cpup->irq = phba->sli4_hba.msix_entries[idx].vector;
8523
8524 /* Associate IO channel with selected CPU */
8525 cpup->channel_id = idx;
8526 num_io_channel++;
8527
8528 if (first_cpu == LPFC_VECTOR_MAP_EMPTY)
8529 first_cpu = cpu;
8530
8531 /* Now affinitize to the selected CPU */
8532 mask = &cpup->maskbits;
8533 cpumask_clear(mask);
8534 cpumask_set_cpu(cpu, mask);
8535 i = irq_set_affinity_hint(phba->sli4_hba.msix_entries[idx].
8536 vector, mask);
8537
8538 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8539 "3330 Set Affinity: CPU %d channel %d "
8540 "irq %d (%x)\n",
8541 cpu, cpup->channel_id,
8542 phba->sli4_hba.msix_entries[idx].vector, i);
8543
8544 /* Spread vector mapping across multple physical CPU nodes */
8545 phys_id++;
8546 if (phys_id > max_phys_id)
James Smartec2087a2013-09-06 12:20:36 -04008547 phys_id = min_phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008548 }
8549
8550 /*
8551 * Finally fill in the IO channel for any remaining CPUs.
8552 * At this point, all IO channels have been assigned to a specific
8553 * MSIx vector, mapped to a specific CPU.
8554 * Base the remaining IO channel assigned, to IO channels already
8555 * assigned to other CPUs on the same phys_id.
8556 */
James Smartec2087a2013-09-06 12:20:36 -04008557 for (i = min_phys_id; i <= max_phys_id; i++) {
James Smart7bb03bb2013-04-17 20:19:16 -04008558 /*
8559 * If there are no io channels already mapped to
8560 * this phys_id, just round robin thru the io_channels.
8561 * Setup chann[] for round robin.
8562 */
8563 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
8564 chann[idx] = idx;
8565
8566 saved_chann = 0;
8567 used_chann = 0;
8568
8569 /*
8570 * First build a list of IO channels already assigned
8571 * to this phys_id before reassigning the same IO
8572 * channels to the remaining CPUs.
8573 */
8574 cpup = phba->sli4_hba.cpu_map;
8575 cpu = first_cpu;
8576 cpup += cpu;
8577 for (idx = 0; idx < phba->sli4_hba.num_present_cpu;
8578 idx++) {
8579 if (cpup->phys_id == i) {
8580 /*
8581 * Save any IO channels that are
8582 * already mapped to this phys_id.
8583 */
8584 if (cpup->irq != LPFC_VECTOR_MAP_EMPTY) {
8585 chann[saved_chann] =
8586 cpup->channel_id;
8587 saved_chann++;
8588 goto out;
8589 }
8590
8591 /* See if we are using round-robin */
8592 if (saved_chann == 0)
8593 saved_chann =
8594 phba->cfg_fcp_io_channel;
8595
8596 /* Associate next IO channel with CPU */
8597 cpup->channel_id = chann[used_chann];
8598 num_io_channel++;
8599 used_chann++;
8600 if (used_chann == saved_chann)
8601 used_chann = 0;
8602
8603 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8604 "3331 Set IO_CHANN "
8605 "CPU %d channel %d\n",
8606 idx, cpup->channel_id);
8607 }
8608out:
8609 cpu++;
8610 if (cpu >= phba->sli4_hba.num_present_cpu) {
8611 cpup = phba->sli4_hba.cpu_map;
8612 cpu = 0;
8613 } else {
8614 cpup++;
8615 }
8616 }
8617 }
8618
8619 if (phba->sli4_hba.num_online_cpu != phba->sli4_hba.num_present_cpu) {
8620 cpup = phba->sli4_hba.cpu_map;
8621 for (idx = 0; idx < phba->sli4_hba.num_present_cpu; idx++) {
8622 if (cpup->channel_id == LPFC_VECTOR_MAP_EMPTY) {
8623 cpup->channel_id = 0;
8624 num_io_channel++;
8625
8626 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8627 "3332 Assign IO_CHANN "
8628 "CPU %d channel %d\n",
8629 idx, cpup->channel_id);
8630 }
8631 cpup++;
8632 }
8633 }
8634
8635 /* Sanity check */
8636 if (num_io_channel != phba->sli4_hba.num_present_cpu)
8637 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8638 "3333 Set affinity mismatch:"
James Smartec2087a2013-09-06 12:20:36 -04008639 "%d chann != %d cpus: %d vectors\n",
James Smart7bb03bb2013-04-17 20:19:16 -04008640 num_io_channel, phba->sli4_hba.num_present_cpu,
8641 vectors);
8642
James Smartec2087a2013-09-06 12:20:36 -04008643 /* Enable using cpu affinity for scheduling */
James Smart7bb03bb2013-04-17 20:19:16 -04008644 phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_BY_CPU;
8645 return 1;
8646}
8647
8648
8649/**
James Smartda0436e2009-05-22 14:51:39 -04008650 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
8651 * @phba: pointer to lpfc hba data structure.
8652 *
8653 * This routine is invoked to enable the MSI-X interrupt vectors to device
8654 * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
8655 * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
8656 * enables either all or nothing, depending on the current availability of
8657 * PCI vector resources. The device driver is responsible for calling the
8658 * individual request_irq() to register each MSI-X vector with a interrupt
8659 * handler, which is done in this function. Note that later when device is
8660 * unloading, the driver should always call free_irq() on all MSI-X vectors
8661 * it has done request_irq() on before calling pci_disable_msix(). Failure
8662 * to do so results in a BUG_ON() and a device will be left with MSI-X
8663 * enabled and leaks its vectors.
8664 *
8665 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008666 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008667 * other values - error
8668 **/
8669static int
8670lpfc_sli4_enable_msix(struct lpfc_hba *phba)
8671{
James Smart75baf692010-06-08 18:31:21 -04008672 int vectors, rc, index;
James Smartda0436e2009-05-22 14:51:39 -04008673
8674 /* Set up MSI-X multi-message vectors */
James Smart82c3e9b2012-09-29 11:29:50 -04008675 for (index = 0; index < phba->cfg_fcp_io_channel; index++)
James Smartda0436e2009-05-22 14:51:39 -04008676 phba->sli4_hba.msix_entries[index].entry = index;
8677
8678 /* Configure MSI-X capability structure */
James Smart82c3e9b2012-09-29 11:29:50 -04008679 vectors = phba->cfg_fcp_io_channel;
James Smart1ba981f2014-02-20 09:56:45 -05008680 if (phba->cfg_fof) {
8681 phba->sli4_hba.msix_entries[index].entry = index;
8682 vectors++;
8683 }
James Smart75baf692010-06-08 18:31:21 -04008684enable_msix_vectors:
James Smartda0436e2009-05-22 14:51:39 -04008685 rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries,
James Smart75baf692010-06-08 18:31:21 -04008686 vectors);
8687 if (rc > 1) {
8688 vectors = rc;
8689 goto enable_msix_vectors;
8690 } else if (rc) {
James Smartda0436e2009-05-22 14:51:39 -04008691 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8692 "0484 PCI enable MSI-X failed (%d)\n", rc);
8693 goto msi_fail_out;
8694 }
James Smart75baf692010-06-08 18:31:21 -04008695
James Smartda0436e2009-05-22 14:51:39 -04008696 /* Log MSI-X vector assignment */
James Smart75baf692010-06-08 18:31:21 -04008697 for (index = 0; index < vectors; index++)
James Smartda0436e2009-05-22 14:51:39 -04008698 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8699 "0489 MSI-X entry[%d]: vector=x%x "
8700 "message=%d\n", index,
8701 phba->sli4_hba.msix_entries[index].vector,
8702 phba->sli4_hba.msix_entries[index].entry);
James Smart67d12732012-08-03 12:36:13 -04008703
James Smart7bb03bb2013-04-17 20:19:16 -04008704 /* Assign MSI-X vectors to interrupt handlers */
James Smart67d12732012-08-03 12:36:13 -04008705 for (index = 0; index < vectors; index++) {
James Smart4305f182012-08-03 12:36:33 -04008706 memset(&phba->sli4_hba.handler_name[index], 0, 16);
8707 sprintf((char *)&phba->sli4_hba.handler_name[index],
8708 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -04008709
James Smart67d12732012-08-03 12:36:13 -04008710 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
8711 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
James Smartba20c852012-08-03 12:36:52 -04008712 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].fcp_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -05008713 if (phba->cfg_fof && (index == (vectors - 1)))
8714 rc = request_irq(
8715 phba->sli4_hba.msix_entries[index].vector,
8716 &lpfc_sli4_fof_intr_handler, IRQF_SHARED,
8717 (char *)&phba->sli4_hba.handler_name[index],
8718 &phba->sli4_hba.fcp_eq_hdl[index]);
8719 else
8720 rc = request_irq(
8721 phba->sli4_hba.msix_entries[index].vector,
James Smart67d12732012-08-03 12:36:13 -04008722 &lpfc_sli4_hba_intr_handler, IRQF_SHARED,
James Smart4305f182012-08-03 12:36:33 -04008723 (char *)&phba->sli4_hba.handler_name[index],
James Smart67d12732012-08-03 12:36:13 -04008724 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -04008725 if (rc) {
8726 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8727 "0486 MSI-X fast-path (%d) "
8728 "request_irq failed (%d)\n", index, rc);
8729 goto cfg_fail_out;
8730 }
8731 }
8732
James Smart1ba981f2014-02-20 09:56:45 -05008733 if (phba->cfg_fof)
8734 vectors--;
8735
James Smart82c3e9b2012-09-29 11:29:50 -04008736 if (vectors != phba->cfg_fcp_io_channel) {
8737 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8738 "3238 Reducing IO channels to match number of "
8739 "MSI-X vectors, requested %d got %d\n",
8740 phba->cfg_fcp_io_channel, vectors);
8741 phba->cfg_fcp_io_channel = vectors;
8742 }
James Smart7bb03bb2013-04-17 20:19:16 -04008743
8744 lpfc_sli4_set_affinity(phba, vectors);
James Smartda0436e2009-05-22 14:51:39 -04008745 return rc;
8746
8747cfg_fail_out:
8748 /* free the irq already requested */
James Smartacbd8612013-09-06 12:21:19 -04008749 for (--index; index >= 0; index--) {
8750 irq_set_affinity_hint(phba->sli4_hba.msix_entries[index].
8751 vector, NULL);
James Smart67d12732012-08-03 12:36:13 -04008752 free_irq(phba->sli4_hba.msix_entries[index].vector,
8753 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartacbd8612013-09-06 12:21:19 -04008754 }
James Smartda0436e2009-05-22 14:51:39 -04008755
8756msi_fail_out:
8757 /* Unconfigure MSI-X capability structure */
8758 pci_disable_msix(phba->pcidev);
8759 return rc;
8760}
8761
8762/**
8763 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
8764 * @phba: pointer to lpfc hba data structure.
8765 *
8766 * This routine is invoked to release the MSI-X vectors and then disable the
8767 * MSI-X interrupt mode to device with SLI-4 interface spec.
8768 **/
8769static void
8770lpfc_sli4_disable_msix(struct lpfc_hba *phba)
8771{
8772 int index;
8773
8774 /* Free up MSI-X multi-message vectors */
James Smartacbd8612013-09-06 12:21:19 -04008775 for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
8776 irq_set_affinity_hint(phba->sli4_hba.msix_entries[index].
8777 vector, NULL);
James Smartda0436e2009-05-22 14:51:39 -04008778 free_irq(phba->sli4_hba.msix_entries[index].vector,
James Smart67d12732012-08-03 12:36:13 -04008779 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartacbd8612013-09-06 12:21:19 -04008780 }
James Smart1ba981f2014-02-20 09:56:45 -05008781 if (phba->cfg_fof) {
8782 free_irq(phba->sli4_hba.msix_entries[index].vector,
8783 &phba->sli4_hba.fcp_eq_hdl[index]);
8784 }
James Smartda0436e2009-05-22 14:51:39 -04008785 /* Disable MSI-X */
8786 pci_disable_msix(phba->pcidev);
8787
8788 return;
8789}
8790
8791/**
8792 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
8793 * @phba: pointer to lpfc hba data structure.
8794 *
8795 * This routine is invoked to enable the MSI interrupt mode to device with
8796 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
8797 * to enable the MSI vector. The device driver is responsible for calling
8798 * the request_irq() to register MSI vector with a interrupt the handler,
8799 * which is done in this function.
8800 *
8801 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008802 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008803 * other values - error
8804 **/
8805static int
8806lpfc_sli4_enable_msi(struct lpfc_hba *phba)
8807{
8808 int rc, index;
8809
8810 rc = pci_enable_msi(phba->pcidev);
8811 if (!rc)
8812 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8813 "0487 PCI enable MSI mode success.\n");
8814 else {
8815 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8816 "0488 PCI enable MSI mode failed (%d)\n", rc);
8817 return rc;
8818 }
8819
8820 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
8821 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8822 if (rc) {
8823 pci_disable_msi(phba->pcidev);
8824 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8825 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -04008826 return rc;
James Smartda0436e2009-05-22 14:51:39 -04008827 }
8828
James Smart67d12732012-08-03 12:36:13 -04008829 for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
James Smartda0436e2009-05-22 14:51:39 -04008830 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
8831 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
8832 }
8833
James Smart1ba981f2014-02-20 09:56:45 -05008834 if (phba->cfg_fof) {
8835 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
8836 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
8837 }
James Smart75baf692010-06-08 18:31:21 -04008838 return 0;
James Smartda0436e2009-05-22 14:51:39 -04008839}
8840
8841/**
8842 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
8843 * @phba: pointer to lpfc hba data structure.
8844 *
8845 * This routine is invoked to disable the MSI interrupt mode to device with
8846 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
8847 * done request_irq() on before calling pci_disable_msi(). Failure to do so
8848 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
8849 * its vector.
8850 **/
8851static void
8852lpfc_sli4_disable_msi(struct lpfc_hba *phba)
8853{
8854 free_irq(phba->pcidev->irq, phba);
8855 pci_disable_msi(phba->pcidev);
8856 return;
8857}
8858
8859/**
8860 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
8861 * @phba: pointer to lpfc hba data structure.
8862 *
8863 * This routine is invoked to enable device interrupt and associate driver's
8864 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
8865 * interface spec. Depends on the interrupt mode configured to the driver,
8866 * the driver will try to fallback from the configured interrupt mode to an
8867 * interrupt mode which is supported by the platform, kernel, and device in
8868 * the order of:
8869 * MSI-X -> MSI -> IRQ.
8870 *
8871 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008872 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008873 * other values - error
8874 **/
8875static uint32_t
8876lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
8877{
8878 uint32_t intr_mode = LPFC_INTR_ERROR;
8879 int retval, index;
8880
8881 if (cfg_mode == 2) {
8882 /* Preparation before conf_msi mbox cmd */
8883 retval = 0;
8884 if (!retval) {
8885 /* Now, try to enable MSI-X interrupt mode */
8886 retval = lpfc_sli4_enable_msix(phba);
8887 if (!retval) {
8888 /* Indicate initialization to MSI-X mode */
8889 phba->intr_type = MSIX;
8890 intr_mode = 2;
8891 }
8892 }
8893 }
8894
8895 /* Fallback to MSI if MSI-X initialization failed */
8896 if (cfg_mode >= 1 && phba->intr_type == NONE) {
8897 retval = lpfc_sli4_enable_msi(phba);
8898 if (!retval) {
8899 /* Indicate initialization to MSI mode */
8900 phba->intr_type = MSI;
8901 intr_mode = 1;
8902 }
8903 }
8904
8905 /* Fallback to INTx if both MSI-X/MSI initalization failed */
8906 if (phba->intr_type == NONE) {
8907 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
8908 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8909 if (!retval) {
8910 /* Indicate initialization to INTx mode */
8911 phba->intr_type = INTx;
8912 intr_mode = 0;
James Smart67d12732012-08-03 12:36:13 -04008913 for (index = 0; index < phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04008914 index++) {
8915 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
8916 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
James Smartba20c852012-08-03 12:36:52 -04008917 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
8918 fcp_eq_in_use, 1);
James Smartda0436e2009-05-22 14:51:39 -04008919 }
James Smart1ba981f2014-02-20 09:56:45 -05008920 if (phba->cfg_fof) {
8921 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
8922 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
8923 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
8924 fcp_eq_in_use, 1);
8925 }
James Smartda0436e2009-05-22 14:51:39 -04008926 }
8927 }
8928 return intr_mode;
8929}
8930
8931/**
8932 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
8933 * @phba: pointer to lpfc hba data structure.
8934 *
8935 * This routine is invoked to disable device interrupt and disassociate
8936 * the driver's interrupt handler(s) from interrupt vector(s) to device
8937 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
8938 * will release the interrupt vector(s) for the message signaled interrupt.
8939 **/
8940static void
8941lpfc_sli4_disable_intr(struct lpfc_hba *phba)
8942{
8943 /* Disable the currently initialized interrupt mode */
8944 if (phba->intr_type == MSIX)
8945 lpfc_sli4_disable_msix(phba);
8946 else if (phba->intr_type == MSI)
8947 lpfc_sli4_disable_msi(phba);
8948 else if (phba->intr_type == INTx)
8949 free_irq(phba->pcidev->irq, phba);
8950
8951 /* Reset interrupt management states */
8952 phba->intr_type = NONE;
8953 phba->sli.slistat.sli_intr = 0;
8954
8955 return;
8956}
8957
8958/**
James Smart3772a992009-05-22 14:50:54 -04008959 * lpfc_unset_hba - Unset SLI3 hba device initialization
8960 * @phba: pointer to lpfc hba data structure.
8961 *
8962 * This routine is invoked to unset the HBA device initialization steps to
8963 * a device with SLI-3 interface spec.
8964 **/
8965static void
8966lpfc_unset_hba(struct lpfc_hba *phba)
8967{
8968 struct lpfc_vport *vport = phba->pport;
8969 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8970
8971 spin_lock_irq(shost->host_lock);
8972 vport->load_flag |= FC_UNLOADING;
8973 spin_unlock_irq(shost->host_lock);
8974
James Smart72859902012-01-18 16:25:38 -05008975 kfree(phba->vpi_bmask);
8976 kfree(phba->vpi_ids);
8977
James Smart3772a992009-05-22 14:50:54 -04008978 lpfc_stop_hba_timers(phba);
8979
8980 phba->pport->work_port_events = 0;
8981
8982 lpfc_sli_hba_down(phba);
8983
8984 lpfc_sli_brdrestart(phba);
8985
8986 lpfc_sli_disable_intr(phba);
8987
8988 return;
8989}
8990
8991/**
James Smart5af5eee2010-10-22 11:06:38 -04008992 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
8993 * @phba: Pointer to HBA context object.
8994 *
8995 * This function is called in the SLI4 code path to wait for completion
8996 * of device's XRIs exchange busy. It will check the XRI exchange busy
8997 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
8998 * that, it will check the XRI exchange busy on outstanding FCP and ELS
8999 * I/Os every 30 seconds, log error message, and wait forever. Only when
9000 * all XRI exchange busy complete, the driver unload shall proceed with
9001 * invoking the function reset ioctl mailbox command to the CNA and the
9002 * the rest of the driver unload resource release.
9003 **/
9004static void
9005lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
9006{
9007 int wait_time = 0;
9008 int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
9009 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9010
9011 while (!fcp_xri_cmpl || !els_xri_cmpl) {
9012 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
9013 if (!fcp_xri_cmpl)
9014 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9015 "2877 FCP XRI exchange busy "
9016 "wait time: %d seconds.\n",
9017 wait_time/1000);
9018 if (!els_xri_cmpl)
9019 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9020 "2878 ELS XRI exchange busy "
9021 "wait time: %d seconds.\n",
9022 wait_time/1000);
9023 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
9024 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
9025 } else {
9026 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
9027 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
9028 }
9029 fcp_xri_cmpl =
9030 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
9031 els_xri_cmpl =
9032 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9033 }
9034}
9035
9036/**
James Smartda0436e2009-05-22 14:51:39 -04009037 * lpfc_sli4_hba_unset - Unset the fcoe hba
9038 * @phba: Pointer to HBA context object.
9039 *
9040 * This function is called in the SLI4 code path to reset the HBA's FCoE
9041 * function. The caller is not required to hold any lock. This routine
9042 * issues PCI function reset mailbox command to reset the FCoE function.
9043 * At the end of the function, it calls lpfc_hba_down_post function to
9044 * free any pending commands.
9045 **/
9046static void
9047lpfc_sli4_hba_unset(struct lpfc_hba *phba)
9048{
9049 int wait_cnt = 0;
9050 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -04009051 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -04009052
9053 lpfc_stop_hba_timers(phba);
9054 phba->sli4_hba.intr_enable = 0;
9055
9056 /*
9057 * Gracefully wait out the potential current outstanding asynchronous
9058 * mailbox command.
9059 */
9060
9061 /* First, block any pending async mailbox command from posted */
9062 spin_lock_irq(&phba->hbalock);
9063 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
9064 spin_unlock_irq(&phba->hbalock);
9065 /* Now, trying to wait it out if we can */
9066 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9067 msleep(10);
9068 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
9069 break;
9070 }
9071 /* Forcefully release the outstanding mailbox command if timed out */
9072 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9073 spin_lock_irq(&phba->hbalock);
9074 mboxq = phba->sli.mbox_active;
9075 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
9076 __lpfc_mbox_cmpl_put(phba, mboxq);
9077 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9078 phba->sli.mbox_active = NULL;
9079 spin_unlock_irq(&phba->hbalock);
9080 }
9081
James Smart5af5eee2010-10-22 11:06:38 -04009082 /* Abort all iocbs associated with the hba */
9083 lpfc_sli_hba_iocb_abort(phba);
9084
9085 /* Wait for completion of device XRI exchange busy */
9086 lpfc_sli4_xri_exchange_busy_wait(phba);
9087
James Smartda0436e2009-05-22 14:51:39 -04009088 /* Disable PCI subsystem interrupt */
9089 lpfc_sli4_disable_intr(phba);
9090
James Smart912e3ac2011-05-24 11:42:11 -04009091 /* Disable SR-IOV if enabled */
9092 if (phba->cfg_sriov_nr_virtfn)
9093 pci_disable_sriov(pdev);
9094
James Smartda0436e2009-05-22 14:51:39 -04009095 /* Stop kthread signal shall trigger work_done one more time */
9096 kthread_stop(phba->worker_thread);
9097
James Smart3677a3a2010-09-29 11:19:14 -04009098 /* Reset SLI4 HBA FCoE function */
9099 lpfc_pci_function_reset(phba);
James Smart5350d872011-10-10 21:33:49 -04009100 lpfc_sli4_queue_destroy(phba);
James Smart3677a3a2010-09-29 11:19:14 -04009101
James Smartda0436e2009-05-22 14:51:39 -04009102 /* Stop the SLI4 device port */
9103 phba->pport->work_port_events = 0;
9104}
9105
James Smart28baac72010-02-12 14:42:03 -05009106 /**
9107 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
9108 * @phba: Pointer to HBA context object.
9109 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9110 *
9111 * This function is called in the SLI4 code path to read the port's
9112 * sli4 capabilities.
9113 *
9114 * This function may be be called from any context that can block-wait
9115 * for the completion. The expectation is that this routine is called
9116 * typically from probe_one or from the online routine.
9117 **/
9118int
9119lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9120{
9121 int rc;
9122 struct lpfc_mqe *mqe;
9123 struct lpfc_pc_sli4_params *sli4_params;
9124 uint32_t mbox_tmo;
9125
9126 rc = 0;
9127 mqe = &mboxq->u.mqe;
9128
9129 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -05009130 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -05009131 if (!phba->sli4_hba.intr_enable)
9132 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9133 else {
James Smarta183a152011-10-10 21:32:43 -04009134 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -05009135 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
9136 }
9137
9138 if (unlikely(rc))
9139 return 1;
9140
9141 sli4_params = &phba->sli4_hba.pc_sli4_params;
9142 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
9143 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
9144 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
9145 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
9146 &mqe->un.sli4_params);
9147 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
9148 &mqe->un.sli4_params);
9149 sli4_params->proto_types = mqe->un.sli4_params.word3;
9150 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
9151 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
9152 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
9153 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
9154 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
9155 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
9156 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
9157 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
9158 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
9159 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
9160 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
9161 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
9162 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
9163 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
9164 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
9165 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
9166 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
9167 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
9168 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
9169 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -04009170
9171 /* Make sure that sge_supp_len can be handled by the driver */
9172 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
9173 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
9174
James Smart28baac72010-02-12 14:42:03 -05009175 return rc;
9176}
9177
James Smartda0436e2009-05-22 14:51:39 -04009178/**
James Smartfedd3b72011-02-16 12:39:24 -05009179 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
9180 * @phba: Pointer to HBA context object.
9181 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9182 *
9183 * This function is called in the SLI4 code path to read the port's
9184 * sli4 capabilities.
9185 *
9186 * This function may be be called from any context that can block-wait
9187 * for the completion. The expectation is that this routine is called
9188 * typically from probe_one or from the online routine.
9189 **/
9190int
9191lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9192{
9193 int rc;
9194 struct lpfc_mqe *mqe = &mboxq->u.mqe;
9195 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -04009196 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -05009197 int length;
9198 struct lpfc_sli4_parameters *mbx_sli4_parameters;
9199
James Smart6d368e52011-05-24 11:44:12 -04009200 /*
9201 * By default, the driver assumes the SLI4 port requires RPI
9202 * header postings. The SLI4_PARAM response will correct this
9203 * assumption.
9204 */
9205 phba->sli4_hba.rpi_hdrs_in_use = 1;
9206
James Smartfedd3b72011-02-16 12:39:24 -05009207 /* Read the port's SLI4 Config Parameters */
9208 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
9209 sizeof(struct lpfc_sli4_cfg_mhdr));
9210 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9211 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
9212 length, LPFC_SLI4_MBX_EMBED);
9213 if (!phba->sli4_hba.intr_enable)
9214 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -04009215 else {
9216 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
9217 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
9218 }
James Smartfedd3b72011-02-16 12:39:24 -05009219 if (unlikely(rc))
9220 return rc;
9221 sli4_params = &phba->sli4_hba.pc_sli4_params;
9222 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
9223 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
9224 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
9225 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
9226 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
9227 mbx_sli4_parameters);
9228 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
9229 mbx_sli4_parameters);
9230 if (bf_get(cfg_phwq, mbx_sli4_parameters))
9231 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
9232 else
9233 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
9234 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
9235 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
James Smart1ba981f2014-02-20 09:56:45 -05009236 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -05009237 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
9238 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
9239 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
9240 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
James Smart0c651872013-07-15 18:33:23 -04009241 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -05009242 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
9243 mbx_sli4_parameters);
9244 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
9245 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -04009246 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
9247 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart05580562011-05-24 11:40:48 -04009248
9249 /* Make sure that sge_supp_len can be handled by the driver */
9250 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
9251 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
9252
James Smartfedd3b72011-02-16 12:39:24 -05009253 return 0;
9254}
9255
9256/**
James Smart3772a992009-05-22 14:50:54 -04009257 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
9258 * @pdev: pointer to PCI device
9259 * @pid: pointer to PCI device identifier
9260 *
9261 * This routine is to be called to attach a device with SLI-3 interface spec
9262 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9263 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
9264 * information of the device and driver to see if the driver state that it can
9265 * support this kind of device. If the match is successful, the driver core
9266 * invokes this routine. If this routine determines it can claim the HBA, it
9267 * does all the initialization that it needs to do to handle the HBA properly.
9268 *
9269 * Return code
9270 * 0 - driver can claim the device
9271 * negative value - driver can not claim the device
9272 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009273static int
James Smart3772a992009-05-22 14:50:54 -04009274lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
9275{
9276 struct lpfc_hba *phba;
9277 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -04009278 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -04009279 int error;
9280 uint32_t cfg_mode, intr_mode;
9281
9282 /* Allocate memory for HBA structure */
9283 phba = lpfc_hba_alloc(pdev);
9284 if (!phba)
9285 return -ENOMEM;
9286
9287 /* Perform generic PCI device enabling operation */
9288 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -04009289 if (error)
James Smart3772a992009-05-22 14:50:54 -04009290 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -04009291
9292 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
9293 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
9294 if (error)
9295 goto out_disable_pci_dev;
9296
9297 /* Set up SLI-3 specific device PCI memory space */
9298 error = lpfc_sli_pci_mem_setup(phba);
9299 if (error) {
9300 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9301 "1402 Failed to set up pci memory space.\n");
9302 goto out_disable_pci_dev;
9303 }
9304
9305 /* Set up phase-1 common device driver resources */
9306 error = lpfc_setup_driver_resource_phase1(phba);
9307 if (error) {
9308 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9309 "1403 Failed to set up driver resource.\n");
9310 goto out_unset_pci_mem_s3;
9311 }
9312
9313 /* Set up SLI-3 specific device driver resources */
9314 error = lpfc_sli_driver_resource_setup(phba);
9315 if (error) {
9316 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9317 "1404 Failed to set up driver resource.\n");
9318 goto out_unset_pci_mem_s3;
9319 }
9320
9321 /* Initialize and populate the iocb list per host */
9322 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
9323 if (error) {
9324 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9325 "1405 Failed to initialize iocb list.\n");
9326 goto out_unset_driver_resource_s3;
9327 }
9328
9329 /* Set up common device driver resources */
9330 error = lpfc_setup_driver_resource_phase2(phba);
9331 if (error) {
9332 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9333 "1406 Failed to set up driver resource.\n");
9334 goto out_free_iocb_list;
9335 }
9336
James Smart079b5c92011-08-21 21:48:49 -04009337 /* Get the default values for Model Name and Description */
9338 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
9339
James Smart3772a992009-05-22 14:50:54 -04009340 /* Create SCSI host to the physical port */
9341 error = lpfc_create_shost(phba);
9342 if (error) {
9343 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9344 "1407 Failed to create scsi host.\n");
9345 goto out_unset_driver_resource;
9346 }
9347
9348 /* Configure sysfs attributes */
9349 vport = phba->pport;
9350 error = lpfc_alloc_sysfs_attr(vport);
9351 if (error) {
9352 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9353 "1476 Failed to allocate sysfs attr\n");
9354 goto out_destroy_shost;
9355 }
9356
James Smart6669f9b2009-10-02 15:16:45 -04009357 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -04009358 /* Now, trying to enable interrupt and bring up the device */
9359 cfg_mode = phba->cfg_use_msi;
9360 while (true) {
9361 /* Put device to a known state before enabling interrupt */
9362 lpfc_stop_port(phba);
9363 /* Configure and enable interrupt */
9364 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
9365 if (intr_mode == LPFC_INTR_ERROR) {
9366 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9367 "0431 Failed to enable interrupt.\n");
9368 error = -ENODEV;
9369 goto out_free_sysfs_attr;
9370 }
9371 /* SLI-3 HBA setup */
9372 if (lpfc_sli_hba_setup(phba)) {
9373 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9374 "1477 Failed to set up hba\n");
9375 error = -ENODEV;
9376 goto out_remove_device;
9377 }
9378
9379 /* Wait 50ms for the interrupts of previous mailbox commands */
9380 msleep(50);
9381 /* Check active interrupts on message signaled interrupts */
9382 if (intr_mode == 0 ||
9383 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
9384 /* Log the current active interrupt mode */
9385 phba->intr_mode = intr_mode;
9386 lpfc_log_intr_mode(phba, intr_mode);
9387 break;
9388 } else {
9389 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9390 "0447 Configure interrupt mode (%d) "
9391 "failed active interrupt test.\n",
9392 intr_mode);
9393 /* Disable the current interrupt mode */
9394 lpfc_sli_disable_intr(phba);
9395 /* Try next level of interrupt mode */
9396 cfg_mode = --intr_mode;
9397 }
9398 }
9399
9400 /* Perform post initialization setup */
9401 lpfc_post_init_setup(phba);
9402
9403 /* Check if there are static vports to be created. */
9404 lpfc_create_static_vport(phba);
9405
9406 return 0;
9407
9408out_remove_device:
9409 lpfc_unset_hba(phba);
9410out_free_sysfs_attr:
9411 lpfc_free_sysfs_attr(vport);
9412out_destroy_shost:
9413 lpfc_destroy_shost(phba);
9414out_unset_driver_resource:
9415 lpfc_unset_driver_resource_phase2(phba);
9416out_free_iocb_list:
9417 lpfc_free_iocb_list(phba);
9418out_unset_driver_resource_s3:
9419 lpfc_sli_driver_resource_unset(phba);
9420out_unset_pci_mem_s3:
9421 lpfc_sli_pci_mem_unset(phba);
9422out_disable_pci_dev:
9423 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -04009424 if (shost)
9425 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -04009426out_free_phba:
9427 lpfc_hba_free(phba);
9428 return error;
9429}
9430
9431/**
9432 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -04009433 * @pdev: pointer to PCI device
9434 *
James Smart3772a992009-05-22 14:50:54 -04009435 * This routine is to be called to disattach a device with SLI-3 interface
9436 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9437 * removed from PCI bus, it performs all the necessary cleanup for the HBA
9438 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -04009439 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009440static void
James Smart3772a992009-05-22 14:50:54 -04009441lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -05009442{
James Smart2e0fef82007-06-17 19:56:36 -05009443 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9444 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -05009445 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -05009446 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -05009447 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05009448 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
9449
James Smart549e55c2007-08-02 11:09:51 -04009450 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04009451 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04009452 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05009453
James Smart858c9f62007-06-17 19:56:39 -05009454 lpfc_free_sysfs_attr(vport);
9455
James Smarteada2722008-12-04 22:39:13 -05009456 /* Release all the vports against this physical port */
9457 vports = lpfc_create_vport_work_array(phba);
9458 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -04009459 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9460 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
9461 continue;
James Smarteada2722008-12-04 22:39:13 -05009462 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -04009463 }
James Smarteada2722008-12-04 22:39:13 -05009464 lpfc_destroy_vport_work_array(phba, vports);
9465
9466 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -05009467 fc_remove_host(shost);
9468 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04009469 lpfc_cleanup(vport);
9470
James Smart2e0fef82007-06-17 19:56:36 -05009471 /*
9472 * Bring down the SLI Layer. This step disable all interrupts,
9473 * clears the rings, discards all mailbox commands, and resets
9474 * the HBA.
9475 */
James Smarta257bf92009-04-06 18:48:10 -04009476
Justin P. Mattock48e34d02010-12-30 15:07:58 -08009477 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -05009478 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -04009479 /* Stop kthread signal shall trigger work_done one more time */
9480 kthread_stop(phba->worker_thread);
9481 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -05009482 lpfc_sli_brdrestart(phba);
9483
James Smart72859902012-01-18 16:25:38 -05009484 kfree(phba->vpi_bmask);
9485 kfree(phba->vpi_ids);
9486
James Smart3772a992009-05-22 14:50:54 -04009487 lpfc_stop_hba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05009488 spin_lock_irq(&phba->hbalock);
9489 list_del_init(&vport->listentry);
9490 spin_unlock_irq(&phba->hbalock);
9491
James Smart858c9f62007-06-17 19:56:39 -05009492 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05009493
James Smart912e3ac2011-05-24 11:42:11 -04009494 /* Disable SR-IOV if enabled */
9495 if (phba->cfg_sriov_nr_virtfn)
9496 pci_disable_sriov(pdev);
9497
James Smart5b75da22008-12-04 22:39:35 -05009498 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009499 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -05009500
James Smart858c9f62007-06-17 19:56:39 -05009501 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05009502
9503 /*
9504 * Call scsi_free before mem_free since scsi bufs are released to their
9505 * corresponding pools here.
9506 */
9507 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -04009508 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -05009509
James Smart34b02dc2008-08-24 21:49:55 -04009510 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
9511 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -05009512
James Smart2e0fef82007-06-17 19:56:36 -05009513 /* Free resources associated with SLI2 interface */
9514 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -04009515 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -05009516
9517 /* unmap adapter SLIM and Control Registers */
9518 iounmap(phba->ctrl_regs_memmap_p);
9519 iounmap(phba->slim_memmap_p);
9520
James Smart3772a992009-05-22 14:50:54 -04009521 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -05009522
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05009523 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05009524 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05009525}
9526
Linas Vepstas8d63f372007-02-14 14:28:36 -06009527/**
James Smart3772a992009-05-22 14:50:54 -04009528 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05009529 * @pdev: pointer to PCI device
9530 * @msg: power management message
9531 *
James Smart3772a992009-05-22 14:50:54 -04009532 * This routine is to be called from the kernel's PCI subsystem to support
9533 * system Power Management (PM) to device with SLI-3 interface spec. When
9534 * PM invokes this method, it quiesces the device by stopping the driver's
9535 * worker thread for the device, turning off device's interrupt and DMA,
9536 * and bring the device offline. Note that as the driver implements the
9537 * minimum PM requirements to a power-aware driver's PM support for the
9538 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
9539 * to the suspend() method call will be treated as SUSPEND and the driver will
9540 * fully reinitialize its device during resume() method call, the driver will
9541 * set device to PCI_D3hot state in PCI config space instead of setting it
9542 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -05009543 *
9544 * Return code
James Smart3772a992009-05-22 14:50:54 -04009545 * 0 - driver suspended the device
9546 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05009547 **/
9548static int
James Smart3772a992009-05-22 14:50:54 -04009549lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -05009550{
9551 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9552 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9553
9554 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9555 "0473 PCI device Power Management suspend.\n");
9556
9557 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -04009558 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -05009559 lpfc_offline(phba);
9560 kthread_stop(phba->worker_thread);
9561
9562 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -04009563 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -05009564
9565 /* Save device state to PCI config space */
9566 pci_save_state(pdev);
9567 pci_set_power_state(pdev, PCI_D3hot);
9568
9569 return 0;
9570}
9571
9572/**
James Smart3772a992009-05-22 14:50:54 -04009573 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05009574 * @pdev: pointer to PCI device
9575 *
James Smart3772a992009-05-22 14:50:54 -04009576 * This routine is to be called from the kernel's PCI subsystem to support
9577 * system Power Management (PM) to device with SLI-3 interface spec. When PM
9578 * invokes this method, it restores the device's PCI config space state and
9579 * fully reinitializes the device and brings it online. Note that as the
9580 * driver implements the minimum PM requirements to a power-aware driver's
9581 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
9582 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
9583 * driver will fully reinitialize its device during resume() method call,
9584 * the device will be set to PCI_D0 directly in PCI config space before
9585 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -05009586 *
9587 * Return code
James Smart3772a992009-05-22 14:50:54 -04009588 * 0 - driver suspended the device
9589 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05009590 **/
9591static int
James Smart3772a992009-05-22 14:50:54 -04009592lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -05009593{
9594 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9595 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -05009596 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05009597 int error;
9598
9599 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9600 "0452 PCI device Power Management resume.\n");
9601
9602 /* Restore device state from PCI config space */
9603 pci_set_power_state(pdev, PCI_D0);
9604 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -04009605
James Smart1dfb5a42010-02-12 14:40:50 -05009606 /*
9607 * As the new kernel behavior of pci_restore_state() API call clears
9608 * device saved_state flag, need to save the restored state again.
9609 */
9610 pci_save_state(pdev);
9611
James Smart3a55b532008-12-04 22:38:54 -05009612 if (pdev->is_busmaster)
9613 pci_set_master(pdev);
9614
9615 /* Startup the kernel thread for this host adapter. */
9616 phba->worker_thread = kthread_run(lpfc_do_work, phba,
9617 "lpfc_worker_%d", phba->brd_no);
9618 if (IS_ERR(phba->worker_thread)) {
9619 error = PTR_ERR(phba->worker_thread);
9620 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9621 "0434 PM resume failed to start worker "
9622 "thread: error=x%x.\n", error);
9623 return error;
9624 }
9625
James Smart5b75da22008-12-04 22:39:35 -05009626 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009627 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05009628 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -05009629 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -05009630 "0430 PM resume Failed to enable interrupt\n");
9631 return -EIO;
9632 } else
9633 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05009634
9635 /* Restart HBA and bring it online */
9636 lpfc_sli_brdrestart(phba);
9637 lpfc_online(phba);
9638
James Smart5b75da22008-12-04 22:39:35 -05009639 /* Log the current active interrupt mode */
9640 lpfc_log_intr_mode(phba, phba->intr_mode);
9641
James Smart3a55b532008-12-04 22:38:54 -05009642 return 0;
9643}
9644
9645/**
James Smart891478a2009-11-18 15:40:23 -05009646 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
9647 * @phba: pointer to lpfc hba data structure.
9648 *
9649 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -04009650 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -05009651 **/
9652static void
9653lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
9654{
James Smarte2af0d22010-03-15 11:25:32 -04009655 struct lpfc_sli *psli = &phba->sli;
9656 struct lpfc_sli_ring *pring;
9657
James Smart891478a2009-11-18 15:40:23 -05009658 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9659 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -04009660
9661 /*
9662 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
9663 * and let the SCSI mid-layer to retry them to recover.
9664 */
9665 pring = &psli->ring[psli->fcp_ring];
9666 lpfc_sli_abort_iocb_ring(phba, pring);
James Smart891478a2009-11-18 15:40:23 -05009667}
9668
9669/**
James Smart0d878412009-10-02 15:16:56 -04009670 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
9671 * @phba: pointer to lpfc hba data structure.
9672 *
9673 * This routine is called to prepare the SLI3 device for PCI slot reset. It
9674 * disables the device interrupt and pci device, and aborts the internal FCP
9675 * pending I/Os.
9676 **/
9677static void
9678lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
9679{
James Smart0d878412009-10-02 15:16:56 -04009680 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -05009681 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -04009682
James Smart75baf692010-06-08 18:31:21 -04009683 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -04009684 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -04009685
James Smarte2af0d22010-03-15 11:25:32 -04009686 /* Block all SCSI devices' I/Os on the host */
9687 lpfc_scsi_dev_block(phba);
9688
James Smartea714f32013-04-17 20:18:47 -04009689 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9690 lpfc_sli_flush_fcp_rings(phba);
9691
James Smarte2af0d22010-03-15 11:25:32 -04009692 /* stop all timers */
9693 lpfc_stop_hba_timers(phba);
9694
James Smart0d878412009-10-02 15:16:56 -04009695 /* Disable interrupt and pci device */
9696 lpfc_sli_disable_intr(phba);
9697 pci_disable_device(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -04009698}
9699
9700/**
9701 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
9702 * @phba: pointer to lpfc hba data structure.
9703 *
9704 * This routine is called to prepare the SLI3 device for PCI slot permanently
9705 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
9706 * pending I/Os.
9707 **/
9708static void
James Smart75baf692010-06-08 18:31:21 -04009709lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -04009710{
9711 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -05009712 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -04009713 /* Block all SCSI devices' I/Os on the host */
9714 lpfc_scsi_dev_block(phba);
9715
9716 /* stop all timers */
9717 lpfc_stop_hba_timers(phba);
9718
James Smart0d878412009-10-02 15:16:56 -04009719 /* Clean up all driver's outstanding SCSI I/Os */
9720 lpfc_sli_flush_fcp_rings(phba);
9721}
9722
9723/**
James Smart3772a992009-05-22 14:50:54 -04009724 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -04009725 * @pdev: pointer to PCI device.
9726 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -06009727 *
James Smart3772a992009-05-22 14:50:54 -04009728 * This routine is called from the PCI subsystem for I/O error handling to
9729 * device with SLI-3 interface spec. This function is called by the PCI
9730 * subsystem after a PCI bus error affecting this device has been detected.
9731 * When this function is invoked, it will need to stop all the I/Os and
9732 * interrupt(s) to the device. Once that is done, it will return
9733 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
9734 * as desired.
James Smarte59058c2008-08-24 21:49:00 -04009735 *
9736 * Return codes
James Smart0d878412009-10-02 15:16:56 -04009737 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -04009738 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
9739 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -04009740 **/
James Smart3772a992009-05-22 14:50:54 -04009741static pci_ers_result_t
9742lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -06009743{
James Smart51ef4c22007-08-02 11:10:31 -04009744 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9745 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009746
James Smart0d878412009-10-02 15:16:56 -04009747 switch (state) {
9748 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -05009749 /* Non-fatal error, prepare for recovery */
9750 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -04009751 return PCI_ERS_RESULT_CAN_RECOVER;
9752 case pci_channel_io_frozen:
9753 /* Fatal error, prepare for slot reset */
9754 lpfc_sli_prep_dev_for_reset(phba);
9755 return PCI_ERS_RESULT_NEED_RESET;
9756 case pci_channel_io_perm_failure:
9757 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -04009758 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06009759 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -04009760 default:
9761 /* Unknown state, prepare and request slot reset */
9762 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9763 "0472 Unknown PCI error state: x%x\n", state);
9764 lpfc_sli_prep_dev_for_reset(phba);
9765 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -04009766 }
Linas Vepstas8d63f372007-02-14 14:28:36 -06009767}
9768
9769/**
James Smart3772a992009-05-22 14:50:54 -04009770 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -04009771 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -06009772 *
James Smart3772a992009-05-22 14:50:54 -04009773 * This routine is called from the PCI subsystem for error handling to
9774 * device with SLI-3 interface spec. This is called after PCI bus has been
9775 * reset to restart the PCI card from scratch, as if from a cold-boot.
9776 * During the PCI subsystem error recovery, after driver returns
9777 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
9778 * recovery and then call this routine before calling the .resume method
9779 * to recover the device. This function will initialize the HBA device,
9780 * enable the interrupt, but it will just put the HBA to offline state
9781 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -04009782 *
9783 * Return codes
James Smart3772a992009-05-22 14:50:54 -04009784 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
9785 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -06009786 */
James Smart3772a992009-05-22 14:50:54 -04009787static pci_ers_result_t
9788lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -06009789{
James Smart51ef4c22007-08-02 11:10:31 -04009790 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9791 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009792 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -05009793 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009794
9795 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11009796 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -06009797 printk(KERN_ERR "lpfc: Cannot re-enable "
9798 "PCI device after reset.\n");
9799 return PCI_ERS_RESULT_DISCONNECT;
9800 }
9801
James Smart97207482008-12-04 22:39:19 -05009802 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -05009803
9804 /*
9805 * As the new kernel behavior of pci_restore_state() API call clears
9806 * device saved_state flag, need to save the restored state again.
9807 */
9808 pci_save_state(pdev);
9809
James Smart97207482008-12-04 22:39:19 -05009810 if (pdev->is_busmaster)
9811 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -06009812
James Smart92d7f7b2007-06-17 19:56:38 -05009813 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -04009814 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05009815 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06009816
James Smart5b75da22008-12-04 22:39:35 -05009817 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009818 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05009819 if (intr_mode == LPFC_INTR_ERROR) {
9820 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9821 "0427 Cannot re-enable interrupt after "
9822 "slot reset.\n");
9823 return PCI_ERS_RESULT_DISCONNECT;
9824 } else
9825 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009826
James Smart75baf692010-06-08 18:31:21 -04009827 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -04009828 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -06009829 lpfc_offline(phba);
9830 lpfc_sli_brdrestart(phba);
9831
James Smart5b75da22008-12-04 22:39:35 -05009832 /* Log the current active interrupt mode */
9833 lpfc_log_intr_mode(phba, phba->intr_mode);
9834
Linas Vepstas8d63f372007-02-14 14:28:36 -06009835 return PCI_ERS_RESULT_RECOVERED;
9836}
9837
9838/**
James Smart3772a992009-05-22 14:50:54 -04009839 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -04009840 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -06009841 *
James Smart3772a992009-05-22 14:50:54 -04009842 * This routine is called from the PCI subsystem for error handling to device
9843 * with SLI-3 interface spec. It is called when kernel error recovery tells
9844 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
9845 * error recovery. After this call, traffic can start to flow from this device
9846 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -06009847 */
James Smart3772a992009-05-22 14:50:54 -04009848static void
9849lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -06009850{
James Smart51ef4c22007-08-02 11:10:31 -04009851 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9852 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009853
James Smarte2af0d22010-03-15 11:25:32 -04009854 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -04009855 lpfc_online(phba);
James Smart0d878412009-10-02 15:16:56 -04009856
9857 /* Clean up Advanced Error Reporting (AER) if needed */
9858 if (phba->hba_flag & HBA_AER_ENABLED)
9859 pci_cleanup_aer_uncorrect_error_status(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -06009860}
9861
James Smart3772a992009-05-22 14:50:54 -04009862/**
James Smartda0436e2009-05-22 14:51:39 -04009863 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
9864 * @phba: pointer to lpfc hba data structure.
9865 *
9866 * returns the number of ELS/CT IOCBs to reserve
9867 **/
9868int
9869lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
9870{
9871 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
9872
James Smartf1126682009-06-10 17:22:44 -04009873 if (phba->sli_rev == LPFC_SLI_REV4) {
9874 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -04009875 return 10;
James Smartf1126682009-06-10 17:22:44 -04009876 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -04009877 return 25;
James Smartf1126682009-06-10 17:22:44 -04009878 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -04009879 return 50;
James Smartf1126682009-06-10 17:22:44 -04009880 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -04009881 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -04009882 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -04009883 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -04009884 else if (max_xri <= 2048)
9885 return 200;
9886 else
9887 return 250;
James Smartf1126682009-06-10 17:22:44 -04009888 } else
9889 return 0;
James Smartda0436e2009-05-22 14:51:39 -04009890}
9891
9892/**
James Smart52d52442011-05-24 11:42:45 -04009893 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -04009894 * @fw: pointer to firmware image returned from request_firmware.
James Smartce396282012-09-29 11:30:56 -04009895 * @phba: pointer to lpfc hba data structure.
James Smart52d52442011-05-24 11:42:45 -04009896 *
James Smart52d52442011-05-24 11:42:45 -04009897 **/
James Smartce396282012-09-29 11:30:56 -04009898static void
9899lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -04009900{
James Smartce396282012-09-29 11:30:56 -04009901 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -05009902 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -04009903 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -04009904 struct list_head dma_buffer_list;
9905 int i, rc = 0;
9906 struct lpfc_dmabuf *dmabuf, *next;
9907 uint32_t offset = 0, temp_offset = 0;
9908
James Smartc71ab862012-10-31 14:44:33 -04009909 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -04009910 if (!fw) {
9911 rc = -ENXIO;
9912 goto out;
9913 }
9914 image = (struct lpfc_grp_hdr *)fw->data;
9915
James Smart52d52442011-05-24 11:42:45 -04009916 INIT_LIST_HEAD(&dma_buffer_list);
James Smart079b5c92011-08-21 21:48:49 -04009917 if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) ||
9918 (bf_get_be32(lpfc_grp_hdr_file_type, image) !=
9919 LPFC_FILE_TYPE_GROUP) ||
9920 (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) ||
9921 (be32_to_cpu(image->size) != fw->size)) {
James Smart52d52442011-05-24 11:42:45 -04009922 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9923 "3022 Invalid FW image found. "
James Smart079b5c92011-08-21 21:48:49 -04009924 "Magic:%x Type:%x ID:%x\n",
9925 be32_to_cpu(image->magic_number),
9926 bf_get_be32(lpfc_grp_hdr_file_type, image),
9927 bf_get_be32(lpfc_grp_hdr_id, image));
James Smartce396282012-09-29 11:30:56 -04009928 rc = -EINVAL;
9929 goto release_out;
James Smart52d52442011-05-24 11:42:45 -04009930 }
9931 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -04009932 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -04009933 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartce396282012-09-29 11:30:56 -04009934 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -04009935 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -04009936 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -04009937 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
9938 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
9939 GFP_KERNEL);
9940 if (!dmabuf) {
9941 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -04009942 goto release_out;
James Smart52d52442011-05-24 11:42:45 -04009943 }
9944 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
9945 SLI4_PAGE_SIZE,
9946 &dmabuf->phys,
9947 GFP_KERNEL);
9948 if (!dmabuf->virt) {
9949 kfree(dmabuf);
9950 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -04009951 goto release_out;
James Smart52d52442011-05-24 11:42:45 -04009952 }
9953 list_add_tail(&dmabuf->list, &dma_buffer_list);
9954 }
9955 while (offset < fw->size) {
9956 temp_offset = offset;
9957 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -04009958 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -04009959 memcpy(dmabuf->virt,
9960 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -04009961 fw->size - temp_offset);
9962 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -04009963 break;
9964 }
James Smart52d52442011-05-24 11:42:45 -04009965 memcpy(dmabuf->virt, fw->data + temp_offset,
9966 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -04009967 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -04009968 }
9969 rc = lpfc_wr_object(phba, &dma_buffer_list,
9970 (fw->size - offset), &offset);
James Smartce396282012-09-29 11:30:56 -04009971 if (rc)
9972 goto release_out;
James Smart52d52442011-05-24 11:42:45 -04009973 }
9974 rc = offset;
9975 }
James Smartce396282012-09-29 11:30:56 -04009976
9977release_out:
James Smart52d52442011-05-24 11:42:45 -04009978 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
9979 list_del(&dmabuf->list);
9980 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
9981 dmabuf->virt, dmabuf->phys);
9982 kfree(dmabuf);
9983 }
James Smartce396282012-09-29 11:30:56 -04009984 release_firmware(fw);
9985out:
9986 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc71ab862012-10-31 14:44:33 -04009987 "3024 Firmware update done: %d.\n", rc);
James Smartce396282012-09-29 11:30:56 -04009988 return;
James Smart52d52442011-05-24 11:42:45 -04009989}
9990
9991/**
James Smartc71ab862012-10-31 14:44:33 -04009992 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
9993 * @phba: pointer to lpfc hba data structure.
9994 *
9995 * This routine is called to perform Linux generic firmware upgrade on device
9996 * that supports such feature.
9997 **/
9998int
9999lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
10000{
10001 uint8_t file_name[ELX_MODEL_NAME_SIZE];
10002 int ret;
10003 const struct firmware *fw;
10004
10005 /* Only supported on SLI4 interface type 2 for now */
10006 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
10007 LPFC_SLI_INTF_IF_TYPE_2)
10008 return -EPERM;
10009
10010 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
10011
10012 if (fw_upgrade == INT_FW_UPGRADE) {
10013 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
10014 file_name, &phba->pcidev->dev,
10015 GFP_KERNEL, (void *)phba,
10016 lpfc_write_firmware);
10017 } else if (fw_upgrade == RUN_FW_UPGRADE) {
10018 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
10019 if (!ret)
10020 lpfc_write_firmware(fw, (void *)phba);
10021 } else {
10022 ret = -EINVAL;
10023 }
10024
10025 return ret;
10026}
10027
10028/**
James Smartda0436e2009-05-22 14:51:39 -040010029 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
10030 * @pdev: pointer to PCI device
10031 * @pid: pointer to PCI device identifier
10032 *
10033 * This routine is called from the kernel's PCI subsystem to device with
10034 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10035 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10036 * information of the device and driver to see if the driver state that it
10037 * can support this kind of device. If the match is successful, the driver
10038 * core invokes this routine. If this routine determines it can claim the HBA,
10039 * it does all the initialization that it needs to do to handle the HBA
10040 * properly.
10041 *
10042 * Return code
10043 * 0 - driver can claim the device
10044 * negative value - driver can not claim the device
10045 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010046static int
James Smartda0436e2009-05-22 14:51:39 -040010047lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
10048{
10049 struct lpfc_hba *phba;
10050 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040010051 struct Scsi_Host *shost = NULL;
James Smartce396282012-09-29 11:30:56 -040010052 int error, ret;
James Smartda0436e2009-05-22 14:51:39 -040010053 uint32_t cfg_mode, intr_mode;
James Smart67d12732012-08-03 12:36:13 -040010054 int adjusted_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -040010055
10056 /* Allocate memory for HBA structure */
10057 phba = lpfc_hba_alloc(pdev);
10058 if (!phba)
10059 return -ENOMEM;
10060
10061 /* Perform generic PCI device enabling operation */
10062 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040010063 if (error)
James Smartda0436e2009-05-22 14:51:39 -040010064 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -040010065
10066 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
10067 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
10068 if (error)
10069 goto out_disable_pci_dev;
10070
10071 /* Set up SLI-4 specific device PCI memory space */
10072 error = lpfc_sli4_pci_mem_setup(phba);
10073 if (error) {
10074 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10075 "1410 Failed to set up pci memory space.\n");
10076 goto out_disable_pci_dev;
10077 }
10078
10079 /* Set up phase-1 common device driver resources */
10080 error = lpfc_setup_driver_resource_phase1(phba);
10081 if (error) {
10082 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10083 "1411 Failed to set up driver resource.\n");
10084 goto out_unset_pci_mem_s4;
10085 }
10086
10087 /* Set up SLI-4 Specific device driver resources */
10088 error = lpfc_sli4_driver_resource_setup(phba);
10089 if (error) {
10090 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10091 "1412 Failed to set up driver resource.\n");
10092 goto out_unset_pci_mem_s4;
10093 }
10094
10095 /* Initialize and populate the iocb list per host */
James Smart2a9bf3d2010-06-07 15:24:45 -040010096
10097 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10098 "2821 initialize iocb list %d.\n",
10099 phba->cfg_iocb_cnt*1024);
10100 error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
10101
James Smartda0436e2009-05-22 14:51:39 -040010102 if (error) {
10103 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10104 "1413 Failed to initialize iocb list.\n");
10105 goto out_unset_driver_resource_s4;
10106 }
10107
James Smart19ca7602010-11-20 23:11:55 -050010108 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -040010109 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -050010110
James Smartda0436e2009-05-22 14:51:39 -040010111 /* Set up common device driver resources */
10112 error = lpfc_setup_driver_resource_phase2(phba);
10113 if (error) {
10114 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10115 "1414 Failed to set up driver resource.\n");
10116 goto out_free_iocb_list;
10117 }
10118
James Smart079b5c92011-08-21 21:48:49 -040010119 /* Get the default values for Model Name and Description */
10120 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
10121
James Smartda0436e2009-05-22 14:51:39 -040010122 /* Create SCSI host to the physical port */
10123 error = lpfc_create_shost(phba);
10124 if (error) {
10125 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10126 "1415 Failed to create scsi host.\n");
10127 goto out_unset_driver_resource;
10128 }
10129
10130 /* Configure sysfs attributes */
10131 vport = phba->pport;
10132 error = lpfc_alloc_sysfs_attr(vport);
10133 if (error) {
10134 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10135 "1416 Failed to allocate sysfs attr\n");
10136 goto out_destroy_shost;
10137 }
10138
James Smart6669f9b2009-10-02 15:16:45 -040010139 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -040010140 /* Now, trying to enable interrupt and bring up the device */
10141 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -040010142
James Smart7b15db32013-01-03 15:43:29 -050010143 /* Put device to a known state before enabling interrupt */
10144 lpfc_stop_port(phba);
10145 /* Configure and enable interrupt */
10146 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
10147 if (intr_mode == LPFC_INTR_ERROR) {
10148 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10149 "0426 Failed to enable interrupt.\n");
10150 error = -ENODEV;
10151 goto out_free_sysfs_attr;
James Smartda0436e2009-05-22 14:51:39 -040010152 }
James Smart7b15db32013-01-03 15:43:29 -050010153 /* Default to single EQ for non-MSI-X */
10154 if (phba->intr_type != MSIX)
10155 adjusted_fcp_io_channel = 1;
10156 else
10157 adjusted_fcp_io_channel = phba->cfg_fcp_io_channel;
10158 phba->cfg_fcp_io_channel = adjusted_fcp_io_channel;
10159 /* Set up SLI-4 HBA */
10160 if (lpfc_sli4_hba_setup(phba)) {
10161 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10162 "1421 Failed to set up hba\n");
10163 error = -ENODEV;
10164 goto out_disable_intr;
10165 }
10166
10167 /* Log the current active interrupt mode */
10168 phba->intr_mode = intr_mode;
10169 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -040010170
10171 /* Perform post initialization setup */
10172 lpfc_post_init_setup(phba);
10173
James Smartc71ab862012-10-31 14:44:33 -040010174 /* check for firmware upgrade or downgrade */
10175 if (phba->cfg_request_firmware_upgrade)
10176 ret = lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -040010177
James Smart1c6834a2009-07-19 10:01:26 -040010178 /* Check if there are static vports to be created. */
10179 lpfc_create_static_vport(phba);
James Smartda0436e2009-05-22 14:51:39 -040010180 return 0;
10181
10182out_disable_intr:
10183 lpfc_sli4_disable_intr(phba);
10184out_free_sysfs_attr:
10185 lpfc_free_sysfs_attr(vport);
10186out_destroy_shost:
10187 lpfc_destroy_shost(phba);
10188out_unset_driver_resource:
10189 lpfc_unset_driver_resource_phase2(phba);
10190out_free_iocb_list:
10191 lpfc_free_iocb_list(phba);
10192out_unset_driver_resource_s4:
10193 lpfc_sli4_driver_resource_unset(phba);
10194out_unset_pci_mem_s4:
10195 lpfc_sli4_pci_mem_unset(phba);
10196out_disable_pci_dev:
10197 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040010198 if (shost)
10199 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -040010200out_free_phba:
10201 lpfc_hba_free(phba);
10202 return error;
10203}
10204
10205/**
10206 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
10207 * @pdev: pointer to PCI device
10208 *
10209 * This routine is called from the kernel's PCI subsystem to device with
10210 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10211 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10212 * device to be removed from the PCI subsystem properly.
10213 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010214static void
James Smartda0436e2009-05-22 14:51:39 -040010215lpfc_pci_remove_one_s4(struct pci_dev *pdev)
10216{
10217 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10218 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
10219 struct lpfc_vport **vports;
10220 struct lpfc_hba *phba = vport->phba;
10221 int i;
10222
10223 /* Mark the device unloading flag */
10224 spin_lock_irq(&phba->hbalock);
10225 vport->load_flag |= FC_UNLOADING;
10226 spin_unlock_irq(&phba->hbalock);
10227
10228 /* Free the HBA sysfs attributes */
10229 lpfc_free_sysfs_attr(vport);
10230
10231 /* Release all the vports against this physical port */
10232 vports = lpfc_create_vport_work_array(phba);
10233 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040010234 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10235 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
10236 continue;
James Smartda0436e2009-05-22 14:51:39 -040010237 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040010238 }
James Smartda0436e2009-05-22 14:51:39 -040010239 lpfc_destroy_vport_work_array(phba, vports);
10240
10241 /* Remove FC host and then SCSI host with the physical port */
10242 fc_remove_host(shost);
10243 scsi_remove_host(shost);
10244
10245 /* Perform cleanup on the physical port */
10246 lpfc_cleanup(vport);
10247
10248 /*
10249 * Bring down the SLI Layer. This step disables all interrupts,
10250 * clears the rings, discards all mailbox commands, and resets
10251 * the HBA FCoE function.
10252 */
10253 lpfc_debugfs_terminate(vport);
10254 lpfc_sli4_hba_unset(phba);
10255
10256 spin_lock_irq(&phba->hbalock);
10257 list_del_init(&vport->listentry);
10258 spin_unlock_irq(&phba->hbalock);
10259
James Smart3677a3a2010-09-29 11:19:14 -040010260 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -040010261 * buffers are released to their corresponding pools here.
10262 */
10263 lpfc_scsi_free(phba);
James Smart67d12732012-08-03 12:36:13 -040010264
James Smartda0436e2009-05-22 14:51:39 -040010265 lpfc_sli4_driver_resource_unset(phba);
10266
10267 /* Unmap adapter Control and Doorbell registers */
10268 lpfc_sli4_pci_mem_unset(phba);
10269
10270 /* Release PCI resources and disable device's PCI function */
10271 scsi_host_put(shost);
10272 lpfc_disable_pci_dev(phba);
10273
10274 /* Finally, free the driver's device data structure */
10275 lpfc_hba_free(phba);
10276
10277 return;
10278}
10279
10280/**
10281 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
10282 * @pdev: pointer to PCI device
10283 * @msg: power management message
10284 *
10285 * This routine is called from the kernel's PCI subsystem to support system
10286 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
10287 * this method, it quiesces the device by stopping the driver's worker
10288 * thread for the device, turning off device's interrupt and DMA, and bring
10289 * the device offline. Note that as the driver implements the minimum PM
10290 * requirements to a power-aware driver's PM support for suspend/resume -- all
10291 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
10292 * method call will be treated as SUSPEND and the driver will fully
10293 * reinitialize its device during resume() method call, the driver will set
10294 * device to PCI_D3hot state in PCI config space instead of setting it
10295 * according to the @msg provided by the PM.
10296 *
10297 * Return code
10298 * 0 - driver suspended the device
10299 * Error otherwise
10300 **/
10301static int
10302lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
10303{
10304 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10305 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10306
10307 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -040010308 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -040010309
10310 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040010311 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -040010312 lpfc_offline(phba);
10313 kthread_stop(phba->worker_thread);
10314
10315 /* Disable interrupt from device */
10316 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040010317 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040010318
10319 /* Save device state to PCI config space */
10320 pci_save_state(pdev);
10321 pci_set_power_state(pdev, PCI_D3hot);
10322
10323 return 0;
10324}
10325
10326/**
10327 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
10328 * @pdev: pointer to PCI device
10329 *
10330 * This routine is called from the kernel's PCI subsystem to support system
10331 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
10332 * this method, it restores the device's PCI config space state and fully
10333 * reinitializes the device and brings it online. Note that as the driver
10334 * implements the minimum PM requirements to a power-aware driver's PM for
10335 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10336 * to the suspend() method call will be treated as SUSPEND and the driver
10337 * will fully reinitialize its device during resume() method call, the device
10338 * will be set to PCI_D0 directly in PCI config space before restoring the
10339 * state.
10340 *
10341 * Return code
10342 * 0 - driver suspended the device
10343 * Error otherwise
10344 **/
10345static int
10346lpfc_pci_resume_one_s4(struct pci_dev *pdev)
10347{
10348 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10349 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10350 uint32_t intr_mode;
10351 int error;
10352
10353 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10354 "0292 PCI device Power Management resume.\n");
10355
10356 /* Restore device state from PCI config space */
10357 pci_set_power_state(pdev, PCI_D0);
10358 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050010359
10360 /*
10361 * As the new kernel behavior of pci_restore_state() API call clears
10362 * device saved_state flag, need to save the restored state again.
10363 */
10364 pci_save_state(pdev);
10365
James Smartda0436e2009-05-22 14:51:39 -040010366 if (pdev->is_busmaster)
10367 pci_set_master(pdev);
10368
10369 /* Startup the kernel thread for this host adapter. */
10370 phba->worker_thread = kthread_run(lpfc_do_work, phba,
10371 "lpfc_worker_%d", phba->brd_no);
10372 if (IS_ERR(phba->worker_thread)) {
10373 error = PTR_ERR(phba->worker_thread);
10374 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10375 "0293 PM resume failed to start worker "
10376 "thread: error=x%x.\n", error);
10377 return error;
10378 }
10379
10380 /* Configure and enable interrupt */
10381 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
10382 if (intr_mode == LPFC_INTR_ERROR) {
10383 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10384 "0294 PM resume Failed to enable interrupt\n");
10385 return -EIO;
10386 } else
10387 phba->intr_mode = intr_mode;
10388
10389 /* Restart HBA and bring it online */
10390 lpfc_sli_brdrestart(phba);
10391 lpfc_online(phba);
10392
10393 /* Log the current active interrupt mode */
10394 lpfc_log_intr_mode(phba, phba->intr_mode);
10395
10396 return 0;
10397}
10398
10399/**
James Smart75baf692010-06-08 18:31:21 -040010400 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
10401 * @phba: pointer to lpfc hba data structure.
10402 *
10403 * This routine is called to prepare the SLI4 device for PCI slot recover. It
10404 * aborts all the outstanding SCSI I/Os to the pci device.
10405 **/
10406static void
10407lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
10408{
10409 struct lpfc_sli *psli = &phba->sli;
10410 struct lpfc_sli_ring *pring;
10411
10412 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10413 "2828 PCI channel I/O abort preparing for recovery\n");
10414 /*
10415 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10416 * and let the SCSI mid-layer to retry them to recover.
10417 */
10418 pring = &psli->ring[psli->fcp_ring];
10419 lpfc_sli_abort_iocb_ring(phba, pring);
10420}
10421
10422/**
10423 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
10424 * @phba: pointer to lpfc hba data structure.
10425 *
10426 * This routine is called to prepare the SLI4 device for PCI slot reset. It
10427 * disables the device interrupt and pci device, and aborts the internal FCP
10428 * pending I/Os.
10429 **/
10430static void
10431lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
10432{
10433 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10434 "2826 PCI channel disable preparing for reset\n");
10435
10436 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040010437 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010438
10439 /* Block all SCSI devices' I/Os on the host */
10440 lpfc_scsi_dev_block(phba);
10441
James Smartea714f32013-04-17 20:18:47 -040010442 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10443 lpfc_sli_flush_fcp_rings(phba);
10444
James Smart75baf692010-06-08 18:31:21 -040010445 /* stop all timers */
10446 lpfc_stop_hba_timers(phba);
10447
10448 /* Disable interrupt and pci device */
10449 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040010450 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -040010451 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -040010452}
10453
10454/**
10455 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
10456 * @phba: pointer to lpfc hba data structure.
10457 *
10458 * This routine is called to prepare the SLI4 device for PCI slot permanently
10459 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10460 * pending I/Os.
10461 **/
10462static void
10463lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
10464{
10465 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10466 "2827 PCI channel permanent disable for failure\n");
10467
10468 /* Block all SCSI devices' I/Os on the host */
10469 lpfc_scsi_dev_block(phba);
10470
10471 /* stop all timers */
10472 lpfc_stop_hba_timers(phba);
10473
10474 /* Clean up all driver's outstanding SCSI I/Os */
10475 lpfc_sli_flush_fcp_rings(phba);
10476}
10477
10478/**
James Smartda0436e2009-05-22 14:51:39 -040010479 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
10480 * @pdev: pointer to PCI device.
10481 * @state: the current PCI connection state.
10482 *
10483 * This routine is called from the PCI subsystem for error handling to device
10484 * with SLI-4 interface spec. This function is called by the PCI subsystem
10485 * after a PCI bus error affecting this device has been detected. When this
10486 * function is invoked, it will need to stop all the I/Os and interrupt(s)
10487 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
10488 * for the PCI subsystem to perform proper recovery as desired.
10489 *
10490 * Return codes
10491 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10492 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10493 **/
10494static pci_ers_result_t
10495lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
10496{
James Smart75baf692010-06-08 18:31:21 -040010497 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10498 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10499
10500 switch (state) {
10501 case pci_channel_io_normal:
10502 /* Non-fatal error, prepare for recovery */
10503 lpfc_sli4_prep_dev_for_recover(phba);
10504 return PCI_ERS_RESULT_CAN_RECOVER;
10505 case pci_channel_io_frozen:
10506 /* Fatal error, prepare for slot reset */
10507 lpfc_sli4_prep_dev_for_reset(phba);
10508 return PCI_ERS_RESULT_NEED_RESET;
10509 case pci_channel_io_perm_failure:
10510 /* Permanent failure, prepare for device down */
10511 lpfc_sli4_prep_dev_for_perm_failure(phba);
10512 return PCI_ERS_RESULT_DISCONNECT;
10513 default:
10514 /* Unknown state, prepare and request slot reset */
10515 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10516 "2825 Unknown PCI error state: x%x\n", state);
10517 lpfc_sli4_prep_dev_for_reset(phba);
10518 return PCI_ERS_RESULT_NEED_RESET;
10519 }
James Smartda0436e2009-05-22 14:51:39 -040010520}
10521
10522/**
10523 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
10524 * @pdev: pointer to PCI device.
10525 *
10526 * This routine is called from the PCI subsystem for error handling to device
10527 * with SLI-4 interface spec. It is called after PCI bus has been reset to
10528 * restart the PCI card from scratch, as if from a cold-boot. During the
10529 * PCI subsystem error recovery, after the driver returns
10530 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10531 * recovery and then call this routine before calling the .resume method to
10532 * recover the device. This function will initialize the HBA device, enable
10533 * the interrupt, but it will just put the HBA to offline state without
10534 * passing any I/O traffic.
10535 *
10536 * Return codes
10537 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10538 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10539 */
10540static pci_ers_result_t
10541lpfc_io_slot_reset_s4(struct pci_dev *pdev)
10542{
James Smart75baf692010-06-08 18:31:21 -040010543 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10544 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10545 struct lpfc_sli *psli = &phba->sli;
10546 uint32_t intr_mode;
10547
10548 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
10549 if (pci_enable_device_mem(pdev)) {
10550 printk(KERN_ERR "lpfc: Cannot re-enable "
10551 "PCI device after reset.\n");
10552 return PCI_ERS_RESULT_DISCONNECT;
10553 }
10554
10555 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040010556
10557 /*
10558 * As the new kernel behavior of pci_restore_state() API call clears
10559 * device saved_state flag, need to save the restored state again.
10560 */
10561 pci_save_state(pdev);
10562
James Smart75baf692010-06-08 18:31:21 -040010563 if (pdev->is_busmaster)
10564 pci_set_master(pdev);
10565
10566 spin_lock_irq(&phba->hbalock);
10567 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
10568 spin_unlock_irq(&phba->hbalock);
10569
10570 /* Configure and enable interrupt */
10571 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
10572 if (intr_mode == LPFC_INTR_ERROR) {
10573 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10574 "2824 Cannot re-enable interrupt after "
10575 "slot reset.\n");
10576 return PCI_ERS_RESULT_DISCONNECT;
10577 } else
10578 phba->intr_mode = intr_mode;
10579
10580 /* Log the current active interrupt mode */
10581 lpfc_log_intr_mode(phba, phba->intr_mode);
10582
James Smartda0436e2009-05-22 14:51:39 -040010583 return PCI_ERS_RESULT_RECOVERED;
10584}
10585
10586/**
10587 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
10588 * @pdev: pointer to PCI device
10589 *
10590 * This routine is called from the PCI subsystem for error handling to device
10591 * with SLI-4 interface spec. It is called when kernel error recovery tells
10592 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10593 * error recovery. After this call, traffic can start to flow from this device
10594 * again.
10595 **/
10596static void
10597lpfc_io_resume_s4(struct pci_dev *pdev)
10598{
James Smart75baf692010-06-08 18:31:21 -040010599 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10600 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10601
10602 /*
10603 * In case of slot reset, as function reset is performed through
10604 * mailbox command which needs DMA to be enabled, this operation
10605 * has to be moved to the io resume phase. Taking device offline
10606 * will perform the necessary cleanup.
10607 */
10608 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
10609 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040010610 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010611 lpfc_offline(phba);
10612 lpfc_sli_brdrestart(phba);
10613 /* Bring the device back online */
10614 lpfc_online(phba);
10615 }
10616
10617 /* Clean up Advanced Error Reporting (AER) if needed */
10618 if (phba->hba_flag & HBA_AER_ENABLED)
10619 pci_cleanup_aer_uncorrect_error_status(pdev);
James Smartda0436e2009-05-22 14:51:39 -040010620}
10621
10622/**
James Smart3772a992009-05-22 14:50:54 -040010623 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
10624 * @pdev: pointer to PCI device
10625 * @pid: pointer to PCI device identifier
10626 *
10627 * This routine is to be registered to the kernel's PCI subsystem. When an
10628 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
10629 * at PCI device-specific information of the device and driver to see if the
10630 * driver state that it can support this kind of device. If the match is
10631 * successful, the driver core invokes this routine. This routine dispatches
10632 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
10633 * do all the initialization that it needs to do to handle the HBA device
10634 * properly.
10635 *
10636 * Return code
10637 * 0 - driver can claim the device
10638 * negative value - driver can not claim the device
10639 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010640static int
James Smart3772a992009-05-22 14:50:54 -040010641lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
10642{
10643 int rc;
James Smart8fa38512009-07-19 10:01:03 -040010644 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040010645
James Smart28baac72010-02-12 14:42:03 -050010646 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040010647 return -ENODEV;
10648
James Smart8fa38512009-07-19 10:01:03 -040010649 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050010650 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040010651 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040010652 else
James Smart3772a992009-05-22 14:50:54 -040010653 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040010654
James Smart3772a992009-05-22 14:50:54 -040010655 return rc;
10656}
10657
10658/**
10659 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
10660 * @pdev: pointer to PCI device
10661 *
10662 * This routine is to be registered to the kernel's PCI subsystem. When an
10663 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
10664 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
10665 * remove routine, which will perform all the necessary cleanup for the
10666 * device to be removed from the PCI subsystem properly.
10667 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010668static void
James Smart3772a992009-05-22 14:50:54 -040010669lpfc_pci_remove_one(struct pci_dev *pdev)
10670{
10671 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10672 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10673
10674 switch (phba->pci_dev_grp) {
10675 case LPFC_PCI_DEV_LP:
10676 lpfc_pci_remove_one_s3(pdev);
10677 break;
James Smartda0436e2009-05-22 14:51:39 -040010678 case LPFC_PCI_DEV_OC:
10679 lpfc_pci_remove_one_s4(pdev);
10680 break;
James Smart3772a992009-05-22 14:50:54 -040010681 default:
10682 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10683 "1424 Invalid PCI device group: 0x%x\n",
10684 phba->pci_dev_grp);
10685 break;
10686 }
10687 return;
10688}
10689
10690/**
10691 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
10692 * @pdev: pointer to PCI device
10693 * @msg: power management message
10694 *
10695 * This routine is to be registered to the kernel's PCI subsystem to support
10696 * system Power Management (PM). When PM invokes this method, it dispatches
10697 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
10698 * suspend the device.
10699 *
10700 * Return code
10701 * 0 - driver suspended the device
10702 * Error otherwise
10703 **/
10704static int
10705lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
10706{
10707 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10708 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10709 int rc = -ENODEV;
10710
10711 switch (phba->pci_dev_grp) {
10712 case LPFC_PCI_DEV_LP:
10713 rc = lpfc_pci_suspend_one_s3(pdev, msg);
10714 break;
James Smartda0436e2009-05-22 14:51:39 -040010715 case LPFC_PCI_DEV_OC:
10716 rc = lpfc_pci_suspend_one_s4(pdev, msg);
10717 break;
James Smart3772a992009-05-22 14:50:54 -040010718 default:
10719 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10720 "1425 Invalid PCI device group: 0x%x\n",
10721 phba->pci_dev_grp);
10722 break;
10723 }
10724 return rc;
10725}
10726
10727/**
10728 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
10729 * @pdev: pointer to PCI device
10730 *
10731 * This routine is to be registered to the kernel's PCI subsystem to support
10732 * system Power Management (PM). When PM invokes this method, it dispatches
10733 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
10734 * resume the device.
10735 *
10736 * Return code
10737 * 0 - driver suspended the device
10738 * Error otherwise
10739 **/
10740static int
10741lpfc_pci_resume_one(struct pci_dev *pdev)
10742{
10743 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10744 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10745 int rc = -ENODEV;
10746
10747 switch (phba->pci_dev_grp) {
10748 case LPFC_PCI_DEV_LP:
10749 rc = lpfc_pci_resume_one_s3(pdev);
10750 break;
James Smartda0436e2009-05-22 14:51:39 -040010751 case LPFC_PCI_DEV_OC:
10752 rc = lpfc_pci_resume_one_s4(pdev);
10753 break;
James Smart3772a992009-05-22 14:50:54 -040010754 default:
10755 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10756 "1426 Invalid PCI device group: 0x%x\n",
10757 phba->pci_dev_grp);
10758 break;
10759 }
10760 return rc;
10761}
10762
10763/**
10764 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
10765 * @pdev: pointer to PCI device.
10766 * @state: the current PCI connection state.
10767 *
10768 * This routine is registered to the PCI subsystem for error handling. This
10769 * function is called by the PCI subsystem after a PCI bus error affecting
10770 * this device has been detected. When this routine is invoked, it dispatches
10771 * the action to the proper SLI-3 or SLI-4 device error detected handling
10772 * routine, which will perform the proper error detected operation.
10773 *
10774 * Return codes
10775 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10776 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10777 **/
10778static pci_ers_result_t
10779lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
10780{
10781 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10782 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10783 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
10784
10785 switch (phba->pci_dev_grp) {
10786 case LPFC_PCI_DEV_LP:
10787 rc = lpfc_io_error_detected_s3(pdev, state);
10788 break;
James Smartda0436e2009-05-22 14:51:39 -040010789 case LPFC_PCI_DEV_OC:
10790 rc = lpfc_io_error_detected_s4(pdev, state);
10791 break;
James Smart3772a992009-05-22 14:50:54 -040010792 default:
10793 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10794 "1427 Invalid PCI device group: 0x%x\n",
10795 phba->pci_dev_grp);
10796 break;
10797 }
10798 return rc;
10799}
10800
10801/**
10802 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
10803 * @pdev: pointer to PCI device.
10804 *
10805 * This routine is registered to the PCI subsystem for error handling. This
10806 * function is called after PCI bus has been reset to restart the PCI card
10807 * from scratch, as if from a cold-boot. When this routine is invoked, it
10808 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
10809 * routine, which will perform the proper device reset.
10810 *
10811 * Return codes
10812 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10813 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10814 **/
10815static pci_ers_result_t
10816lpfc_io_slot_reset(struct pci_dev *pdev)
10817{
10818 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10819 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10820 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
10821
10822 switch (phba->pci_dev_grp) {
10823 case LPFC_PCI_DEV_LP:
10824 rc = lpfc_io_slot_reset_s3(pdev);
10825 break;
James Smartda0436e2009-05-22 14:51:39 -040010826 case LPFC_PCI_DEV_OC:
10827 rc = lpfc_io_slot_reset_s4(pdev);
10828 break;
James Smart3772a992009-05-22 14:50:54 -040010829 default:
10830 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10831 "1428 Invalid PCI device group: 0x%x\n",
10832 phba->pci_dev_grp);
10833 break;
10834 }
10835 return rc;
10836}
10837
10838/**
10839 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
10840 * @pdev: pointer to PCI device
10841 *
10842 * This routine is registered to the PCI subsystem for error handling. It
10843 * is called when kernel error recovery tells the lpfc driver that it is
10844 * OK to resume normal PCI operation after PCI bus error recovery. When
10845 * this routine is invoked, it dispatches the action to the proper SLI-3
10846 * or SLI-4 device io_resume routine, which will resume the device operation.
10847 **/
10848static void
10849lpfc_io_resume(struct pci_dev *pdev)
10850{
10851 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10852 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10853
10854 switch (phba->pci_dev_grp) {
10855 case LPFC_PCI_DEV_LP:
10856 lpfc_io_resume_s3(pdev);
10857 break;
James Smartda0436e2009-05-22 14:51:39 -040010858 case LPFC_PCI_DEV_OC:
10859 lpfc_io_resume_s4(pdev);
10860 break;
James Smart3772a992009-05-22 14:50:54 -040010861 default:
10862 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10863 "1429 Invalid PCI device group: 0x%x\n",
10864 phba->pci_dev_grp);
10865 break;
10866 }
10867 return;
10868}
10869
James Smart1ba981f2014-02-20 09:56:45 -050010870/**
10871 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
10872 * @phba: pointer to lpfc hba data structure.
10873 *
10874 * This routine checks to see if OAS is supported for this adapter. If
10875 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
10876 * the enable oas flag is cleared and the pool created for OAS device data
10877 * is destroyed.
10878 *
10879 **/
10880void
10881lpfc_sli4_oas_verify(struct lpfc_hba *phba)
10882{
10883
10884 if (!phba->cfg_EnableXLane)
10885 return;
10886
10887 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
10888 phba->cfg_fof = 1;
10889 } else {
10890 phba->cfg_EnableXLane = 0;
10891 if (phba->device_data_mem_pool)
10892 mempool_destroy(phba->device_data_mem_pool);
10893 phba->device_data_mem_pool = NULL;
10894 }
10895
10896 return;
10897}
10898
10899/**
10900 * lpfc_fof_queue_setup - Set up all the fof queues
10901 * @phba: pointer to lpfc hba data structure.
10902 *
10903 * This routine is invoked to set up all the fof queues for the FC HBA
10904 * operation.
10905 *
10906 * Return codes
10907 * 0 - successful
10908 * -ENOMEM - No available memory
10909 **/
10910int
10911lpfc_fof_queue_setup(struct lpfc_hba *phba)
10912{
10913 struct lpfc_sli *psli = &phba->sli;
10914 int rc;
10915
10916 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
10917 if (rc)
10918 return -ENOMEM;
10919
10920 if (phba->cfg_EnableXLane) {
10921
10922 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
10923 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
10924 if (rc)
10925 goto out_oas_cq;
10926
10927 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
10928 phba->sli4_hba.oas_cq, LPFC_FCP);
10929 if (rc)
10930 goto out_oas_wq;
10931
10932 phba->sli4_hba.oas_cq->pring = &psli->ring[LPFC_FCP_OAS_RING];
10933 phba->sli4_hba.oas_ring = &psli->ring[LPFC_FCP_OAS_RING];
10934 }
10935
10936 return 0;
10937
10938out_oas_wq:
10939 if (phba->cfg_EnableXLane)
10940 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
10941out_oas_cq:
10942 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
10943 return rc;
10944
10945}
10946
10947/**
10948 * lpfc_fof_queue_create - Create all the fof queues
10949 * @phba: pointer to lpfc hba data structure.
10950 *
10951 * This routine is invoked to allocate all the fof queues for the FC HBA
10952 * operation. For each SLI4 queue type, the parameters such as queue entry
10953 * count (queue depth) shall be taken from the module parameter. For now,
10954 * we just use some constant number as place holder.
10955 *
10956 * Return codes
10957 * 0 - successful
10958 * -ENOMEM - No availble memory
10959 * -EIO - The mailbox failed to complete successfully.
10960 **/
10961int
10962lpfc_fof_queue_create(struct lpfc_hba *phba)
10963{
10964 struct lpfc_queue *qdesc;
10965
10966 /* Create FOF EQ */
10967 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
10968 phba->sli4_hba.eq_ecount);
10969 if (!qdesc)
10970 goto out_error;
10971
10972 phba->sli4_hba.fof_eq = qdesc;
10973
10974 if (phba->cfg_EnableXLane) {
10975
10976 /* Create OAS CQ */
10977 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
10978 phba->sli4_hba.cq_ecount);
10979 if (!qdesc)
10980 goto out_error;
10981
10982 phba->sli4_hba.oas_cq = qdesc;
10983
10984 /* Create OAS WQ */
10985 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
10986 phba->sli4_hba.wq_ecount);
10987 if (!qdesc)
10988 goto out_error;
10989
10990 phba->sli4_hba.oas_wq = qdesc;
10991
10992 }
10993 return 0;
10994
10995out_error:
10996 lpfc_fof_queue_destroy(phba);
10997 return -ENOMEM;
10998}
10999
11000/**
11001 * lpfc_fof_queue_destroy - Destroy all the fof queues
11002 * @phba: pointer to lpfc hba data structure.
11003 *
11004 * This routine is invoked to release all the SLI4 queues with the FC HBA
11005 * operation.
11006 *
11007 * Return codes
11008 * 0 - successful
11009 **/
11010int
11011lpfc_fof_queue_destroy(struct lpfc_hba *phba)
11012{
11013 /* Release FOF Event queue */
11014 if (phba->sli4_hba.fof_eq != NULL) {
11015 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
11016 phba->sli4_hba.fof_eq = NULL;
11017 }
11018
11019 /* Release OAS Completion queue */
11020 if (phba->sli4_hba.oas_cq != NULL) {
11021 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
11022 phba->sli4_hba.oas_cq = NULL;
11023 }
11024
11025 /* Release OAS Work queue */
11026 if (phba->sli4_hba.oas_wq != NULL) {
11027 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
11028 phba->sli4_hba.oas_wq = NULL;
11029 }
11030 return 0;
11031}
11032
dea31012005-04-17 16:05:31 -050011033static struct pci_device_id lpfc_id_table[] = {
11034 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
11035 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -040011036 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
11037 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011038 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
11039 PCI_ANY_ID, PCI_ANY_ID, },
11040 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
11041 PCI_ANY_ID, PCI_ANY_ID, },
11042 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
11043 PCI_ANY_ID, PCI_ANY_ID, },
11044 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
11045 PCI_ANY_ID, PCI_ANY_ID, },
11046 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
11047 PCI_ANY_ID, PCI_ANY_ID, },
11048 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
11049 PCI_ANY_ID, PCI_ANY_ID, },
11050 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
11051 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011052 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
11053 PCI_ANY_ID, PCI_ANY_ID, },
11054 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
11055 PCI_ANY_ID, PCI_ANY_ID, },
11056 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
11057 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011058 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
11059 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011060 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
11061 PCI_ANY_ID, PCI_ANY_ID, },
11062 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
11063 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011064 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
11065 PCI_ANY_ID, PCI_ANY_ID, },
11066 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
11067 PCI_ANY_ID, PCI_ANY_ID, },
11068 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
11069 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -040011070 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
11071 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011072 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
11073 PCI_ANY_ID, PCI_ANY_ID, },
11074 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
11075 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011076 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
11077 PCI_ANY_ID, PCI_ANY_ID, },
11078 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
11079 PCI_ANY_ID, PCI_ANY_ID, },
11080 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
11081 PCI_ANY_ID, PCI_ANY_ID, },
11082 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
11083 PCI_ANY_ID, PCI_ANY_ID, },
11084 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
11085 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011086 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
11087 PCI_ANY_ID, PCI_ANY_ID, },
11088 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
11089 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -040011090 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
11091 PCI_ANY_ID, PCI_ANY_ID, },
11092 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
11093 PCI_ANY_ID, PCI_ANY_ID, },
11094 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
11095 PCI_ANY_ID, PCI_ANY_ID, },
11096 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
11097 PCI_ANY_ID, PCI_ANY_ID, },
11098 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
11099 PCI_ANY_ID, PCI_ANY_ID, },
11100 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
11101 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -040011102 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
11103 PCI_ANY_ID, PCI_ANY_ID, },
11104 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
11105 PCI_ANY_ID, PCI_ANY_ID, },
11106 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
11107 PCI_ANY_ID, PCI_ANY_ID, },
James Smart3772a992009-05-22 14:50:54 -040011108 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
11109 PCI_ANY_ID, PCI_ANY_ID, },
James Smarta747c9c2009-11-18 15:41:10 -050011110 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT,
11111 PCI_ANY_ID, PCI_ANY_ID, },
11112 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON,
James Smart6669f9b2009-10-02 15:16:45 -040011113 PCI_ANY_ID, PCI_ANY_ID, },
James Smart98fc5dd2010-06-07 15:24:29 -040011114 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS,
11115 PCI_ANY_ID, PCI_ANY_ID, },
James Smart085c6472010-11-20 23:11:37 -050011116 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC,
11117 PCI_ANY_ID, PCI_ANY_ID, },
11118 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE,
11119 PCI_ANY_ID, PCI_ANY_ID, },
James Smartc0c11512011-05-24 11:41:34 -040011120 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF,
11121 PCI_ANY_ID, PCI_ANY_ID, },
11122 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF,
11123 PCI_ANY_ID, PCI_ANY_ID, },
James Smartf8cafd32012-08-03 12:42:51 -040011124 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK,
11125 PCI_ANY_ID, PCI_ANY_ID, },
11126 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF,
11127 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011128 { 0 }
11129};
11130
11131MODULE_DEVICE_TABLE(pci, lpfc_id_table);
11132
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070011133static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060011134 .error_detected = lpfc_io_error_detected,
11135 .slot_reset = lpfc_io_slot_reset,
11136 .resume = lpfc_io_resume,
11137};
11138
dea31012005-04-17 16:05:31 -050011139static struct pci_driver lpfc_driver = {
11140 .name = LPFC_DRIVER_NAME,
11141 .id_table = lpfc_id_table,
11142 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011143 .remove = lpfc_pci_remove_one,
James Smart3a55b532008-12-04 22:38:54 -050011144 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040011145 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050011146 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050011147};
11148
James Smart3ef6d242012-01-18 16:23:48 -050011149static const struct file_operations lpfc_mgmt_fop = {
Al Viro858feac2013-04-14 22:39:37 -040011150 .owner = THIS_MODULE,
James Smart3ef6d242012-01-18 16:23:48 -050011151};
11152
11153static struct miscdevice lpfc_mgmt_dev = {
11154 .minor = MISC_DYNAMIC_MINOR,
11155 .name = "lpfcmgmt",
11156 .fops = &lpfc_mgmt_fop,
11157};
11158
James Smarte59058c2008-08-24 21:49:00 -040011159/**
James Smart3621a712009-04-06 18:47:14 -040011160 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040011161 *
11162 * This routine is to be invoked when the lpfc module is loaded into the
11163 * kernel. The special kernel macro module_init() is used to indicate the
11164 * role of this routine to the kernel as lpfc module entry point.
11165 *
11166 * Return codes
11167 * 0 - successful
11168 * -ENOMEM - FC attach transport failed
11169 * all others - failed
11170 */
dea31012005-04-17 16:05:31 -050011171static int __init
11172lpfc_init(void)
11173{
James Smart7bb03bb2013-04-17 20:19:16 -040011174 int cpu;
dea31012005-04-17 16:05:31 -050011175 int error = 0;
11176
11177 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040011178 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050011179
James Smart3ef6d242012-01-18 16:23:48 -050011180 error = misc_register(&lpfc_mgmt_dev);
11181 if (error)
11182 printk(KERN_ERR "Could not register lpfcmgmt device, "
11183 "misc_register returned with status %d", error);
11184
James Smart7ee5d432007-10-27 13:37:17 -040011185 if (lpfc_enable_npiv) {
11186 lpfc_transport_functions.vport_create = lpfc_vport_create;
11187 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
11188 }
dea31012005-04-17 16:05:31 -050011189 lpfc_transport_template =
11190 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040011191 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050011192 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040011193 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -040011194 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -040011195 fc_attach_transport(&lpfc_vport_transport_functions);
11196 if (lpfc_vport_transport_template == NULL) {
11197 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040011198 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -040011199 }
James Smart7ee5d432007-10-27 13:37:17 -040011200 }
James Smart7bb03bb2013-04-17 20:19:16 -040011201
11202 /* Initialize in case vector mapping is needed */
James Smartb246de12013-05-31 17:03:07 -040011203 lpfc_used_cpu = NULL;
11204 lpfc_present_cpu = 0;
11205 for_each_present_cpu(cpu)
11206 lpfc_present_cpu++;
James Smart7bb03bb2013-04-17 20:19:16 -040011207
dea31012005-04-17 16:05:31 -050011208 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050011209 if (error) {
dea31012005-04-17 16:05:31 -050011210 fc_release_transport(lpfc_transport_template);
James Smartd7c255b2008-08-24 21:50:00 -040011211 if (lpfc_enable_npiv)
11212 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050011213 }
dea31012005-04-17 16:05:31 -050011214
11215 return error;
11216}
11217
James Smarte59058c2008-08-24 21:49:00 -040011218/**
James Smart3621a712009-04-06 18:47:14 -040011219 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040011220 *
11221 * This routine is invoked when the lpfc module is removed from the kernel.
11222 * The special kernel macro module_exit() is used to indicate the role of
11223 * this routine to the kernel as lpfc module exit point.
11224 */
dea31012005-04-17 16:05:31 -050011225static void __exit
11226lpfc_exit(void)
11227{
James Smart3ef6d242012-01-18 16:23:48 -050011228 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050011229 pci_unregister_driver(&lpfc_driver);
11230 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040011231 if (lpfc_enable_npiv)
11232 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050011233 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040011234 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
11235 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050011236 (1L << _dump_buf_data_order), _dump_buf_data);
11237 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
11238 }
11239
11240 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040011241 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
11242 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050011243 (1L << _dump_buf_dif_order), _dump_buf_dif);
11244 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
11245 }
James Smartb246de12013-05-31 17:03:07 -040011246 kfree(lpfc_used_cpu);
dea31012005-04-17 16:05:31 -050011247}
11248
11249module_init(lpfc_init);
11250module_exit(lpfc_exit);
11251MODULE_LICENSE("GPL");
11252MODULE_DESCRIPTION(LPFC_MODULE_DESC);
11253MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
11254MODULE_VERSION("0:" LPFC_DRIVER_VERSION);