blob: d9753e3e9737540370e463604839f178e1f0886c [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 Smartf25e8e72015-04-07 15:07:28 -04004 * Copyright (C) 2004-2015 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))
James Smarta2fc4aef2014-09-03 12:57:55 -0400309 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
James Smart97207482008-12-04 22:39:19 -0500310 prg->ver, prg->rev, prg->lev);
311 else
James Smarta2fc4aef2014-09-03 12:57:55 -0400312 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
James Smart97207482008-12-04 22:39:19 -0500313 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 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400652static int
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) &&
James Smartd38dd522015-08-31 16:48:17 -0400702 !(phba->lmt & LMT_16Gb)) ||
703 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
704 !(phba->lmt & LMT_32Gb))) {
James Smart026abb82011-12-13 13:20:45 -0500705 /* Reset link speed to auto */
706 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
707 "1302 Invalid speed for this board:%d "
708 "Reset link speed to auto.\n",
709 phba->cfg_link_speed);
710 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
711 }
James Smart1b511972011-12-13 13:23:09 -0500712 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
James Smart84d1b002010-02-12 14:42:33 -0500713 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart1b511972011-12-13 13:23:09 -0500714 if (phba->sli_rev < LPFC_SLI_REV4)
715 lpfc_set_loopback_flag(phba);
James Smart6e7288d2010-06-07 15:23:35 -0400716 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart76a95d72010-11-20 23:11:48 -0500717 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
James Smart84d1b002010-02-12 14:42:33 -0500718 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
719 "0498 Adapter failed to init, mbxCmd x%x "
720 "INIT_LINK, mbxStatus x%x\n",
721 mb->mbxCommand, mb->mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -0500722 if (phba->sli_rev <= LPFC_SLI_REV3) {
723 /* Clear all interrupt enable conditions */
724 writel(0, phba->HCregaddr);
725 readl(phba->HCregaddr); /* flush */
726 /* Clear all pending interrupts */
727 writel(0xffffffff, phba->HAregaddr);
728 readl(phba->HAregaddr); /* flush */
729 }
James Smart84d1b002010-02-12 14:42:33 -0500730 phba->link_state = LPFC_HBA_ERROR;
James Smart6e7288d2010-06-07 15:23:35 -0400731 if (rc != MBX_BUSY || flag == MBX_POLL)
James Smart84d1b002010-02-12 14:42:33 -0500732 mempool_free(pmb, phba->mbox_mem_pool);
733 return -EIO;
734 }
James Smarte40a02c2010-02-26 14:13:54 -0500735 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
James Smart6e7288d2010-06-07 15:23:35 -0400736 if (flag == MBX_POLL)
737 mempool_free(pmb, phba->mbox_mem_pool);
James Smart84d1b002010-02-12 14:42:33 -0500738
739 return 0;
740}
741
742/**
743 * lpfc_hba_down_link - this routine downs the FC link
James Smart6e7288d2010-06-07 15:23:35 -0400744 * @phba: pointer to lpfc hba data structure.
745 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500746 *
747 * This routine will issue the DOWN_LINK mailbox command call.
748 * It is available to other drivers through the lpfc_hba data
749 * structure for use to stop the link.
750 *
751 * Return code
752 * 0 - success
753 * Any other value - error
754 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400755static int
James Smart6e7288d2010-06-07 15:23:35 -0400756lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500757{
758 LPFC_MBOXQ_t *pmb;
759 int rc;
760
761 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
762 if (!pmb) {
763 phba->link_state = LPFC_HBA_ERROR;
764 return -ENOMEM;
765 }
766
767 lpfc_printf_log(phba,
768 KERN_ERR, LOG_INIT,
769 "0491 Adapter Link is disabled.\n");
770 lpfc_down_link(phba, pmb);
771 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart6e7288d2010-06-07 15:23:35 -0400772 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart84d1b002010-02-12 14:42:33 -0500773 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
774 lpfc_printf_log(phba,
775 KERN_ERR, LOG_INIT,
776 "2522 Adapter failed to issue DOWN_LINK"
777 " mbox command rc 0x%x\n", rc);
778
779 mempool_free(pmb, phba->mbox_mem_pool);
780 return -EIO;
781 }
James Smart6e7288d2010-06-07 15:23:35 -0400782 if (flag == MBX_POLL)
783 mempool_free(pmb, phba->mbox_mem_pool);
784
James Smart84d1b002010-02-12 14:42:33 -0500785 return 0;
786}
787
788/**
James Smart3621a712009-04-06 18:47:14 -0400789 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400790 * @phba: pointer to lpfc HBA data structure.
791 *
792 * This routine will do LPFC uninitialization before the HBA is reset when
793 * bringing down the SLI Layer.
794 *
795 * Return codes
796 * 0 - success.
797 * Any other value - error.
798 **/
dea31012005-04-17 16:05:31 -0500799int
James Smart2e0fef82007-06-17 19:56:36 -0500800lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500801{
James Smart1b32f6a2008-02-08 18:49:39 -0500802 struct lpfc_vport **vports;
803 int i;
James Smart3772a992009-05-22 14:50:54 -0400804
805 if (phba->sli_rev <= LPFC_SLI_REV3) {
806 /* Disable interrupts */
807 writel(0, phba->HCregaddr);
808 readl(phba->HCregaddr); /* flush */
809 }
dea31012005-04-17 16:05:31 -0500810
James Smart1b32f6a2008-02-08 18:49:39 -0500811 if (phba->pport->load_flag & FC_UNLOADING)
812 lpfc_cleanup_discovery_resources(phba->pport);
813 else {
814 vports = lpfc_create_vport_work_array(phba);
815 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -0400816 for (i = 0; i <= phba->max_vports &&
817 vports[i] != NULL; i++)
James Smart1b32f6a2008-02-08 18:49:39 -0500818 lpfc_cleanup_discovery_resources(vports[i]);
819 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500820 }
821 return 0;
dea31012005-04-17 16:05:31 -0500822}
823
James Smarte59058c2008-08-24 21:49:00 -0400824/**
James Smart68e814f2014-05-21 08:04:59 -0400825 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
826 * rspiocb which got deferred
827 *
828 * @phba: pointer to lpfc HBA data structure.
829 *
830 * This routine will cleanup completed slow path events after HBA is reset
831 * when bringing down the SLI Layer.
832 *
833 *
834 * Return codes
835 * void.
836 **/
837static void
838lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
839{
840 struct lpfc_iocbq *rspiocbq;
841 struct hbq_dmabuf *dmabuf;
842 struct lpfc_cq_event *cq_event;
843
844 spin_lock_irq(&phba->hbalock);
845 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
846 spin_unlock_irq(&phba->hbalock);
847
848 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
849 /* Get the response iocb from the head of work queue */
850 spin_lock_irq(&phba->hbalock);
851 list_remove_head(&phba->sli4_hba.sp_queue_event,
852 cq_event, struct lpfc_cq_event, list);
853 spin_unlock_irq(&phba->hbalock);
854
855 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
856 case CQE_CODE_COMPL_WQE:
857 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
858 cq_event);
859 lpfc_sli_release_iocbq(phba, rspiocbq);
860 break;
861 case CQE_CODE_RECEIVE:
862 case CQE_CODE_RECEIVE_V1:
863 dmabuf = container_of(cq_event, struct hbq_dmabuf,
864 cq_event);
865 lpfc_in_buf_free(phba, &dmabuf->dbuf);
866 }
867 }
868}
869
870/**
James Smartbcece5f2014-04-04 13:51:34 -0400871 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
872 * @phba: pointer to lpfc HBA data structure.
873 *
874 * This routine will cleanup posted ELS buffers after the HBA is reset
875 * when bringing down the SLI Layer.
876 *
877 *
878 * Return codes
879 * void.
880 **/
881static void
882lpfc_hba_free_post_buf(struct lpfc_hba *phba)
883{
884 struct lpfc_sli *psli = &phba->sli;
885 struct lpfc_sli_ring *pring;
886 struct lpfc_dmabuf *mp, *next_mp;
James Smart07eab622014-04-04 13:51:44 -0400887 LIST_HEAD(buflist);
888 int count;
James Smartbcece5f2014-04-04 13:51:34 -0400889
890 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
891 lpfc_sli_hbqbuf_free_all(phba);
892 else {
893 /* Cleanup preposted buffers on the ELS ring */
James Smartbcece5f2014-04-04 13:51:34 -0400894 pring = &psli->ring[LPFC_ELS_RING];
James Smart07eab622014-04-04 13:51:44 -0400895 spin_lock_irq(&phba->hbalock);
896 list_splice_init(&pring->postbufq, &buflist);
897 spin_unlock_irq(&phba->hbalock);
898
899 count = 0;
900 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
James Smartbcece5f2014-04-04 13:51:34 -0400901 list_del(&mp->list);
James Smart07eab622014-04-04 13:51:44 -0400902 count++;
James Smartbcece5f2014-04-04 13:51:34 -0400903 lpfc_mbuf_free(phba, mp->virt, mp->phys);
904 kfree(mp);
905 }
James Smart07eab622014-04-04 13:51:44 -0400906
907 spin_lock_irq(&phba->hbalock);
908 pring->postbufq_cnt -= count;
James Smartbcece5f2014-04-04 13:51:34 -0400909 spin_unlock_irq(&phba->hbalock);
910 }
911}
912
913/**
914 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
915 * @phba: pointer to lpfc HBA data structure.
916 *
917 * This routine will cleanup the txcmplq after the HBA is reset when bringing
918 * down the SLI Layer.
919 *
920 * Return codes
921 * void
922 **/
923static void
924lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
925{
926 struct lpfc_sli *psli = &phba->sli;
927 struct lpfc_sli_ring *pring;
928 LIST_HEAD(completions);
929 int i;
930
James Smartbcece5f2014-04-04 13:51:34 -0400931 for (i = 0; i < psli->num_rings; i++) {
932 pring = &psli->ring[i];
933 if (phba->sli_rev >= LPFC_SLI_REV4)
934 spin_lock_irq(&pring->ring_lock);
935 else
936 spin_lock_irq(&phba->hbalock);
937 /* At this point in time the HBA is either reset or DOA. Either
938 * way, nothing should be on txcmplq as it will NEVER complete.
939 */
940 list_splice_init(&pring->txcmplq, &completions);
James Smartdb55fba2014-04-04 13:52:02 -0400941 pring->txcmplq_cnt = 0;
James Smartbcece5f2014-04-04 13:51:34 -0400942
943 if (phba->sli_rev >= LPFC_SLI_REV4)
944 spin_unlock_irq(&pring->ring_lock);
945 else
946 spin_unlock_irq(&phba->hbalock);
947
948 /* Cancel all the IOCBs from the completions list */
949 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
950 IOERR_SLI_ABORTED);
951 lpfc_sli_abort_iocb_ring(phba, pring);
952 }
953}
954
955/**
James Smart3772a992009-05-22 14:50:54 -0400956 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smartbcece5f2014-04-04 13:51:34 -0400957 int i;
James Smarte59058c2008-08-24 21:49:00 -0400958 * @phba: pointer to lpfc HBA data structure.
959 *
960 * This routine will do uninitialization after the HBA is reset when bring
961 * down the SLI Layer.
962 *
963 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200964 * 0 - success.
James Smarte59058c2008-08-24 21:49:00 -0400965 * Any other value - error.
966 **/
James Smart3772a992009-05-22 14:50:54 -0400967static int
968lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500969{
James Smartbcece5f2014-04-04 13:51:34 -0400970 lpfc_hba_free_post_buf(phba);
971 lpfc_hba_clean_txcmplq(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500972 return 0;
973}
James Smart5af5eee2010-10-22 11:06:38 -0400974
James Smartda0436e2009-05-22 14:51:39 -0400975/**
976 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
977 * @phba: pointer to lpfc HBA data structure.
978 *
979 * This routine will do uninitialization after the HBA is reset when bring
980 * down the SLI Layer.
981 *
982 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200983 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -0400984 * Any other value - error.
985 **/
986static int
987lpfc_hba_down_post_s4(struct lpfc_hba *phba)
988{
989 struct lpfc_scsi_buf *psb, *psb_next;
990 LIST_HEAD(aborts);
James Smartda0436e2009-05-22 14:51:39 -0400991 unsigned long iflag = 0;
James Smart0f65ff62010-02-26 14:14:23 -0500992 struct lpfc_sglq *sglq_entry = NULL;
James Smartdafe8ce2014-09-03 12:56:40 -0400993 struct lpfc_sli *psli = &phba->sli;
994 struct lpfc_sli_ring *pring;
James Smart0f65ff62010-02-26 14:14:23 -0500995
James Smartbcece5f2014-04-04 13:51:34 -0400996 lpfc_hba_free_post_buf(phba);
997 lpfc_hba_clean_txcmplq(phba);
James Smartdafe8ce2014-09-03 12:56:40 -0400998 pring = &psli->ring[LPFC_ELS_RING];
James Smartbcece5f2014-04-04 13:51:34 -0400999
James Smartda0436e2009-05-22 14:51:39 -04001000 /* At this point in time the HBA is either reset or DOA. Either
1001 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
1002 * on the lpfc_sgl_list so that it can either be freed if the
1003 * driver is unloading or reposted if the driver is restarting
1004 * the port.
1005 */
1006 spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */
1007 /* scsl_buf_list */
1008 /* abts_sgl_list_lock required because worker thread uses this
1009 * list.
1010 */
1011 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05001012 list_for_each_entry(sglq_entry,
1013 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1014 sglq_entry->state = SGL_FREED;
1015
James Smartdafe8ce2014-09-03 12:56:40 -04001016 spin_lock(&pring->ring_lock);
James Smartda0436e2009-05-22 14:51:39 -04001017 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
1018 &phba->sli4_hba.lpfc_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04001019 spin_unlock(&pring->ring_lock);
James Smartda0436e2009-05-22 14:51:39 -04001020 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
1021 /* abts_scsi_buf_list_lock required because worker thread uses this
1022 * list.
1023 */
1024 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1025 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
1026 &aborts);
1027 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1028 spin_unlock_irq(&phba->hbalock);
1029
1030 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1031 psb->pCmd = NULL;
1032 psb->status = IOSTAT_SUCCESS;
1033 }
James Smarta40fc5f2013-04-17 20:17:40 -04001034 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1035 list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
1036 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
James Smart68e814f2014-05-21 08:04:59 -04001037
1038 lpfc_sli4_free_sp_events(phba);
James Smartda0436e2009-05-22 14:51:39 -04001039 return 0;
1040}
1041
1042/**
1043 * lpfc_hba_down_post - Wrapper func for hba down post routine
1044 * @phba: pointer to lpfc HBA data structure.
1045 *
1046 * This routine wraps the actual SLI3 or SLI4 routine for performing
1047 * uninitialization after the HBA is reset when bring down the SLI Layer.
1048 *
1049 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001050 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001051 * Any other value - error.
1052 **/
1053int
1054lpfc_hba_down_post(struct lpfc_hba *phba)
1055{
1056 return (*phba->lpfc_hba_down_post)(phba);
1057}
Jamie Wellnitz41415862006-02-28 19:25:27 -05001058
James Smarte59058c2008-08-24 21:49:00 -04001059/**
James Smart3621a712009-04-06 18:47:14 -04001060 * lpfc_hb_timeout - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001061 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1062 *
1063 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1064 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1065 * work-port-events bitmap and the worker thread is notified. This timeout
1066 * event will be used by the worker thread to invoke the actual timeout
1067 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1068 * be performed in the timeout handler and the HBA timeout event bit shall
1069 * be cleared by the worker thread after it has taken the event bitmap out.
1070 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001071static void
James Smart858c9f62007-06-17 19:56:39 -05001072lpfc_hb_timeout(unsigned long ptr)
1073{
1074 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001075 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -05001076 unsigned long iflag;
1077
1078 phba = (struct lpfc_hba *)ptr;
James Smart93996272008-08-24 21:50:30 -04001079
1080 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -05001081 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001082 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1083 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -05001084 phba->pport->work_port_events |= WORKER_HB_TMO;
1085 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1086
James Smart93996272008-08-24 21:50:30 -04001087 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -04001088 if (!tmo_posted)
1089 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -05001090 return;
1091}
1092
James Smarte59058c2008-08-24 21:49:00 -04001093/**
James Smart19ca7602010-11-20 23:11:55 -05001094 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1095 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1096 *
1097 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1098 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1099 * work-port-events bitmap and the worker thread is notified. This timeout
1100 * event will be used by the worker thread to invoke the actual timeout
1101 * handler routine, lpfc_rrq_handler. Any periodical operations will
1102 * be performed in the timeout handler and the RRQ timeout event bit shall
1103 * be cleared by the worker thread after it has taken the event bitmap out.
1104 **/
1105static void
1106lpfc_rrq_timeout(unsigned long ptr)
1107{
1108 struct lpfc_hba *phba;
James Smart19ca7602010-11-20 23:11:55 -05001109 unsigned long iflag;
1110
1111 phba = (struct lpfc_hba *)ptr;
1112 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001113 if (!(phba->pport->load_flag & FC_UNLOADING))
1114 phba->hba_flag |= HBA_RRQ_ACTIVE;
1115 else
1116 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
James Smart19ca7602010-11-20 23:11:55 -05001117 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001118
1119 if (!(phba->pport->load_flag & FC_UNLOADING))
1120 lpfc_worker_wake_up(phba);
James Smart19ca7602010-11-20 23:11:55 -05001121}
1122
1123/**
James Smart3621a712009-04-06 18:47:14 -04001124 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -04001125 * @phba: pointer to lpfc hba data structure.
1126 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1127 *
1128 * This is the callback function to the lpfc heart-beat mailbox command.
1129 * If configured, the lpfc driver issues the heart-beat mailbox command to
1130 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1131 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1132 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1133 * heart-beat outstanding state. Once the mailbox command comes back and
1134 * no error conditions detected, the heart-beat mailbox command timer is
1135 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1136 * state is cleared for the next heart-beat. If the timer expired with the
1137 * heart-beat outstanding state set, the driver will put the HBA offline.
1138 **/
James Smart858c9f62007-06-17 19:56:39 -05001139static void
1140lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1141{
1142 unsigned long drvr_flag;
1143
1144 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1145 phba->hb_outstanding = 0;
1146 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1147
James Smart93996272008-08-24 21:50:30 -04001148 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -05001149 mempool_free(pmboxq, phba->mbox_mem_pool);
1150 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1151 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -04001152 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -05001153 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001154 jiffies +
1155 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001156 return;
1157}
1158
James Smarte59058c2008-08-24 21:49:00 -04001159/**
James Smart3621a712009-04-06 18:47:14 -04001160 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001161 * @phba: pointer to lpfc hba data structure.
1162 *
1163 * This is the actual HBA-timer timeout handler to be invoked by the worker
1164 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1165 * handler performs any periodic operations needed for the device. If such
1166 * periodic event has already been attended to either in the interrupt handler
1167 * or by processing slow-ring or fast-ring events within the HBA-timer
1168 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1169 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1170 * is configured and there is no heart-beat mailbox command outstanding, a
1171 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1172 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1173 * to offline.
1174 **/
James Smart858c9f62007-06-17 19:56:39 -05001175void
1176lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1177{
James Smart45ed1192009-10-02 15:17:02 -04001178 struct lpfc_vport **vports;
James Smart858c9f62007-06-17 19:56:39 -05001179 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -05001180 struct lpfc_dmabuf *buf_ptr;
James Smart45ed1192009-10-02 15:17:02 -04001181 int retval, i;
James Smart858c9f62007-06-17 19:56:39 -05001182 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -05001183 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -05001184
James Smart45ed1192009-10-02 15:17:02 -04001185 vports = lpfc_create_vport_work_array(phba);
1186 if (vports != NULL)
James Smart4258e982015-12-16 18:11:58 -05001187 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart45ed1192009-10-02 15:17:02 -04001188 lpfc_rcv_seq_check_edtov(vports[i]);
James Smart4258e982015-12-16 18:11:58 -05001189 lpfc_fdmi_num_disc_check(vports[i]);
1190 }
James Smart45ed1192009-10-02 15:17:02 -04001191 lpfc_destroy_vport_work_array(phba, vports);
1192
James Smart858c9f62007-06-17 19:56:39 -05001193 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -04001194 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -05001195 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1196 return;
1197
1198 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -05001199
James Smart256ec0d2013-04-17 20:14:58 -04001200 if (time_after(phba->last_completion_time +
1201 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1202 jiffies)) {
James Smart858c9f62007-06-17 19:56:39 -05001203 spin_unlock_irq(&phba->pport->work_port_lock);
1204 if (!phba->hb_outstanding)
1205 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001206 jiffies +
1207 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001208 else
1209 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001210 jiffies +
1211 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001212 return;
1213 }
1214 spin_unlock_irq(&phba->pport->work_port_lock);
1215
James Smart0ff10d42008-01-11 01:52:36 -05001216 if (phba->elsbuf_cnt &&
1217 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1218 spin_lock_irq(&phba->hbalock);
1219 list_splice_init(&phba->elsbuf, &completions);
1220 phba->elsbuf_cnt = 0;
1221 phba->elsbuf_prev_cnt = 0;
1222 spin_unlock_irq(&phba->hbalock);
1223
1224 while (!list_empty(&completions)) {
1225 list_remove_head(&completions, buf_ptr,
1226 struct lpfc_dmabuf, list);
1227 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1228 kfree(buf_ptr);
1229 }
1230 }
1231 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1232
James Smart858c9f62007-06-17 19:56:39 -05001233 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -05001234 if (phba->cfg_enable_hba_heartbeat) {
1235 if (!phba->hb_outstanding) {
James Smartbc739052010-08-04 16:11:18 -04001236 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1237 (list_empty(&psli->mboxq))) {
1238 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1239 GFP_KERNEL);
1240 if (!pmboxq) {
1241 mod_timer(&phba->hb_tmofunc,
1242 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001243 msecs_to_jiffies(1000 *
1244 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001245 return;
1246 }
James Smart13815c82008-01-11 01:52:48 -05001247
James Smartbc739052010-08-04 16:11:18 -04001248 lpfc_heart_beat(phba, pmboxq);
1249 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1250 pmboxq->vport = phba->pport;
1251 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1252 MBX_NOWAIT);
James Smart13815c82008-01-11 01:52:48 -05001253
James Smartbc739052010-08-04 16:11:18 -04001254 if (retval != MBX_BUSY &&
1255 retval != MBX_SUCCESS) {
1256 mempool_free(pmboxq,
1257 phba->mbox_mem_pool);
1258 mod_timer(&phba->hb_tmofunc,
1259 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001260 msecs_to_jiffies(1000 *
1261 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001262 return;
1263 }
1264 phba->skipped_hb = 0;
1265 phba->hb_outstanding = 1;
1266 } else if (time_before_eq(phba->last_completion_time,
1267 phba->skipped_hb)) {
1268 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1269 "2857 Last completion time not "
1270 " updated in %d ms\n",
1271 jiffies_to_msecs(jiffies
1272 - phba->last_completion_time));
1273 } else
1274 phba->skipped_hb = jiffies;
1275
James Smart858c9f62007-06-17 19:56:39 -05001276 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001277 jiffies +
1278 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001279 return;
James Smart13815c82008-01-11 01:52:48 -05001280 } else {
1281 /*
1282 * If heart beat timeout called with hb_outstanding set
James Smartdcf2a4e2010-09-29 11:18:53 -04001283 * we need to give the hb mailbox cmd a chance to
1284 * complete or TMO.
James Smart13815c82008-01-11 01:52:48 -05001285 */
James Smartdcf2a4e2010-09-29 11:18:53 -04001286 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1287 "0459 Adapter heartbeat still out"
1288 "standing:last compl time was %d ms.\n",
1289 jiffies_to_msecs(jiffies
1290 - phba->last_completion_time));
1291 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001292 jiffies +
1293 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001294 }
James Smart4258e982015-12-16 18:11:58 -05001295 } else {
1296 mod_timer(&phba->hb_tmofunc,
1297 jiffies +
1298 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001299 }
1300}
1301
James Smarte59058c2008-08-24 21:49:00 -04001302/**
James Smart3621a712009-04-06 18:47:14 -04001303 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -04001304 * @phba: pointer to lpfc hba data structure.
1305 *
1306 * This routine is called to bring the HBA offline when HBA hardware error
1307 * other than Port Error 6 has been detected.
1308 **/
James Smart09372822008-01-11 01:52:54 -05001309static void
1310lpfc_offline_eratt(struct lpfc_hba *phba)
1311{
1312 struct lpfc_sli *psli = &phba->sli;
1313
1314 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001315 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -05001316 spin_unlock_irq(&phba->hbalock);
James Smart618a5232012-06-12 13:54:36 -04001317 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart09372822008-01-11 01:52:54 -05001318
1319 lpfc_offline(phba);
1320 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001321 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001322 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001323 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001324 lpfc_hba_down_post(phba);
1325 lpfc_sli_brdready(phba, HS_MBRDY);
1326 lpfc_unblock_mgmt_io(phba);
1327 phba->link_state = LPFC_HBA_ERROR;
1328 return;
1329}
1330
James Smarte59058c2008-08-24 21:49:00 -04001331/**
James Smartda0436e2009-05-22 14:51:39 -04001332 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1333 * @phba: pointer to lpfc hba data structure.
1334 *
1335 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1336 * other than Port Error 6 has been detected.
1337 **/
James Smarta88dbb62013-04-17 20:18:39 -04001338void
James Smartda0436e2009-05-22 14:51:39 -04001339lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1340{
James Smart946727d2015-04-07 15:07:09 -04001341 spin_lock_irq(&phba->hbalock);
1342 phba->link_state = LPFC_HBA_ERROR;
1343 spin_unlock_irq(&phba->hbalock);
1344
James Smart618a5232012-06-12 13:54:36 -04001345 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smartda0436e2009-05-22 14:51:39 -04001346 lpfc_offline(phba);
James Smartda0436e2009-05-22 14:51:39 -04001347 lpfc_hba_down_post(phba);
James Smartda0436e2009-05-22 14:51:39 -04001348 lpfc_unblock_mgmt_io(phba);
James Smartda0436e2009-05-22 14:51:39 -04001349}
1350
1351/**
James Smarta257bf92009-04-06 18:48:10 -04001352 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1353 * @phba: pointer to lpfc hba data structure.
1354 *
1355 * This routine is invoked to handle the deferred HBA hardware error
1356 * conditions. This type of error is indicated by HBA by setting ER1
1357 * and another ER bit in the host status register. The driver will
1358 * wait until the ER1 bit clears before handling the error condition.
1359 **/
1360static void
1361lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1362{
1363 uint32_t old_host_status = phba->work_hs;
James Smarta257bf92009-04-06 18:48:10 -04001364 struct lpfc_sli *psli = &phba->sli;
1365
James Smartf4b4c682009-05-22 14:53:12 -04001366 /* If the pci channel is offline, ignore possible errors,
1367 * since we cannot communicate with the pci card anyway.
1368 */
1369 if (pci_channel_offline(phba->pcidev)) {
1370 spin_lock_irq(&phba->hbalock);
1371 phba->hba_flag &= ~DEFER_ERATT;
1372 spin_unlock_irq(&phba->hbalock);
1373 return;
1374 }
1375
James Smarta257bf92009-04-06 18:48:10 -04001376 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1377 "0479 Deferred Adapter Hardware Error "
1378 "Data: x%x x%x x%x\n",
1379 phba->work_hs,
1380 phba->work_status[0], phba->work_status[1]);
1381
1382 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001383 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001384 spin_unlock_irq(&phba->hbalock);
1385
1386
1387 /*
1388 * Firmware stops when it triggred erratt. That could cause the I/Os
1389 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1390 * SCSI layer retry it after re-establishing link.
1391 */
James Smartdb55fba2014-04-04 13:52:02 -04001392 lpfc_sli_abort_fcp_rings(phba);
James Smarta257bf92009-04-06 18:48:10 -04001393
1394 /*
1395 * There was a firmware error. Take the hba offline and then
1396 * attempt to restart it.
1397 */
James Smart618a5232012-06-12 13:54:36 -04001398 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smarta257bf92009-04-06 18:48:10 -04001399 lpfc_offline(phba);
1400
1401 /* Wait for the ER1 bit to clear.*/
1402 while (phba->work_hs & HS_FFER1) {
1403 msleep(100);
James Smart9940b972011-03-11 16:06:12 -05001404 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1405 phba->work_hs = UNPLUG_ERR ;
1406 break;
1407 }
James Smarta257bf92009-04-06 18:48:10 -04001408 /* If driver is unloading let the worker thread continue */
1409 if (phba->pport->load_flag & FC_UNLOADING) {
1410 phba->work_hs = 0;
1411 break;
1412 }
1413 }
1414
1415 /*
1416 * This is to ptrotect against a race condition in which
1417 * first write to the host attention register clear the
1418 * host status register.
1419 */
1420 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1421 phba->work_hs = old_host_status & ~HS_FFER1;
1422
James Smart3772a992009-05-22 14:50:54 -04001423 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001424 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001425 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001426 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1427 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1428}
1429
James Smart3772a992009-05-22 14:50:54 -04001430static void
1431lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1432{
1433 struct lpfc_board_event_header board_event;
1434 struct Scsi_Host *shost;
1435
1436 board_event.event_type = FC_REG_BOARD_EVENT;
1437 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1438 shost = lpfc_shost_from_vport(phba->pport);
1439 fc_host_post_vendor_event(shost, fc_get_event_number(),
1440 sizeof(board_event),
1441 (char *) &board_event,
1442 LPFC_NL_VENDOR_ID);
1443}
1444
James Smarta257bf92009-04-06 18:48:10 -04001445/**
James Smart3772a992009-05-22 14:50:54 -04001446 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001447 * @phba: pointer to lpfc hba data structure.
1448 *
1449 * This routine is invoked to handle the following HBA hardware error
1450 * conditions:
1451 * 1 - HBA error attention interrupt
1452 * 2 - DMA ring index out of range
1453 * 3 - Mailbox command came back as unknown
1454 **/
James Smart3772a992009-05-22 14:50:54 -04001455static void
1456lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001457{
James Smart2e0fef82007-06-17 19:56:36 -05001458 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001459 struct lpfc_sli *psli = &phba->sli;
James Smartd2873e42006-08-18 17:46:43 -04001460 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001461 unsigned long temperature;
1462 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001463 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001464
Linas Vepstas8d63f372007-02-14 14:28:36 -06001465 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001466 * since we cannot communicate with the pci card anyway.
1467 */
1468 if (pci_channel_offline(phba->pcidev)) {
1469 spin_lock_irq(&phba->hbalock);
1470 phba->hba_flag &= ~DEFER_ERATT;
1471 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001472 return;
James Smart3772a992009-05-22 14:50:54 -04001473 }
1474
James Smart13815c82008-01-11 01:52:48 -05001475 /* If resets are disabled then leave the HBA alone and return */
1476 if (!phba->cfg_enable_hba_reset)
1477 return;
dea31012005-04-17 16:05:31 -05001478
James Smartea2151b2008-09-07 11:52:10 -04001479 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001480 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001481
James Smarta257bf92009-04-06 18:48:10 -04001482 if (phba->hba_flag & DEFER_ERATT)
1483 lpfc_handle_deferred_eratt(phba);
1484
James Smartdcf2a4e2010-09-29 11:18:53 -04001485 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1486 if (phba->work_hs & HS_FFER6)
1487 /* Re-establishing Link */
1488 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1489 "1301 Re-establishing Link "
1490 "Data: x%x x%x x%x\n",
1491 phba->work_hs, phba->work_status[0],
1492 phba->work_status[1]);
1493 if (phba->work_hs & HS_FFER8)
1494 /* Device Zeroization */
1495 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1496 "2861 Host Authentication device "
1497 "zeroization Data:x%x x%x x%x\n",
1498 phba->work_hs, phba->work_status[0],
1499 phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001500
James Smart92d7f7b2007-06-17 19:56:38 -05001501 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001502 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001503 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001504
1505 /*
1506 * Firmware stops when it triggled erratt with HS_FFER6.
1507 * That could cause the I/Os dropped by the firmware.
1508 * Error iocb (I/O) on txcmplq and let the SCSI layer
1509 * retry it after re-establishing link.
1510 */
James Smartdb55fba2014-04-04 13:52:02 -04001511 lpfc_sli_abort_fcp_rings(phba);
dea31012005-04-17 16:05:31 -05001512
dea31012005-04-17 16:05:31 -05001513 /*
1514 * There was a firmware error. Take the hba offline and then
1515 * attempt to restart it.
1516 */
James Smart618a5232012-06-12 13:54:36 -04001517 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
dea31012005-04-17 16:05:31 -05001518 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001519 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001520 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001521 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001522 return;
1523 }
James Smart46fa3112007-04-25 09:51:45 -04001524 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001525 } else if (phba->work_hs & HS_CRIT_TEMP) {
1526 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1527 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1528 temp_event_data.event_code = LPFC_CRIT_TEMP;
1529 temp_event_data.data = (uint32_t)temperature;
1530
1531 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001532 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001533 "(%ld), taking this port offline "
1534 "Data: x%x x%x x%x\n",
1535 temperature, phba->work_hs,
1536 phba->work_status[0], phba->work_status[1]);
1537
1538 shost = lpfc_shost_from_vport(phba->pport);
1539 fc_host_post_vendor_event(shost, fc_get_event_number(),
1540 sizeof(temp_event_data),
1541 (char *) &temp_event_data,
1542 SCSI_NL_VID_TYPE_PCI
1543 | PCI_VENDOR_ID_EMULEX);
1544
James Smart7af67052007-10-27 13:38:11 -04001545 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001546 phba->over_temp_state = HBA_OVER_TEMP;
1547 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001548 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001549
dea31012005-04-17 16:05:31 -05001550 } else {
1551 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001552 * failure is a value other than FFER6. Do not call the offline
1553 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001554 */
1555 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001556 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001557 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001558 phba->work_hs,
dea31012005-04-17 16:05:31 -05001559 phba->work_status[0], phba->work_status[1]);
1560
James Smartd2873e42006-08-18 17:46:43 -04001561 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001562 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001563 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001564 sizeof(event_data), (char *) &event_data,
1565 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1566
James Smart09372822008-01-11 01:52:54 -05001567 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001568 }
James Smart93996272008-08-24 21:50:30 -04001569 return;
dea31012005-04-17 16:05:31 -05001570}
1571
James Smarte59058c2008-08-24 21:49:00 -04001572/**
James Smart618a5232012-06-12 13:54:36 -04001573 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1574 * @phba: pointer to lpfc hba data structure.
1575 * @mbx_action: flag for mailbox shutdown action.
1576 *
1577 * This routine is invoked to perform an SLI4 port PCI function reset in
1578 * response to port status register polling attention. It waits for port
1579 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1580 * During this process, interrupt vectors are freed and later requested
1581 * for handling possible port resource change.
1582 **/
1583static int
James Smarte10b2022014-02-20 09:57:43 -05001584lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1585 bool en_rn_msg)
James Smart618a5232012-06-12 13:54:36 -04001586{
1587 int rc;
1588 uint32_t intr_mode;
1589
1590 /*
1591 * On error status condition, driver need to wait for port
1592 * ready before performing reset.
1593 */
1594 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1595 if (!rc) {
1596 /* need reset: attempt for port recovery */
James Smarte10b2022014-02-20 09:57:43 -05001597 if (en_rn_msg)
1598 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1599 "2887 Reset Needed: Attempting Port "
1600 "Recovery...\n");
James Smart618a5232012-06-12 13:54:36 -04001601 lpfc_offline_prep(phba, mbx_action);
1602 lpfc_offline(phba);
1603 /* release interrupt for possible resource change */
1604 lpfc_sli4_disable_intr(phba);
1605 lpfc_sli_brdrestart(phba);
1606 /* request and enable interrupt */
1607 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1608 if (intr_mode == LPFC_INTR_ERROR) {
1609 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1610 "3175 Failed to enable interrupt\n");
1611 return -EIO;
1612 } else {
1613 phba->intr_mode = intr_mode;
1614 }
1615 rc = lpfc_online(phba);
1616 if (rc == 0)
1617 lpfc_unblock_mgmt_io(phba);
1618 }
1619 return rc;
1620}
1621
1622/**
James Smartda0436e2009-05-22 14:51:39 -04001623 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1624 * @phba: pointer to lpfc hba data structure.
1625 *
1626 * This routine is invoked to handle the SLI4 HBA hardware error attention
1627 * conditions.
1628 **/
1629static void
1630lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1631{
1632 struct lpfc_vport *vport = phba->pport;
1633 uint32_t event_data;
1634 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001635 uint32_t if_type;
James Smart2e90f4b2011-12-13 13:22:37 -05001636 struct lpfc_register portstat_reg = {0};
1637 uint32_t reg_err1, reg_err2;
1638 uint32_t uerrlo_reg, uemasklo_reg;
1639 uint32_t pci_rd_rc1, pci_rd_rc2;
James Smarte10b2022014-02-20 09:57:43 -05001640 bool en_rn_msg = true;
James Smart946727d2015-04-07 15:07:09 -04001641 struct temp_event temp_event_data;
James Smart73d91e52011-10-10 21:32:10 -04001642 int rc;
James Smartda0436e2009-05-22 14:51:39 -04001643
1644 /* If the pci channel is offline, ignore possible errors, since
1645 * we cannot communicate with the pci card anyway.
1646 */
1647 if (pci_channel_offline(phba->pcidev))
1648 return;
James Smartda0436e2009-05-22 14:51:39 -04001649
James Smart2fcee4b2010-12-15 17:57:46 -05001650 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1651 switch (if_type) {
1652 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart2e90f4b2011-12-13 13:22:37 -05001653 pci_rd_rc1 = lpfc_readl(
1654 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1655 &uerrlo_reg);
1656 pci_rd_rc2 = lpfc_readl(
1657 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1658 &uemasklo_reg);
1659 /* consider PCI bus read error as pci_channel_offline */
1660 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1661 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001662 lpfc_sli4_offline_eratt(phba);
1663 break;
James Smart946727d2015-04-07 15:07:09 -04001664
James Smart2fcee4b2010-12-15 17:57:46 -05001665 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2e90f4b2011-12-13 13:22:37 -05001666 pci_rd_rc1 = lpfc_readl(
1667 phba->sli4_hba.u.if_type2.STATUSregaddr,
1668 &portstat_reg.word0);
1669 /* consider PCI bus read error as pci_channel_offline */
James Smart6b5151f2012-01-18 16:24:06 -05001670 if (pci_rd_rc1 == -EIO) {
1671 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1672 "3151 PCI bus read access failure: x%x\n",
1673 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
James Smart2e90f4b2011-12-13 13:22:37 -05001674 return;
James Smart6b5151f2012-01-18 16:24:06 -05001675 }
James Smart2e90f4b2011-12-13 13:22:37 -05001676 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1677 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
James Smart2fcee4b2010-12-15 17:57:46 -05001678 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
James Smart2fcee4b2010-12-15 17:57:46 -05001679 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1680 "2889 Port Overtemperature event, "
James Smart946727d2015-04-07 15:07:09 -04001681 "taking port offline Data: x%x x%x\n",
1682 reg_err1, reg_err2);
1683
1684 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1685 temp_event_data.event_code = LPFC_CRIT_TEMP;
1686 temp_event_data.data = 0xFFFFFFFF;
1687
1688 shost = lpfc_shost_from_vport(phba->pport);
1689 fc_host_post_vendor_event(shost, fc_get_event_number(),
1690 sizeof(temp_event_data),
1691 (char *)&temp_event_data,
1692 SCSI_NL_VID_TYPE_PCI
1693 | PCI_VENDOR_ID_EMULEX);
1694
James Smart2fcee4b2010-12-15 17:57:46 -05001695 spin_lock_irq(&phba->hbalock);
1696 phba->over_temp_state = HBA_OVER_TEMP;
1697 spin_unlock_irq(&phba->hbalock);
1698 lpfc_sli4_offline_eratt(phba);
James Smart946727d2015-04-07 15:07:09 -04001699 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001700 }
James Smart2e90f4b2011-12-13 13:22:37 -05001701 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smarte10b2022014-02-20 09:57:43 -05001702 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
James Smart2e90f4b2011-12-13 13:22:37 -05001703 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte10b2022014-02-20 09:57:43 -05001704 "3143 Port Down: Firmware Update "
1705 "Detected\n");
1706 en_rn_msg = false;
1707 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smart2e90f4b2011-12-13 13:22:37 -05001708 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1709 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1710 "3144 Port Down: Debug Dump\n");
1711 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1712 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1713 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1714 "3145 Port Down: Provisioning\n");
James Smart618a5232012-06-12 13:54:36 -04001715
James Smart946727d2015-04-07 15:07:09 -04001716 /* If resets are disabled then leave the HBA alone and return */
1717 if (!phba->cfg_enable_hba_reset)
1718 return;
1719
James Smart618a5232012-06-12 13:54:36 -04001720 /* Check port status register for function reset */
James Smarte10b2022014-02-20 09:57:43 -05001721 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1722 en_rn_msg);
James Smart618a5232012-06-12 13:54:36 -04001723 if (rc == 0) {
1724 /* don't report event on forced debug dump */
1725 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1726 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1727 return;
1728 else
1729 break;
James Smart2fcee4b2010-12-15 17:57:46 -05001730 }
James Smart618a5232012-06-12 13:54:36 -04001731 /* fall through for not able to recover */
James Smart6b5151f2012-01-18 16:24:06 -05001732 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1733 "3152 Unrecoverable error, bring the port "
1734 "offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05001735 lpfc_sli4_offline_eratt(phba);
1736 break;
1737 case LPFC_SLI_INTF_IF_TYPE_1:
1738 default:
1739 break;
1740 }
James Smart2e90f4b2011-12-13 13:22:37 -05001741 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1742 "3123 Report dump event to upper layer\n");
1743 /* Send an internal error event to mgmt application */
1744 lpfc_board_errevt_to_mgmt(phba);
1745
1746 event_data = FC_REG_DUMP_EVENT;
1747 shost = lpfc_shost_from_vport(vport);
1748 fc_host_post_vendor_event(shost, fc_get_event_number(),
1749 sizeof(event_data), (char *) &event_data,
1750 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
James Smartda0436e2009-05-22 14:51:39 -04001751}
1752
1753/**
1754 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1755 * @phba: pointer to lpfc HBA data structure.
1756 *
1757 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1758 * routine from the API jump table function pointer from the lpfc_hba struct.
1759 *
1760 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001761 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001762 * Any other value - error.
1763 **/
1764void
1765lpfc_handle_eratt(struct lpfc_hba *phba)
1766{
1767 (*phba->lpfc_handle_eratt)(phba);
1768}
1769
1770/**
James Smart3621a712009-04-06 18:47:14 -04001771 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04001772 * @phba: pointer to lpfc hba data structure.
1773 *
1774 * This routine is invoked from the worker thread to handle a HBA host
1775 * attention link event.
1776 **/
dea31012005-04-17 16:05:31 -05001777void
James Smart2e0fef82007-06-17 19:56:36 -05001778lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001779{
James Smart2e0fef82007-06-17 19:56:36 -05001780 struct lpfc_vport *vport = phba->pport;
1781 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001782 LPFC_MBOXQ_t *pmb;
1783 volatile uint32_t control;
1784 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05001785 int rc = 0;
dea31012005-04-17 16:05:31 -05001786
1787 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001788 if (!pmb) {
1789 rc = 1;
dea31012005-04-17 16:05:31 -05001790 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05001791 }
dea31012005-04-17 16:05:31 -05001792
1793 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001794 if (!mp) {
1795 rc = 2;
dea31012005-04-17 16:05:31 -05001796 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05001797 }
dea31012005-04-17 16:05:31 -05001798
1799 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05001800 if (!mp->virt) {
1801 rc = 3;
dea31012005-04-17 16:05:31 -05001802 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05001803 }
dea31012005-04-17 16:05:31 -05001804
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001805 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04001806 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05001807
1808 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05001809 lpfc_read_topology(phba, pmb, mp);
1810 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05001811 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04001812 /* Block ELS IOCBs until we have processed this mbox command */
1813 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04001814 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05001815 if (rc == MBX_NOT_FINISHED) {
1816 rc = 4;
James Smart14691152006-12-02 13:34:28 -05001817 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05001818 }
dea31012005-04-17 16:05:31 -05001819
1820 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05001821 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001822 writel(HA_LATT, phba->HAregaddr);
1823 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001824 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001825
1826 return;
1827
James Smart14691152006-12-02 13:34:28 -05001828lpfc_handle_latt_free_mbuf:
James Smart0d2b6b82008-06-14 22:52:47 -04001829 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05001830 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05001831lpfc_handle_latt_free_mp:
1832 kfree(mp);
1833lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04001834 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001835lpfc_handle_latt_err_exit:
1836 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001837 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001838 psli->sli_flag |= LPFC_PROCESS_LA;
1839 control = readl(phba->HCregaddr);
1840 control |= HC_LAINT_ENA;
1841 writel(control, phba->HCregaddr);
1842 readl(phba->HCregaddr); /* flush */
1843
1844 /* Clear Link Attention in HA REG */
1845 writel(HA_LATT, phba->HAregaddr);
1846 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001847 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001848 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001849 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001850
James Smart09372822008-01-11 01:52:54 -05001851 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1852 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05001853
1854 return;
1855}
1856
James Smarte59058c2008-08-24 21:49:00 -04001857/**
James Smart3621a712009-04-06 18:47:14 -04001858 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04001859 * @phba: pointer to lpfc hba data structure.
1860 * @vpd: pointer to the vital product data.
1861 * @len: length of the vital product data in bytes.
1862 *
1863 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1864 * an array of characters. In this routine, the ModelName, ProgramType, and
1865 * ModelDesc, etc. fields of the phba data structure will be populated.
1866 *
1867 * Return codes
1868 * 0 - pointer to the VPD passed in is NULL
1869 * 1 - success
1870 **/
James Smart3772a992009-05-22 14:50:54 -04001871int
James Smart2e0fef82007-06-17 19:56:36 -05001872lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05001873{
1874 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05001875 int Length;
dea31012005-04-17 16:05:31 -05001876 int i, j;
1877 int finished = 0;
1878 int index = 0;
1879
1880 if (!vpd)
1881 return 0;
1882
1883 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05001884 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001885 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001886 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
1887 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001888 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05001889 switch (vpd[index]) {
1890 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001891 case 0x91:
dea31012005-04-17 16:05:31 -05001892 index += 1;
1893 lenlo = vpd[index];
1894 index += 1;
1895 lenhi = vpd[index];
1896 index += 1;
1897 i = ((((unsigned short)lenhi) << 8) + lenlo);
1898 index += i;
1899 break;
1900 case 0x90:
1901 index += 1;
1902 lenlo = vpd[index];
1903 index += 1;
1904 lenhi = vpd[index];
1905 index += 1;
1906 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001907 if (Length > len - index)
1908 Length = len - index;
dea31012005-04-17 16:05:31 -05001909 while (Length > 0) {
1910 /* Look for Serial Number */
1911 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
1912 index += 2;
1913 i = vpd[index];
1914 index += 1;
1915 j = 0;
1916 Length -= (3+i);
1917 while(i--) {
1918 phba->SerialNumber[j++] = vpd[index++];
1919 if (j == 31)
1920 break;
1921 }
1922 phba->SerialNumber[j] = 0;
1923 continue;
1924 }
1925 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
1926 phba->vpd_flag |= VPD_MODEL_DESC;
1927 index += 2;
1928 i = vpd[index];
1929 index += 1;
1930 j = 0;
1931 Length -= (3+i);
1932 while(i--) {
1933 phba->ModelDesc[j++] = vpd[index++];
1934 if (j == 255)
1935 break;
1936 }
1937 phba->ModelDesc[j] = 0;
1938 continue;
1939 }
1940 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
1941 phba->vpd_flag |= VPD_MODEL_NAME;
1942 index += 2;
1943 i = vpd[index];
1944 index += 1;
1945 j = 0;
1946 Length -= (3+i);
1947 while(i--) {
1948 phba->ModelName[j++] = vpd[index++];
1949 if (j == 79)
1950 break;
1951 }
1952 phba->ModelName[j] = 0;
1953 continue;
1954 }
1955 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
1956 phba->vpd_flag |= VPD_PROGRAM_TYPE;
1957 index += 2;
1958 i = vpd[index];
1959 index += 1;
1960 j = 0;
1961 Length -= (3+i);
1962 while(i--) {
1963 phba->ProgramType[j++] = vpd[index++];
1964 if (j == 255)
1965 break;
1966 }
1967 phba->ProgramType[j] = 0;
1968 continue;
1969 }
1970 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1971 phba->vpd_flag |= VPD_PORT;
1972 index += 2;
1973 i = vpd[index];
1974 index += 1;
1975 j = 0;
1976 Length -= (3+i);
1977 while(i--) {
James Smartcd1c8302011-10-10 21:33:25 -04001978 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1979 (phba->sli4_hba.pport_name_sta ==
1980 LPFC_SLI4_PPNAME_GET)) {
1981 j++;
1982 index++;
1983 } else
1984 phba->Port[j++] = vpd[index++];
1985 if (j == 19)
1986 break;
dea31012005-04-17 16:05:31 -05001987 }
James Smartcd1c8302011-10-10 21:33:25 -04001988 if ((phba->sli_rev != LPFC_SLI_REV4) ||
1989 (phba->sli4_hba.pport_name_sta ==
1990 LPFC_SLI4_PPNAME_NON))
1991 phba->Port[j] = 0;
dea31012005-04-17 16:05:31 -05001992 continue;
1993 }
1994 else {
1995 index += 2;
1996 i = vpd[index];
1997 index += 1;
1998 index += i;
1999 Length -= (3 + i);
2000 }
2001 }
2002 finished = 0;
2003 break;
2004 case 0x78:
2005 finished = 1;
2006 break;
2007 default:
2008 index ++;
2009 break;
2010 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002011 }
dea31012005-04-17 16:05:31 -05002012
2013 return(1);
2014}
2015
James Smarte59058c2008-08-24 21:49:00 -04002016/**
James Smart3621a712009-04-06 18:47:14 -04002017 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04002018 * @phba: pointer to lpfc hba data structure.
2019 * @mdp: pointer to the data structure to hold the derived model name.
2020 * @descp: pointer to the data structure to hold the derived description.
2021 *
2022 * This routine retrieves HBA's description based on its registered PCI device
2023 * ID. The @descp passed into this function points to an array of 256 chars. It
2024 * shall be returned with the model name, maximum speed, and the host bus type.
2025 * The @mdp passed into this function points to an array of 80 chars. When the
2026 * function returns, the @mdp will be filled with the model name.
2027 **/
dea31012005-04-17 16:05:31 -05002028static void
James Smart2e0fef82007-06-17 19:56:36 -05002029lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05002030{
2031 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05002032 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002033 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04002034 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04002035 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002036 struct {
James Smarta747c9c2009-11-18 15:41:10 -05002037 char *name;
2038 char *bus;
2039 char *function;
2040 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002041
2042 if (mdp && mdp[0] != '\0'
2043 && descp && descp[0] != '\0')
2044 return;
2045
James Smartd38dd522015-08-31 16:48:17 -04002046 if (phba->lmt & LMT_32Gb)
2047 max_speed = 32;
2048 else if (phba->lmt & LMT_16Gb)
James Smartc0c11512011-05-24 11:41:34 -04002049 max_speed = 16;
2050 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002051 max_speed = 10;
2052 else if (phba->lmt & LMT_8Gb)
2053 max_speed = 8;
2054 else if (phba->lmt & LMT_4Gb)
2055 max_speed = 4;
2056 else if (phba->lmt & LMT_2Gb)
2057 max_speed = 2;
James Smart4169d862012-09-29 11:32:09 -04002058 else if (phba->lmt & LMT_1Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002059 max_speed = 1;
James Smart4169d862012-09-29 11:32:09 -04002060 else
2061 max_speed = 0;
dea31012005-04-17 16:05:31 -05002062
2063 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05002064
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002065 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002066 case PCI_DEVICE_ID_FIREFLY:
James Smart12222f42014-05-21 08:05:19 -04002067 m = (typeof(m)){"LP6000", "PCI",
2068 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002069 break;
dea31012005-04-17 16:05:31 -05002070 case PCI_DEVICE_ID_SUPERFLY:
2071 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart12222f42014-05-21 08:05:19 -04002072 m = (typeof(m)){"LP7000", "PCI", ""};
dea31012005-04-17 16:05:31 -05002073 else
James Smart12222f42014-05-21 08:05:19 -04002074 m = (typeof(m)){"LP7000E", "PCI", ""};
2075 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002076 break;
2077 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002078 m = (typeof(m)){"LP8000", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002079 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002080 break;
2081 case PCI_DEVICE_ID_CENTAUR:
2082 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart12222f42014-05-21 08:05:19 -04002083 m = (typeof(m)){"LP9002", "PCI", ""};
dea31012005-04-17 16:05:31 -05002084 else
James Smart12222f42014-05-21 08:05:19 -04002085 m = (typeof(m)){"LP9000", "PCI", ""};
2086 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002087 break;
2088 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002089 m = (typeof(m)){"LP952", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002090 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002091 break;
2092 case PCI_DEVICE_ID_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05002093 m = (typeof(m)){"LP9802", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002094 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002095 break;
2096 case PCI_DEVICE_ID_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05002097 m = (typeof(m)){"LP10000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002098 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002099 break;
2100 case PCI_DEVICE_ID_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05002101 m = (typeof(m)){"LPX1000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002102 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002103 break;
2104 case PCI_DEVICE_ID_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002105 m = (typeof(m)){"LP982", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002106 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002107 break;
2108 case PCI_DEVICE_ID_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002109 m = (typeof(m)){"LP1050", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002110 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002111 break;
2112 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05002113 m = (typeof(m)){"LP11000", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002114 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002115 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002116 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002117 m = (typeof(m)){"LP11000-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002118 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002119 break;
2120 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002121 m = (typeof(m)){"LP11002-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002122 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002123 break;
2124 case PCI_DEVICE_ID_NEPTUNE:
James Smart12222f42014-05-21 08:05:19 -04002125 m = (typeof(m)){"LPe1000", "PCIe",
2126 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002127 break;
2128 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart12222f42014-05-21 08:05:19 -04002129 m = (typeof(m)){"LPe1000-SP", "PCIe",
2130 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002131 break;
2132 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart12222f42014-05-21 08:05:19 -04002133 m = (typeof(m)){"LPe1002-SP", "PCIe",
2134 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002135 break;
dea31012005-04-17 16:05:31 -05002136 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05002137 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002138 break;
2139 case PCI_DEVICE_ID_BSMB:
James Smart12222f42014-05-21 08:05:19 -04002140 m = (typeof(m)){"LP111", "PCI-X2",
2141 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002142 break;
2143 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05002144 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002145 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002146 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002147 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002148 break;
2149 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002150 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04002151 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002152 break;
dea31012005-04-17 16:05:31 -05002153 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05002154 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002155 break;
2156 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05002157 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002158 break;
2159 case PCI_DEVICE_ID_LP101:
James Smart12222f42014-05-21 08:05:19 -04002160 m = (typeof(m)){"LP101", "PCI-X",
2161 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002162 break;
2163 case PCI_DEVICE_ID_LP10000S:
James Smart12222f42014-05-21 08:05:19 -04002164 m = (typeof(m)){"LP10000-S", "PCI",
2165 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002166 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002167 case PCI_DEVICE_ID_LP11000S:
James Smart12222f42014-05-21 08:05:19 -04002168 m = (typeof(m)){"LP11000-S", "PCI-X2",
2169 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05002170 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002171 case PCI_DEVICE_ID_LPE11000S:
James Smart12222f42014-05-21 08:05:19 -04002172 m = (typeof(m)){"LPe11000-S", "PCIe",
2173 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002174 break;
James Smartb87eab32007-04-25 09:53:28 -04002175 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05002176 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002177 break;
2178 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05002179 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002180 break;
2181 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05002182 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002183 break;
2184 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002185 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002186 break;
2187 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002188 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002189 break;
2190 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05002191 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002192 break;
James Smart84774a42008-08-24 21:50:06 -04002193 case PCI_DEVICE_ID_HORNET:
James Smart12222f42014-05-21 08:05:19 -04002194 m = (typeof(m)){"LP21000", "PCIe",
2195 "Obsolete, Unsupported FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002196 GE = 1;
2197 break;
2198 case PCI_DEVICE_ID_PROTEUS_VF:
James Smarta747c9c2009-11-18 15:41:10 -05002199 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002200 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002201 break;
2202 case PCI_DEVICE_ID_PROTEUS_PF:
James Smarta747c9c2009-11-18 15:41:10 -05002203 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002204 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002205 break;
2206 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05002207 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002208 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002209 break;
James Smartda0436e2009-05-22 14:51:39 -04002210 case PCI_DEVICE_ID_TIGERSHARK:
2211 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002212 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04002213 break;
James Smarta747c9c2009-11-18 15:41:10 -05002214 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04002215 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002216 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2217 break;
2218 case PCI_DEVICE_ID_FALCON:
2219 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2220 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04002221 break;
James Smart98fc5dd2010-06-07 15:24:29 -04002222 case PCI_DEVICE_ID_BALIUS:
2223 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
James Smart12222f42014-05-21 08:05:19 -04002224 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart98fc5dd2010-06-07 15:24:29 -04002225 break;
James Smart085c6472010-11-20 23:11:37 -05002226 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04002227 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05002228 break;
James Smart12222f42014-05-21 08:05:19 -04002229 case PCI_DEVICE_ID_LANCER_FC_VF:
2230 m = (typeof(m)){"LPe16000", "PCIe",
2231 "Obsolete, Unsupported Fibre Channel Adapter"};
2232 break;
James Smart085c6472010-11-20 23:11:37 -05002233 case PCI_DEVICE_ID_LANCER_FCOE:
2234 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04002235 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05002236 break;
James Smart12222f42014-05-21 08:05:19 -04002237 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2238 oneConnect = 1;
2239 m = (typeof(m)){"OCe15100", "PCIe",
2240 "Obsolete, Unsupported FCoE"};
2241 break;
James Smartd38dd522015-08-31 16:48:17 -04002242 case PCI_DEVICE_ID_LANCER_G6_FC:
2243 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2244 break;
James Smartf8cafd32012-08-03 12:42:51 -04002245 case PCI_DEVICE_ID_SKYHAWK:
2246 case PCI_DEVICE_ID_SKYHAWK_VF:
2247 oneConnect = 1;
2248 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2249 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002250 default:
James Smarta747c9c2009-11-18 15:41:10 -05002251 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002252 break;
dea31012005-04-17 16:05:31 -05002253 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002254
2255 if (mdp && mdp[0] == '\0')
2256 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04002257 /*
2258 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04002259 * and we put the port number on the end
2260 */
2261 if (descp && descp[0] == '\0') {
2262 if (oneConnect)
2263 snprintf(descp, 255,
James Smart4169d862012-09-29 11:32:09 -04002264 "Emulex OneConnect %s, %s Initiator %s",
James Smarta747c9c2009-11-18 15:41:10 -05002265 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04002266 phba->Port);
James Smart4169d862012-09-29 11:32:09 -04002267 else if (max_speed == 0)
2268 snprintf(descp, 255,
Sebastian Herbszt290237d2015-08-31 16:48:08 -04002269 "Emulex %s %s %s",
James Smart4169d862012-09-29 11:32:09 -04002270 m.name, m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002271 else
2272 snprintf(descp, 255,
2273 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05002274 m.name, max_speed, (GE) ? "GE" : "Gb",
2275 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002276 }
dea31012005-04-17 16:05:31 -05002277}
2278
James Smarte59058c2008-08-24 21:49:00 -04002279/**
James Smart3621a712009-04-06 18:47:14 -04002280 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04002281 * @phba: pointer to lpfc hba data structure.
2282 * @pring: pointer to a IOCB ring.
2283 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2284 *
2285 * This routine posts a given number of IOCBs with the associated DMA buffer
2286 * descriptors specified by the cnt argument to the given IOCB ring.
2287 *
2288 * Return codes
2289 * The number of IOCBs NOT able to be posted to the IOCB ring.
2290 **/
dea31012005-04-17 16:05:31 -05002291int
James Smart495a7142008-06-14 22:52:59 -04002292lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002293{
2294 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002295 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002296 struct lpfc_dmabuf *mp1, *mp2;
2297
2298 cnt += pring->missbufcnt;
2299
2300 /* While there are buffers to post */
2301 while (cnt > 0) {
2302 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002303 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002304 if (iocb == NULL) {
2305 pring->missbufcnt = cnt;
2306 return cnt;
2307 }
dea31012005-04-17 16:05:31 -05002308 icmd = &iocb->iocb;
2309
2310 /* 2 buffers can be posted per command */
2311 /* Allocate buffer to post */
2312 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2313 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002314 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2315 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002316 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002317 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002318 pring->missbufcnt = cnt;
2319 return cnt;
2320 }
2321
2322 INIT_LIST_HEAD(&mp1->list);
2323 /* Allocate buffer to post */
2324 if (cnt > 1) {
2325 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2326 if (mp2)
2327 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2328 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002329 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002330 kfree(mp2);
dea31012005-04-17 16:05:31 -05002331 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2332 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002333 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002334 pring->missbufcnt = cnt;
2335 return cnt;
2336 }
2337
2338 INIT_LIST_HEAD(&mp2->list);
2339 } else {
2340 mp2 = NULL;
2341 }
2342
2343 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2344 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2345 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2346 icmd->ulpBdeCount = 1;
2347 cnt--;
2348 if (mp2) {
2349 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2350 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2351 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2352 cnt--;
2353 icmd->ulpBdeCount = 2;
2354 }
2355
2356 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2357 icmd->ulpLe = 1;
2358
James Smart3772a992009-05-22 14:50:54 -04002359 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2360 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002361 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2362 kfree(mp1);
2363 cnt++;
2364 if (mp2) {
2365 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2366 kfree(mp2);
2367 cnt++;
2368 }
James Bottomley604a3e32005-10-29 10:28:33 -05002369 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002370 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002371 return cnt;
2372 }
dea31012005-04-17 16:05:31 -05002373 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002374 if (mp2)
dea31012005-04-17 16:05:31 -05002375 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002376 }
2377 pring->missbufcnt = 0;
2378 return 0;
2379}
2380
James Smarte59058c2008-08-24 21:49:00 -04002381/**
James Smart3621a712009-04-06 18:47:14 -04002382 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002383 * @phba: pointer to lpfc hba data structure.
2384 *
2385 * This routine posts initial receive IOCB buffers to the ELS ring. The
2386 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2387 * set to 64 IOCBs.
2388 *
2389 * Return codes
2390 * 0 - success (currently always success)
2391 **/
dea31012005-04-17 16:05:31 -05002392static int
James Smart2e0fef82007-06-17 19:56:36 -05002393lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002394{
2395 struct lpfc_sli *psli = &phba->sli;
2396
2397 /* Ring 0, ELS / CT buffers */
James Smart495a7142008-06-14 22:52:59 -04002398 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002399 /* Ring 2 - FCP no buffers needed */
2400
2401 return 0;
2402}
2403
2404#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2405
James Smarte59058c2008-08-24 21:49:00 -04002406/**
James Smart3621a712009-04-06 18:47:14 -04002407 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002408 * @HashResultPointer: pointer to an array as hash table.
2409 *
2410 * This routine sets up the initial values to the array of hash table entries
2411 * for the LC HBAs.
2412 **/
dea31012005-04-17 16:05:31 -05002413static void
2414lpfc_sha_init(uint32_t * HashResultPointer)
2415{
2416 HashResultPointer[0] = 0x67452301;
2417 HashResultPointer[1] = 0xEFCDAB89;
2418 HashResultPointer[2] = 0x98BADCFE;
2419 HashResultPointer[3] = 0x10325476;
2420 HashResultPointer[4] = 0xC3D2E1F0;
2421}
2422
James Smarte59058c2008-08-24 21:49:00 -04002423/**
James Smart3621a712009-04-06 18:47:14 -04002424 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002425 * @HashResultPointer: pointer to an initial/result hash table.
2426 * @HashWorkingPointer: pointer to an working hash table.
2427 *
2428 * This routine iterates an initial hash table pointed by @HashResultPointer
2429 * with the values from the working hash table pointeed by @HashWorkingPointer.
2430 * The results are putting back to the initial hash table, returned through
2431 * the @HashResultPointer as the result hash table.
2432 **/
dea31012005-04-17 16:05:31 -05002433static void
2434lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2435{
2436 int t;
2437 uint32_t TEMP;
2438 uint32_t A, B, C, D, E;
2439 t = 16;
2440 do {
2441 HashWorkingPointer[t] =
2442 S(1,
2443 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2444 8] ^
2445 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2446 } while (++t <= 79);
2447 t = 0;
2448 A = HashResultPointer[0];
2449 B = HashResultPointer[1];
2450 C = HashResultPointer[2];
2451 D = HashResultPointer[3];
2452 E = HashResultPointer[4];
2453
2454 do {
2455 if (t < 20) {
2456 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2457 } else if (t < 40) {
2458 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2459 } else if (t < 60) {
2460 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2461 } else {
2462 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2463 }
2464 TEMP += S(5, A) + E + HashWorkingPointer[t];
2465 E = D;
2466 D = C;
2467 C = S(30, B);
2468 B = A;
2469 A = TEMP;
2470 } while (++t <= 79);
2471
2472 HashResultPointer[0] += A;
2473 HashResultPointer[1] += B;
2474 HashResultPointer[2] += C;
2475 HashResultPointer[3] += D;
2476 HashResultPointer[4] += E;
2477
2478}
2479
James Smarte59058c2008-08-24 21:49:00 -04002480/**
James Smart3621a712009-04-06 18:47:14 -04002481 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002482 * @RandomChallenge: pointer to the entry of host challenge random number array.
2483 * @HashWorking: pointer to the entry of the working hash array.
2484 *
2485 * This routine calculates the working hash array referred by @HashWorking
2486 * from the challenge random numbers associated with the host, referred by
2487 * @RandomChallenge. The result is put into the entry of the working hash
2488 * array and returned by reference through @HashWorking.
2489 **/
dea31012005-04-17 16:05:31 -05002490static void
2491lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2492{
2493 *HashWorking = (*RandomChallenge ^ *HashWorking);
2494}
2495
James Smarte59058c2008-08-24 21:49:00 -04002496/**
James Smart3621a712009-04-06 18:47:14 -04002497 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002498 * @phba: pointer to lpfc hba data structure.
2499 * @hbainit: pointer to an array of unsigned 32-bit integers.
2500 *
2501 * This routine performs the special handling for LC HBA initialization.
2502 **/
dea31012005-04-17 16:05:31 -05002503void
2504lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2505{
2506 int t;
2507 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002508 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002509
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002510 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002511 if (!HashWorking)
2512 return;
2513
dea31012005-04-17 16:05:31 -05002514 HashWorking[0] = HashWorking[78] = *pwwnn++;
2515 HashWorking[1] = HashWorking[79] = *pwwnn;
2516
2517 for (t = 0; t < 7; t++)
2518 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2519
2520 lpfc_sha_init(hbainit);
2521 lpfc_sha_iterate(hbainit, HashWorking);
2522 kfree(HashWorking);
2523}
2524
James Smarte59058c2008-08-24 21:49:00 -04002525/**
James Smart3621a712009-04-06 18:47:14 -04002526 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002527 * @vport: pointer to a virtual N_Port data structure.
2528 *
2529 * This routine performs the necessary cleanups before deleting the @vport.
2530 * It invokes the discovery state machine to perform necessary state
2531 * transitions and to release the ndlps associated with the @vport. Note,
2532 * the physical port is treated as @vport 0.
2533 **/
James Smart87af33f2007-10-27 13:37:43 -04002534void
James Smart2e0fef82007-06-17 19:56:36 -05002535lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002536{
James Smart87af33f2007-10-27 13:37:43 -04002537 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002538 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002539 int i = 0;
dea31012005-04-17 16:05:31 -05002540
James Smart87af33f2007-10-27 13:37:43 -04002541 if (phba->link_state > LPFC_LINK_DOWN)
2542 lpfc_port_link_failure(vport);
2543
2544 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002545 if (!NLP_CHK_NODE_ACT(ndlp)) {
2546 ndlp = lpfc_enable_node(vport, ndlp,
2547 NLP_STE_UNUSED_NODE);
2548 if (!ndlp)
2549 continue;
2550 spin_lock_irq(&phba->ndlp_lock);
2551 NLP_SET_FREE_REQ(ndlp);
2552 spin_unlock_irq(&phba->ndlp_lock);
2553 /* Trigger the release of the ndlp memory */
2554 lpfc_nlp_put(ndlp);
2555 continue;
2556 }
2557 spin_lock_irq(&phba->ndlp_lock);
2558 if (NLP_CHK_FREE_REQ(ndlp)) {
2559 /* The ndlp should not be in memory free mode already */
2560 spin_unlock_irq(&phba->ndlp_lock);
2561 continue;
2562 } else
2563 /* Indicate request for freeing ndlp memory */
2564 NLP_SET_FREE_REQ(ndlp);
2565 spin_unlock_irq(&phba->ndlp_lock);
2566
James Smart58da1ff2008-04-07 10:15:56 -04002567 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2568 ndlp->nlp_DID == Fabric_DID) {
2569 /* Just free up ndlp with Fabric_DID for vports */
2570 lpfc_nlp_put(ndlp);
2571 continue;
2572 }
2573
James Smarteff4a012012-01-18 16:25:25 -05002574 /* take care of nodes in unused state before the state
2575 * machine taking action.
2576 */
2577 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2578 lpfc_nlp_put(ndlp);
2579 continue;
2580 }
2581
James Smart87af33f2007-10-27 13:37:43 -04002582 if (ndlp->nlp_type & NLP_FABRIC)
2583 lpfc_disc_state_machine(vport, ndlp, NULL,
2584 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002585
James Smart87af33f2007-10-27 13:37:43 -04002586 lpfc_disc_state_machine(vport, ndlp, NULL,
2587 NLP_EVT_DEVICE_RM);
2588 }
2589
James Smarta8adb832007-10-27 13:37:53 -04002590 /* At this point, ALL ndlp's should be gone
2591 * because of the previous NLP_EVT_DEVICE_RM.
2592 * Lets wait for this to happen, if needed.
2593 */
James Smart87af33f2007-10-27 13:37:43 -04002594 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002595 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04002596 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04002597 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002598 list_for_each_entry_safe(ndlp, next_ndlp,
2599 &vport->fc_nodes, nlp_listp) {
2600 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2601 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04002602 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05002603 "usgmap:x%x refcnt:%d\n",
2604 ndlp->nlp_DID, (void *)ndlp,
2605 ndlp->nlp_usg_map,
2606 atomic_read(
2607 &ndlp->kref.refcount));
2608 }
James Smarta8adb832007-10-27 13:37:53 -04002609 break;
James Smart87af33f2007-10-27 13:37:43 -04002610 }
James Smarta8adb832007-10-27 13:37:53 -04002611
2612 /* Wait for any activity on ndlps to settle */
2613 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002614 }
James Smart1151e3e2011-02-16 12:39:35 -05002615 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002616}
2617
James Smarte59058c2008-08-24 21:49:00 -04002618/**
James Smart3621a712009-04-06 18:47:14 -04002619 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002620 * @vport: pointer to a virtual N_Port data structure.
2621 *
2622 * This routine stops all the timers associated with a @vport. This function
2623 * is invoked before disabling or deleting a @vport. Note that the physical
2624 * port is treated as @vport 0.
2625 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002626void
2627lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002628{
James Smart92d7f7b2007-06-17 19:56:38 -05002629 del_timer_sync(&vport->els_tmofunc);
James Smart92494142011-02-16 12:39:44 -05002630 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002631 lpfc_can_disctmo(vport);
2632 return;
dea31012005-04-17 16:05:31 -05002633}
2634
James Smarte59058c2008-08-24 21:49:00 -04002635/**
James Smartecfd03c2010-02-12 14:41:27 -05002636 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2637 * @phba: pointer to lpfc hba data structure.
2638 *
2639 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2640 * caller of this routine should already hold the host lock.
2641 **/
2642void
2643__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2644{
James Smart5ac6b302010-10-22 11:05:36 -04002645 /* Clear pending FCF rediscovery wait flag */
2646 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2647
James Smartecfd03c2010-02-12 14:41:27 -05002648 /* Now, try to stop the timer */
2649 del_timer(&phba->fcf.redisc_wait);
2650}
2651
2652/**
2653 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2654 * @phba: pointer to lpfc hba data structure.
2655 *
2656 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2657 * checks whether the FCF rediscovery wait timer is pending with the host
2658 * lock held before proceeding with disabling the timer and clearing the
2659 * wait timer pendig flag.
2660 **/
2661void
2662lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2663{
2664 spin_lock_irq(&phba->hbalock);
2665 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2666 /* FCF rediscovery timer already fired or stopped */
2667 spin_unlock_irq(&phba->hbalock);
2668 return;
2669 }
2670 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002671 /* Clear failover in progress flags */
2672 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002673 spin_unlock_irq(&phba->hbalock);
2674}
2675
2676/**
James Smart3772a992009-05-22 14:50:54 -04002677 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002678 * @phba: pointer to lpfc hba data structure.
2679 *
2680 * This routine stops all the timers associated with a HBA. This function is
2681 * invoked before either putting a HBA offline or unloading the driver.
2682 **/
James Smart3772a992009-05-22 14:50:54 -04002683void
2684lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002685{
James Smart51ef4c22007-08-02 11:10:31 -04002686 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05002687 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002688 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002689 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002690 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002691 if (phba->sli_rev == LPFC_SLI_REV4) {
2692 del_timer_sync(&phba->rrq_tmr);
2693 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2694 }
James Smart3772a992009-05-22 14:50:54 -04002695 phba->hb_outstanding = 0;
2696
2697 switch (phba->pci_dev_grp) {
2698 case LPFC_PCI_DEV_LP:
2699 /* Stop any LightPulse device specific driver timers */
2700 del_timer_sync(&phba->fcp_poll_timer);
2701 break;
2702 case LPFC_PCI_DEV_OC:
2703 /* Stop any OneConnect device sepcific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002704 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002705 break;
2706 default:
2707 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2708 "0297 Invalid device group (x%x)\n",
2709 phba->pci_dev_grp);
2710 break;
2711 }
James Smart2e0fef82007-06-17 19:56:36 -05002712 return;
dea31012005-04-17 16:05:31 -05002713}
2714
James Smarte59058c2008-08-24 21:49:00 -04002715/**
James Smart3621a712009-04-06 18:47:14 -04002716 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002717 * @phba: pointer to lpfc hba data structure.
2718 *
2719 * This routine marks a HBA's management interface as blocked. Once the HBA's
2720 * management interface is marked as blocked, all the user space access to
2721 * the HBA, whether they are from sysfs interface or libdfc interface will
2722 * all be blocked. The HBA is set to block the management interface when the
2723 * driver prepares the HBA interface for online or offline.
2724 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01002725static void
James Smart618a5232012-06-12 13:54:36 -04002726lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
Adrian Bunka6ababd2007-11-05 18:07:33 +01002727{
2728 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04002729 uint8_t actcmd = MBX_HEARTBEAT;
2730 unsigned long timeout;
2731
Adrian Bunka6ababd2007-11-05 18:07:33 +01002732 spin_lock_irqsave(&phba->hbalock, iflag);
2733 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart618a5232012-06-12 13:54:36 -04002734 spin_unlock_irqrestore(&phba->hbalock, iflag);
2735 if (mbx_action == LPFC_MBX_NO_WAIT)
2736 return;
2737 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2738 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002739 if (phba->sli.mbox_active) {
James Smart6e7288d2010-06-07 15:23:35 -04002740 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
James Smarta183a152011-10-10 21:32:43 -04002741 /* Determine how long we might wait for the active mailbox
2742 * command to be gracefully completed by firmware.
2743 */
2744 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
2745 phba->sli.mbox_active) * 1000) + jiffies;
2746 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002747 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002748
James Smart6e7288d2010-06-07 15:23:35 -04002749 /* Wait for the outstnading mailbox command to complete */
2750 while (phba->sli.mbox_active) {
2751 /* Check active mailbox complete status every 2ms */
2752 msleep(2);
2753 if (time_after(jiffies, timeout)) {
2754 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2755 "2813 Mgmt IO is Blocked %x "
2756 "- mbox cmd %x still active\n",
2757 phba->sli.sli_flag, actcmd);
2758 break;
2759 }
2760 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002761}
2762
James Smarte59058c2008-08-24 21:49:00 -04002763/**
James Smart6b5151f2012-01-18 16:24:06 -05002764 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
2765 * @phba: pointer to lpfc hba data structure.
2766 *
2767 * Allocate RPIs for all active remote nodes. This is needed whenever
2768 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
2769 * is to fixup the temporary rpi assignments.
2770 **/
2771void
2772lpfc_sli4_node_prep(struct lpfc_hba *phba)
2773{
2774 struct lpfc_nodelist *ndlp, *next_ndlp;
2775 struct lpfc_vport **vports;
2776 int i;
2777
2778 if (phba->sli_rev != LPFC_SLI_REV4)
2779 return;
2780
2781 vports = lpfc_create_vport_work_array(phba);
2782 if (vports != NULL) {
2783 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2784 if (vports[i]->load_flag & FC_UNLOADING)
2785 continue;
2786
2787 list_for_each_entry_safe(ndlp, next_ndlp,
2788 &vports[i]->fc_nodes,
2789 nlp_listp) {
James Smartbe6bb942015-04-07 15:07:22 -04002790 if (NLP_CHK_NODE_ACT(ndlp)) {
James Smart6b5151f2012-01-18 16:24:06 -05002791 ndlp->nlp_rpi =
2792 lpfc_sli4_alloc_rpi(phba);
James Smartbe6bb942015-04-07 15:07:22 -04002793 lpfc_printf_vlog(ndlp->vport, KERN_INFO,
2794 LOG_NODE,
2795 "0009 rpi:%x DID:%x "
2796 "flg:%x map:%x %p\n",
2797 ndlp->nlp_rpi,
2798 ndlp->nlp_DID,
2799 ndlp->nlp_flag,
2800 ndlp->nlp_usg_map,
2801 ndlp);
2802 }
James Smart6b5151f2012-01-18 16:24:06 -05002803 }
2804 }
2805 }
2806 lpfc_destroy_vport_work_array(phba, vports);
2807}
2808
2809/**
James Smart3621a712009-04-06 18:47:14 -04002810 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04002811 * @phba: pointer to lpfc hba data structure.
2812 *
2813 * This routine initializes the HBA and brings a HBA online. During this
2814 * process, the management interface is blocked to prevent user space access
2815 * to the HBA interfering with the driver initialization.
2816 *
2817 * Return codes
2818 * 0 - successful
2819 * 1 - failed
2820 **/
dea31012005-04-17 16:05:31 -05002821int
James Smart2e0fef82007-06-17 19:56:36 -05002822lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002823{
Julia Lawall372bd282008-12-16 16:15:08 +01002824 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04002825 struct lpfc_vport **vports;
2826 int i;
James Smart16a3a202013-04-17 20:14:38 -04002827 bool vpis_cleared = false;
James Smart2e0fef82007-06-17 19:56:36 -05002828
dea31012005-04-17 16:05:31 -05002829 if (!phba)
2830 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01002831 vport = phba->pport;
dea31012005-04-17 16:05:31 -05002832
James Smart2e0fef82007-06-17 19:56:36 -05002833 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05002834 return 0;
2835
James Smarted957682007-06-17 19:56:37 -05002836 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002837 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05002838
James Smart618a5232012-06-12 13:54:36 -04002839 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05002840
James Smart46fa3112007-04-25 09:51:45 -04002841 if (!lpfc_sli_queue_setup(phba)) {
2842 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002843 return 1;
James Smart46fa3112007-04-25 09:51:45 -04002844 }
2845
James Smartda0436e2009-05-22 14:51:39 -04002846 if (phba->sli_rev == LPFC_SLI_REV4) {
2847 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
2848 lpfc_unblock_mgmt_io(phba);
2849 return 1;
2850 }
James Smart16a3a202013-04-17 20:14:38 -04002851 spin_lock_irq(&phba->hbalock);
2852 if (!phba->sli4_hba.max_cfg_param.vpi_used)
2853 vpis_cleared = true;
2854 spin_unlock_irq(&phba->hbalock);
James Smartda0436e2009-05-22 14:51:39 -04002855 } else {
2856 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
2857 lpfc_unblock_mgmt_io(phba);
2858 return 1;
2859 }
James Smart46fa3112007-04-25 09:51:45 -04002860 }
dea31012005-04-17 16:05:31 -05002861
James Smart549e55c2007-08-02 11:09:51 -04002862 vports = lpfc_create_vport_work_array(phba);
2863 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002864 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002865 struct Scsi_Host *shost;
2866 shost = lpfc_shost_from_vport(vports[i]);
2867 spin_lock_irq(shost->host_lock);
2868 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
2869 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2870 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart16a3a202013-04-17 20:14:38 -04002871 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart1c6834a2009-07-19 10:01:26 -04002872 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart16a3a202013-04-17 20:14:38 -04002873 if ((vpis_cleared) &&
2874 (vports[i]->port_type !=
2875 LPFC_PHYSICAL_PORT))
2876 vports[i]->vpi = 0;
2877 }
James Smart549e55c2007-08-02 11:09:51 -04002878 spin_unlock_irq(shost->host_lock);
2879 }
James Smart09372822008-01-11 01:52:54 -05002880 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002881
James Smart46fa3112007-04-25 09:51:45 -04002882 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002883 return 0;
2884}
2885
James Smarte59058c2008-08-24 21:49:00 -04002886/**
James Smart3621a712009-04-06 18:47:14 -04002887 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04002888 * @phba: pointer to lpfc hba data structure.
2889 *
2890 * This routine marks a HBA's management interface as not blocked. Once the
2891 * HBA's management interface is marked as not blocked, all the user space
2892 * access to the HBA, whether they are from sysfs interface or libdfc
2893 * interface will be allowed. The HBA is set to block the management interface
2894 * when the driver prepares the HBA interface for online or offline and then
2895 * set to unblock the management interface afterwards.
2896 **/
James Smart46fa3112007-04-25 09:51:45 -04002897void
James Smart46fa3112007-04-25 09:51:45 -04002898lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
2899{
2900 unsigned long iflag;
2901
James Smart2e0fef82007-06-17 19:56:36 -05002902 spin_lock_irqsave(&phba->hbalock, iflag);
2903 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
2904 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04002905}
2906
James Smarte59058c2008-08-24 21:49:00 -04002907/**
James Smart3621a712009-04-06 18:47:14 -04002908 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04002909 * @phba: pointer to lpfc hba data structure.
2910 *
2911 * This routine is invoked to prepare a HBA to be brought offline. It performs
2912 * unregistration login to all the nodes on all vports and flushes the mailbox
2913 * queue to make it ready to be brought offline.
2914 **/
James Smart46fa3112007-04-25 09:51:45 -04002915void
James Smart618a5232012-06-12 13:54:36 -04002916lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04002917{
James Smart2e0fef82007-06-17 19:56:36 -05002918 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04002919 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04002920 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05002921 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04002922 int i;
dea31012005-04-17 16:05:31 -05002923
James Smart2e0fef82007-06-17 19:56:36 -05002924 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002925 return;
dea31012005-04-17 16:05:31 -05002926
James Smart618a5232012-06-12 13:54:36 -04002927 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05002928
2929 lpfc_linkdown(phba);
2930
James Smart87af33f2007-10-27 13:37:43 -04002931 /* Issue an unreg_login to all nodes on all vports */
2932 vports = lpfc_create_vport_work_array(phba);
2933 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04002934 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04002935 if (vports[i]->load_flag & FC_UNLOADING)
2936 continue;
James Smart72100cc2010-02-12 14:43:01 -05002937 shost = lpfc_shost_from_vport(vports[i]);
2938 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05002939 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002940 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2941 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05002942 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05002943
James Smart87af33f2007-10-27 13:37:43 -04002944 shost = lpfc_shost_from_vport(vports[i]);
2945 list_for_each_entry_safe(ndlp, next_ndlp,
2946 &vports[i]->fc_nodes,
2947 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002948 if (!NLP_CHK_NODE_ACT(ndlp))
2949 continue;
James Smart87af33f2007-10-27 13:37:43 -04002950 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2951 continue;
2952 if (ndlp->nlp_type & NLP_FABRIC) {
2953 lpfc_disc_state_machine(vports[i], ndlp,
2954 NULL, NLP_EVT_DEVICE_RECOVERY);
2955 lpfc_disc_state_machine(vports[i], ndlp,
2956 NULL, NLP_EVT_DEVICE_RM);
2957 }
2958 spin_lock_irq(shost->host_lock);
2959 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart401ee0c2012-03-01 22:35:34 -05002960 spin_unlock_irq(shost->host_lock);
James Smart6b5151f2012-01-18 16:24:06 -05002961 /*
2962 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05002963 * RPI. Get a new RPI when the adapter port
2964 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05002965 */
James Smartbe6bb942015-04-07 15:07:22 -04002966 if (phba->sli_rev == LPFC_SLI_REV4) {
2967 lpfc_printf_vlog(ndlp->vport,
2968 KERN_INFO, LOG_NODE,
2969 "0011 lpfc_offline: "
2970 "ndlp:x%p did %x "
2971 "usgmap:x%x rpi:%x\n",
2972 ndlp, ndlp->nlp_DID,
2973 ndlp->nlp_usg_map,
2974 ndlp->nlp_rpi);
2975
James Smart6b5151f2012-01-18 16:24:06 -05002976 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smartbe6bb942015-04-07 15:07:22 -04002977 }
James Smart87af33f2007-10-27 13:37:43 -04002978 lpfc_unreg_rpi(vports[i], ndlp);
2979 }
2980 }
2981 }
James Smart09372822008-01-11 01:52:54 -05002982 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002983
James Smart618a5232012-06-12 13:54:36 -04002984 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
James Smart46fa3112007-04-25 09:51:45 -04002985}
2986
James Smarte59058c2008-08-24 21:49:00 -04002987/**
James Smart3621a712009-04-06 18:47:14 -04002988 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04002989 * @phba: pointer to lpfc hba data structure.
2990 *
2991 * This routine actually brings a HBA offline. It stops all the timers
2992 * associated with the HBA, brings down the SLI layer, and eventually
2993 * marks the HBA as in offline state for the upper layer protocol.
2994 **/
James Smart46fa3112007-04-25 09:51:45 -04002995void
James Smart2e0fef82007-06-17 19:56:36 -05002996lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04002997{
James Smart549e55c2007-08-02 11:09:51 -04002998 struct Scsi_Host *shost;
2999 struct lpfc_vport **vports;
3000 int i;
James Smart46fa3112007-04-25 09:51:45 -04003001
James Smart549e55c2007-08-02 11:09:51 -04003002 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003003 return;
James Smart688a8862006-07-06 15:49:56 -04003004
James Smartda0436e2009-05-22 14:51:39 -04003005 /* stop port and all timers associated with this hba */
3006 lpfc_stop_port(phba);
James Smart51ef4c22007-08-02 11:10:31 -04003007 vports = lpfc_create_vport_work_array(phba);
3008 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003009 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04003010 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05003011 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05003012 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003013 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05003014 /* Bring down the SLI Layer and cleanup. The HBA is offline
3015 now. */
3016 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003017 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04003018 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003019 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04003020 vports = lpfc_create_vport_work_array(phba);
3021 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003022 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003023 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04003024 spin_lock_irq(shost->host_lock);
3025 vports[i]->work_port_events = 0;
3026 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3027 spin_unlock_irq(shost->host_lock);
3028 }
James Smart09372822008-01-11 01:52:54 -05003029 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003030}
3031
James Smarte59058c2008-08-24 21:49:00 -04003032/**
James Smart3621a712009-04-06 18:47:14 -04003033 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04003034 * @phba: pointer to lpfc hba data structure.
3035 *
3036 * This routine is to free all the SCSI buffers and IOCBs from the driver
3037 * list back to kernel. It is called from lpfc_pci_remove_one to free
3038 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04003039 **/
James Smart8a9d2e82012-05-09 21:16:12 -04003040static void
James Smart2e0fef82007-06-17 19:56:36 -05003041lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003042{
3043 struct lpfc_scsi_buf *sb, *sb_next;
3044 struct lpfc_iocbq *io, *io_next;
3045
James Smart2e0fef82007-06-17 19:56:36 -05003046 spin_lock_irq(&phba->hbalock);
James Smarta40fc5f2013-04-17 20:17:40 -04003047
dea31012005-04-17 16:05:31 -05003048 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smarta40fc5f2013-04-17 20:17:40 -04003049
3050 spin_lock(&phba->scsi_buf_list_put_lock);
3051 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3052 list) {
dea31012005-04-17 16:05:31 -05003053 list_del(&sb->list);
3054 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05003055 sb->dma_handle);
dea31012005-04-17 16:05:31 -05003056 kfree(sb);
3057 phba->total_scsi_bufs--;
3058 }
James Smarta40fc5f2013-04-17 20:17:40 -04003059 spin_unlock(&phba->scsi_buf_list_put_lock);
3060
3061 spin_lock(&phba->scsi_buf_list_get_lock);
3062 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3063 list) {
3064 list_del(&sb->list);
3065 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
3066 sb->dma_handle);
3067 kfree(sb);
3068 phba->total_scsi_bufs--;
3069 }
3070 spin_unlock(&phba->scsi_buf_list_get_lock);
dea31012005-04-17 16:05:31 -05003071
3072 /* Release all the lpfc_iocbq entries maintained by this host. */
3073 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
3074 list_del(&io->list);
3075 kfree(io);
3076 phba->total_iocbq_bufs--;
3077 }
James Smart6d368e52011-05-24 11:44:12 -04003078
James Smart2e0fef82007-06-17 19:56:36 -05003079 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003080}
3081
3082/**
3083 * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping
3084 * @phba: pointer to lpfc hba data structure.
3085 *
3086 * This routine first calculates the sizes of the current els and allocated
3087 * scsi sgl lists, and then goes through all sgls to updates the physical
3088 * XRIs assigned due to port function reset. During port initialization, the
3089 * current els and allocated scsi sgl lists are 0s.
3090 *
3091 * Return codes
3092 * 0 - successful (for now, it always returns 0)
3093 **/
3094int
3095lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba)
3096{
3097 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3098 struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL;
3099 uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt;
3100 LIST_HEAD(els_sgl_list);
3101 LIST_HEAD(scsi_sgl_list);
3102 int rc;
James Smartdafe8ce2014-09-03 12:56:40 -04003103 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart8a9d2e82012-05-09 21:16:12 -04003104
3105 /*
3106 * update on pci function's els xri-sgl list
3107 */
3108 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3109 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3110 /* els xri-sgl expanded */
3111 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3112 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3113 "3157 ELS xri-sgl count increased from "
3114 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3115 els_xri_cnt);
3116 /* allocate the additional els sgls */
3117 for (i = 0; i < xri_cnt; i++) {
3118 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3119 GFP_KERNEL);
3120 if (sglq_entry == NULL) {
3121 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3122 "2562 Failure to allocate an "
3123 "ELS sgl entry:%d\n", i);
3124 rc = -ENOMEM;
3125 goto out_free_mem;
3126 }
3127 sglq_entry->buff_type = GEN_BUFF_TYPE;
3128 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3129 &sglq_entry->phys);
3130 if (sglq_entry->virt == NULL) {
3131 kfree(sglq_entry);
3132 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3133 "2563 Failure to allocate an "
3134 "ELS mbuf:%d\n", i);
3135 rc = -ENOMEM;
3136 goto out_free_mem;
3137 }
3138 sglq_entry->sgl = sglq_entry->virt;
3139 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3140 sglq_entry->state = SGL_FREED;
3141 list_add_tail(&sglq_entry->list, &els_sgl_list);
3142 }
James Smart38c20672013-03-01 16:37:44 -05003143 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04003144 spin_lock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003145 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04003146 spin_unlock(&pring->ring_lock);
James Smart38c20672013-03-01 16:37:44 -05003147 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003148 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3149 /* els xri-sgl shrinked */
3150 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3151 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3152 "3158 ELS xri-sgl count decreased from "
3153 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3154 els_xri_cnt);
3155 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04003156 spin_lock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003157 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04003158 spin_unlock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003159 spin_unlock_irq(&phba->hbalock);
3160 /* release extra els sgls from list */
3161 for (i = 0; i < xri_cnt; i++) {
3162 list_remove_head(&els_sgl_list,
3163 sglq_entry, struct lpfc_sglq, list);
3164 if (sglq_entry) {
3165 lpfc_mbuf_free(phba, sglq_entry->virt,
3166 sglq_entry->phys);
3167 kfree(sglq_entry);
3168 }
3169 }
3170 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04003171 spin_lock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003172 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04003173 spin_unlock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003174 spin_unlock_irq(&phba->hbalock);
3175 } else
3176 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3177 "3163 ELS xri-sgl count unchanged: %d\n",
3178 els_xri_cnt);
3179 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3180
3181 /* update xris to els sgls on the list */
3182 sglq_entry = NULL;
3183 sglq_entry_next = NULL;
3184 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3185 &phba->sli4_hba.lpfc_sgl_list, list) {
3186 lxri = lpfc_sli4_next_xritag(phba);
3187 if (lxri == NO_XRI) {
3188 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3189 "2400 Failed to allocate xri for "
3190 "ELS sgl\n");
3191 rc = -ENOMEM;
3192 goto out_free_mem;
3193 }
3194 sglq_entry->sli4_lxritag = lxri;
3195 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3196 }
3197
3198 /*
3199 * update on pci function's allocated scsi xri-sgl list
3200 */
3201 phba->total_scsi_bufs = 0;
3202
3203 /* maximum number of xris available for scsi buffers */
3204 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3205 els_xri_cnt;
3206
3207 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3208 "2401 Current allocated SCSI xri-sgl count:%d, "
3209 "maximum SCSI xri count:%d\n",
3210 phba->sli4_hba.scsi_xri_cnt,
3211 phba->sli4_hba.scsi_xri_max);
3212
James Smarta40fc5f2013-04-17 20:17:40 -04003213 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003214 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003215 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3216 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
James Smart164cecd2013-09-06 12:22:38 -04003217 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003218 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003219
3220 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3221 /* max scsi xri shrinked below the allocated scsi buffers */
3222 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3223 phba->sli4_hba.scsi_xri_max;
3224 /* release the extra allocated scsi buffers */
3225 for (i = 0; i < scsi_xri_cnt; i++) {
3226 list_remove_head(&scsi_sgl_list, psb,
3227 struct lpfc_scsi_buf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04003228 if (psb) {
3229 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
3230 psb->data, psb->dma_handle);
3231 kfree(psb);
3232 }
James Smart8a9d2e82012-05-09 21:16:12 -04003233 }
James Smarta40fc5f2013-04-17 20:17:40 -04003234 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003235 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
James Smarta40fc5f2013-04-17 20:17:40 -04003236 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003237 }
3238
3239 /* update xris associated to remaining allocated scsi buffers */
3240 psb = NULL;
3241 psb_next = NULL;
3242 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3243 lxri = lpfc_sli4_next_xritag(phba);
3244 if (lxri == NO_XRI) {
3245 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3246 "2560 Failed to allocate xri for "
3247 "scsi buffer\n");
3248 rc = -ENOMEM;
3249 goto out_free_mem;
3250 }
3251 psb->cur_iocbq.sli4_lxritag = lxri;
3252 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3253 }
James Smarta40fc5f2013-04-17 20:17:40 -04003254 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003255 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003256 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3257 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
James Smart164cecd2013-09-06 12:22:38 -04003258 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003259 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003260
dea31012005-04-17 16:05:31 -05003261 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003262
3263out_free_mem:
3264 lpfc_free_els_sgl_list(phba);
3265 lpfc_scsi_free(phba);
3266 return rc;
dea31012005-04-17 16:05:31 -05003267}
3268
James Smarte59058c2008-08-24 21:49:00 -04003269/**
James Smart3621a712009-04-06 18:47:14 -04003270 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04003271 * @phba: pointer to lpfc hba data structure.
3272 * @instance: a unique integer ID to this FC port.
3273 * @dev: pointer to the device data structure.
3274 *
3275 * This routine creates a FC port for the upper layer protocol. The FC port
3276 * can be created on top of either a physical port or a virtual port provided
3277 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3278 * and associates the FC port created before adding the shost into the SCSI
3279 * layer.
3280 *
3281 * Return codes
3282 * @vport - pointer to the virtual N_Port data structure.
3283 * NULL - port create failed.
3284 **/
James Smart2e0fef82007-06-17 19:56:36 -05003285struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04003286lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04003287{
James Smart2e0fef82007-06-17 19:56:36 -05003288 struct lpfc_vport *vport;
3289 struct Scsi_Host *shost;
3290 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04003291
James Smartea4142f2015-04-07 15:07:13 -04003292 if (dev != &phba->pcidev->dev) {
James Smart3de2a652007-08-02 11:09:59 -04003293 shost = scsi_host_alloc(&lpfc_vport_template,
3294 sizeof(struct lpfc_vport));
James Smartea4142f2015-04-07 15:07:13 -04003295 } else {
3296 if (phba->sli_rev == LPFC_SLI_REV4)
3297 shost = scsi_host_alloc(&lpfc_template,
James Smart3de2a652007-08-02 11:09:59 -04003298 sizeof(struct lpfc_vport));
James Smartea4142f2015-04-07 15:07:13 -04003299 else
3300 shost = scsi_host_alloc(&lpfc_template_s3,
3301 sizeof(struct lpfc_vport));
3302 }
James Smart2e0fef82007-06-17 19:56:36 -05003303 if (!shost)
3304 goto out;
James Smart47a86172007-04-25 09:53:22 -04003305
James Smart2e0fef82007-06-17 19:56:36 -05003306 vport = (struct lpfc_vport *) shost->hostdata;
3307 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05003308 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05003309 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05003310 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04003311
James Smart3de2a652007-08-02 11:09:59 -04003312 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05003313 shost->unique_id = instance;
3314 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04003315 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05003316 shost->this_id = -1;
3317 shost->max_cmd_len = 16;
James Smart8b0dff12015-05-22 10:42:38 -04003318 shost->nr_hw_queues = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04003319 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05003320 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04003321 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smartda0436e2009-05-22 14:51:39 -04003322 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
3323 }
James Smart81301a92008-12-04 22:39:46 -05003324
James Smart47a86172007-04-25 09:53:22 -04003325 /*
James Smart2e0fef82007-06-17 19:56:36 -05003326 * Set initial can_queue value since 0 is no longer supported and
3327 * scsi_add_host will fail. This will be adjusted later based on the
3328 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04003329 */
James Smart2e0fef82007-06-17 19:56:36 -05003330 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04003331 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05003332 shost->transportt = lpfc_vport_transport_template;
3333 vport->port_type = LPFC_NPIV_PORT;
3334 } else {
3335 shost->transportt = lpfc_transport_template;
3336 vport->port_type = LPFC_PHYSICAL_PORT;
3337 }
James Smart47a86172007-04-25 09:53:22 -04003338
James Smart2e0fef82007-06-17 19:56:36 -05003339 /* Initialize all internally managed lists. */
3340 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04003341 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05003342 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04003343
James Smart2e0fef82007-06-17 19:56:36 -05003344 init_timer(&vport->fc_disctmo);
3345 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003346 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04003347
James Smart2e0fef82007-06-17 19:56:36 -05003348 init_timer(&vport->els_tmofunc);
3349 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003350 vport->els_tmofunc.data = (unsigned long)vport;
James Smart92494142011-02-16 12:39:44 -05003351
3352 init_timer(&vport->delayed_disc_tmo);
3353 vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
3354 vport->delayed_disc_tmo.data = (unsigned long)vport;
3355
James Bottomleyd139b9b2009-11-05 13:33:12 -06003356 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05003357 if (error)
3358 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04003359
James Smart549e55c2007-08-02 11:09:51 -04003360 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003361 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04003362 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003363 return vport;
James Smart47a86172007-04-25 09:53:22 -04003364
James Smart2e0fef82007-06-17 19:56:36 -05003365out_put_shost:
3366 scsi_host_put(shost);
3367out:
3368 return NULL;
James Smart47a86172007-04-25 09:53:22 -04003369}
3370
James Smarte59058c2008-08-24 21:49:00 -04003371/**
James Smart3621a712009-04-06 18:47:14 -04003372 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04003373 * @vport: pointer to an lpfc virtual N_Port data structure.
3374 *
3375 * This routine destroys a FC port from the upper layer protocol. All the
3376 * resources associated with the port are released.
3377 **/
James Smart2e0fef82007-06-17 19:56:36 -05003378void
3379destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04003380{
James Smart92d7f7b2007-06-17 19:56:38 -05003381 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3382 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003383
James Smart858c9f62007-06-17 19:56:39 -05003384 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05003385 fc_remove_host(shost);
3386 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04003387
James Smart92d7f7b2007-06-17 19:56:38 -05003388 spin_lock_irq(&phba->hbalock);
3389 list_del_init(&vport->listentry);
3390 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04003391
James Smart92d7f7b2007-06-17 19:56:38 -05003392 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04003393 return;
James Smart47a86172007-04-25 09:53:22 -04003394}
3395
James Smarte59058c2008-08-24 21:49:00 -04003396/**
James Smart3621a712009-04-06 18:47:14 -04003397 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04003398 *
3399 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3400 * uses the kernel idr facility to perform the task.
3401 *
3402 * Return codes:
3403 * instance - a unique integer ID allocated as the new instance.
3404 * -1 - lpfc get instance failed.
3405 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003406int
3407lpfc_get_instance(void)
3408{
Tejun Heoab516032013-02-27 17:04:44 -08003409 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003410
Tejun Heoab516032013-02-27 17:04:44 -08003411 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
3412 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003413}
3414
James Smarte59058c2008-08-24 21:49:00 -04003415/**
James Smart3621a712009-04-06 18:47:14 -04003416 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04003417 * @shost: pointer to SCSI host data structure.
3418 * @time: elapsed time of the scan in jiffies.
3419 *
3420 * This routine is called by the SCSI layer with a SCSI host to determine
3421 * whether the scan host is finished.
3422 *
3423 * Note: there is no scan_start function as adapter initialization will have
3424 * asynchronously kicked off the link initialization.
3425 *
3426 * Return codes
3427 * 0 - SCSI host scan is not over yet.
3428 * 1 - SCSI host scan is over.
3429 **/
James Smart47a86172007-04-25 09:53:22 -04003430int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
3431{
James Smart2e0fef82007-06-17 19:56:36 -05003432 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3433 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05003434 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04003435
James Smart858c9f62007-06-17 19:56:39 -05003436 spin_lock_irq(shost->host_lock);
3437
James Smart51ef4c22007-08-02 11:10:31 -04003438 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05003439 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003440 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05003441 }
James Smart256ec0d2013-04-17 20:14:58 -04003442 if (time >= msecs_to_jiffies(30 * 1000)) {
James Smart2e0fef82007-06-17 19:56:36 -05003443 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003444 "0461 Scanning longer than 30 "
3445 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003446 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003447 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003448 }
James Smart256ec0d2013-04-17 20:14:58 -04003449 if (time >= msecs_to_jiffies(15 * 1000) &&
3450 phba->link_state <= LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05003451 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003452 "0465 Link down longer than 15 "
3453 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003454 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05003455 goto finished;
James Smart47a86172007-04-25 09:53:22 -04003456 }
3457
James Smart2e0fef82007-06-17 19:56:36 -05003458 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05003459 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003460 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05003461 goto finished;
James Smart256ec0d2013-04-17 20:14:58 -04003462 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
James Smart858c9f62007-06-17 19:56:39 -05003463 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003464 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05003465 goto finished;
3466
3467 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003468
3469finished:
James Smart858c9f62007-06-17 19:56:39 -05003470 spin_unlock_irq(shost->host_lock);
3471 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003472}
3473
James Smarte59058c2008-08-24 21:49:00 -04003474/**
James Smart3621a712009-04-06 18:47:14 -04003475 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04003476 * @shost: pointer to SCSI host data structure.
3477 *
3478 * This routine initializes a given SCSI host attributes on a FC port. The
3479 * SCSI host can be either on top of a physical port or a virtual port.
3480 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003481void lpfc_host_attrib_init(struct Scsi_Host *shost)
3482{
3483 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3484 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003485 /*
James Smart2e0fef82007-06-17 19:56:36 -05003486 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04003487 */
3488
James Smart2e0fef82007-06-17 19:56:36 -05003489 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
3490 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04003491 fc_host_supported_classes(shost) = FC_COS_CLASS3;
3492
3493 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003494 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003495 fc_host_supported_fc4s(shost)[2] = 1;
3496 fc_host_supported_fc4s(shost)[7] = 1;
3497
James Smart92d7f7b2007-06-17 19:56:38 -05003498 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
3499 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04003500
3501 fc_host_supported_speeds(shost) = 0;
James Smartd38dd522015-08-31 16:48:17 -04003502 if (phba->lmt & LMT_32Gb)
3503 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
James Smart88a2cfb2011-07-22 18:36:33 -04003504 if (phba->lmt & LMT_16Gb)
3505 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
James Smart47a86172007-04-25 09:53:22 -04003506 if (phba->lmt & LMT_10Gb)
3507 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04003508 if (phba->lmt & LMT_8Gb)
3509 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04003510 if (phba->lmt & LMT_4Gb)
3511 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
3512 if (phba->lmt & LMT_2Gb)
3513 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
3514 if (phba->lmt & LMT_1Gb)
3515 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
3516
3517 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05003518 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
3519 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04003520
Mike Christie0af5d702010-09-15 16:52:31 -05003521 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
3522
James Smart47a86172007-04-25 09:53:22 -04003523 /* This value is also unchanging */
3524 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003525 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003526 fc_host_active_fc4s(shost)[2] = 1;
3527 fc_host_active_fc4s(shost)[7] = 1;
3528
James Smart92d7f7b2007-06-17 19:56:38 -05003529 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04003530 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04003531 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04003532 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04003533}
dea31012005-04-17 16:05:31 -05003534
James Smarte59058c2008-08-24 21:49:00 -04003535/**
James Smartda0436e2009-05-22 14:51:39 -04003536 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04003537 * @phba: pointer to lpfc hba data structure.
3538 *
James Smartda0436e2009-05-22 14:51:39 -04003539 * This routine is invoked to stop an SLI3 device port, it stops the device
3540 * from generating interrupts and stops the device driver's timers for the
3541 * device.
James Smarte59058c2008-08-24 21:49:00 -04003542 **/
James Smartdb2378e2008-02-08 18:49:51 -05003543static void
James Smartda0436e2009-05-22 14:51:39 -04003544lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05003545{
James Smartda0436e2009-05-22 14:51:39 -04003546 /* Clear all interrupt enable conditions */
3547 writel(0, phba->HCregaddr);
3548 readl(phba->HCregaddr); /* flush */
3549 /* Clear all pending interrupts */
3550 writel(0xffffffff, phba->HAregaddr);
3551 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04003552
James Smartda0436e2009-05-22 14:51:39 -04003553 /* Reset some HBA SLI setup states */
3554 lpfc_stop_hba_timers(phba);
3555 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05003556}
3557
James Smarte59058c2008-08-24 21:49:00 -04003558/**
James Smartda0436e2009-05-22 14:51:39 -04003559 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05003560 * @phba: pointer to lpfc hba data structure.
3561 *
James Smartda0436e2009-05-22 14:51:39 -04003562 * This routine is invoked to stop an SLI4 device port, it stops the device
3563 * from generating interrupts and stops the device driver's timers for the
3564 * device.
3565 **/
3566static void
3567lpfc_stop_port_s4(struct lpfc_hba *phba)
3568{
3569 /* Reset some HBA SLI4 setup states */
3570 lpfc_stop_hba_timers(phba);
3571 phba->pport->work_port_events = 0;
3572 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04003573}
3574
3575/**
3576 * lpfc_stop_port - Wrapper function for stopping hba port
3577 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05003578 *
James Smartda0436e2009-05-22 14:51:39 -04003579 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3580 * the API jump table function pointer from the lpfc_hba struct.
3581 **/
3582void
3583lpfc_stop_port(struct lpfc_hba *phba)
3584{
3585 phba->lpfc_stop_port(phba);
3586}
3587
3588/**
James Smartecfd03c2010-02-12 14:41:27 -05003589 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3590 * @phba: Pointer to hba for which this call is being executed.
3591 *
3592 * This routine starts the timer waiting for the FCF rediscovery to complete.
3593 **/
3594void
3595lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
3596{
3597 unsigned long fcf_redisc_wait_tmo =
3598 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
3599 /* Start fcf rediscovery wait period timer */
3600 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
3601 spin_lock_irq(&phba->hbalock);
3602 /* Allow action to new fcf asynchronous event */
3603 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
3604 /* Mark the FCF rediscovery pending state */
3605 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
3606 spin_unlock_irq(&phba->hbalock);
3607}
3608
3609/**
3610 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
3611 * @ptr: Map to lpfc_hba data structure pointer.
3612 *
3613 * This routine is invoked when waiting for FCF table rediscover has been
3614 * timed out. If new FCF record(s) has (have) been discovered during the
3615 * wait period, a new FCF event shall be added to the FCOE async event
3616 * list, and then worker thread shall be waked up for processing from the
3617 * worker thread context.
3618 **/
Rashika Kheriae399b222014-09-03 12:55:28 -04003619static void
James Smartecfd03c2010-02-12 14:41:27 -05003620lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
3621{
3622 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
3623
3624 /* Don't send FCF rediscovery event if timer cancelled */
3625 spin_lock_irq(&phba->hbalock);
3626 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
3627 spin_unlock_irq(&phba->hbalock);
3628 return;
3629 }
3630 /* Clear FCF rediscovery timer pending flag */
3631 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
3632 /* FCF rediscovery event to worker thread */
3633 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
3634 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003635 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04003636 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05003637 /* wake up worker thread */
3638 lpfc_worker_wake_up(phba);
3639}
3640
3641/**
James Smartda0436e2009-05-22 14:51:39 -04003642 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
3643 * @phba: pointer to lpfc hba data structure.
3644 * @acqe_link: pointer to the async link completion queue entry.
3645 *
3646 * This routine is to parse the SLI4 link-attention link fault code and
3647 * translate it into the base driver's read link attention mailbox command
3648 * status.
3649 *
3650 * Return: Link-attention status in terms of base driver's coding.
3651 **/
3652static uint16_t
3653lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
3654 struct lpfc_acqe_link *acqe_link)
3655{
3656 uint16_t latt_fault;
3657
3658 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
3659 case LPFC_ASYNC_LINK_FAULT_NONE:
3660 case LPFC_ASYNC_LINK_FAULT_LOCAL:
3661 case LPFC_ASYNC_LINK_FAULT_REMOTE:
3662 latt_fault = 0;
3663 break;
3664 default:
3665 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3666 "0398 Invalid link fault code: x%x\n",
3667 bf_get(lpfc_acqe_link_fault, acqe_link));
3668 latt_fault = MBXERR_ERROR;
3669 break;
3670 }
3671 return latt_fault;
3672}
3673
3674/**
3675 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
3676 * @phba: pointer to lpfc hba data structure.
3677 * @acqe_link: pointer to the async link completion queue entry.
3678 *
3679 * This routine is to parse the SLI4 link attention type and translate it
3680 * into the base driver's link attention type coding.
3681 *
3682 * Return: Link attention type in terms of base driver's coding.
3683 **/
3684static uint8_t
3685lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
3686 struct lpfc_acqe_link *acqe_link)
3687{
3688 uint8_t att_type;
3689
3690 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
3691 case LPFC_ASYNC_LINK_STATUS_DOWN:
3692 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05003693 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04003694 break;
3695 case LPFC_ASYNC_LINK_STATUS_UP:
3696 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05003697 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003698 break;
3699 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05003700 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04003701 break;
3702 default:
3703 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3704 "0399 Invalid link attention type: x%x\n",
3705 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003706 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003707 break;
3708 }
3709 return att_type;
3710}
3711
3712/**
3713 * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
3714 * @phba: pointer to lpfc hba data structure.
3715 * @acqe_link: pointer to the async link completion queue entry.
3716 *
3717 * This routine is to parse the SLI4 link-attention link speed and translate
3718 * it into the base driver's link-attention link speed coding.
3719 *
3720 * Return: Link-attention link speed in terms of base driver's coding.
3721 **/
3722static uint8_t
3723lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba,
3724 struct lpfc_acqe_link *acqe_link)
3725{
3726 uint8_t link_speed;
3727
3728 switch (bf_get(lpfc_acqe_link_speed, acqe_link)) {
3729 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smartda0436e2009-05-22 14:51:39 -04003730 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smartda0436e2009-05-22 14:51:39 -04003731 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart76a95d72010-11-20 23:11:48 -05003732 link_speed = LPFC_LINK_SPEED_UNKNOWN;
James Smartda0436e2009-05-22 14:51:39 -04003733 break;
3734 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart76a95d72010-11-20 23:11:48 -05003735 link_speed = LPFC_LINK_SPEED_1GHZ;
James Smartda0436e2009-05-22 14:51:39 -04003736 break;
3737 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart76a95d72010-11-20 23:11:48 -05003738 link_speed = LPFC_LINK_SPEED_10GHZ;
James Smartda0436e2009-05-22 14:51:39 -04003739 break;
James Smart26d830e2015-04-07 15:07:17 -04003740 case LPFC_ASYNC_LINK_SPEED_20GBPS:
3741 case LPFC_ASYNC_LINK_SPEED_25GBPS:
3742 case LPFC_ASYNC_LINK_SPEED_40GBPS:
3743 link_speed = LPFC_LINK_SPEED_UNKNOWN;
3744 break;
James Smartda0436e2009-05-22 14:51:39 -04003745 default:
3746 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3747 "0483 Invalid link-attention link speed: x%x\n",
3748 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003749 link_speed = LPFC_LINK_SPEED_UNKNOWN;
James Smartda0436e2009-05-22 14:51:39 -04003750 break;
3751 }
3752 return link_speed;
3753}
3754
3755/**
James Smart8b68cd52012-09-29 11:32:37 -04003756 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
3757 * @phba: pointer to lpfc hba data structure.
3758 *
3759 * This routine is to get an SLI3 FC port's link speed in Mbps.
3760 *
3761 * Return: link speed in terms of Mbps.
3762 **/
3763uint32_t
3764lpfc_sli_port_speed_get(struct lpfc_hba *phba)
3765{
3766 uint32_t link_speed;
3767
3768 if (!lpfc_is_link_up(phba))
3769 return 0;
3770
3771 switch (phba->fc_linkspeed) {
3772 case LPFC_LINK_SPEED_1GHZ:
3773 link_speed = 1000;
3774 break;
3775 case LPFC_LINK_SPEED_2GHZ:
3776 link_speed = 2000;
3777 break;
3778 case LPFC_LINK_SPEED_4GHZ:
3779 link_speed = 4000;
3780 break;
3781 case LPFC_LINK_SPEED_8GHZ:
3782 link_speed = 8000;
3783 break;
3784 case LPFC_LINK_SPEED_10GHZ:
3785 link_speed = 10000;
3786 break;
3787 case LPFC_LINK_SPEED_16GHZ:
3788 link_speed = 16000;
3789 break;
3790 default:
3791 link_speed = 0;
3792 }
3793 return link_speed;
3794}
3795
3796/**
3797 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
3798 * @phba: pointer to lpfc hba data structure.
3799 * @evt_code: asynchronous event code.
3800 * @speed_code: asynchronous event link speed code.
3801 *
3802 * This routine is to parse the giving SLI4 async event link speed code into
3803 * value of Mbps for the link speed.
3804 *
3805 * Return: link speed in terms of Mbps.
3806 **/
3807static uint32_t
3808lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
3809 uint8_t speed_code)
3810{
3811 uint32_t port_speed;
3812
3813 switch (evt_code) {
3814 case LPFC_TRAILER_CODE_LINK:
3815 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04003816 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smart8b68cd52012-09-29 11:32:37 -04003817 port_speed = 0;
3818 break;
James Smart26d830e2015-04-07 15:07:17 -04003819 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04003820 port_speed = 10;
3821 break;
James Smart26d830e2015-04-07 15:07:17 -04003822 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04003823 port_speed = 100;
3824 break;
James Smart26d830e2015-04-07 15:07:17 -04003825 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04003826 port_speed = 1000;
3827 break;
James Smart26d830e2015-04-07 15:07:17 -04003828 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04003829 port_speed = 10000;
3830 break;
James Smart26d830e2015-04-07 15:07:17 -04003831 case LPFC_ASYNC_LINK_SPEED_20GBPS:
3832 port_speed = 20000;
3833 break;
3834 case LPFC_ASYNC_LINK_SPEED_25GBPS:
3835 port_speed = 25000;
3836 break;
3837 case LPFC_ASYNC_LINK_SPEED_40GBPS:
3838 port_speed = 40000;
3839 break;
James Smart8b68cd52012-09-29 11:32:37 -04003840 default:
3841 port_speed = 0;
3842 }
3843 break;
3844 case LPFC_TRAILER_CODE_FC:
3845 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04003846 case LPFC_FC_LA_SPEED_UNKNOWN:
James Smart8b68cd52012-09-29 11:32:37 -04003847 port_speed = 0;
3848 break;
James Smart26d830e2015-04-07 15:07:17 -04003849 case LPFC_FC_LA_SPEED_1G:
James Smart8b68cd52012-09-29 11:32:37 -04003850 port_speed = 1000;
3851 break;
James Smart26d830e2015-04-07 15:07:17 -04003852 case LPFC_FC_LA_SPEED_2G:
James Smart8b68cd52012-09-29 11:32:37 -04003853 port_speed = 2000;
3854 break;
James Smart26d830e2015-04-07 15:07:17 -04003855 case LPFC_FC_LA_SPEED_4G:
James Smart8b68cd52012-09-29 11:32:37 -04003856 port_speed = 4000;
3857 break;
James Smart26d830e2015-04-07 15:07:17 -04003858 case LPFC_FC_LA_SPEED_8G:
James Smart8b68cd52012-09-29 11:32:37 -04003859 port_speed = 8000;
3860 break;
James Smart26d830e2015-04-07 15:07:17 -04003861 case LPFC_FC_LA_SPEED_10G:
James Smart8b68cd52012-09-29 11:32:37 -04003862 port_speed = 10000;
3863 break;
James Smart26d830e2015-04-07 15:07:17 -04003864 case LPFC_FC_LA_SPEED_16G:
James Smart8b68cd52012-09-29 11:32:37 -04003865 port_speed = 16000;
3866 break;
James Smartd38dd522015-08-31 16:48:17 -04003867 case LPFC_FC_LA_SPEED_32G:
3868 port_speed = 32000;
3869 break;
James Smart8b68cd52012-09-29 11:32:37 -04003870 default:
3871 port_speed = 0;
3872 }
3873 break;
3874 default:
3875 port_speed = 0;
3876 }
3877 return port_speed;
3878}
3879
3880/**
James Smart70f3c072010-12-15 17:57:33 -05003881 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04003882 * @phba: pointer to lpfc hba data structure.
3883 * @acqe_link: pointer to the async link completion queue entry.
3884 *
James Smart70f3c072010-12-15 17:57:33 -05003885 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04003886 **/
3887static void
3888lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
3889 struct lpfc_acqe_link *acqe_link)
3890{
3891 struct lpfc_dmabuf *mp;
3892 LPFC_MBOXQ_t *pmb;
3893 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05003894 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04003895 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05003896 int rc;
James Smartda0436e2009-05-22 14:51:39 -04003897
3898 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05003899 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04003900 return;
James Smart32b97932009-07-19 10:01:21 -04003901 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04003902 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3903 if (!pmb) {
3904 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3905 "0395 The mboxq allocation failed\n");
3906 return;
3907 }
3908 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3909 if (!mp) {
3910 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3911 "0396 The lpfc_dmabuf allocation failed\n");
3912 goto out_free_pmb;
3913 }
3914 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
3915 if (!mp->virt) {
3916 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3917 "0397 The mbuf allocation failed\n");
3918 goto out_free_dmabuf;
3919 }
3920
3921 /* Cleanup any outstanding ELS commands */
3922 lpfc_els_flush_all_cmd(phba);
3923
3924 /* Block ELS IOCBs until we have done process link event */
3925 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
3926
3927 /* Update link event statistics */
3928 phba->sli.slistat.link_event++;
3929
James Smart76a95d72010-11-20 23:11:48 -05003930 /* Create lpfc_handle_latt mailbox command from link ACQE */
3931 lpfc_read_topology(phba, pmb, mp);
3932 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04003933 pmb->vport = phba->pport;
3934
James Smartda0436e2009-05-22 14:51:39 -04003935 /* Keep the link status for extra SLI4 state machine reference */
3936 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04003937 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
3938 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04003939 phba->sli4_hba.link_state.duplex =
3940 bf_get(lpfc_acqe_link_duplex, acqe_link);
3941 phba->sli4_hba.link_state.status =
3942 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05003943 phba->sli4_hba.link_state.type =
3944 bf_get(lpfc_acqe_link_type, acqe_link);
3945 phba->sli4_hba.link_state.number =
3946 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04003947 phba->sli4_hba.link_state.fault =
3948 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05003949 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04003950 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
3951
James Smart70f3c072010-12-15 17:57:33 -05003952 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04003953 "2900 Async FC/FCoE Link event - Speed:%dGBit "
3954 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
3955 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05003956 phba->sli4_hba.link_state.speed,
3957 phba->sli4_hba.link_state.topology,
3958 phba->sli4_hba.link_state.status,
3959 phba->sli4_hba.link_state.type,
3960 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04003961 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05003962 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05003963 /*
3964 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
3965 * topology info. Note: Optional for non FC-AL ports.
3966 */
3967 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3968 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3969 if (rc == MBX_NOT_FINISHED)
3970 goto out_free_dmabuf;
3971 return;
3972 }
3973 /*
3974 * For FCoE Mode: fill in all the topology information we need and call
3975 * the READ_TOPOLOGY completion routine to continue without actually
3976 * sending the READ_TOPOLOGY mailbox command to the port.
3977 */
3978 /* Parse and translate status field */
3979 mb = &pmb->u.mb;
3980 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
3981
3982 /* Parse and translate link attention fields */
3983 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3984 la->eventTag = acqe_link->event_tag;
3985 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
3986 bf_set(lpfc_mbx_read_top_link_spd, la,
3987 lpfc_sli4_parse_latt_link_speed(phba, acqe_link));
3988
3989 /* Fake the the following irrelvant fields */
3990 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
3991 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
3992 bf_set(lpfc_mbx_read_top_il, la, 0);
3993 bf_set(lpfc_mbx_read_top_pb, la, 0);
3994 bf_set(lpfc_mbx_read_top_fa, la, 0);
3995 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04003996
3997 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05003998 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04003999
4000 return;
4001
4002out_free_dmabuf:
4003 kfree(mp);
4004out_free_pmb:
4005 mempool_free(pmb, phba->mbox_mem_pool);
4006}
4007
4008/**
James Smart70f3c072010-12-15 17:57:33 -05004009 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
4010 * @phba: pointer to lpfc hba data structure.
4011 * @acqe_fc: pointer to the async fc completion queue entry.
4012 *
4013 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
4014 * that the event was received and then issue a read_topology mailbox command so
4015 * that the rest of the driver will treat it the same as SLI3.
4016 **/
4017static void
4018lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
4019{
4020 struct lpfc_dmabuf *mp;
4021 LPFC_MBOXQ_t *pmb;
4022 int rc;
4023
4024 if (bf_get(lpfc_trailer_type, acqe_fc) !=
4025 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
4026 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4027 "2895 Non FC link Event detected.(%d)\n",
4028 bf_get(lpfc_trailer_type, acqe_fc));
4029 return;
4030 }
4031 /* Keep the link status for extra SLI4 state machine reference */
4032 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004033 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
4034 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05004035 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
4036 phba->sli4_hba.link_state.topology =
4037 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
4038 phba->sli4_hba.link_state.status =
4039 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
4040 phba->sli4_hba.link_state.type =
4041 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
4042 phba->sli4_hba.link_state.number =
4043 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
4044 phba->sli4_hba.link_state.fault =
4045 bf_get(lpfc_acqe_link_fault, acqe_fc);
4046 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004047 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart70f3c072010-12-15 17:57:33 -05004048 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4049 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4050 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4051 "%dMbps Fault:%d\n",
4052 phba->sli4_hba.link_state.speed,
4053 phba->sli4_hba.link_state.topology,
4054 phba->sli4_hba.link_state.status,
4055 phba->sli4_hba.link_state.type,
4056 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004057 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004058 phba->sli4_hba.link_state.fault);
4059 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4060 if (!pmb) {
4061 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4062 "2897 The mboxq allocation failed\n");
4063 return;
4064 }
4065 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4066 if (!mp) {
4067 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4068 "2898 The lpfc_dmabuf allocation failed\n");
4069 goto out_free_pmb;
4070 }
4071 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4072 if (!mp->virt) {
4073 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4074 "2899 The mbuf allocation failed\n");
4075 goto out_free_dmabuf;
4076 }
4077
4078 /* Cleanup any outstanding ELS commands */
4079 lpfc_els_flush_all_cmd(phba);
4080
4081 /* Block ELS IOCBs until we have done process link event */
4082 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
4083
4084 /* Update link event statistics */
4085 phba->sli.slistat.link_event++;
4086
4087 /* Create lpfc_handle_latt mailbox command from link ACQE */
4088 lpfc_read_topology(phba, pmb, mp);
4089 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4090 pmb->vport = phba->pport;
4091
4092 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4093 if (rc == MBX_NOT_FINISHED)
4094 goto out_free_dmabuf;
4095 return;
4096
4097out_free_dmabuf:
4098 kfree(mp);
4099out_free_pmb:
4100 mempool_free(pmb, phba->mbox_mem_pool);
4101}
4102
4103/**
4104 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4105 * @phba: pointer to lpfc hba data structure.
4106 * @acqe_fc: pointer to the async SLI completion queue entry.
4107 *
4108 * This routine is to handle the SLI4 asynchronous SLI events.
4109 **/
4110static void
4111lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
4112{
James Smart4b8bae02012-06-12 13:55:07 -04004113 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04004114 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04004115 uint8_t status;
James Smart946727d2015-04-07 15:07:09 -04004116 uint8_t evt_type;
4117 struct temp_event temp_event_data;
James Smart4b8bae02012-06-12 13:55:07 -04004118 struct lpfc_acqe_misconfigured_event *misconfigured;
James Smart946727d2015-04-07 15:07:09 -04004119 struct Scsi_Host *shost;
James Smart4b8bae02012-06-12 13:55:07 -04004120
James Smart946727d2015-04-07 15:07:09 -04004121 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
4122
4123 /* Special case Lancer */
4124 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
4125 LPFC_SLI_INTF_IF_TYPE_2) {
James Smart4b8bae02012-06-12 13:55:07 -04004126 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4127 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4128 "x%08x SLI Event Type:%d\n",
4129 acqe_sli->event_data1, acqe_sli->event_data2,
James Smart946727d2015-04-07 15:07:09 -04004130 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004131 return;
4132 }
4133
4134 port_name = phba->Port[0];
4135 if (port_name == 0x00)
4136 port_name = '?'; /* get port name is empty */
4137
James Smart946727d2015-04-07 15:07:09 -04004138 switch (evt_type) {
4139 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
4140 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4141 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
4142 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4143
4144 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4145 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4146 acqe_sli->event_data1, port_name);
4147
4148 shost = lpfc_shost_from_vport(phba->pport);
4149 fc_host_post_vendor_event(shost, fc_get_event_number(),
4150 sizeof(temp_event_data),
4151 (char *)&temp_event_data,
4152 SCSI_NL_VID_TYPE_PCI
4153 | PCI_VENDOR_ID_EMULEX);
4154 break;
4155 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
4156 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4157 temp_event_data.event_code = LPFC_NORMAL_TEMP;
4158 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4159
4160 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4161 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4162 acqe_sli->event_data1, port_name);
4163
4164 shost = lpfc_shost_from_vport(phba->pport);
4165 fc_host_post_vendor_event(shost, fc_get_event_number(),
4166 sizeof(temp_event_data),
4167 (char *)&temp_event_data,
4168 SCSI_NL_VID_TYPE_PCI
4169 | PCI_VENDOR_ID_EMULEX);
4170 break;
4171 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
4172 misconfigured = (struct lpfc_acqe_misconfigured_event *)
James Smart4b8bae02012-06-12 13:55:07 -04004173 &acqe_sli->event_data1;
4174
James Smart946727d2015-04-07 15:07:09 -04004175 /* fetch the status for this port */
4176 switch (phba->sli4_hba.lnk_info.lnk_no) {
4177 case LPFC_LINK_NUMBER_0:
4178 status = bf_get(lpfc_sli_misconfigured_port0,
James Smart4b8bae02012-06-12 13:55:07 -04004179 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004180 break;
4181 case LPFC_LINK_NUMBER_1:
4182 status = bf_get(lpfc_sli_misconfigured_port1,
James Smart4b8bae02012-06-12 13:55:07 -04004183 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004184 break;
4185 case LPFC_LINK_NUMBER_2:
4186 status = bf_get(lpfc_sli_misconfigured_port2,
James Smart4b8bae02012-06-12 13:55:07 -04004187 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004188 break;
4189 case LPFC_LINK_NUMBER_3:
4190 status = bf_get(lpfc_sli_misconfigured_port3,
James Smart4b8bae02012-06-12 13:55:07 -04004191 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004192 break;
4193 default:
4194 status = ~LPFC_SLI_EVENT_STATUS_VALID;
4195 break;
4196 }
James Smart4b8bae02012-06-12 13:55:07 -04004197
James Smart946727d2015-04-07 15:07:09 -04004198 switch (status) {
4199 case LPFC_SLI_EVENT_STATUS_VALID:
4200 return; /* no message if the sfp is okay */
4201 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
4202 sprintf(message, "Optics faulted/incorrectly "
4203 "installed/not installed - Reseat optics, "
4204 "if issue not resolved, replace.");
4205 break;
4206 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
4207 sprintf(message,
4208 "Optics of two types installed - Remove one "
4209 "optic or install matching pair of optics.");
4210 break;
4211 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
4212 sprintf(message, "Incompatible optics - Replace with "
James Smart292098b2012-09-29 11:31:41 -04004213 "compatible optics for card to function.");
James Smart946727d2015-04-07 15:07:09 -04004214 break;
4215 default:
4216 /* firmware is reporting a status we don't know about */
4217 sprintf(message, "Unknown event status x%02x", status);
4218 break;
4219 }
4220
4221 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4222 "3176 Misconfigured Physical Port - "
4223 "Port Name %c %s\n", port_name, message);
4224 break;
4225 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
4226 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4227 "3192 Remote DPort Test Initiated - "
4228 "Event Data1:x%08x Event Data2: x%08x\n",
4229 acqe_sli->event_data1, acqe_sli->event_data2);
James Smart4b8bae02012-06-12 13:55:07 -04004230 break;
4231 default:
James Smart946727d2015-04-07 15:07:09 -04004232 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4233 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
4234 "x%08x SLI Event Type:%d\n",
4235 acqe_sli->event_data1, acqe_sli->event_data2,
4236 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004237 break;
4238 }
James Smart70f3c072010-12-15 17:57:33 -05004239}
4240
4241/**
James Smartfc2b9892010-02-26 14:15:29 -05004242 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
4243 * @vport: pointer to vport data structure.
4244 *
4245 * This routine is to perform Clear Virtual Link (CVL) on a vport in
4246 * response to a CVL event.
4247 *
4248 * Return the pointer to the ndlp with the vport if successful, otherwise
4249 * return NULL.
4250 **/
4251static struct lpfc_nodelist *
4252lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
4253{
4254 struct lpfc_nodelist *ndlp;
4255 struct Scsi_Host *shost;
4256 struct lpfc_hba *phba;
4257
4258 if (!vport)
4259 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05004260 phba = vport->phba;
4261 if (!phba)
4262 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04004263 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4264 if (!ndlp) {
4265 /* Cannot find existing Fabric ndlp, so allocate a new one */
4266 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4267 if (!ndlp)
4268 return 0;
4269 lpfc_nlp_init(vport, ndlp, Fabric_DID);
4270 /* Set the node type */
4271 ndlp->nlp_type |= NLP_FABRIC;
4272 /* Put ndlp onto node list */
4273 lpfc_enqueue_node(vport, ndlp);
4274 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4275 /* re-setup ndlp without removing from node list */
4276 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4277 if (!ndlp)
4278 return 0;
4279 }
James Smart63e801c2010-11-20 23:14:19 -05004280 if ((phba->pport->port_state < LPFC_FLOGI) &&
4281 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004282 return NULL;
4283 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05004284 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
4285 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004286 return NULL;
4287 shost = lpfc_shost_from_vport(vport);
4288 if (!shost)
4289 return NULL;
4290 lpfc_linkdown_port(vport);
4291 lpfc_cleanup_pending_mbox(vport);
4292 spin_lock_irq(shost->host_lock);
4293 vport->fc_flag |= FC_VPORT_CVL_RCVD;
4294 spin_unlock_irq(shost->host_lock);
4295
4296 return ndlp;
4297}
4298
4299/**
4300 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4301 * @vport: pointer to lpfc hba data structure.
4302 *
4303 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4304 * response to a FCF dead event.
4305 **/
4306static void
4307lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
4308{
4309 struct lpfc_vport **vports;
4310 int i;
4311
4312 vports = lpfc_create_vport_work_array(phba);
4313 if (vports)
4314 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4315 lpfc_sli4_perform_vport_cvl(vports[i]);
4316 lpfc_destroy_vport_work_array(phba, vports);
4317}
4318
4319/**
James Smart76a95d72010-11-20 23:11:48 -05004320 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04004321 * @phba: pointer to lpfc hba data structure.
4322 * @acqe_link: pointer to the async fcoe completion queue entry.
4323 *
4324 * This routine is to handle the SLI4 asynchronous fcoe event.
4325 **/
4326static void
James Smart76a95d72010-11-20 23:11:48 -05004327lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05004328 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04004329{
James Smart70f3c072010-12-15 17:57:33 -05004330 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004331 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04004332 struct lpfc_vport *vport;
4333 struct lpfc_nodelist *ndlp;
4334 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05004335 int active_vlink_present;
4336 struct lpfc_vport **vports;
4337 int i;
James Smartda0436e2009-05-22 14:51:39 -04004338
James Smart70f3c072010-12-15 17:57:33 -05004339 phba->fc_eventTag = acqe_fip->event_tag;
4340 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004341 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05004342 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
4343 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
4344 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04004345 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4346 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004347 "2546 New FCF event, evt_tag:x%x, "
4348 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004349 acqe_fip->event_tag,
4350 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04004351 else
4352 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
4353 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004354 "2788 FCF param modified event, "
4355 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004356 acqe_fip->event_tag,
4357 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04004358 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004359 /*
4360 * During period of FCF discovery, read the FCF
4361 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04004362 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05004363 */
4364 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4365 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004366 "2779 Read FCF (x%x) for updating "
4367 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05004368 acqe_fip->index);
4369 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004370 }
James Smart38b92ef2010-08-04 16:11:39 -04004371
4372 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04004373 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04004374 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04004375 spin_unlock_irq(&phba->hbalock);
4376 break;
4377 }
4378 /* If fast FCF failover rescan event is pending, do nothing */
4379 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
4380 spin_unlock_irq(&phba->hbalock);
4381 break;
4382 }
4383
James Smartc2b97122013-05-31 17:05:36 -04004384 /* If the FCF has been in discovered state, do nothing. */
4385 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
James Smart3804dc82010-07-14 15:31:37 -04004386 spin_unlock_irq(&phba->hbalock);
4387 break;
4388 }
4389 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04004390
James Smart0c9ab6f2010-02-26 14:15:57 -05004391 /* Otherwise, scan the entire FCF table and re-discover SAN */
4392 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004393 "2770 Start FCF table scan per async FCF "
4394 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004395 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004396 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
4397 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04004398 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004399 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4400 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04004401 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04004402 break;
4403
James Smart70f3c072010-12-15 17:57:33 -05004404 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04004405 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04004406 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004407 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
4408 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004409 break;
4410
James Smart70f3c072010-12-15 17:57:33 -05004411 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05004412 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004413 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004414 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05004415 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04004416 /*
4417 * If we are in the middle of FCF failover process, clear
4418 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04004419 */
James Smartfc2b9892010-02-26 14:15:29 -05004420 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004421 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05004422 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004423 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05004424 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004425 break;
4426 }
James Smart38b92ef2010-08-04 16:11:39 -04004427 spin_unlock_irq(&phba->hbalock);
4428
4429 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05004430 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04004431 break;
4432
4433 /*
4434 * Otherwise, request the port to rediscover the entire FCF
4435 * table for a fast recovery from case that the current FCF
4436 * is no longer valid as we are not in the middle of FCF
4437 * failover process already.
4438 */
James Smartc2b97122013-05-31 17:05:36 -04004439 spin_lock_irq(&phba->hbalock);
4440 /* Mark the fast failover process in progress */
4441 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
4442 spin_unlock_irq(&phba->hbalock);
4443
4444 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
4445 "2771 Start FCF fast failover process due to "
4446 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
4447 "\n", acqe_fip->event_tag, acqe_fip->index);
4448 rc = lpfc_sli4_redisc_fcf_table(phba);
4449 if (rc) {
4450 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4451 LOG_DISCOVERY,
4452 "2772 Issue FCF rediscover mabilbox "
4453 "command failed, fail through to FCF "
4454 "dead event\n");
4455 spin_lock_irq(&phba->hbalock);
4456 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
4457 spin_unlock_irq(&phba->hbalock);
4458 /*
4459 * Last resort will fail over by treating this
4460 * as a link down to FCF registration.
4461 */
4462 lpfc_sli4_fcf_dead_failthrough(phba);
4463 } else {
4464 /* Reset FCF roundrobin bmask for new discovery */
4465 lpfc_sli4_clear_fcf_rr_bmask(phba);
4466 /*
4467 * Handling fast FCF failover to a DEAD FCF event is
4468 * considered equalivant to receiving CVL to all vports.
4469 */
4470 lpfc_sli4_perform_all_vport_cvl(phba);
4471 }
James Smartda0436e2009-05-22 14:51:39 -04004472 break;
James Smart70f3c072010-12-15 17:57:33 -05004473 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05004474 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004475 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04004476 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05004477 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04004478
James Smart6669f9b2009-10-02 15:16:45 -04004479 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04004480 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004481 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004482 if (!ndlp)
4483 break;
James Smart695a8142010-01-26 23:08:03 -05004484 active_vlink_present = 0;
4485
4486 vports = lpfc_create_vport_work_array(phba);
4487 if (vports) {
4488 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
4489 i++) {
4490 if ((!(vports[i]->fc_flag &
4491 FC_VPORT_CVL_RCVD)) &&
4492 (vports[i]->port_state > LPFC_FDISC)) {
4493 active_vlink_present = 1;
4494 break;
4495 }
4496 }
4497 lpfc_destroy_vport_work_array(phba, vports);
4498 }
4499
James Smartcc823552015-05-21 13:55:26 -04004500 /*
4501 * Don't re-instantiate if vport is marked for deletion.
4502 * If we are here first then vport_delete is going to wait
4503 * for discovery to complete.
4504 */
4505 if (!(vport->load_flag & FC_UNLOADING) &&
4506 active_vlink_present) {
James Smart695a8142010-01-26 23:08:03 -05004507 /*
4508 * If there are other active VLinks present,
4509 * re-instantiate the Vlink using FDISC.
4510 */
James Smart256ec0d2013-04-17 20:14:58 -04004511 mod_timer(&ndlp->nlp_delayfunc,
4512 jiffies + msecs_to_jiffies(1000));
James Smartfc2b9892010-02-26 14:15:29 -05004513 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004514 spin_lock_irq(shost->host_lock);
4515 ndlp->nlp_flag |= NLP_DELAY_TMO;
4516 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05004517 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
4518 vport->port_state = LPFC_FDISC;
4519 } else {
James Smartecfd03c2010-02-12 14:41:27 -05004520 /*
4521 * Otherwise, we request port to rediscover
4522 * the entire FCF table for a fast recovery
4523 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05004524 * is no longer valid if we are not already
4525 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05004526 */
James Smartfc2b9892010-02-26 14:15:29 -05004527 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004528 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05004529 spin_unlock_irq(&phba->hbalock);
4530 break;
4531 }
4532 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05004533 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004534 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004535 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4536 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004537 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05004538 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05004539 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05004540 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004541 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4542 LOG_DISCOVERY,
4543 "2774 Issue FCF rediscover "
4544 "mabilbox command failed, "
4545 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05004546 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004547 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004548 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05004549 /*
4550 * Last resort will be re-try on the
4551 * the current registered FCF entry.
4552 */
4553 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04004554 } else
4555 /*
4556 * Reset FCF roundrobin bmask for new
4557 * discovery.
4558 */
James Smart7d791df2011-07-22 18:37:52 -04004559 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04004560 }
4561 break;
James Smartda0436e2009-05-22 14:51:39 -04004562 default:
4563 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4564 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05004565 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004566 break;
4567 }
4568}
4569
4570/**
4571 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
4572 * @phba: pointer to lpfc hba data structure.
4573 * @acqe_link: pointer to the async dcbx completion queue entry.
4574 *
4575 * This routine is to handle the SLI4 asynchronous dcbx event.
4576 **/
4577static void
4578lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
4579 struct lpfc_acqe_dcbx *acqe_dcbx)
4580{
James Smart4d9ab992009-10-02 15:16:39 -04004581 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004582 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4583 "0290 The SLI4 DCBX asynchronous event is not "
4584 "handled yet\n");
4585}
4586
4587/**
James Smartb19a0612010-04-06 14:48:51 -04004588 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
4589 * @phba: pointer to lpfc hba data structure.
4590 * @acqe_link: pointer to the async grp5 completion queue entry.
4591 *
4592 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
4593 * is an asynchronous notified of a logical link speed change. The Port
4594 * reports the logical link speed in units of 10Mbps.
4595 **/
4596static void
4597lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
4598 struct lpfc_acqe_grp5 *acqe_grp5)
4599{
4600 uint16_t prev_ll_spd;
4601
4602 phba->fc_eventTag = acqe_grp5->event_tag;
4603 phba->fcoe_eventtag = acqe_grp5->event_tag;
4604 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
4605 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004606 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04004607 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4608 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04004609 "from %dMbps to %dMbps\n", prev_ll_spd,
4610 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04004611}
4612
4613/**
James Smartda0436e2009-05-22 14:51:39 -04004614 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
4615 * @phba: pointer to lpfc hba data structure.
4616 *
4617 * This routine is invoked by the worker thread to process all the pending
4618 * SLI4 asynchronous events.
4619 **/
4620void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
4621{
4622 struct lpfc_cq_event *cq_event;
4623
4624 /* First, declare the async event has been handled */
4625 spin_lock_irq(&phba->hbalock);
4626 phba->hba_flag &= ~ASYNC_EVENT;
4627 spin_unlock_irq(&phba->hbalock);
4628 /* Now, handle all the async events */
4629 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
4630 /* Get the first event from the head of the event queue */
4631 spin_lock_irq(&phba->hbalock);
4632 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
4633 cq_event, struct lpfc_cq_event, list);
4634 spin_unlock_irq(&phba->hbalock);
4635 /* Process the asynchronous event */
4636 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
4637 case LPFC_TRAILER_CODE_LINK:
4638 lpfc_sli4_async_link_evt(phba,
4639 &cq_event->cqe.acqe_link);
4640 break;
4641 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05004642 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004643 break;
4644 case LPFC_TRAILER_CODE_DCBX:
4645 lpfc_sli4_async_dcbx_evt(phba,
4646 &cq_event->cqe.acqe_dcbx);
4647 break;
James Smartb19a0612010-04-06 14:48:51 -04004648 case LPFC_TRAILER_CODE_GRP5:
4649 lpfc_sli4_async_grp5_evt(phba,
4650 &cq_event->cqe.acqe_grp5);
4651 break;
James Smart70f3c072010-12-15 17:57:33 -05004652 case LPFC_TRAILER_CODE_FC:
4653 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
4654 break;
4655 case LPFC_TRAILER_CODE_SLI:
4656 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
4657 break;
James Smartda0436e2009-05-22 14:51:39 -04004658 default:
4659 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4660 "1804 Invalid asynchrous event code: "
4661 "x%x\n", bf_get(lpfc_trailer_code,
4662 &cq_event->cqe.mcqe_cmpl));
4663 break;
4664 }
4665 /* Free the completion event processed to the free pool */
4666 lpfc_sli4_cq_event_release(phba, cq_event);
4667 }
4668}
4669
4670/**
James Smartecfd03c2010-02-12 14:41:27 -05004671 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
4672 * @phba: pointer to lpfc hba data structure.
4673 *
4674 * This routine is invoked by the worker thread to process FCF table
4675 * rediscovery pending completion event.
4676 **/
4677void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
4678{
4679 int rc;
4680
4681 spin_lock_irq(&phba->hbalock);
4682 /* Clear FCF rediscovery timeout event */
4683 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
4684 /* Clear driver fast failover FCF record flag */
4685 phba->fcf.failover_rec.flag = 0;
4686 /* Set state for FCF fast failover */
4687 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
4688 spin_unlock_irq(&phba->hbalock);
4689
4690 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05004691 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004692 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05004693 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05004694 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004695 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4696 "2747 Issue FCF scan read FCF mailbox "
4697 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05004698}
4699
4700/**
James Smartda0436e2009-05-22 14:51:39 -04004701 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
4702 * @phba: pointer to lpfc hba data structure.
4703 * @dev_grp: The HBA PCI-Device group number.
4704 *
4705 * This routine is invoked to set up the per HBA PCI-Device group function
4706 * API jump table entries.
4707 *
4708 * Return: 0 if success, otherwise -ENODEV
4709 **/
4710int
4711lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05004712{
4713 int rc;
4714
James Smartda0436e2009-05-22 14:51:39 -04004715 /* Set up lpfc PCI-device group */
4716 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05004717
James Smartda0436e2009-05-22 14:51:39 -04004718 /* The LPFC_PCI_DEV_OC uses SLI4 */
4719 if (dev_grp == LPFC_PCI_DEV_OC)
4720 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05004721
James Smartda0436e2009-05-22 14:51:39 -04004722 /* Set up device INIT API function jump table */
4723 rc = lpfc_init_api_table_setup(phba, dev_grp);
4724 if (rc)
4725 return -ENODEV;
4726 /* Set up SCSI API function jump table */
4727 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
4728 if (rc)
4729 return -ENODEV;
4730 /* Set up SLI API function jump table */
4731 rc = lpfc_sli_api_table_setup(phba, dev_grp);
4732 if (rc)
4733 return -ENODEV;
4734 /* Set up MBOX API function jump table */
4735 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
4736 if (rc)
4737 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05004738
James Smartda0436e2009-05-22 14:51:39 -04004739 return 0;
James Smart5b75da22008-12-04 22:39:35 -05004740}
4741
4742/**
James Smart3621a712009-04-06 18:47:14 -04004743 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05004744 * @phba: pointer to lpfc hba data structure.
4745 * @intr_mode: active interrupt mode adopted.
4746 *
4747 * This routine it invoked to log the currently used active interrupt mode
4748 * to the device.
James Smart3772a992009-05-22 14:50:54 -04004749 **/
4750static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05004751{
4752 switch (intr_mode) {
4753 case 0:
4754 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4755 "0470 Enable INTx interrupt mode.\n");
4756 break;
4757 case 1:
4758 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4759 "0481 Enabled MSI interrupt mode.\n");
4760 break;
4761 case 2:
4762 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4763 "0480 Enabled MSI-X interrupt mode.\n");
4764 break;
4765 default:
4766 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4767 "0482 Illegal interrupt mode.\n");
4768 break;
4769 }
4770 return;
4771}
4772
James Smart5b75da22008-12-04 22:39:35 -05004773/**
James Smart3772a992009-05-22 14:50:54 -04004774 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05004775 * @phba: pointer to lpfc hba data structure.
4776 *
James Smart3772a992009-05-22 14:50:54 -04004777 * This routine is invoked to enable the PCI device that is common to all
4778 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05004779 *
4780 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004781 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004782 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05004783 **/
James Smart3772a992009-05-22 14:50:54 -04004784static int
4785lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05004786{
James Smart3772a992009-05-22 14:50:54 -04004787 struct pci_dev *pdev;
James Smart079b5c92011-08-21 21:48:49 -04004788 int bars = 0;
James Smart5b75da22008-12-04 22:39:35 -05004789
James Smart3772a992009-05-22 14:50:54 -04004790 /* Obtain PCI device reference */
4791 if (!phba->pcidev)
4792 goto out_error;
4793 else
4794 pdev = phba->pcidev;
4795 /* Select PCI BARs */
4796 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4797 /* Enable PCI device */
4798 if (pci_enable_device_mem(pdev))
4799 goto out_error;
4800 /* Request PCI resource for the device */
4801 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
4802 goto out_disable_device;
4803 /* Set up device as PCI master and save state for EEH */
4804 pci_set_master(pdev);
4805 pci_try_set_mwi(pdev);
4806 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05004807
James Smart05580562011-05-24 11:40:48 -04004808 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
Jon Mason453193e2013-09-11 15:38:13 -07004809 if (pci_is_pcie(pdev))
James Smart05580562011-05-24 11:40:48 -04004810 pdev->needs_freset = 1;
4811
James Smart3772a992009-05-22 14:50:54 -04004812 return 0;
James Smart5b75da22008-12-04 22:39:35 -05004813
James Smart3772a992009-05-22 14:50:54 -04004814out_disable_device:
4815 pci_disable_device(pdev);
4816out_error:
James Smart079b5c92011-08-21 21:48:49 -04004817 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4818 "1401 Failed to enable pci device, bars:x%x\n", bars);
James Smart3772a992009-05-22 14:50:54 -04004819 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05004820}
4821
4822/**
James Smart3772a992009-05-22 14:50:54 -04004823 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05004824 * @phba: pointer to lpfc hba data structure.
4825 *
James Smart3772a992009-05-22 14:50:54 -04004826 * This routine is invoked to disable the PCI device that is common to all
4827 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05004828 **/
4829static void
James Smart3772a992009-05-22 14:50:54 -04004830lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05004831{
James Smart3772a992009-05-22 14:50:54 -04004832 struct pci_dev *pdev;
4833 int bars;
James Smart5b75da22008-12-04 22:39:35 -05004834
James Smart3772a992009-05-22 14:50:54 -04004835 /* Obtain PCI device reference */
4836 if (!phba->pcidev)
4837 return;
4838 else
4839 pdev = phba->pcidev;
4840 /* Select PCI BARs */
4841 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4842 /* Release PCI resource and disable PCI device */
4843 pci_release_selected_regions(pdev, bars);
4844 pci_disable_device(pdev);
James Smart5b75da22008-12-04 22:39:35 -05004845
4846 return;
4847}
4848
4849/**
James Smart3772a992009-05-22 14:50:54 -04004850 * lpfc_reset_hba - Reset a hba
4851 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04004852 *
James Smart3772a992009-05-22 14:50:54 -04004853 * This routine is invoked to reset a hba device. It brings the HBA
4854 * offline, performs a board restart, and then brings the board back
4855 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
4856 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04004857 **/
James Smart3772a992009-05-22 14:50:54 -04004858void
4859lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05004860{
James Smart3772a992009-05-22 14:50:54 -04004861 /* If resets are disabled then set error state and return. */
4862 if (!phba->cfg_enable_hba_reset) {
4863 phba->link_state = LPFC_HBA_ERROR;
4864 return;
4865 }
James Smartee620212014-04-04 13:51:53 -04004866 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
4867 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
4868 else
4869 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart3772a992009-05-22 14:50:54 -04004870 lpfc_offline(phba);
4871 lpfc_sli_brdrestart(phba);
4872 lpfc_online(phba);
4873 lpfc_unblock_mgmt_io(phba);
4874}
dea31012005-04-17 16:05:31 -05004875
James Smart3772a992009-05-22 14:50:54 -04004876/**
James Smart0a96e972011-07-22 18:37:28 -04004877 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
4878 * @phba: pointer to lpfc hba data structure.
4879 *
4880 * This function enables the PCI SR-IOV virtual functions to a physical
4881 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4882 * enable the number of virtual functions to the physical function. As
4883 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4884 * API call does not considered as an error condition for most of the device.
4885 **/
4886uint16_t
4887lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
4888{
4889 struct pci_dev *pdev = phba->pcidev;
4890 uint16_t nr_virtfn;
4891 int pos;
4892
James Smart0a96e972011-07-22 18:37:28 -04004893 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4894 if (pos == 0)
4895 return 0;
4896
4897 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
4898 return nr_virtfn;
4899}
4900
4901/**
James Smart912e3ac2011-05-24 11:42:11 -04004902 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
4903 * @phba: pointer to lpfc hba data structure.
4904 * @nr_vfn: number of virtual functions to be enabled.
4905 *
4906 * This function enables the PCI SR-IOV virtual functions to a physical
4907 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4908 * enable the number of virtual functions to the physical function. As
4909 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4910 * API call does not considered as an error condition for most of the device.
4911 **/
4912int
4913lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
4914{
4915 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04004916 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04004917 int rc;
4918
James Smart0a96e972011-07-22 18:37:28 -04004919 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
4920 if (nr_vfn > max_nr_vfn) {
4921 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4922 "3057 Requested vfs (%d) greater than "
4923 "supported vfs (%d)", nr_vfn, max_nr_vfn);
4924 return -EINVAL;
4925 }
4926
James Smart912e3ac2011-05-24 11:42:11 -04004927 rc = pci_enable_sriov(pdev, nr_vfn);
4928 if (rc) {
4929 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4930 "2806 Failed to enable sriov on this device "
4931 "with vfn number nr_vf:%d, rc:%d\n",
4932 nr_vfn, rc);
4933 } else
4934 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4935 "2807 Successful enable sriov on this device "
4936 "with vfn number nr_vf:%d\n", nr_vfn);
4937 return rc;
4938}
4939
4940/**
James Smart3772a992009-05-22 14:50:54 -04004941 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
4942 * @phba: pointer to lpfc hba data structure.
4943 *
4944 * This routine is invoked to set up the driver internal resources specific to
4945 * support the SLI-3 HBA device it attached to.
4946 *
4947 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004948 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004949 * other values - error
4950 **/
4951static int
4952lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
4953{
4954 struct lpfc_sli *psli;
James Smart912e3ac2011-05-24 11:42:11 -04004955 int rc;
dea31012005-04-17 16:05:31 -05004956
James Smart3772a992009-05-22 14:50:54 -04004957 /*
4958 * Initialize timers used by driver
4959 */
dea31012005-04-17 16:05:31 -05004960
James Smart3772a992009-05-22 14:50:54 -04004961 /* Heartbeat timer */
4962 init_timer(&phba->hb_tmofunc);
4963 phba->hb_tmofunc.function = lpfc_hb_timeout;
4964 phba->hb_tmofunc.data = (unsigned long)phba;
4965
4966 psli = &phba->sli;
4967 /* MBOX heartbeat timer */
4968 init_timer(&psli->mbox_tmo);
4969 psli->mbox_tmo.function = lpfc_mbox_timeout;
4970 psli->mbox_tmo.data = (unsigned long) phba;
4971 /* FCP polling mode timer */
4972 init_timer(&phba->fcp_poll_timer);
4973 phba->fcp_poll_timer.function = lpfc_poll_timeout;
4974 phba->fcp_poll_timer.data = (unsigned long) phba;
4975 /* Fabric block timer */
4976 init_timer(&phba->fabric_block_timer);
4977 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
4978 phba->fabric_block_timer.data = (unsigned long) phba;
4979 /* EA polling mode timer */
4980 init_timer(&phba->eratt_poll);
4981 phba->eratt_poll.function = lpfc_poll_eratt;
4982 phba->eratt_poll.data = (unsigned long) phba;
4983
4984 /* Host attention work mask setup */
4985 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
4986 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
4987
4988 /* Get all the module params for configuring this host */
4989 lpfc_get_cfgparam(phba);
James Smart49198b32010-04-06 15:04:33 -04004990 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
4991 phba->menlo_flag |= HBA_MENLO_SUPPORT;
4992 /* check for menlo minimum sg count */
4993 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
4994 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
4995 }
4996
James Smart2a76a282012-08-03 12:35:54 -04004997 if (!phba->sli.ring)
Firo Yangc6cb9b42015-08-31 16:48:09 -04004998 phba->sli.ring = kzalloc(LPFC_SLI3_MAX_RING *
James Smart2a76a282012-08-03 12:35:54 -04004999 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
5000 if (!phba->sli.ring)
5001 return -ENOMEM;
5002
James Smart3772a992009-05-22 14:50:54 -04005003 /*
James Smart96f70772013-04-17 20:16:15 -04005004 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smart3772a992009-05-22 14:50:54 -04005005 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart3772a992009-05-22 14:50:54 -04005006 */
James Smart3772a992009-05-22 14:50:54 -04005007
James Smart96f70772013-04-17 20:16:15 -04005008 /* Initialize the host templates the configured values. */
James Smart3772a992009-05-22 14:50:54 -04005009 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
Bodo Stroesser5f406fa2015-08-31 16:48:10 -04005010 lpfc_template_s3.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart3772a992009-05-22 14:50:54 -04005011
James Smart96f70772013-04-17 20:16:15 -04005012 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
5013 if (phba->cfg_enable_bg) {
5014 /*
5015 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5016 * the FCP rsp, and a BDE for each. Sice we have no control
5017 * over how many protection data segments the SCSI Layer
5018 * will hand us (ie: there could be one for every block
5019 * in the IO), we just allocate enough BDEs to accomidate
5020 * our max amount and we need to limit lpfc_sg_seg_cnt to
5021 * minimize the risk of running out.
5022 */
5023 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5024 sizeof(struct fcp_rsp) +
5025 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
5026
5027 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
5028 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
5029
5030 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
5031 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
5032 } else {
5033 /*
5034 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5035 * the FCP rsp, a BDE for each, and a BDE for up to
5036 * cfg_sg_seg_cnt data segments.
5037 */
5038 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5039 sizeof(struct fcp_rsp) +
5040 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
5041
5042 /* Total BDEs in BPL for scsi_sg_list */
5043 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5044 }
5045
5046 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5047 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
5048 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5049 phba->cfg_total_seg_cnt);
5050
James Smart3772a992009-05-22 14:50:54 -04005051 phba->max_vpi = LPFC_MAX_VPI;
5052 /* This will be set to correct value after config_port mbox */
5053 phba->max_vports = 0;
5054
5055 /*
5056 * Initialize the SLI Layer to run with lpfc HBAs.
5057 */
5058 lpfc_sli_setup(phba);
5059 lpfc_sli_queue_setup(phba);
5060
5061 /* Allocate device driver memory */
5062 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
5063 return -ENOMEM;
5064
James Smart912e3ac2011-05-24 11:42:11 -04005065 /*
5066 * Enable sr-iov virtual functions if supported and configured
5067 * through the module parameter.
5068 */
5069 if (phba->cfg_sriov_nr_virtfn > 0) {
5070 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5071 phba->cfg_sriov_nr_virtfn);
5072 if (rc) {
5073 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5074 "2808 Requested number of SR-IOV "
5075 "virtual functions (%d) is not "
5076 "supported\n",
5077 phba->cfg_sriov_nr_virtfn);
5078 phba->cfg_sriov_nr_virtfn = 0;
5079 }
5080 }
5081
James Smart3772a992009-05-22 14:50:54 -04005082 return 0;
5083}
5084
5085/**
5086 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
5087 * @phba: pointer to lpfc hba data structure.
5088 *
5089 * This routine is invoked to unset the driver internal resources set up
5090 * specific for supporting the SLI-3 HBA device it attached to.
5091 **/
5092static void
5093lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
5094{
5095 /* Free device driver memory allocated */
5096 lpfc_mem_free_all(phba);
5097
5098 return;
5099}
5100
5101/**
James Smartda0436e2009-05-22 14:51:39 -04005102 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
5103 * @phba: pointer to lpfc hba data structure.
5104 *
5105 * This routine is invoked to set up the driver internal resources specific to
5106 * support the SLI-4 HBA device it attached to.
5107 *
5108 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005109 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04005110 * other values - error
5111 **/
5112static int
5113lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5114{
James Smart7bb03bb2013-04-17 20:19:16 -04005115 struct lpfc_vector_map_info *cpup;
James Smartda0436e2009-05-22 14:51:39 -04005116 struct lpfc_sli *psli;
James Smart28baac72010-02-12 14:42:03 -05005117 LPFC_MBOXQ_t *mboxq;
James Smart96f70772013-04-17 20:16:15 -04005118 int rc, i, hbq_count, max_buf_size;
James Smart28baac72010-02-12 14:42:03 -05005119 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
5120 struct lpfc_mqe *mqe;
James Smart09294d42013-04-17 20:16:05 -04005121 int longs;
James Smart1ba981f2014-02-20 09:56:45 -05005122 int fof_vectors = 0;
James Smartda0436e2009-05-22 14:51:39 -04005123
James Smart716d3bc2013-09-06 12:18:28 -04005124 /* Get all the module params for configuring this host */
5125 lpfc_get_cfgparam(phba);
5126
James Smartda0436e2009-05-22 14:51:39 -04005127 /* Before proceed, wait for POST done and device ready */
5128 rc = lpfc_sli4_post_status_check(phba);
5129 if (rc)
5130 return -ENODEV;
5131
5132 /*
5133 * Initialize timers used by driver
5134 */
5135
5136 /* Heartbeat timer */
5137 init_timer(&phba->hb_tmofunc);
5138 phba->hb_tmofunc.function = lpfc_hb_timeout;
5139 phba->hb_tmofunc.data = (unsigned long)phba;
James Smart19ca7602010-11-20 23:11:55 -05005140 init_timer(&phba->rrq_tmr);
5141 phba->rrq_tmr.function = lpfc_rrq_timeout;
5142 phba->rrq_tmr.data = (unsigned long)phba;
James Smartda0436e2009-05-22 14:51:39 -04005143
5144 psli = &phba->sli;
5145 /* MBOX heartbeat timer */
5146 init_timer(&psli->mbox_tmo);
5147 psli->mbox_tmo.function = lpfc_mbox_timeout;
5148 psli->mbox_tmo.data = (unsigned long) phba;
5149 /* Fabric block timer */
5150 init_timer(&phba->fabric_block_timer);
5151 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
5152 phba->fabric_block_timer.data = (unsigned long) phba;
5153 /* EA polling mode timer */
5154 init_timer(&phba->eratt_poll);
5155 phba->eratt_poll.function = lpfc_poll_eratt;
5156 phba->eratt_poll.data = (unsigned long) phba;
James Smartecfd03c2010-02-12 14:41:27 -05005157 /* FCF rediscover timer */
5158 init_timer(&phba->fcf.redisc_wait);
5159 phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
5160 phba->fcf.redisc_wait.data = (unsigned long)phba;
5161
James Smartda0436e2009-05-22 14:51:39 -04005162 /*
James Smart7ad20aa2011-05-24 11:44:28 -04005163 * Control structure for handling external multi-buffer mailbox
5164 * command pass-through.
5165 */
5166 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
5167 sizeof(struct lpfc_mbox_ext_buf_ctx));
5168 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
5169
James Smartda0436e2009-05-22 14:51:39 -04005170 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04005171
James Smartda0436e2009-05-22 14:51:39 -04005172 /* This will be set to correct value after the read_config mbox */
5173 phba->max_vports = 0;
5174
5175 /* Program the default value of vlan_id and fc_map */
5176 phba->valid_vlan = 0;
5177 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5178 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5179 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5180
5181 /*
James Smart2a76a282012-08-03 12:35:54 -04005182 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
5183 * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple.
5184 */
5185 if (!phba->sli.ring)
5186 phba->sli.ring = kzalloc(
James Smart67d12732012-08-03 12:36:13 -04005187 (LPFC_SLI3_MAX_RING + phba->cfg_fcp_io_channel) *
James Smart2a76a282012-08-03 12:35:54 -04005188 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
5189 if (!phba->sli.ring)
5190 return -ENOMEM;
James Smart085c6472010-11-20 23:11:37 -05005191
James Smart09294d42013-04-17 20:16:05 -04005192 /*
5193 * It doesn't matter what family our adapter is in, we are
5194 * limited to 2 Pages, 512 SGEs, for our SGL.
5195 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
5196 */
5197 max_buf_size = (2 * SLI4_PAGE_SIZE);
5198 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2)
5199 phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2;
James Smart09294d42013-04-17 20:16:05 -04005200
James Smartda0436e2009-05-22 14:51:39 -04005201 /*
James Smart96f70772013-04-17 20:16:15 -04005202 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smartda0436e2009-05-22 14:51:39 -04005203 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart28baac72010-02-12 14:42:03 -05005204 */
James Smart085c6472010-11-20 23:11:37 -05005205
James Smart96f70772013-04-17 20:16:15 -04005206 if (phba->cfg_enable_bg) {
5207 /*
5208 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5209 * the FCP rsp, and a SGE for each. Sice we have no control
5210 * over how many protection data segments the SCSI Layer
5211 * will hand us (ie: there could be one for every block
5212 * in the IO), we just allocate enough SGEs to accomidate
5213 * our max amount and we need to limit lpfc_sg_seg_cnt to
5214 * minimize the risk of running out.
5215 */
5216 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5217 sizeof(struct fcp_rsp) + max_buf_size;
5218
5219 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
5220 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
5221
5222 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
5223 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
5224 } else {
5225 /*
5226 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5227 * the FCP rsp, a SGE for each, and a SGE for up to
5228 * cfg_sg_seg_cnt data segments.
5229 */
5230 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5231 sizeof(struct fcp_rsp) +
5232 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge));
5233
5234 /* Total SGEs for scsi_sg_list */
5235 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5236 /*
5237 * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only need
5238 * to post 1 page for the SGL.
5239 */
James Smart085c6472010-11-20 23:11:37 -05005240 }
James Smartacd68592012-01-18 16:25:09 -05005241
James Smart96f70772013-04-17 20:16:15 -04005242 /* Initialize the host templates with the updated values. */
5243 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5244 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5245
5246 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
5247 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
5248 else
5249 phba->cfg_sg_dma_buf_size =
5250 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
5251
5252 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5253 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
5254 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5255 phba->cfg_total_seg_cnt);
James Smartda0436e2009-05-22 14:51:39 -04005256
5257 /* Initialize buffer queue management fields */
5258 hbq_count = lpfc_sli_hbq_count();
5259 for (i = 0; i < hbq_count; ++i)
5260 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
5261 INIT_LIST_HEAD(&phba->rb_pend_list);
5262 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
5263 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
5264
5265 /*
5266 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
5267 */
5268 /* Initialize the Abort scsi buffer list used by driver */
5269 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
5270 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
5271 /* This abort list used by worker thread */
5272 spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
5273
5274 /*
James Smart6d368e52011-05-24 11:44:12 -04005275 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04005276 */
5277
5278 /* Driver internel slow-path CQ Event pool */
5279 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
5280 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04005281 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04005282 /* Asynchronous event CQ Event work queue list */
5283 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
5284 /* Fast-path XRI aborted CQ Event work queue list */
5285 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
5286 /* Slow-path XRI aborted CQ Event work queue list */
5287 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
5288 /* Receive queue CQ Event work queue list */
5289 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
5290
James Smart6d368e52011-05-24 11:44:12 -04005291 /* Initialize extent block lists. */
5292 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
5293 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
5294 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
5295 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
5296
James Smartda0436e2009-05-22 14:51:39 -04005297 /* Initialize the driver internal SLI layer lists. */
5298 lpfc_sli_setup(phba);
5299 lpfc_sli_queue_setup(phba);
5300
5301 /* Allocate device driver memory */
5302 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
5303 if (rc)
5304 return -ENOMEM;
5305
James Smart2fcee4b2010-12-15 17:57:46 -05005306 /* IF Type 2 ports get initialized now. */
5307 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5308 LPFC_SLI_INTF_IF_TYPE_2) {
5309 rc = lpfc_pci_function_reset(phba);
5310 if (unlikely(rc))
5311 return -ENODEV;
James Smart946727d2015-04-07 15:07:09 -04005312 phba->temp_sensor_support = 1;
James Smart2fcee4b2010-12-15 17:57:46 -05005313 }
5314
James Smartda0436e2009-05-22 14:51:39 -04005315 /* Create the bootstrap mailbox command */
5316 rc = lpfc_create_bootstrap_mbox(phba);
5317 if (unlikely(rc))
5318 goto out_free_mem;
5319
5320 /* Set up the host's endian order with the device. */
5321 rc = lpfc_setup_endian_order(phba);
5322 if (unlikely(rc))
5323 goto out_free_bsmbx;
5324
5325 /* Set up the hba's configuration parameters. */
5326 rc = lpfc_sli4_read_config(phba);
5327 if (unlikely(rc))
5328 goto out_free_bsmbx;
James Smartcff261f2013-12-17 20:29:47 -05005329 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
5330 if (unlikely(rc))
5331 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005332
James Smart2fcee4b2010-12-15 17:57:46 -05005333 /* IF Type 0 ports get initialized now. */
5334 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5335 LPFC_SLI_INTF_IF_TYPE_0) {
5336 rc = lpfc_pci_function_reset(phba);
5337 if (unlikely(rc))
5338 goto out_free_bsmbx;
5339 }
James Smartda0436e2009-05-22 14:51:39 -04005340
James Smartcb5172e2010-03-15 11:25:07 -04005341 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
5342 GFP_KERNEL);
5343 if (!mboxq) {
5344 rc = -ENOMEM;
5345 goto out_free_bsmbx;
5346 }
5347
James Smartfedd3b72011-02-16 12:39:24 -05005348 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04005349 lpfc_supported_pages(mboxq);
5350 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05005351 if (!rc) {
5352 mqe = &mboxq->u.mqe;
5353 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
5354 LPFC_MAX_SUPPORTED_PAGES);
5355 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
5356 switch (pn_page[i]) {
5357 case LPFC_SLI4_PARAMETERS:
5358 phba->sli4_hba.pc_sli4_params.supported = 1;
5359 break;
5360 default:
5361 break;
5362 }
5363 }
5364 /* Read the port's SLI4 Parameters capabilities if supported. */
5365 if (phba->sli4_hba.pc_sli4_params.supported)
5366 rc = lpfc_pc_sli4_params_get(phba, mboxq);
5367 if (rc) {
5368 mempool_free(mboxq, phba->mbox_mem_pool);
5369 rc = -EIO;
5370 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04005371 }
5372 }
James Smartfedd3b72011-02-16 12:39:24 -05005373 /*
5374 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04005375 * If this call fails, it isn't critical unless the SLI4 parameters come
5376 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05005377 */
James Smart6d368e52011-05-24 11:44:12 -04005378 rc = lpfc_get_sli4_parameters(phba, mboxq);
5379 if (rc) {
5380 if (phba->sli4_hba.extents_in_use &&
5381 phba->sli4_hba.rpi_hdrs_in_use) {
5382 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5383 "2999 Unsupported SLI4 Parameters "
5384 "Extents and RPI headers enabled.\n");
5385 goto out_free_bsmbx;
5386 }
5387 }
James Smartcb5172e2010-03-15 11:25:07 -04005388 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -05005389
5390 /* Verify OAS is supported */
5391 lpfc_sli4_oas_verify(phba);
5392 if (phba->cfg_fof)
5393 fof_vectors = 1;
5394
James Smart5350d872011-10-10 21:33:49 -04005395 /* Verify all the SLI4 queues */
5396 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04005397 if (rc)
5398 goto out_free_bsmbx;
5399
5400 /* Create driver internal CQE event pool */
5401 rc = lpfc_sli4_cq_event_pool_create(phba);
5402 if (rc)
James Smart5350d872011-10-10 21:33:49 -04005403 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005404
James Smart8a9d2e82012-05-09 21:16:12 -04005405 /* Initialize sgl lists per host */
5406 lpfc_init_sgl_list(phba);
5407
5408 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04005409 rc = lpfc_init_active_sgl_array(phba);
5410 if (rc) {
5411 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5412 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04005413 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04005414 }
James Smartda0436e2009-05-22 14:51:39 -04005415 rc = lpfc_sli4_init_rpi_hdrs(phba);
5416 if (rc) {
5417 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5418 "1432 Failed to initialize rpi headers.\n");
5419 goto out_free_active_sgl;
5420 }
5421
James Smarta93ff372010-10-22 11:06:08 -04005422 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05005423 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
5424 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
5425 GFP_KERNEL);
5426 if (!phba->fcf.fcf_rr_bmask) {
5427 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5428 "2759 Failed allocate memory for FCF round "
5429 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04005430 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05005431 goto out_remove_rpi_hdrs;
5432 }
5433
James Smart67d12732012-08-03 12:36:13 -04005434 phba->sli4_hba.fcp_eq_hdl =
5435 kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
James Smart1ba981f2014-02-20 09:56:45 -05005436 (fof_vectors + phba->cfg_fcp_io_channel)),
5437 GFP_KERNEL);
James Smart67d12732012-08-03 12:36:13 -04005438 if (!phba->sli4_hba.fcp_eq_hdl) {
5439 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5440 "2572 Failed allocate memory for "
5441 "fast-path per-EQ handle array\n");
5442 rc = -ENOMEM;
5443 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04005444 }
5445
5446 phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
James Smart1ba981f2014-02-20 09:56:45 -05005447 (fof_vectors +
5448 phba->cfg_fcp_io_channel)), GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04005449 if (!phba->sli4_hba.msix_entries) {
5450 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5451 "2573 Failed allocate memory for msi-x "
5452 "interrupt vector entries\n");
James Smart05580562011-05-24 11:40:48 -04005453 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04005454 goto out_free_fcp_eq_hdl;
5455 }
5456
James Smart7bb03bb2013-04-17 20:19:16 -04005457 phba->sli4_hba.cpu_map = kzalloc((sizeof(struct lpfc_vector_map_info) *
5458 phba->sli4_hba.num_present_cpu),
5459 GFP_KERNEL);
5460 if (!phba->sli4_hba.cpu_map) {
5461 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5462 "3327 Failed allocate memory for msi-x "
5463 "interrupt vector mapping\n");
5464 rc = -ENOMEM;
5465 goto out_free_msix;
5466 }
James Smartb246de12013-05-31 17:03:07 -04005467 if (lpfc_used_cpu == NULL) {
5468 lpfc_used_cpu = kzalloc((sizeof(uint16_t) * lpfc_present_cpu),
5469 GFP_KERNEL);
5470 if (!lpfc_used_cpu) {
5471 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5472 "3335 Failed allocate memory for msi-x "
5473 "interrupt vector mapping\n");
5474 kfree(phba->sli4_hba.cpu_map);
5475 rc = -ENOMEM;
5476 goto out_free_msix;
5477 }
5478 for (i = 0; i < lpfc_present_cpu; i++)
5479 lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
5480 }
5481
James Smart7bb03bb2013-04-17 20:19:16 -04005482 /* Initialize io channels for round robin */
5483 cpup = phba->sli4_hba.cpu_map;
5484 rc = 0;
5485 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
5486 cpup->channel_id = rc;
5487 rc++;
5488 if (rc >= phba->cfg_fcp_io_channel)
5489 rc = 0;
5490 }
5491
James Smart912e3ac2011-05-24 11:42:11 -04005492 /*
5493 * Enable sr-iov virtual functions if supported and configured
5494 * through the module parameter.
5495 */
5496 if (phba->cfg_sriov_nr_virtfn > 0) {
5497 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5498 phba->cfg_sriov_nr_virtfn);
5499 if (rc) {
5500 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5501 "3020 Requested number of SR-IOV "
5502 "virtual functions (%d) is not "
5503 "supported\n",
5504 phba->cfg_sriov_nr_virtfn);
5505 phba->cfg_sriov_nr_virtfn = 0;
5506 }
5507 }
5508
James Smart5248a742011-07-22 18:37:06 -04005509 return 0;
James Smartda0436e2009-05-22 14:51:39 -04005510
James Smart7bb03bb2013-04-17 20:19:16 -04005511out_free_msix:
5512 kfree(phba->sli4_hba.msix_entries);
James Smartda0436e2009-05-22 14:51:39 -04005513out_free_fcp_eq_hdl:
5514 kfree(phba->sli4_hba.fcp_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05005515out_free_fcf_rr_bmask:
5516 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04005517out_remove_rpi_hdrs:
5518 lpfc_sli4_remove_rpi_hdrs(phba);
5519out_free_active_sgl:
5520 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04005521out_destroy_cq_event_pool:
5522 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04005523out_free_bsmbx:
5524 lpfc_destroy_bootstrap_mbox(phba);
5525out_free_mem:
5526 lpfc_mem_free(phba);
5527 return rc;
5528}
5529
5530/**
5531 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
5532 * @phba: pointer to lpfc hba data structure.
5533 *
5534 * This routine is invoked to unset the driver internal resources set up
5535 * specific for supporting the SLI-4 HBA device it attached to.
5536 **/
5537static void
5538lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
5539{
5540 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
5541
James Smart7bb03bb2013-04-17 20:19:16 -04005542 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
5543 kfree(phba->sli4_hba.cpu_map);
5544 phba->sli4_hba.num_present_cpu = 0;
5545 phba->sli4_hba.num_online_cpu = 0;
James Smart76fd07a2014-02-20 09:57:18 -05005546 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04005547
James Smartda0436e2009-05-22 14:51:39 -04005548 /* Free memory allocated for msi-x interrupt vector entries */
5549 kfree(phba->sli4_hba.msix_entries);
5550
5551 /* Free memory allocated for fast-path work queue handles */
5552 kfree(phba->sli4_hba.fcp_eq_hdl);
5553
5554 /* Free the allocated rpi headers. */
5555 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04005556 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04005557
James Smart0c9ab6f2010-02-26 14:15:57 -05005558 /* Free eligible FCF index bmask */
5559 kfree(phba->fcf.fcf_rr_bmask);
5560
James Smartda0436e2009-05-22 14:51:39 -04005561 /* Free the ELS sgl list */
5562 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04005563 lpfc_free_els_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04005564
James Smartda0436e2009-05-22 14:51:39 -04005565 /* Free the completion queue EQ event pool */
5566 lpfc_sli4_cq_event_release_all(phba);
5567 lpfc_sli4_cq_event_pool_destroy(phba);
5568
James Smart6d368e52011-05-24 11:44:12 -04005569 /* Release resource identifiers. */
5570 lpfc_sli4_dealloc_resource_identifiers(phba);
5571
James Smartda0436e2009-05-22 14:51:39 -04005572 /* Free the bsmbx region. */
5573 lpfc_destroy_bootstrap_mbox(phba);
5574
5575 /* Free the SLI Layer memory with SLI4 HBAs */
5576 lpfc_mem_free_all(phba);
5577
5578 /* Free the current connect table */
5579 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04005580 &phba->fcf_conn_rec_list, list) {
5581 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04005582 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04005583 }
James Smartda0436e2009-05-22 14:51:39 -04005584
5585 return;
5586}
5587
5588/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005589 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04005590 * @phba: The hba struct for which this call is being executed.
5591 * @dev_grp: The HBA PCI-Device group number.
5592 *
5593 * This routine sets up the device INIT interface API function jump table
5594 * in @phba struct.
5595 *
5596 * Returns: 0 - success, -ENODEV - failure.
5597 **/
5598int
5599lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5600{
James Smart84d1b002010-02-12 14:42:33 -05005601 phba->lpfc_hba_init_link = lpfc_hba_init_link;
5602 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05005603 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04005604 switch (dev_grp) {
5605 case LPFC_PCI_DEV_LP:
5606 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
5607 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
5608 phba->lpfc_stop_port = lpfc_stop_port_s3;
5609 break;
James Smartda0436e2009-05-22 14:51:39 -04005610 case LPFC_PCI_DEV_OC:
5611 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
5612 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
5613 phba->lpfc_stop_port = lpfc_stop_port_s4;
5614 break;
James Smart3772a992009-05-22 14:50:54 -04005615 default:
5616 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5617 "1431 Invalid HBA PCI-device group: 0x%x\n",
5618 dev_grp);
5619 return -ENODEV;
5620 break;
5621 }
5622 return 0;
5623}
5624
5625/**
5626 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
5627 * @phba: pointer to lpfc hba data structure.
5628 *
5629 * This routine is invoked to set up the driver internal resources before the
5630 * device specific resource setup to support the HBA device it attached to.
5631 *
5632 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005633 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005634 * other values - error
5635 **/
5636static int
5637lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
5638{
5639 /*
5640 * Driver resources common to all SLI revisions
5641 */
James Smartea2151b2008-09-07 11:52:10 -04005642 atomic_set(&phba->fast_event_count, 0);
James Smart2e0fef82007-06-17 19:56:36 -05005643 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005644
James Smarte47c9092008-02-08 18:49:26 -05005645 /* Initialize ndlp management spinlock */
5646 spin_lock_init(&phba->ndlp_lock);
5647
James Smart2e0fef82007-06-17 19:56:36 -05005648 INIT_LIST_HEAD(&phba->port_list);
James Smart3772a992009-05-22 14:50:54 -04005649 INIT_LIST_HEAD(&phba->work_list);
James Smart84774a42008-08-24 21:50:06 -04005650 init_waitqueue_head(&phba->wait_4_mlo_m_q);
dea31012005-04-17 16:05:31 -05005651
James Smart3772a992009-05-22 14:50:54 -04005652 /* Initialize the wait queue head for the kernel thread */
5653 init_waitqueue_head(&phba->work_waitq);
James Smart858c9f62007-06-17 19:56:39 -05005654
James Smart3772a992009-05-22 14:50:54 -04005655 /* Initialize the scsi buffer list used by driver for scsi IO */
James Smarta40fc5f2013-04-17 20:17:40 -04005656 spin_lock_init(&phba->scsi_buf_list_get_lock);
5657 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5658 spin_lock_init(&phba->scsi_buf_list_put_lock);
5659 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
dea31012005-04-17 16:05:31 -05005660
James Smart3772a992009-05-22 14:50:54 -04005661 /* Initialize the fabric iocb list */
5662 INIT_LIST_HEAD(&phba->fabric_iocb_list);
dea31012005-04-17 16:05:31 -05005663
James Smart3772a992009-05-22 14:50:54 -04005664 /* Initialize list to save ELS buffers */
5665 INIT_LIST_HEAD(&phba->elsbuf);
dea31012005-04-17 16:05:31 -05005666
James Smart3772a992009-05-22 14:50:54 -04005667 /* Initialize FCF connection rec list */
5668 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
dea31012005-04-17 16:05:31 -05005669
James Smart1ba981f2014-02-20 09:56:45 -05005670 /* Initialize OAS configuration list */
5671 spin_lock_init(&phba->devicelock);
5672 INIT_LIST_HEAD(&phba->luns);
5673
James Smart3772a992009-05-22 14:50:54 -04005674 return 0;
5675}
dea31012005-04-17 16:05:31 -05005676
James Smart3772a992009-05-22 14:50:54 -04005677/**
5678 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
5679 * @phba: pointer to lpfc hba data structure.
5680 *
5681 * This routine is invoked to set up the driver internal resources after the
5682 * device specific resource setup to support the HBA device it attached to.
5683 *
5684 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005685 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005686 * other values - error
5687 **/
5688static int
5689lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
5690{
5691 int error;
5692
5693 /* Startup the kernel thread for this host adapter. */
5694 phba->worker_thread = kthread_run(lpfc_do_work, phba,
5695 "lpfc_worker_%d", phba->brd_no);
5696 if (IS_ERR(phba->worker_thread)) {
5697 error = PTR_ERR(phba->worker_thread);
5698 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005699 }
5700
James Smart3772a992009-05-22 14:50:54 -04005701 return 0;
5702}
5703
5704/**
5705 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
5706 * @phba: pointer to lpfc hba data structure.
5707 *
5708 * This routine is invoked to unset the driver internal resources set up after
5709 * the device specific resource setup for supporting the HBA device it
5710 * attached to.
5711 **/
5712static void
5713lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
5714{
5715 /* Stop kernel worker thread */
5716 kthread_stop(phba->worker_thread);
5717}
5718
5719/**
5720 * lpfc_free_iocb_list - Free iocb list.
5721 * @phba: pointer to lpfc hba data structure.
5722 *
5723 * This routine is invoked to free the driver's IOCB list and memory.
5724 **/
5725static void
5726lpfc_free_iocb_list(struct lpfc_hba *phba)
5727{
5728 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
5729
5730 spin_lock_irq(&phba->hbalock);
5731 list_for_each_entry_safe(iocbq_entry, iocbq_next,
5732 &phba->lpfc_iocb_list, list) {
5733 list_del(&iocbq_entry->list);
5734 kfree(iocbq_entry);
5735 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005736 }
James Smart3772a992009-05-22 14:50:54 -04005737 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005738
James Smart3772a992009-05-22 14:50:54 -04005739 return;
5740}
dea31012005-04-17 16:05:31 -05005741
James Smart3772a992009-05-22 14:50:54 -04005742/**
5743 * lpfc_init_iocb_list - Allocate and initialize iocb list.
5744 * @phba: pointer to lpfc hba data structure.
5745 *
5746 * This routine is invoked to allocate and initizlize the driver's IOCB
5747 * list and set up the IOCB tag array accordingly.
5748 *
5749 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005750 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005751 * other values - error
5752 **/
5753static int
5754lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
5755{
5756 struct lpfc_iocbq *iocbq_entry = NULL;
5757 uint16_t iotag;
5758 int i;
dea31012005-04-17 16:05:31 -05005759
5760 /* Initialize and populate the iocb list per host. */
5761 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04005762 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07005763 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05005764 if (iocbq_entry == NULL) {
5765 printk(KERN_ERR "%s: only allocated %d iocbs of "
5766 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07005767 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05005768 goto out_free_iocbq;
5769 }
5770
James Bottomley604a3e32005-10-29 10:28:33 -05005771 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
5772 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04005773 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05005774 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04005775 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05005776 goto out_free_iocbq;
5777 }
James Smart6d368e52011-05-24 11:44:12 -04005778 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04005779 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05005780
5781 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005782 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
5783 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05005784 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005785 }
5786
James Smart3772a992009-05-22 14:50:54 -04005787 return 0;
5788
5789out_free_iocbq:
5790 lpfc_free_iocb_list(phba);
5791
5792 return -ENOMEM;
5793}
5794
5795/**
James Smart8a9d2e82012-05-09 21:16:12 -04005796 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04005797 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04005798 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04005799 *
James Smart8a9d2e82012-05-09 21:16:12 -04005800 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04005801 **/
James Smart8a9d2e82012-05-09 21:16:12 -04005802void
5803lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04005804{
5805 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04005806
5807 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
5808 list_del(&sglq_entry->list);
5809 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
5810 kfree(sglq_entry);
5811 }
5812}
5813
5814/**
5815 * lpfc_free_els_sgl_list - Free els sgl list.
5816 * @phba: pointer to lpfc hba data structure.
5817 *
5818 * This routine is invoked to free the driver's els sgl list and memory.
5819 **/
5820static void
5821lpfc_free_els_sgl_list(struct lpfc_hba *phba)
5822{
James Smartda0436e2009-05-22 14:51:39 -04005823 LIST_HEAD(sglq_list);
James Smartdafe8ce2014-09-03 12:56:40 -04005824 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smartda0436e2009-05-22 14:51:39 -04005825
James Smart8a9d2e82012-05-09 21:16:12 -04005826 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04005827 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04005828 spin_lock(&pring->ring_lock);
James Smartda0436e2009-05-22 14:51:39 -04005829 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
James Smartdafe8ce2014-09-03 12:56:40 -04005830 spin_unlock(&pring->ring_lock);
James Smartda0436e2009-05-22 14:51:39 -04005831 spin_unlock_irq(&phba->hbalock);
5832
James Smart8a9d2e82012-05-09 21:16:12 -04005833 /* Now free the sgl list */
5834 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04005835}
5836
5837/**
5838 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
5839 * @phba: pointer to lpfc hba data structure.
5840 *
5841 * This routine is invoked to allocate the driver's active sgl memory.
5842 * This array will hold the sglq_entry's for active IOs.
5843 **/
5844static int
5845lpfc_init_active_sgl_array(struct lpfc_hba *phba)
5846{
5847 int size;
5848 size = sizeof(struct lpfc_sglq *);
5849 size *= phba->sli4_hba.max_cfg_param.max_xri;
5850
5851 phba->sli4_hba.lpfc_sglq_active_list =
5852 kzalloc(size, GFP_KERNEL);
5853 if (!phba->sli4_hba.lpfc_sglq_active_list)
5854 return -ENOMEM;
5855 return 0;
5856}
5857
5858/**
5859 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
5860 * @phba: pointer to lpfc hba data structure.
5861 *
5862 * This routine is invoked to walk through the array of active sglq entries
5863 * and free all of the resources.
5864 * This is just a place holder for now.
5865 **/
5866static void
5867lpfc_free_active_sgl(struct lpfc_hba *phba)
5868{
5869 kfree(phba->sli4_hba.lpfc_sglq_active_list);
5870}
5871
5872/**
5873 * lpfc_init_sgl_list - Allocate and initialize sgl list.
5874 * @phba: pointer to lpfc hba data structure.
5875 *
5876 * This routine is invoked to allocate and initizlize the driver's sgl
5877 * list and set up the sgl xritag tag array accordingly.
5878 *
James Smartda0436e2009-05-22 14:51:39 -04005879 **/
James Smart8a9d2e82012-05-09 21:16:12 -04005880static void
James Smartda0436e2009-05-22 14:51:39 -04005881lpfc_init_sgl_list(struct lpfc_hba *phba)
5882{
James Smartda0436e2009-05-22 14:51:39 -04005883 /* Initialize and populate the sglq list per host/VF. */
5884 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
5885 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
5886
James Smart8a9d2e82012-05-09 21:16:12 -04005887 /* els xri-sgl book keeping */
5888 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04005889
James Smart8a9d2e82012-05-09 21:16:12 -04005890 /* scsi xri-buffer book keeping */
James Smartda0436e2009-05-22 14:51:39 -04005891 phba->sli4_hba.scsi_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04005892}
5893
5894/**
5895 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
5896 * @phba: pointer to lpfc hba data structure.
5897 *
5898 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04005899 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04005900 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04005901 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
5902 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04005903 *
5904 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005905 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04005906 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04005907 **/
5908int
5909lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
5910{
5911 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04005912 struct lpfc_rpi_hdr *rpi_hdr;
5913
5914 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05005915 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04005916 return rc;
James Smart6d368e52011-05-24 11:44:12 -04005917 if (phba->sli4_hba.extents_in_use)
5918 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04005919
5920 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
5921 if (!rpi_hdr) {
5922 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5923 "0391 Error during rpi post operation\n");
5924 lpfc_sli4_remove_rpis(phba);
5925 rc = -ENODEV;
5926 }
5927
5928 return rc;
5929}
5930
5931/**
5932 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
5933 * @phba: pointer to lpfc hba data structure.
5934 *
5935 * This routine is invoked to allocate a single 4KB memory region to
5936 * support rpis and stores them in the phba. This single region
5937 * provides support for up to 64 rpis. The region is used globally
5938 * by the device.
5939 *
5940 * Returns:
5941 * A valid rpi hdr on success.
5942 * A NULL pointer on any failure.
5943 **/
5944struct lpfc_rpi_hdr *
5945lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
5946{
5947 uint16_t rpi_limit, curr_rpi_range;
5948 struct lpfc_dmabuf *dmabuf;
5949 struct lpfc_rpi_hdr *rpi_hdr;
James Smart9589b0622011-04-16 11:03:17 -04005950 uint32_t rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04005951
James Smart6d368e52011-05-24 11:44:12 -04005952 /*
5953 * If the SLI4 port supports extents, posting the rpi header isn't
5954 * required. Set the expected maximum count and let the actual value
5955 * get set when extents are fully allocated.
5956 */
5957 if (!phba->sli4_hba.rpi_hdrs_in_use)
5958 return NULL;
5959 if (phba->sli4_hba.extents_in_use)
5960 return NULL;
5961
5962 /* The limit on the logical index is just the max_rpi count. */
James Smartda0436e2009-05-22 14:51:39 -04005963 rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
James Smart6d368e52011-05-24 11:44:12 -04005964 phba->sli4_hba.max_cfg_param.max_rpi - 1;
James Smartda0436e2009-05-22 14:51:39 -04005965
5966 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04005967 /*
5968 * Establish the starting RPI in this header block. The starting
5969 * rpi is normalized to a zero base because the physical rpi is
5970 * port based.
5971 */
James Smart97f2ecf2012-03-01 22:35:23 -05005972 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04005973 spin_unlock_irq(&phba->hbalock);
5974
5975 /*
5976 * The port has a limited number of rpis. The increment here
5977 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
5978 * and to allow the full max_rpi range per port.
5979 */
5980 if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
James Smart9589b0622011-04-16 11:03:17 -04005981 rpi_count = rpi_limit - curr_rpi_range;
5982 else
5983 rpi_count = LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04005984
James Smart6d368e52011-05-24 11:44:12 -04005985 if (!rpi_count)
5986 return NULL;
James Smartda0436e2009-05-22 14:51:39 -04005987 /*
5988 * First allocate the protocol header region for the port. The
5989 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
5990 */
5991 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5992 if (!dmabuf)
5993 return NULL;
5994
Joe Perches1aee3832014-09-03 12:56:12 -04005995 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
5996 LPFC_HDR_TEMPLATE_SIZE,
5997 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04005998 if (!dmabuf->virt) {
5999 rpi_hdr = NULL;
6000 goto err_free_dmabuf;
6001 }
6002
James Smartda0436e2009-05-22 14:51:39 -04006003 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
6004 rpi_hdr = NULL;
6005 goto err_free_coherent;
6006 }
6007
6008 /* Save the rpi header data for cleanup later. */
6009 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
6010 if (!rpi_hdr)
6011 goto err_free_coherent;
6012
6013 rpi_hdr->dmabuf = dmabuf;
6014 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
6015 rpi_hdr->page_count = 1;
6016 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006017
6018 /* The rpi_hdr stores the logical index only. */
6019 rpi_hdr->start_rpi = curr_rpi_range;
James Smartda0436e2009-05-22 14:51:39 -04006020 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
6021
6022 /*
James Smart6d368e52011-05-24 11:44:12 -04006023 * The next_rpi stores the next logical module-64 rpi value used
6024 * to post physical rpis in subsequent rpi postings.
James Smartda0436e2009-05-22 14:51:39 -04006025 */
James Smart9589b0622011-04-16 11:03:17 -04006026 phba->sli4_hba.next_rpi += rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04006027 spin_unlock_irq(&phba->hbalock);
6028 return rpi_hdr;
6029
6030 err_free_coherent:
6031 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
6032 dmabuf->virt, dmabuf->phys);
6033 err_free_dmabuf:
6034 kfree(dmabuf);
6035 return NULL;
6036}
6037
6038/**
6039 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
6040 * @phba: pointer to lpfc hba data structure.
6041 *
6042 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04006043 * to support rpis for SLI4 ports not supporting extents. This routine
6044 * presumes the caller has released all rpis consumed by fabric or port
6045 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04006046 **/
6047void
6048lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
6049{
6050 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
6051
James Smart6d368e52011-05-24 11:44:12 -04006052 if (!phba->sli4_hba.rpi_hdrs_in_use)
6053 goto exit;
6054
James Smartda0436e2009-05-22 14:51:39 -04006055 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
6056 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
6057 list_del(&rpi_hdr->list);
6058 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
6059 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
6060 kfree(rpi_hdr->dmabuf);
6061 kfree(rpi_hdr);
6062 }
James Smart6d368e52011-05-24 11:44:12 -04006063 exit:
6064 /* There are no rpis available to the port now. */
6065 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04006066}
6067
6068/**
James Smart3772a992009-05-22 14:50:54 -04006069 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
6070 * @pdev: pointer to pci device data structure.
6071 *
6072 * This routine is invoked to allocate the driver hba data structure for an
6073 * HBA device. If the allocation is successful, the phba reference to the
6074 * PCI device data structure is set.
6075 *
6076 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006077 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04006078 * NULL - error
6079 **/
6080static struct lpfc_hba *
6081lpfc_hba_alloc(struct pci_dev *pdev)
6082{
6083 struct lpfc_hba *phba;
6084
6085 /* Allocate memory for HBA structure */
6086 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
6087 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02006088 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04006089 return NULL;
6090 }
6091
6092 /* Set reference to PCI device in HBA structure */
6093 phba->pcidev = pdev;
6094
6095 /* Assign an unused board number */
6096 phba->brd_no = lpfc_get_instance();
6097 if (phba->brd_no < 0) {
6098 kfree(phba);
6099 return NULL;
6100 }
6101
James Smart4fede782010-01-26 23:08:55 -05006102 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04006103 INIT_LIST_HEAD(&phba->ct_ev_waiters);
6104
James Smart3772a992009-05-22 14:50:54 -04006105 return phba;
6106}
6107
6108/**
6109 * lpfc_hba_free - Free driver hba data structure with a device.
6110 * @phba: pointer to lpfc hba data structure.
6111 *
6112 * This routine is invoked to free the driver hba data structure with an
6113 * HBA device.
6114 **/
6115static void
6116lpfc_hba_free(struct lpfc_hba *phba)
6117{
6118 /* Release the driver assigned board number */
6119 idr_remove(&lpfc_hba_index, phba->brd_no);
6120
James Smart2a76a282012-08-03 12:35:54 -04006121 /* Free memory allocated with sli rings */
6122 kfree(phba->sli.ring);
6123 phba->sli.ring = NULL;
6124
James Smart3772a992009-05-22 14:50:54 -04006125 kfree(phba);
6126 return;
6127}
6128
6129/**
6130 * lpfc_create_shost - Create hba physical port with associated scsi host.
6131 * @phba: pointer to lpfc hba data structure.
6132 *
6133 * This routine is invoked to create HBA physical port and associate a SCSI
6134 * host with it.
6135 *
6136 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006137 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006138 * other values - error
6139 **/
6140static int
6141lpfc_create_shost(struct lpfc_hba *phba)
6142{
6143 struct lpfc_vport *vport;
6144 struct Scsi_Host *shost;
6145
6146 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05006147 phba->fc_edtov = FF_DEF_EDTOV;
6148 phba->fc_ratov = FF_DEF_RATOV;
6149 phba->fc_altov = FF_DEF_ALTOV;
6150 phba->fc_arbtov = FF_DEF_ARBTOV;
6151
James Smartd7c47992010-06-08 18:31:54 -04006152 atomic_set(&phba->sdev_cnt, 0);
James Smart3de2a652007-08-02 11:09:59 -04006153 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05006154 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04006155 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05006156
6157 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05006158 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05006159 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04006160 /* Put reference to SCSI host to driver's device private data */
6161 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05006162
James Smart4258e982015-12-16 18:11:58 -05006163 /*
6164 * At this point we are fully registered with PSA. In addition,
6165 * any initial discovery should be completed.
6166 */
6167 vport->load_flag |= FC_ALLOW_FDMI;
6168 if (phba->cfg_fdmi_on > LPFC_FDMI_NO_SUPPORT) {
6169
6170 /* Setup appropriate attribute masks */
6171 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
6172 if (phba->cfg_fdmi_on == LPFC_FDMI_SMART_SAN)
6173 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
6174 else
6175 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
6176 }
James Smart3772a992009-05-22 14:50:54 -04006177 return 0;
6178}
dea31012005-04-17 16:05:31 -05006179
James Smart3772a992009-05-22 14:50:54 -04006180/**
6181 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
6182 * @phba: pointer to lpfc hba data structure.
6183 *
6184 * This routine is invoked to destroy HBA physical port and the associated
6185 * SCSI host.
6186 **/
6187static void
6188lpfc_destroy_shost(struct lpfc_hba *phba)
6189{
6190 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04006191
James Smart3772a992009-05-22 14:50:54 -04006192 /* Destroy physical port that associated with the SCSI host */
6193 destroy_port(vport);
6194
6195 return;
6196}
6197
6198/**
6199 * lpfc_setup_bg - Setup Block guard structures and debug areas.
6200 * @phba: pointer to lpfc hba data structure.
6201 * @shost: the shost to be used to detect Block guard settings.
6202 *
6203 * This routine sets up the local Block guard protocol settings for @shost.
6204 * This routine also allocates memory for debugging bg buffers.
6205 **/
6206static void
6207lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
6208{
James Smartbbeb79b2012-06-12 13:54:27 -04006209 uint32_t old_mask;
6210 uint32_t old_guard;
6211
James Smart3772a992009-05-22 14:50:54 -04006212 int pagecnt = 10;
6213 if (lpfc_prot_mask && lpfc_prot_guard) {
6214 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6215 "1478 Registering BlockGuard with the "
6216 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04006217
6218 old_mask = lpfc_prot_mask;
6219 old_guard = lpfc_prot_guard;
6220
6221 /* Only allow supported values */
6222 lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
6223 SHOST_DIX_TYPE0_PROTECTION |
6224 SHOST_DIX_TYPE1_PROTECTION);
6225 lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC);
6226
6227 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
6228 if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
6229 lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
6230
6231 if (lpfc_prot_mask && lpfc_prot_guard) {
6232 if ((old_mask != lpfc_prot_mask) ||
6233 (old_guard != lpfc_prot_guard))
6234 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6235 "1475 Registering BlockGuard with the "
6236 "SCSI layer: mask %d guard %d\n",
6237 lpfc_prot_mask, lpfc_prot_guard);
6238
6239 scsi_host_set_prot(shost, lpfc_prot_mask);
6240 scsi_host_set_guard(shost, lpfc_prot_guard);
6241 } else
6242 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6243 "1479 Not Registering BlockGuard with the SCSI "
6244 "layer, Bad protection parameters: %d %d\n",
6245 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04006246 }
James Smartbbeb79b2012-06-12 13:54:27 -04006247
James Smart81301a92008-12-04 22:39:46 -05006248 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05006249 while (pagecnt) {
6250 spin_lock_init(&_dump_buf_lock);
6251 _dump_buf_data =
6252 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6253 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04006254 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6255 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04006256 "_dump_buf_data at 0x%p\n",
6257 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05006258 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04006259 memset(_dump_buf_data, 0,
6260 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05006261 break;
James Smart3772a992009-05-22 14:50:54 -04006262 } else
James Smart81301a92008-12-04 22:39:46 -05006263 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05006264 }
James Smart81301a92008-12-04 22:39:46 -05006265 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04006266 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6267 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04006268 "memory for hexdump\n");
6269 } else
James Smart6a9c52c2009-10-02 15:16:51 -04006270 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6271 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05006272 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05006273 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05006274 while (pagecnt) {
6275 _dump_buf_dif =
6276 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6277 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04006278 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6279 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04006280 "_dump_buf_dif at 0x%p\n",
6281 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05006282 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04006283 memset(_dump_buf_dif, 0,
6284 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05006285 break;
James Smart3772a992009-05-22 14:50:54 -04006286 } else
James Smart81301a92008-12-04 22:39:46 -05006287 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05006288 }
James Smart81301a92008-12-04 22:39:46 -05006289 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04006290 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6291 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04006292 "memory for hexdump\n");
6293 } else
James Smart6a9c52c2009-10-02 15:16:51 -04006294 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6295 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04006296 _dump_buf_dif);
6297}
6298
6299/**
6300 * lpfc_post_init_setup - Perform necessary device post initialization setup.
6301 * @phba: pointer to lpfc hba data structure.
6302 *
6303 * This routine is invoked to perform all the necessary post initialization
6304 * setup for the device.
6305 **/
6306static void
6307lpfc_post_init_setup(struct lpfc_hba *phba)
6308{
6309 struct Scsi_Host *shost;
6310 struct lpfc_adapter_event_header adapter_event;
6311
6312 /* Get the default values for Model Name and Description */
6313 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
6314
6315 /*
6316 * hba setup may have changed the hba_queue_depth so we need to
6317 * adjust the value of can_queue.
6318 */
6319 shost = pci_get_drvdata(phba->pcidev);
6320 shost->can_queue = phba->cfg_hba_queue_depth - 10;
6321 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
6322 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05006323
6324 lpfc_host_attrib_init(shost);
6325
James Smart2e0fef82007-06-17 19:56:36 -05006326 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
6327 spin_lock_irq(shost->host_lock);
6328 lpfc_poll_start_timer(phba);
6329 spin_unlock_irq(shost->host_lock);
6330 }
James Smart8f6d98d2006-08-01 07:34:00 -04006331
James Smart93996272008-08-24 21:50:30 -04006332 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6333 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04006334 /* Send board arrival event to upper layer */
6335 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
6336 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
6337 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04006338 sizeof(adapter_event),
6339 (char *) &adapter_event,
6340 LPFC_NL_VENDOR_ID);
6341 return;
6342}
6343
6344/**
6345 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
6346 * @phba: pointer to lpfc hba data structure.
6347 *
6348 * This routine is invoked to set up the PCI device memory space for device
6349 * with SLI-3 interface spec.
6350 *
6351 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006352 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006353 * other values - error
6354 **/
6355static int
6356lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
6357{
6358 struct pci_dev *pdev;
6359 unsigned long bar0map_len, bar2map_len;
6360 int i, hbq_count;
6361 void *ptr;
6362 int error = -ENODEV;
6363
6364 /* Obtain PCI device reference */
6365 if (!phba->pcidev)
6366 return error;
6367 else
6368 pdev = phba->pcidev;
6369
6370 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05006371 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
6372 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
6373 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
6374 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smart3772a992009-05-22 14:50:54 -04006375 return error;
Michael Reed8e685972009-09-18 12:02:05 -05006376 }
6377 }
James Smart3772a992009-05-22 14:50:54 -04006378
6379 /* Get the bus address of Bar0 and Bar2 and the number of bytes
6380 * required by each mapping.
6381 */
6382 phba->pci_bar0_map = pci_resource_start(pdev, 0);
6383 bar0map_len = pci_resource_len(pdev, 0);
6384
6385 phba->pci_bar2_map = pci_resource_start(pdev, 2);
6386 bar2map_len = pci_resource_len(pdev, 2);
6387
6388 /* Map HBA SLIM to a kernel virtual address. */
6389 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
6390 if (!phba->slim_memmap_p) {
6391 dev_printk(KERN_ERR, &pdev->dev,
6392 "ioremap failed for SLIM memory.\n");
6393 goto out;
6394 }
6395
6396 /* Map HBA Control Registers to a kernel virtual address. */
6397 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
6398 if (!phba->ctrl_regs_memmap_p) {
6399 dev_printk(KERN_ERR, &pdev->dev,
6400 "ioremap failed for HBA control registers.\n");
6401 goto out_iounmap_slim;
6402 }
6403
6404 /* Allocate memory for SLI-2 structures */
Joe Perches1aee3832014-09-03 12:56:12 -04006405 phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6406 &phba->slim2p.phys, GFP_KERNEL);
James Smart3772a992009-05-22 14:50:54 -04006407 if (!phba->slim2p.virt)
6408 goto out_iounmap;
6409
James Smart3772a992009-05-22 14:50:54 -04006410 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04006411 phba->mbox_ext = (phba->slim2p.virt +
6412 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04006413 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
6414 phba->IOCBs = (phba->slim2p.virt +
6415 offsetof(struct lpfc_sli2_slim, IOCBs));
6416
6417 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
6418 lpfc_sli_hbq_size(),
6419 &phba->hbqslimp.phys,
6420 GFP_KERNEL);
6421 if (!phba->hbqslimp.virt)
6422 goto out_free_slim;
6423
6424 hbq_count = lpfc_sli_hbq_count();
6425 ptr = phba->hbqslimp.virt;
6426 for (i = 0; i < hbq_count; ++i) {
6427 phba->hbqs[i].hbq_virt = ptr;
6428 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
6429 ptr += (lpfc_hbq_defs[i]->entry_count *
6430 sizeof(struct lpfc_hbq_entry));
6431 }
6432 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
6433 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
6434
6435 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
6436
6437 INIT_LIST_HEAD(&phba->rb_pend_list);
6438
6439 phba->MBslimaddr = phba->slim_memmap_p;
6440 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
6441 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
6442 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
6443 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04006444
dea31012005-04-17 16:05:31 -05006445 return 0;
6446
dea31012005-04-17 16:05:31 -05006447out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04006448 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6449 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05006450out_iounmap:
6451 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006452out_iounmap_slim:
dea31012005-04-17 16:05:31 -05006453 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05006454out:
6455 return error;
6456}
6457
James Smarte59058c2008-08-24 21:49:00 -04006458/**
James Smart3772a992009-05-22 14:50:54 -04006459 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
6460 * @phba: pointer to lpfc hba data structure.
6461 *
6462 * This routine is invoked to unset the PCI device memory space for device
6463 * with SLI-3 interface spec.
6464 **/
6465static void
6466lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
6467{
6468 struct pci_dev *pdev;
6469
6470 /* Obtain PCI device reference */
6471 if (!phba->pcidev)
6472 return;
6473 else
6474 pdev = phba->pcidev;
6475
6476 /* Free coherent DMA memory allocated */
6477 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
6478 phba->hbqslimp.virt, phba->hbqslimp.phys);
6479 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6480 phba->slim2p.virt, phba->slim2p.phys);
6481
6482 /* I/O memory unmap */
6483 iounmap(phba->ctrl_regs_memmap_p);
6484 iounmap(phba->slim_memmap_p);
6485
6486 return;
6487}
6488
6489/**
James Smartda0436e2009-05-22 14:51:39 -04006490 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
6491 * @phba: pointer to lpfc hba data structure.
6492 *
6493 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
6494 * done and check status.
6495 *
6496 * Return 0 if successful, otherwise -ENODEV.
6497 **/
6498int
6499lpfc_sli4_post_status_check(struct lpfc_hba *phba)
6500{
James Smart2fcee4b2010-12-15 17:57:46 -05006501 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
6502 struct lpfc_register reg_data;
6503 int i, port_error = 0;
6504 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04006505
James Smart9940b972011-03-11 16:06:12 -05006506 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
6507 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05006508 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04006509 return -ENODEV;
6510
James Smartda0436e2009-05-22 14:51:39 -04006511 /* Wait up to 30 seconds for the SLI Port POST done and ready */
6512 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05006513 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
6514 &portsmphr_reg.word0) ||
6515 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006516 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04006517 port_error = -ENODEV;
6518 break;
6519 }
James Smart2fcee4b2010-12-15 17:57:46 -05006520 if (LPFC_POST_STAGE_PORT_READY ==
6521 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04006522 break;
James Smartda0436e2009-05-22 14:51:39 -04006523 msleep(10);
6524 }
6525
James Smart2fcee4b2010-12-15 17:57:46 -05006526 /*
6527 * If there was a port error during POST, then don't proceed with
6528 * other register reads as the data may not be valid. Just exit.
6529 */
6530 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04006531 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006532 "1408 Port Failed POST - portsmphr=0x%x, "
6533 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
6534 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
6535 portsmphr_reg.word0,
6536 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
6537 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
6538 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
6539 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
6540 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
6541 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
6542 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
6543 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
6544 } else {
James Smart28baac72010-02-12 14:42:03 -05006545 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006546 "2534 Device Info: SLIFamily=0x%x, "
6547 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
6548 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05006549 bf_get(lpfc_sli_intf_sli_family,
6550 &phba->sli4_hba.sli_intf),
6551 bf_get(lpfc_sli_intf_slirev,
6552 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006553 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05006554 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006555 bf_get(lpfc_sli_intf_sli_hint1,
6556 &phba->sli4_hba.sli_intf),
6557 bf_get(lpfc_sli_intf_sli_hint2,
6558 &phba->sli4_hba.sli_intf),
6559 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05006560 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05006561 /*
6562 * Check for other Port errors during the initialization
6563 * process. Fail the load if the port did not come up
6564 * correctly.
6565 */
6566 if_type = bf_get(lpfc_sli_intf_if_type,
6567 &phba->sli4_hba.sli_intf);
6568 switch (if_type) {
6569 case LPFC_SLI_INTF_IF_TYPE_0:
6570 phba->sli4_hba.ue_mask_lo =
6571 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
6572 phba->sli4_hba.ue_mask_hi =
6573 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
6574 uerrlo_reg.word0 =
6575 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
6576 uerrhi_reg.word0 =
6577 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
6578 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
6579 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
6580 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6581 "1422 Unrecoverable Error "
6582 "Detected during POST "
6583 "uerr_lo_reg=0x%x, "
6584 "uerr_hi_reg=0x%x, "
6585 "ue_mask_lo_reg=0x%x, "
6586 "ue_mask_hi_reg=0x%x\n",
6587 uerrlo_reg.word0,
6588 uerrhi_reg.word0,
6589 phba->sli4_hba.ue_mask_lo,
6590 phba->sli4_hba.ue_mask_hi);
6591 port_error = -ENODEV;
6592 }
6593 break;
6594 case LPFC_SLI_INTF_IF_TYPE_2:
6595 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05006596 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
6597 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04006598 (bf_get(lpfc_sliport_status_err, &reg_data) &&
6599 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006600 phba->work_status[0] =
6601 readl(phba->sli4_hba.u.if_type2.
6602 ERR1regaddr);
6603 phba->work_status[1] =
6604 readl(phba->sli4_hba.u.if_type2.
6605 ERR2regaddr);
6606 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05006607 "2888 Unrecoverable port error "
6608 "following POST: port status reg "
6609 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05006610 "error 1=0x%x, error 2=0x%x\n",
6611 reg_data.word0,
6612 portsmphr_reg.word0,
6613 phba->work_status[0],
6614 phba->work_status[1]);
6615 port_error = -ENODEV;
6616 }
6617 break;
6618 case LPFC_SLI_INTF_IF_TYPE_1:
6619 default:
6620 break;
6621 }
James Smart28baac72010-02-12 14:42:03 -05006622 }
James Smartda0436e2009-05-22 14:51:39 -04006623 return port_error;
6624}
6625
6626/**
6627 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
6628 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05006629 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04006630 *
6631 * This routine is invoked to set up SLI4 BAR0 PCI config space register
6632 * memory map.
6633 **/
6634static void
James Smart2fcee4b2010-12-15 17:57:46 -05006635lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04006636{
James Smart2fcee4b2010-12-15 17:57:46 -05006637 switch (if_type) {
6638 case LPFC_SLI_INTF_IF_TYPE_0:
6639 phba->sli4_hba.u.if_type0.UERRLOregaddr =
6640 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
6641 phba->sli4_hba.u.if_type0.UERRHIregaddr =
6642 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
6643 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
6644 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
6645 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
6646 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
6647 phba->sli4_hba.SLIINTFregaddr =
6648 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6649 break;
6650 case LPFC_SLI_INTF_IF_TYPE_2:
6651 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006652 phba->sli4_hba.conf_regs_memmap_p +
6653 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006654 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006655 phba->sli4_hba.conf_regs_memmap_p +
6656 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006657 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006658 phba->sli4_hba.conf_regs_memmap_p +
6659 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006660 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006661 phba->sli4_hba.conf_regs_memmap_p +
6662 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006663 phba->sli4_hba.SLIINTFregaddr =
6664 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6665 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006666 phba->sli4_hba.conf_regs_memmap_p +
6667 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006668 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006669 phba->sli4_hba.conf_regs_memmap_p +
6670 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006671 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006672 phba->sli4_hba.conf_regs_memmap_p +
6673 LPFC_ULP0_WQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006674 phba->sli4_hba.EQCQDBregaddr =
6675 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
6676 phba->sli4_hba.MQDBregaddr =
6677 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
6678 phba->sli4_hba.BMBXregaddr =
6679 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
6680 break;
6681 case LPFC_SLI_INTF_IF_TYPE_1:
6682 default:
6683 dev_printk(KERN_ERR, &phba->pcidev->dev,
6684 "FATAL - unsupported SLI4 interface type - %d\n",
6685 if_type);
6686 break;
6687 }
James Smartda0436e2009-05-22 14:51:39 -04006688}
6689
6690/**
6691 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
6692 * @phba: pointer to lpfc hba data structure.
6693 *
6694 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
6695 * memory map.
6696 **/
6697static void
6698lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
6699{
James Smart2fcee4b2010-12-15 17:57:46 -05006700 phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
6701 LPFC_SLIPORT_IF0_SMPHR;
James Smartda0436e2009-05-22 14:51:39 -04006702 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006703 LPFC_HST_ISR0;
James Smartda0436e2009-05-22 14:51:39 -04006704 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006705 LPFC_HST_IMR0;
James Smartda0436e2009-05-22 14:51:39 -04006706 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006707 LPFC_HST_ISCR0;
James Smartda0436e2009-05-22 14:51:39 -04006708}
6709
6710/**
6711 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
6712 * @phba: pointer to lpfc hba data structure.
6713 * @vf: virtual function number
6714 *
6715 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
6716 * based on the given viftual function number, @vf.
6717 *
6718 * Return 0 if successful, otherwise -ENODEV.
6719 **/
6720static int
6721lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
6722{
6723 if (vf > LPFC_VIR_FUNC_MAX)
6724 return -ENODEV;
6725
6726 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05006727 vf * LPFC_VFR_PAGE_SIZE +
6728 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04006729 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05006730 vf * LPFC_VFR_PAGE_SIZE +
6731 LPFC_ULP0_WQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04006732 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6733 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
6734 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6735 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
6736 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6737 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
6738 return 0;
6739}
6740
6741/**
6742 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
6743 * @phba: pointer to lpfc hba data structure.
6744 *
6745 * This routine is invoked to create the bootstrap mailbox
6746 * region consistent with the SLI-4 interface spec. This
6747 * routine allocates all memory necessary to communicate
6748 * mailbox commands to the port and sets up all alignment
6749 * needs. No locks are expected to be held when calling
6750 * this routine.
6751 *
6752 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006753 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04006754 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04006755 **/
6756static int
6757lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
6758{
6759 uint32_t bmbx_size;
6760 struct lpfc_dmabuf *dmabuf;
6761 struct dma_address *dma_address;
6762 uint32_t pa_addr;
6763 uint64_t phys_addr;
6764
6765 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6766 if (!dmabuf)
6767 return -ENOMEM;
6768
6769 /*
6770 * The bootstrap mailbox region is comprised of 2 parts
6771 * plus an alignment restriction of 16 bytes.
6772 */
6773 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
Joe Perches1aee3832014-09-03 12:56:12 -04006774 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
6775 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04006776 if (!dmabuf->virt) {
6777 kfree(dmabuf);
6778 return -ENOMEM;
6779 }
James Smartda0436e2009-05-22 14:51:39 -04006780
6781 /*
6782 * Initialize the bootstrap mailbox pointers now so that the register
6783 * operations are simple later. The mailbox dma address is required
6784 * to be 16-byte aligned. Also align the virtual memory as each
6785 * maibox is copied into the bmbx mailbox region before issuing the
6786 * command to the port.
6787 */
6788 phba->sli4_hba.bmbx.dmabuf = dmabuf;
6789 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
6790
6791 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
6792 LPFC_ALIGN_16_BYTE);
6793 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
6794 LPFC_ALIGN_16_BYTE);
6795
6796 /*
6797 * Set the high and low physical addresses now. The SLI4 alignment
6798 * requirement is 16 bytes and the mailbox is posted to the port
6799 * as two 30-bit addresses. The other data is a bit marking whether
6800 * the 30-bit address is the high or low address.
6801 * Upcast bmbx aphys to 64bits so shift instruction compiles
6802 * clean on 32 bit machines.
6803 */
6804 dma_address = &phba->sli4_hba.bmbx.dma_address;
6805 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
6806 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
6807 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
6808 LPFC_BMBX_BIT1_ADDR_HI);
6809
6810 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
6811 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
6812 LPFC_BMBX_BIT1_ADDR_LO);
6813 return 0;
6814}
6815
6816/**
6817 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
6818 * @phba: pointer to lpfc hba data structure.
6819 *
6820 * This routine is invoked to teardown the bootstrap mailbox
6821 * region and release all host resources. This routine requires
6822 * the caller to ensure all mailbox commands recovered, no
6823 * additional mailbox comands are sent, and interrupts are disabled
6824 * before calling this routine.
6825 *
6826 **/
6827static void
6828lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
6829{
6830 dma_free_coherent(&phba->pcidev->dev,
6831 phba->sli4_hba.bmbx.bmbx_size,
6832 phba->sli4_hba.bmbx.dmabuf->virt,
6833 phba->sli4_hba.bmbx.dmabuf->phys);
6834
6835 kfree(phba->sli4_hba.bmbx.dmabuf);
6836 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
6837}
6838
6839/**
6840 * lpfc_sli4_read_config - Get the config parameters.
6841 * @phba: pointer to lpfc hba data structure.
6842 *
6843 * This routine is invoked to read the configuration parameters from the HBA.
6844 * The configuration parameters are used to set the base and maximum values
6845 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
6846 * allocation for the port.
6847 *
6848 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006849 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006850 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006851 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006852 **/
James Smartff78d8f2011-12-13 13:21:35 -05006853int
James Smartda0436e2009-05-22 14:51:39 -04006854lpfc_sli4_read_config(struct lpfc_hba *phba)
6855{
6856 LPFC_MBOXQ_t *pmb;
6857 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04006858 union lpfc_sli4_cfg_shdr *shdr;
6859 uint32_t shdr_status, shdr_add_status;
6860 struct lpfc_mbx_get_func_cfg *get_func_cfg;
6861 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04006862 char *pdesc_0;
James Smart8aa134a2012-08-14 14:25:29 -04006863 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04006864
6865 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6866 if (!pmb) {
6867 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6868 "2011 Unable to allocate memory for issuing "
6869 "SLI_CONFIG_SPECIAL mailbox command\n");
6870 return -ENOMEM;
6871 }
6872
6873 lpfc_read_config(phba, pmb);
6874
6875 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
6876 if (rc != MBX_SUCCESS) {
6877 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6878 "2012 Mailbox failed , mbxCmd x%x "
6879 "READ_CONFIG, mbxStatus x%x\n",
6880 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6881 bf_get(lpfc_mqe_status, &pmb->u.mqe));
6882 rc = -EIO;
6883 } else {
6884 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05006885 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
6886 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
6887 phba->sli4_hba.lnk_info.lnk_tp =
6888 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
6889 phba->sli4_hba.lnk_info.lnk_no =
6890 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
6891 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6892 "3081 lnk_type:%d, lnk_numb:%d\n",
6893 phba->sli4_hba.lnk_info.lnk_tp,
6894 phba->sli4_hba.lnk_info.lnk_no);
6895 } else
6896 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6897 "3082 Mailbox (x%x) returned ldv:x0\n",
6898 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart6d368e52011-05-24 11:44:12 -04006899 phba->sli4_hba.extents_in_use =
6900 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04006901 phba->sli4_hba.max_cfg_param.max_xri =
6902 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
6903 phba->sli4_hba.max_cfg_param.xri_base =
6904 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
6905 phba->sli4_hba.max_cfg_param.max_vpi =
6906 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
6907 phba->sli4_hba.max_cfg_param.vpi_base =
6908 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
6909 phba->sli4_hba.max_cfg_param.max_rpi =
6910 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
6911 phba->sli4_hba.max_cfg_param.rpi_base =
6912 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
6913 phba->sli4_hba.max_cfg_param.max_vfi =
6914 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
6915 phba->sli4_hba.max_cfg_param.vfi_base =
6916 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
6917 phba->sli4_hba.max_cfg_param.max_fcfi =
6918 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04006919 phba->sli4_hba.max_cfg_param.max_eq =
6920 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
6921 phba->sli4_hba.max_cfg_param.max_rq =
6922 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
6923 phba->sli4_hba.max_cfg_param.max_wq =
6924 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
6925 phba->sli4_hba.max_cfg_param.max_cq =
6926 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
6927 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
6928 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
6929 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
6930 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05006931 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
6932 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04006933 phba->max_vports = phba->max_vpi;
6934 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04006935 "2003 cfg params Extents? %d "
6936 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04006937 "VPI(B:%d M:%d) "
6938 "VFI(B:%d M:%d) "
6939 "RPI(B:%d M:%d) "
James Smart6d368e52011-05-24 11:44:12 -04006940 "FCFI(Count:%d)\n",
6941 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04006942 phba->sli4_hba.max_cfg_param.xri_base,
6943 phba->sli4_hba.max_cfg_param.max_xri,
6944 phba->sli4_hba.max_cfg_param.vpi_base,
6945 phba->sli4_hba.max_cfg_param.max_vpi,
6946 phba->sli4_hba.max_cfg_param.vfi_base,
6947 phba->sli4_hba.max_cfg_param.max_vfi,
6948 phba->sli4_hba.max_cfg_param.rpi_base,
6949 phba->sli4_hba.max_cfg_param.max_rpi,
James Smartda0436e2009-05-22 14:51:39 -04006950 phba->sli4_hba.max_cfg_param.max_fcfi);
6951 }
James Smart912e3ac2011-05-24 11:42:11 -04006952
6953 if (rc)
6954 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04006955
6956 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -04006957 length = phba->sli4_hba.max_cfg_param.max_xri -
6958 lpfc_sli4_get_els_iocb_cnt(phba);
6959 if (phba->cfg_hba_queue_depth > length) {
6960 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6961 "3361 HBA queue depth changed from %d to %d\n",
6962 phba->cfg_hba_queue_depth, length);
6963 phba->cfg_hba_queue_depth = length;
6964 }
James Smart912e3ac2011-05-24 11:42:11 -04006965
6966 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
6967 LPFC_SLI_INTF_IF_TYPE_2)
6968 goto read_cfg_out;
6969
6970 /* get the pf# and vf# for SLI4 if_type 2 port */
6971 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
6972 sizeof(struct lpfc_sli4_cfg_mhdr));
6973 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
6974 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
6975 length, LPFC_SLI4_MBX_EMBED);
6976
James Smart8aa134a2012-08-14 14:25:29 -04006977 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04006978 shdr = (union lpfc_sli4_cfg_shdr *)
6979 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
6980 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6981 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04006982 if (rc2 || shdr_status || shdr_add_status) {
James Smart912e3ac2011-05-24 11:42:11 -04006983 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6984 "3026 Mailbox failed , mbxCmd x%x "
6985 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
6986 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6987 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04006988 goto read_cfg_out;
6989 }
6990
6991 /* search for fc_fcoe resrouce descriptor */
6992 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
James Smart912e3ac2011-05-24 11:42:11 -04006993
James Smart8aa134a2012-08-14 14:25:29 -04006994 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
6995 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
6996 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
6997 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
6998 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
6999 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
7000 goto read_cfg_out;
7001
James Smart912e3ac2011-05-24 11:42:11 -04007002 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04007003 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04007004 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04007005 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04007006 phba->sli4_hba.iov.pf_number =
7007 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
7008 phba->sli4_hba.iov.vf_number =
7009 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
7010 break;
7011 }
7012 }
7013
7014 if (i < LPFC_RSRC_DESC_MAX_NUM)
7015 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7016 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
7017 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
7018 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04007019 else
James Smart912e3ac2011-05-24 11:42:11 -04007020 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7021 "3028 GET_FUNCTION_CONFIG: failed to find "
7022 "Resrouce Descriptor:x%x\n",
7023 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04007024
7025read_cfg_out:
7026 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04007027 return rc;
7028}
7029
7030/**
James Smart2fcee4b2010-12-15 17:57:46 -05007031 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04007032 * @phba: pointer to lpfc hba data structure.
7033 *
James Smart2fcee4b2010-12-15 17:57:46 -05007034 * This routine is invoked to setup the port-side endian order when
7035 * the port if_type is 0. This routine has no function for other
7036 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04007037 *
7038 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007039 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007040 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007041 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007042 **/
7043static int
7044lpfc_setup_endian_order(struct lpfc_hba *phba)
7045{
7046 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05007047 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04007048 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
7049 HOST_ENDIAN_HIGH_WORD1};
7050
James Smart2fcee4b2010-12-15 17:57:46 -05007051 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7052 switch (if_type) {
7053 case LPFC_SLI_INTF_IF_TYPE_0:
7054 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7055 GFP_KERNEL);
7056 if (!mboxq) {
7057 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7058 "0492 Unable to allocate memory for "
7059 "issuing SLI_CONFIG_SPECIAL mailbox "
7060 "command\n");
7061 return -ENOMEM;
7062 }
James Smartda0436e2009-05-22 14:51:39 -04007063
James Smart2fcee4b2010-12-15 17:57:46 -05007064 /*
7065 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
7066 * two words to contain special data values and no other data.
7067 */
7068 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
7069 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
7070 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7071 if (rc != MBX_SUCCESS) {
7072 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7073 "0493 SLI_CONFIG_SPECIAL mailbox "
7074 "failed with status x%x\n",
7075 rc);
7076 rc = -EIO;
7077 }
7078 mempool_free(mboxq, phba->mbox_mem_pool);
7079 break;
7080 case LPFC_SLI_INTF_IF_TYPE_2:
7081 case LPFC_SLI_INTF_IF_TYPE_1:
7082 default:
7083 break;
James Smartda0436e2009-05-22 14:51:39 -04007084 }
James Smartda0436e2009-05-22 14:51:39 -04007085 return rc;
7086}
7087
7088/**
James Smart5350d872011-10-10 21:33:49 -04007089 * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts
James Smartda0436e2009-05-22 14:51:39 -04007090 * @phba: pointer to lpfc hba data structure.
7091 *
James Smart5350d872011-10-10 21:33:49 -04007092 * This routine is invoked to check the user settable queue counts for EQs and
7093 * CQs. after this routine is called the counts will be set to valid values that
7094 * adhere to the constraints of the system's interrupt vectors and the port's
7095 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04007096 *
7097 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007098 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007099 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007100 **/
7101static int
James Smart5350d872011-10-10 21:33:49 -04007102lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04007103{
James Smart67d12732012-08-03 12:36:13 -04007104 int cfg_fcp_io_channel;
James Smart90695ee2012-08-14 14:25:36 -04007105 uint32_t cpu;
7106 uint32_t i = 0;
James Smart1ba981f2014-02-20 09:56:45 -05007107 int fof_vectors = phba->cfg_fof ? 1 : 0;
James Smartda0436e2009-05-22 14:51:39 -04007108
7109 /*
James Smart67d12732012-08-03 12:36:13 -04007110 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04007111 * device parameters
7112 */
7113
James Smart67d12732012-08-03 12:36:13 -04007114 /* Sanity check on HBA EQ parameters */
7115 cfg_fcp_io_channel = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04007116
James Smart7bb03bb2013-04-17 20:19:16 -04007117 /* It doesn't make sense to have more io channels then online CPUs */
7118 for_each_present_cpu(cpu) {
7119 if (cpu_online(cpu))
7120 i++;
James Smart90695ee2012-08-14 14:25:36 -04007121 }
James Smart7bb03bb2013-04-17 20:19:16 -04007122 phba->sli4_hba.num_online_cpu = i;
James Smartb246de12013-05-31 17:03:07 -04007123 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
James Smart76fd07a2014-02-20 09:57:18 -05007124 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04007125
James Smart90695ee2012-08-14 14:25:36 -04007126 if (i < cfg_fcp_io_channel) {
James Smart82c3e9b2012-09-29 11:29:50 -04007127 lpfc_printf_log(phba,
7128 KERN_ERR, LOG_INIT,
James Smart90695ee2012-08-14 14:25:36 -04007129 "3188 Reducing IO channels to match number of "
James Smart7bb03bb2013-04-17 20:19:16 -04007130 "online CPUs: from %d to %d\n",
7131 cfg_fcp_io_channel, i);
James Smart90695ee2012-08-14 14:25:36 -04007132 cfg_fcp_io_channel = i;
7133 }
7134
James Smart1ba981f2014-02-20 09:56:45 -05007135 if (cfg_fcp_io_channel + fof_vectors >
James Smart67d12732012-08-03 12:36:13 -04007136 phba->sli4_hba.max_cfg_param.max_eq) {
James Smart82c3e9b2012-09-29 11:29:50 -04007137 if (phba->sli4_hba.max_cfg_param.max_eq <
7138 LPFC_FCP_IO_CHAN_MIN) {
James Smartda0436e2009-05-22 14:51:39 -04007139 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7140 "2574 Not enough EQs (%d) from the "
7141 "pci function for supporting FCP "
7142 "EQs (%d)\n",
7143 phba->sli4_hba.max_cfg_param.max_eq,
James Smart67d12732012-08-03 12:36:13 -04007144 phba->cfg_fcp_io_channel);
James Smartda0436e2009-05-22 14:51:39 -04007145 goto out_error;
7146 }
James Smart82c3e9b2012-09-29 11:29:50 -04007147 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7148 "2575 Reducing IO channels to match number of "
7149 "available EQs: from %d to %d\n",
7150 cfg_fcp_io_channel,
7151 phba->sli4_hba.max_cfg_param.max_eq);
James Smart1ba981f2014-02-20 09:56:45 -05007152 cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq -
7153 fof_vectors;
James Smartda0436e2009-05-22 14:51:39 -04007154 }
James Smart67d12732012-08-03 12:36:13 -04007155
James Smartda0436e2009-05-22 14:51:39 -04007156 /* The actual number of FCP event queues adopted */
James Smart67d12732012-08-03 12:36:13 -04007157 phba->cfg_fcp_io_channel = cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04007158
James Smartda0436e2009-05-22 14:51:39 -04007159 /* Get EQ depth from module parameter, fake the default for now */
7160 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
7161 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
7162
James Smart5350d872011-10-10 21:33:49 -04007163 /* Get CQ depth from module parameter, fake the default for now */
7164 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
7165 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
7166
7167 return 0;
7168out_error:
7169 return -ENOMEM;
7170}
7171
7172/**
7173 * lpfc_sli4_queue_create - Create all the SLI4 queues
7174 * @phba: pointer to lpfc hba data structure.
7175 *
7176 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
7177 * operation. For each SLI4 queue type, the parameters such as queue entry
7178 * count (queue depth) shall be taken from the module parameter. For now,
7179 * we just use some constant number as place holder.
7180 *
7181 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07007182 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04007183 * -ENOMEM - No availble memory
7184 * -EIO - The mailbox failed to complete successfully.
7185 **/
7186int
7187lpfc_sli4_queue_create(struct lpfc_hba *phba)
7188{
7189 struct lpfc_queue *qdesc;
James Smart67d12732012-08-03 12:36:13 -04007190 int idx;
James Smart5350d872011-10-10 21:33:49 -04007191
7192 /*
James Smart67d12732012-08-03 12:36:13 -04007193 * Create HBA Record arrays.
James Smart5350d872011-10-10 21:33:49 -04007194 */
James Smart67d12732012-08-03 12:36:13 -04007195 if (!phba->cfg_fcp_io_channel)
7196 return -ERANGE;
James Smart5350d872011-10-10 21:33:49 -04007197
James Smart67d12732012-08-03 12:36:13 -04007198 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
7199 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
7200 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
7201 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
7202 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
7203 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
7204
7205 phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) *
7206 phba->cfg_fcp_io_channel), GFP_KERNEL);
7207 if (!phba->sli4_hba.hba_eq) {
James Smartda0436e2009-05-22 14:51:39 -04007208 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007209 "2576 Failed allocate memory for "
7210 "fast-path EQ record array\n");
James Smartda0436e2009-05-22 14:51:39 -04007211 goto out_error;
7212 }
James Smart67d12732012-08-03 12:36:13 -04007213
7214 phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
7215 phba->cfg_fcp_io_channel), GFP_KERNEL);
7216 if (!phba->sli4_hba.fcp_cq) {
7217 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7218 "2577 Failed allocate memory for fast-path "
7219 "CQ record array\n");
7220 goto out_error;
7221 }
7222
7223 phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
7224 phba->cfg_fcp_io_channel), GFP_KERNEL);
7225 if (!phba->sli4_hba.fcp_wq) {
7226 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7227 "2578 Failed allocate memory for fast-path "
7228 "WQ record array\n");
7229 goto out_error;
7230 }
James Smartda0436e2009-05-22 14:51:39 -04007231
James Smart5350d872011-10-10 21:33:49 -04007232 /*
James Smart67d12732012-08-03 12:36:13 -04007233 * Since the first EQ can have multiple CQs associated with it,
7234 * this array is used to quickly see if we have a FCP fast-path
7235 * CQ match.
James Smart5350d872011-10-10 21:33:49 -04007236 */
James Smart67d12732012-08-03 12:36:13 -04007237 phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) *
7238 phba->cfg_fcp_io_channel), GFP_KERNEL);
7239 if (!phba->sli4_hba.fcp_cq_map) {
7240 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7241 "2545 Failed allocate memory for fast-path "
7242 "CQ map\n");
7243 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007244 }
James Smart67d12732012-08-03 12:36:13 -04007245
7246 /*
7247 * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies
7248 * how many EQs to create.
7249 */
7250 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7251
7252 /* Create EQs */
James Smartda0436e2009-05-22 14:51:39 -04007253 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
7254 phba->sli4_hba.eq_ecount);
7255 if (!qdesc) {
7256 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007257 "0497 Failed allocate EQ (%d)\n", idx);
7258 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007259 }
James Smart67d12732012-08-03 12:36:13 -04007260 phba->sli4_hba.hba_eq[idx] = qdesc;
7261
7262 /* Create Fast Path FCP CQs */
7263 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7264 phba->sli4_hba.cq_ecount);
7265 if (!qdesc) {
7266 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7267 "0499 Failed allocate fast-path FCP "
7268 "CQ (%d)\n", idx);
7269 goto out_error;
7270 }
7271 phba->sli4_hba.fcp_cq[idx] = qdesc;
7272
7273 /* Create Fast Path FCP WQs */
7274 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
7275 phba->sli4_hba.wq_ecount);
7276 if (!qdesc) {
7277 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7278 "0503 Failed allocate fast-path FCP "
7279 "WQ (%d)\n", idx);
7280 goto out_error;
7281 }
7282 phba->sli4_hba.fcp_wq[idx] = qdesc;
James Smartda0436e2009-05-22 14:51:39 -04007283 }
7284
James Smart67d12732012-08-03 12:36:13 -04007285
James Smartda0436e2009-05-22 14:51:39 -04007286 /*
James Smart67d12732012-08-03 12:36:13 -04007287 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04007288 */
7289
James Smartda0436e2009-05-22 14:51:39 -04007290 /* Create slow-path Mailbox Command Complete Queue */
7291 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7292 phba->sli4_hba.cq_ecount);
7293 if (!qdesc) {
7294 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7295 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04007296 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007297 }
7298 phba->sli4_hba.mbx_cq = qdesc;
7299
7300 /* Create slow-path ELS Complete Queue */
7301 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7302 phba->sli4_hba.cq_ecount);
7303 if (!qdesc) {
7304 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7305 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -04007306 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007307 }
7308 phba->sli4_hba.els_cq = qdesc;
7309
James Smartda0436e2009-05-22 14:51:39 -04007310
James Smart5350d872011-10-10 21:33:49 -04007311 /*
James Smart67d12732012-08-03 12:36:13 -04007312 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04007313 */
James Smartda0436e2009-05-22 14:51:39 -04007314
7315 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04007316
7317 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
7318 phba->sli4_hba.mq_ecount);
7319 if (!qdesc) {
7320 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7321 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04007322 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007323 }
7324 phba->sli4_hba.mbx_wq = qdesc;
7325
7326 /*
James Smart67d12732012-08-03 12:36:13 -04007327 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04007328 */
James Smartda0436e2009-05-22 14:51:39 -04007329
7330 /* Create slow-path ELS Work Queue */
7331 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
7332 phba->sli4_hba.wq_ecount);
7333 if (!qdesc) {
7334 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7335 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04007336 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007337 }
7338 phba->sli4_hba.els_wq = qdesc;
7339
James Smartda0436e2009-05-22 14:51:39 -04007340 /*
7341 * Create Receive Queue (RQ)
7342 */
James Smartda0436e2009-05-22 14:51:39 -04007343
7344 /* Create Receive Queue for header */
7345 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
7346 phba->sli4_hba.rq_ecount);
7347 if (!qdesc) {
7348 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7349 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04007350 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007351 }
7352 phba->sli4_hba.hdr_rq = qdesc;
7353
7354 /* Create Receive Queue for data */
7355 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
7356 phba->sli4_hba.rq_ecount);
7357 if (!qdesc) {
7358 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7359 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04007360 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007361 }
7362 phba->sli4_hba.dat_rq = qdesc;
7363
James Smart1ba981f2014-02-20 09:56:45 -05007364 /* Create the Queues needed for Flash Optimized Fabric operations */
7365 if (phba->cfg_fof)
7366 lpfc_fof_queue_create(phba);
James Smartda0436e2009-05-22 14:51:39 -04007367 return 0;
7368
James Smartda0436e2009-05-22 14:51:39 -04007369out_error:
James Smart67d12732012-08-03 12:36:13 -04007370 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04007371 return -ENOMEM;
7372}
7373
7374/**
7375 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
7376 * @phba: pointer to lpfc hba data structure.
7377 *
7378 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
7379 * operation.
7380 *
7381 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007382 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007383 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007384 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007385 **/
James Smart5350d872011-10-10 21:33:49 -04007386void
James Smartda0436e2009-05-22 14:51:39 -04007387lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
7388{
James Smart67d12732012-08-03 12:36:13 -04007389 int idx;
7390
James Smart1ba981f2014-02-20 09:56:45 -05007391 if (phba->cfg_fof)
7392 lpfc_fof_queue_destroy(phba);
7393
James Smart67d12732012-08-03 12:36:13 -04007394 if (phba->sli4_hba.hba_eq != NULL) {
7395 /* Release HBA event queue */
7396 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7397 if (phba->sli4_hba.hba_eq[idx] != NULL) {
7398 lpfc_sli4_queue_free(
7399 phba->sli4_hba.hba_eq[idx]);
7400 phba->sli4_hba.hba_eq[idx] = NULL;
7401 }
7402 }
7403 kfree(phba->sli4_hba.hba_eq);
7404 phba->sli4_hba.hba_eq = NULL;
7405 }
7406
7407 if (phba->sli4_hba.fcp_cq != NULL) {
7408 /* Release FCP completion queue */
7409 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7410 if (phba->sli4_hba.fcp_cq[idx] != NULL) {
7411 lpfc_sli4_queue_free(
7412 phba->sli4_hba.fcp_cq[idx]);
7413 phba->sli4_hba.fcp_cq[idx] = NULL;
7414 }
7415 }
7416 kfree(phba->sli4_hba.fcp_cq);
7417 phba->sli4_hba.fcp_cq = NULL;
7418 }
7419
7420 if (phba->sli4_hba.fcp_wq != NULL) {
7421 /* Release FCP work queue */
7422 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7423 if (phba->sli4_hba.fcp_wq[idx] != NULL) {
7424 lpfc_sli4_queue_free(
7425 phba->sli4_hba.fcp_wq[idx]);
7426 phba->sli4_hba.fcp_wq[idx] = NULL;
7427 }
7428 }
7429 kfree(phba->sli4_hba.fcp_wq);
7430 phba->sli4_hba.fcp_wq = NULL;
7431 }
7432
7433 /* Release FCP CQ mapping array */
7434 if (phba->sli4_hba.fcp_cq_map != NULL) {
7435 kfree(phba->sli4_hba.fcp_cq_map);
7436 phba->sli4_hba.fcp_cq_map = NULL;
7437 }
James Smartda0436e2009-05-22 14:51:39 -04007438
7439 /* Release mailbox command work queue */
James Smart67d12732012-08-03 12:36:13 -04007440 if (phba->sli4_hba.mbx_wq != NULL) {
7441 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
7442 phba->sli4_hba.mbx_wq = NULL;
7443 }
James Smartda0436e2009-05-22 14:51:39 -04007444
7445 /* Release ELS work queue */
James Smart67d12732012-08-03 12:36:13 -04007446 if (phba->sli4_hba.els_wq != NULL) {
7447 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
7448 phba->sli4_hba.els_wq = NULL;
7449 }
James Smartda0436e2009-05-22 14:51:39 -04007450
7451 /* Release unsolicited receive queue */
James Smart67d12732012-08-03 12:36:13 -04007452 if (phba->sli4_hba.hdr_rq != NULL) {
7453 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
7454 phba->sli4_hba.hdr_rq = NULL;
7455 }
7456 if (phba->sli4_hba.dat_rq != NULL) {
7457 lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
7458 phba->sli4_hba.dat_rq = NULL;
7459 }
James Smartda0436e2009-05-22 14:51:39 -04007460
James Smartda0436e2009-05-22 14:51:39 -04007461 /* Release ELS complete queue */
James Smart67d12732012-08-03 12:36:13 -04007462 if (phba->sli4_hba.els_cq != NULL) {
7463 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
7464 phba->sli4_hba.els_cq = NULL;
7465 }
James Smartda0436e2009-05-22 14:51:39 -04007466
7467 /* Release mailbox command complete queue */
James Smart67d12732012-08-03 12:36:13 -04007468 if (phba->sli4_hba.mbx_cq != NULL) {
7469 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
7470 phba->sli4_hba.mbx_cq = NULL;
7471 }
James Smartda0436e2009-05-22 14:51:39 -04007472
7473 return;
7474}
7475
7476/**
7477 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
7478 * @phba: pointer to lpfc hba data structure.
7479 *
7480 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
7481 * operation.
7482 *
7483 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007484 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007485 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007486 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007487 **/
7488int
7489lpfc_sli4_queue_setup(struct lpfc_hba *phba)
7490{
James Smart2a76a282012-08-03 12:35:54 -04007491 struct lpfc_sli *psli = &phba->sli;
7492 struct lpfc_sli_ring *pring;
James Smartda0436e2009-05-22 14:51:39 -04007493 int rc = -ENOMEM;
7494 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
7495 int fcp_cq_index = 0;
James Smart962bc512013-01-03 15:44:00 -05007496 uint32_t shdr_status, shdr_add_status;
7497 union lpfc_sli4_cfg_shdr *shdr;
7498 LPFC_MBOXQ_t *mboxq;
7499 uint32_t length;
7500
7501 /* Check for dual-ULP support */
7502 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7503 if (!mboxq) {
7504 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7505 "3249 Unable to allocate memory for "
7506 "QUERY_FW_CFG mailbox command\n");
7507 return -ENOMEM;
7508 }
7509 length = (sizeof(struct lpfc_mbx_query_fw_config) -
7510 sizeof(struct lpfc_sli4_cfg_mhdr));
7511 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
7512 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
7513 length, LPFC_SLI4_MBX_EMBED);
7514
7515 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7516
7517 shdr = (union lpfc_sli4_cfg_shdr *)
7518 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
7519 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7520 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7521 if (shdr_status || shdr_add_status || rc) {
7522 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7523 "3250 QUERY_FW_CFG mailbox failed with status "
7524 "x%x add_status x%x, mbx status x%x\n",
7525 shdr_status, shdr_add_status, rc);
7526 if (rc != MBX_TIMEOUT)
7527 mempool_free(mboxq, phba->mbox_mem_pool);
7528 rc = -ENXIO;
7529 goto out_error;
7530 }
7531
7532 phba->sli4_hba.fw_func_mode =
7533 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
7534 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
7535 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
James Smart8b017a32015-05-21 13:55:18 -04007536 phba->sli4_hba.physical_port =
7537 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
James Smart962bc512013-01-03 15:44:00 -05007538 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7539 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
7540 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
7541 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
7542
7543 if (rc != MBX_TIMEOUT)
7544 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04007545
7546 /*
James Smart67d12732012-08-03 12:36:13 -04007547 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04007548 */
7549
James Smart67d12732012-08-03 12:36:13 -04007550 /* Set up HBA event queue */
7551 if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) {
James Smart2e90f4b2011-12-13 13:22:37 -05007552 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7553 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007554 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007555 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05007556 }
James Smart67d12732012-08-03 12:36:13 -04007557 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
7558 if (!phba->sli4_hba.hba_eq[fcp_eqidx]) {
James Smartda0436e2009-05-22 14:51:39 -04007559 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7560 "0522 Fast-path EQ (%d) not "
7561 "allocated\n", fcp_eqidx);
James Smart1b511972011-12-13 13:23:09 -05007562 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007563 goto out_destroy_hba_eq;
James Smartda0436e2009-05-22 14:51:39 -04007564 }
James Smart67d12732012-08-03 12:36:13 -04007565 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx],
James Smartbf8dae82012-08-03 12:36:24 -04007566 (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel));
James Smartda0436e2009-05-22 14:51:39 -04007567 if (rc) {
7568 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7569 "0523 Failed setup of fast-path EQ "
James Smarta2fc4aef2014-09-03 12:57:55 -04007570 "(%d), rc = 0x%x\n", fcp_eqidx,
7571 (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007572 goto out_destroy_hba_eq;
James Smartda0436e2009-05-22 14:51:39 -04007573 }
7574 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007575 "2584 HBA EQ setup: "
James Smartda0436e2009-05-22 14:51:39 -04007576 "queue[%d]-id=%d\n", fcp_eqidx,
James Smart67d12732012-08-03 12:36:13 -04007577 phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007578 }
7579
James Smart67d12732012-08-03 12:36:13 -04007580 /* Set up fast-path FCP Response Complete Queue */
7581 if (!phba->sli4_hba.fcp_cq) {
7582 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7583 "3148 Fast-path FCP CQ array not "
7584 "allocated\n");
7585 rc = -ENOMEM;
7586 goto out_destroy_hba_eq;
7587 }
7588
7589 for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) {
7590 if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
7591 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7592 "0526 Fast-path FCP CQ (%d) not "
7593 "allocated\n", fcp_cqidx);
7594 rc = -ENOMEM;
7595 goto out_destroy_fcp_cq;
7596 }
7597 rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
7598 phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP);
7599 if (rc) {
7600 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7601 "0527 Failed setup of fast-path FCP "
James Smarta2fc4aef2014-09-03 12:57:55 -04007602 "CQ (%d), rc = 0x%x\n", fcp_cqidx,
7603 (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007604 goto out_destroy_fcp_cq;
7605 }
7606
7607 /* Setup fcp_cq_map for fast lookup */
7608 phba->sli4_hba.fcp_cq_map[fcp_cqidx] =
7609 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id;
7610
7611 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7612 "2588 FCP CQ setup: cq[%d]-id=%d, "
7613 "parent seq[%d]-id=%d\n",
7614 fcp_cqidx,
7615 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
7616 fcp_cqidx,
7617 phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id);
7618 }
7619
7620 /* Set up fast-path FCP Work Queue */
7621 if (!phba->sli4_hba.fcp_wq) {
7622 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7623 "3149 Fast-path FCP WQ array not "
7624 "allocated\n");
7625 rc = -ENOMEM;
7626 goto out_destroy_fcp_cq;
7627 }
7628
7629 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) {
7630 if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
7631 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7632 "0534 Fast-path FCP WQ (%d) not "
7633 "allocated\n", fcp_wqidx);
7634 rc = -ENOMEM;
7635 goto out_destroy_fcp_wq;
7636 }
7637 rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
7638 phba->sli4_hba.fcp_cq[fcp_wqidx],
7639 LPFC_FCP);
7640 if (rc) {
7641 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7642 "0535 Failed setup of fast-path FCP "
James Smarta2fc4aef2014-09-03 12:57:55 -04007643 "WQ (%d), rc = 0x%x\n", fcp_wqidx,
7644 (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007645 goto out_destroy_fcp_wq;
7646 }
7647
7648 /* Bind this WQ to the next FCP ring */
7649 pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx];
7650 pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx];
7651 phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring;
7652
7653 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7654 "2591 FCP WQ setup: wq[%d]-id=%d, "
7655 "parent cq[%d]-id=%d\n",
7656 fcp_wqidx,
7657 phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
7658 fcp_cq_index,
7659 phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id);
7660 }
James Smartda0436e2009-05-22 14:51:39 -04007661 /*
7662 * Set up Complete Queues (CQs)
7663 */
7664
7665 /* Set up slow-path MBOX Complete Queue as the first CQ */
7666 if (!phba->sli4_hba.mbx_cq) {
7667 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7668 "0528 Mailbox CQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007669 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007670 goto out_destroy_fcp_wq;
James Smartda0436e2009-05-22 14:51:39 -04007671 }
James Smart67d12732012-08-03 12:36:13 -04007672 rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq,
7673 phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04007674 if (rc) {
7675 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7676 "0529 Failed setup of slow-path mailbox CQ: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007677 "rc = 0x%x\n", (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007678 goto out_destroy_fcp_wq;
James Smartda0436e2009-05-22 14:51:39 -04007679 }
7680 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7681 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
7682 phba->sli4_hba.mbx_cq->queue_id,
James Smart67d12732012-08-03 12:36:13 -04007683 phba->sli4_hba.hba_eq[0]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007684
7685 /* Set up slow-path ELS Complete Queue */
7686 if (!phba->sli4_hba.els_cq) {
7687 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7688 "0530 ELS CQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007689 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007690 goto out_destroy_mbx_cq;
7691 }
James Smart67d12732012-08-03 12:36:13 -04007692 rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq,
7693 phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04007694 if (rc) {
7695 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7696 "0531 Failed setup of slow-path ELS CQ: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007697 "rc = 0x%x\n", (uint32_t)rc);
James Smartda0436e2009-05-22 14:51:39 -04007698 goto out_destroy_mbx_cq;
7699 }
7700 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7701 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
7702 phba->sli4_hba.els_cq->queue_id,
James Smart67d12732012-08-03 12:36:13 -04007703 phba->sli4_hba.hba_eq[0]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007704
7705 /*
7706 * Set up all the Work Queues (WQs)
7707 */
7708
7709 /* Set up Mailbox Command Queue */
7710 if (!phba->sli4_hba.mbx_wq) {
7711 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7712 "0538 Slow-path MQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007713 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007714 goto out_destroy_els_cq;
James Smartda0436e2009-05-22 14:51:39 -04007715 }
7716 rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
7717 phba->sli4_hba.mbx_cq, LPFC_MBOX);
7718 if (rc) {
7719 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7720 "0539 Failed setup of slow-path MQ: "
7721 "rc = 0x%x\n", rc);
James Smart67d12732012-08-03 12:36:13 -04007722 goto out_destroy_els_cq;
James Smartda0436e2009-05-22 14:51:39 -04007723 }
7724 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7725 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
7726 phba->sli4_hba.mbx_wq->queue_id,
7727 phba->sli4_hba.mbx_cq->queue_id);
7728
7729 /* Set up slow-path ELS Work Queue */
7730 if (!phba->sli4_hba.els_wq) {
7731 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7732 "0536 Slow-path ELS WQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007733 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007734 goto out_destroy_mbx_wq;
7735 }
7736 rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
7737 phba->sli4_hba.els_cq, LPFC_ELS);
7738 if (rc) {
7739 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7740 "0537 Failed setup of slow-path ELS WQ: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007741 "rc = 0x%x\n", (uint32_t)rc);
James Smartda0436e2009-05-22 14:51:39 -04007742 goto out_destroy_mbx_wq;
7743 }
James Smart2a76a282012-08-03 12:35:54 -04007744
7745 /* Bind this WQ to the ELS ring */
7746 pring = &psli->ring[LPFC_ELS_RING];
7747 pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq;
7748 phba->sli4_hba.els_cq->pring = pring;
7749
James Smartda0436e2009-05-22 14:51:39 -04007750 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7751 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
7752 phba->sli4_hba.els_wq->queue_id,
7753 phba->sli4_hba.els_cq->queue_id);
7754
James Smartda0436e2009-05-22 14:51:39 -04007755 /*
7756 * Create Receive Queue (RQ)
7757 */
7758 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
7759 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7760 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007761 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007762 goto out_destroy_els_wq;
James Smartda0436e2009-05-22 14:51:39 -04007763 }
James Smart73d91e52011-10-10 21:32:10 -04007764
7765 lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
7766 lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
7767
James Smartda0436e2009-05-22 14:51:39 -04007768 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04007769 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04007770 if (rc) {
7771 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7772 "0541 Failed setup of Receive Queue: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007773 "rc = 0x%x\n", (uint32_t)rc);
James Smartda0436e2009-05-22 14:51:39 -04007774 goto out_destroy_fcp_wq;
7775 }
James Smart73d91e52011-10-10 21:32:10 -04007776
James Smartda0436e2009-05-22 14:51:39 -04007777 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7778 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
7779 "parent cq-id=%d\n",
7780 phba->sli4_hba.hdr_rq->queue_id,
7781 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04007782 phba->sli4_hba.els_cq->queue_id);
James Smart1ba981f2014-02-20 09:56:45 -05007783
7784 if (phba->cfg_fof) {
7785 rc = lpfc_fof_queue_setup(phba);
7786 if (rc) {
7787 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7788 "0549 Failed setup of FOF Queues: "
7789 "rc = 0x%x\n", rc);
7790 goto out_destroy_els_rq;
7791 }
7792 }
James Smart2c9c5a02015-04-07 15:07:15 -04007793
7794 /*
7795 * Configure EQ delay multipier for interrupt coalescing using
7796 * MODIFY_EQ_DELAY for all EQs created, LPFC_MAX_EQ_DELAY at a time.
7797 */
7798 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel;
7799 fcp_eqidx += LPFC_MAX_EQ_DELAY)
7800 lpfc_modify_fcp_eq_delay(phba, fcp_eqidx);
James Smartda0436e2009-05-22 14:51:39 -04007801 return 0;
7802
James Smart1ba981f2014-02-20 09:56:45 -05007803out_destroy_els_rq:
7804 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
James Smart2e90f4b2011-12-13 13:22:37 -05007805out_destroy_els_wq:
James Smartda0436e2009-05-22 14:51:39 -04007806 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7807out_destroy_mbx_wq:
7808 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
James Smart2e90f4b2011-12-13 13:22:37 -05007809out_destroy_els_cq:
James Smartda0436e2009-05-22 14:51:39 -04007810 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
7811out_destroy_mbx_cq:
7812 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
James Smart67d12732012-08-03 12:36:13 -04007813out_destroy_fcp_wq:
7814 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
7815 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
7816out_destroy_fcp_cq:
7817 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
7818 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
7819out_destroy_hba_eq:
James Smartda0436e2009-05-22 14:51:39 -04007820 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
James Smart67d12732012-08-03 12:36:13 -04007821 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]);
James Smartda0436e2009-05-22 14:51:39 -04007822out_error:
7823 return rc;
7824}
7825
7826/**
7827 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
7828 * @phba: pointer to lpfc hba data structure.
7829 *
7830 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
7831 * operation.
7832 *
7833 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007834 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007835 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007836 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007837 **/
7838void
7839lpfc_sli4_queue_unset(struct lpfc_hba *phba)
7840{
7841 int fcp_qidx;
7842
James Smart1ba981f2014-02-20 09:56:45 -05007843 /* Unset the queues created for Flash Optimized Fabric operations */
7844 if (phba->cfg_fof)
7845 lpfc_fof_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04007846 /* Unset mailbox command work queue */
7847 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
7848 /* Unset ELS work queue */
7849 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7850 /* Unset unsolicited receive queue */
7851 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
7852 /* Unset FCP work queue */
James Smart67d12732012-08-03 12:36:13 -04007853 if (phba->sli4_hba.fcp_wq) {
7854 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
7855 fcp_qidx++)
7856 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
7857 }
James Smartda0436e2009-05-22 14:51:39 -04007858 /* Unset mailbox command complete queue */
7859 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
7860 /* Unset ELS complete queue */
7861 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
James Smartda0436e2009-05-22 14:51:39 -04007862 /* Unset FCP response complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05007863 if (phba->sli4_hba.fcp_cq) {
James Smart67d12732012-08-03 12:36:13 -04007864 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
7865 fcp_qidx++)
James Smart2e90f4b2011-12-13 13:22:37 -05007866 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
James Smart2e90f4b2011-12-13 13:22:37 -05007867 }
James Smartda0436e2009-05-22 14:51:39 -04007868 /* Unset fast-path event queue */
James Smart67d12732012-08-03 12:36:13 -04007869 if (phba->sli4_hba.hba_eq) {
7870 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
James Smart2e90f4b2011-12-13 13:22:37 -05007871 fcp_qidx++)
James Smart67d12732012-08-03 12:36:13 -04007872 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_qidx]);
James Smart2e90f4b2011-12-13 13:22:37 -05007873 }
James Smartda0436e2009-05-22 14:51:39 -04007874}
7875
7876/**
7877 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
7878 * @phba: pointer to lpfc hba data structure.
7879 *
7880 * This routine is invoked to allocate and set up a pool of completion queue
7881 * events. The body of the completion queue event is a completion queue entry
7882 * CQE. For now, this pool is used for the interrupt service routine to queue
7883 * the following HBA completion queue events for the worker thread to process:
7884 * - Mailbox asynchronous events
7885 * - Receive queue completion unsolicited events
7886 * Later, this can be used for all the slow-path events.
7887 *
7888 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007889 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007890 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007891 **/
7892static int
7893lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
7894{
7895 struct lpfc_cq_event *cq_event;
7896 int i;
7897
7898 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
7899 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
7900 if (!cq_event)
7901 goto out_pool_create_fail;
7902 list_add_tail(&cq_event->list,
7903 &phba->sli4_hba.sp_cqe_event_pool);
7904 }
7905 return 0;
7906
7907out_pool_create_fail:
7908 lpfc_sli4_cq_event_pool_destroy(phba);
7909 return -ENOMEM;
7910}
7911
7912/**
7913 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
7914 * @phba: pointer to lpfc hba data structure.
7915 *
7916 * This routine is invoked to free the pool of completion queue events at
7917 * driver unload time. Note that, it is the responsibility of the driver
7918 * cleanup routine to free all the outstanding completion-queue events
7919 * allocated from this pool back into the pool before invoking this routine
7920 * to destroy the pool.
7921 **/
7922static void
7923lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
7924{
7925 struct lpfc_cq_event *cq_event, *next_cq_event;
7926
7927 list_for_each_entry_safe(cq_event, next_cq_event,
7928 &phba->sli4_hba.sp_cqe_event_pool, list) {
7929 list_del(&cq_event->list);
7930 kfree(cq_event);
7931 }
7932}
7933
7934/**
7935 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7936 * @phba: pointer to lpfc hba data structure.
7937 *
7938 * This routine is the lock free version of the API invoked to allocate a
7939 * completion-queue event from the free pool.
7940 *
7941 * Return: Pointer to the newly allocated completion-queue event if successful
7942 * NULL otherwise.
7943 **/
7944struct lpfc_cq_event *
7945__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
7946{
7947 struct lpfc_cq_event *cq_event = NULL;
7948
7949 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
7950 struct lpfc_cq_event, list);
7951 return cq_event;
7952}
7953
7954/**
7955 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7956 * @phba: pointer to lpfc hba data structure.
7957 *
7958 * This routine is the lock version of the API invoked to allocate a
7959 * completion-queue event from the free pool.
7960 *
7961 * Return: Pointer to the newly allocated completion-queue event if successful
7962 * NULL otherwise.
7963 **/
7964struct lpfc_cq_event *
7965lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
7966{
7967 struct lpfc_cq_event *cq_event;
7968 unsigned long iflags;
7969
7970 spin_lock_irqsave(&phba->hbalock, iflags);
7971 cq_event = __lpfc_sli4_cq_event_alloc(phba);
7972 spin_unlock_irqrestore(&phba->hbalock, iflags);
7973 return cq_event;
7974}
7975
7976/**
7977 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7978 * @phba: pointer to lpfc hba data structure.
7979 * @cq_event: pointer to the completion queue event to be freed.
7980 *
7981 * This routine is the lock free version of the API invoked to release a
7982 * completion-queue event back into the free pool.
7983 **/
7984void
7985__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
7986 struct lpfc_cq_event *cq_event)
7987{
7988 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
7989}
7990
7991/**
7992 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7993 * @phba: pointer to lpfc hba data structure.
7994 * @cq_event: pointer to the completion queue event to be freed.
7995 *
7996 * This routine is the lock version of the API invoked to release a
7997 * completion-queue event back into the free pool.
7998 **/
7999void
8000lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
8001 struct lpfc_cq_event *cq_event)
8002{
8003 unsigned long iflags;
8004 spin_lock_irqsave(&phba->hbalock, iflags);
8005 __lpfc_sli4_cq_event_release(phba, cq_event);
8006 spin_unlock_irqrestore(&phba->hbalock, iflags);
8007}
8008
8009/**
8010 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
8011 * @phba: pointer to lpfc hba data structure.
8012 *
8013 * This routine is to free all the pending completion-queue events to the
8014 * back into the free pool for device reset.
8015 **/
8016static void
8017lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
8018{
8019 LIST_HEAD(cqelist);
8020 struct lpfc_cq_event *cqe;
8021 unsigned long iflags;
8022
8023 /* Retrieve all the pending WCQEs from pending WCQE lists */
8024 spin_lock_irqsave(&phba->hbalock, iflags);
8025 /* Pending FCP XRI abort events */
8026 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
8027 &cqelist);
8028 /* Pending ELS XRI abort events */
8029 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
8030 &cqelist);
8031 /* Pending asynnc events */
8032 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
8033 &cqelist);
8034 spin_unlock_irqrestore(&phba->hbalock, iflags);
8035
8036 while (!list_empty(&cqelist)) {
8037 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
8038 lpfc_sli4_cq_event_release(phba, cqe);
8039 }
8040}
8041
8042/**
8043 * lpfc_pci_function_reset - Reset pci function.
8044 * @phba: pointer to lpfc hba data structure.
8045 *
8046 * This routine is invoked to request a PCI function reset. It will destroys
8047 * all resources assigned to the PCI function which originates this request.
8048 *
8049 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008050 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008051 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008052 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008053 **/
8054int
8055lpfc_pci_function_reset(struct lpfc_hba *phba)
8056{
8057 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05008058 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04008059 uint32_t shdr_status, shdr_add_status;
James Smart2f6fa2c2014-09-03 12:57:08 -04008060 uint32_t rdy_chk;
8061 uint32_t port_reset = 0;
James Smartda0436e2009-05-22 14:51:39 -04008062 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05008063 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -05008064 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -04008065
James Smart2fcee4b2010-12-15 17:57:46 -05008066 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8067 switch (if_type) {
8068 case LPFC_SLI_INTF_IF_TYPE_0:
8069 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8070 GFP_KERNEL);
8071 if (!mboxq) {
8072 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8073 "0494 Unable to allocate memory for "
8074 "issuing SLI_FUNCTION_RESET mailbox "
8075 "command\n");
8076 return -ENOMEM;
8077 }
8078
8079 /* Setup PCI function reset mailbox-ioctl command */
8080 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8081 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
8082 LPFC_SLI4_MBX_EMBED);
8083 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8084 shdr = (union lpfc_sli4_cfg_shdr *)
8085 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
8086 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8087 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
8088 &shdr->response);
8089 if (rc != MBX_TIMEOUT)
8090 mempool_free(mboxq, phba->mbox_mem_pool);
8091 if (shdr_status || shdr_add_status || rc) {
8092 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8093 "0495 SLI_FUNCTION_RESET mailbox "
8094 "failed with status x%x add_status x%x,"
8095 " mbx status x%x\n",
8096 shdr_status, shdr_add_status, rc);
8097 rc = -ENXIO;
8098 }
8099 break;
8100 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2f6fa2c2014-09-03 12:57:08 -04008101wait:
8102 /*
8103 * Poll the Port Status Register and wait for RDY for
8104 * up to 30 seconds. If the port doesn't respond, treat
8105 * it as an error.
8106 */
James Smart77d093f2015-04-07 15:07:08 -04008107 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
James Smart2f6fa2c2014-09-03 12:57:08 -04008108 if (lpfc_readl(phba->sli4_hba.u.if_type2.
8109 STATUSregaddr, &reg_data.word0)) {
8110 rc = -ENODEV;
8111 goto out;
8112 }
8113 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
8114 break;
8115 msleep(20);
8116 }
8117
8118 if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
8119 phba->work_status[0] = readl(
8120 phba->sli4_hba.u.if_type2.ERR1regaddr);
8121 phba->work_status[1] = readl(
8122 phba->sli4_hba.u.if_type2.ERR2regaddr);
8123 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8124 "2890 Port not ready, port status reg "
8125 "0x%x error 1=0x%x, error 2=0x%x\n",
8126 reg_data.word0,
8127 phba->work_status[0],
8128 phba->work_status[1]);
8129 rc = -ENODEV;
8130 goto out;
8131 }
8132
8133 if (!port_reset) {
8134 /*
8135 * Reset the port now
8136 */
James Smart2fcee4b2010-12-15 17:57:46 -05008137 reg_data.word0 = 0;
8138 bf_set(lpfc_sliport_ctrl_end, &reg_data,
8139 LPFC_SLIPORT_LITTLE_ENDIAN);
8140 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
8141 LPFC_SLIPORT_INIT_PORT);
8142 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
8143 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -05008144 /* flush */
James Smart2b81f942012-03-01 22:37:18 -05008145 pci_read_config_word(phba->pcidev,
8146 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -05008147
James Smart2f6fa2c2014-09-03 12:57:08 -04008148 port_reset = 1;
8149 msleep(20);
8150 goto wait;
8151 } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
8152 rc = -ENODEV;
8153 goto out;
James Smart2fcee4b2010-12-15 17:57:46 -05008154 }
8155 break;
James Smart2f6fa2c2014-09-03 12:57:08 -04008156
James Smart2fcee4b2010-12-15 17:57:46 -05008157 case LPFC_SLI_INTF_IF_TYPE_1:
8158 default:
8159 break;
James Smartda0436e2009-05-22 14:51:39 -04008160 }
8161
James Smart73d91e52011-10-10 21:32:10 -04008162out:
James Smart2fcee4b2010-12-15 17:57:46 -05008163 /* Catch the not-ready port failure after a port reset. */
James Smart2f6fa2c2014-09-03 12:57:08 -04008164 if (rc) {
James Smart229adb02013-04-17 20:16:51 -04008165 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8166 "3317 HBA not functional: IP Reset Failed "
James Smart2f6fa2c2014-09-03 12:57:08 -04008167 "try: echo fw_reset > board_mode\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008168 rc = -ENODEV;
James Smart229adb02013-04-17 20:16:51 -04008169 }
James Smart2fcee4b2010-12-15 17:57:46 -05008170
James Smartda0436e2009-05-22 14:51:39 -04008171 return rc;
8172}
8173
8174/**
James Smartda0436e2009-05-22 14:51:39 -04008175 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
8176 * @phba: pointer to lpfc hba data structure.
8177 *
8178 * This routine is invoked to set up the PCI device memory space for device
8179 * with SLI-4 interface spec.
8180 *
8181 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008182 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008183 * other values - error
8184 **/
8185static int
8186lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
8187{
8188 struct pci_dev *pdev;
8189 unsigned long bar0map_len, bar1map_len, bar2map_len;
8190 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05008191 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04008192
8193 /* Obtain PCI device reference */
8194 if (!phba->pcidev)
8195 return error;
8196 else
8197 pdev = phba->pcidev;
8198
8199 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05008200 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
8201 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
8202 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
8203 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smartda0436e2009-05-22 14:51:39 -04008204 return error;
Michael Reed8e685972009-09-18 12:02:05 -05008205 }
8206 }
James Smartda0436e2009-05-22 14:51:39 -04008207
James Smart2fcee4b2010-12-15 17:57:46 -05008208 /*
8209 * The BARs and register set definitions and offset locations are
8210 * dependent on the if_type.
8211 */
8212 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
8213 &phba->sli4_hba.sli_intf.word0)) {
8214 return error;
8215 }
8216
8217 /* There is no SLI3 failback for SLI4 devices. */
8218 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
8219 LPFC_SLI_INTF_VALID) {
8220 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8221 "2894 SLI_INTF reg contents invalid "
8222 "sli_intf reg 0x%x\n",
8223 phba->sli4_hba.sli_intf.word0);
8224 return error;
8225 }
8226
8227 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8228 /*
8229 * Get the bus address of SLI4 device Bar regions and the
8230 * number of bytes required by each mapping. The mapping of the
8231 * particular PCI BARs regions is dependent on the type of
8232 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04008233 */
James Smartf5ca6f22013-09-06 12:21:09 -04008234 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
8235 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
8236 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
James Smart2fcee4b2010-12-15 17:57:46 -05008237
8238 /*
8239 * Map SLI4 PCI Config Space Register base to a kernel virtual
8240 * addr
8241 */
8242 phba->sli4_hba.conf_regs_memmap_p =
8243 ioremap(phba->pci_bar0_map, bar0map_len);
8244 if (!phba->sli4_hba.conf_regs_memmap_p) {
8245 dev_printk(KERN_ERR, &pdev->dev,
8246 "ioremap failed for SLI4 PCI config "
8247 "registers.\n");
8248 goto out;
8249 }
James Smartf5ca6f22013-09-06 12:21:09 -04008250 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008251 /* Set up BAR0 PCI config space register memory map */
8252 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05008253 } else {
8254 phba->pci_bar0_map = pci_resource_start(pdev, 1);
8255 bar0map_len = pci_resource_len(pdev, 1);
James Smart2fcee4b2010-12-15 17:57:46 -05008256 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
8257 dev_printk(KERN_ERR, &pdev->dev,
8258 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
8259 goto out;
8260 }
8261 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008262 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008263 if (!phba->sli4_hba.conf_regs_memmap_p) {
8264 dev_printk(KERN_ERR, &pdev->dev,
8265 "ioremap failed for SLI4 PCI config "
8266 "registers.\n");
8267 goto out;
8268 }
8269 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04008270 }
8271
James Smartc31098c2011-04-16 11:03:33 -04008272 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04008273 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
James Smart2fcee4b2010-12-15 17:57:46 -05008274 /*
8275 * Map SLI4 if type 0 HBA Control Register base to a kernel
8276 * virtual address and setup the registers.
8277 */
James Smartf5ca6f22013-09-06 12:21:09 -04008278 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
8279 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
James Smart2fcee4b2010-12-15 17:57:46 -05008280 phba->sli4_hba.ctrl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008281 ioremap(phba->pci_bar1_map, bar1map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008282 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
8283 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04008284 "ioremap failed for SLI4 HBA control registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008285 goto out_iounmap_conf;
8286 }
James Smartf5ca6f22013-09-06 12:21:09 -04008287 phba->pci_bar2_memmap_p = phba->sli4_hba.ctrl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008288 lpfc_sli4_bar1_register_memmap(phba);
James Smartda0436e2009-05-22 14:51:39 -04008289 }
8290
James Smartc31098c2011-04-16 11:03:33 -04008291 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04008292 (pci_resource_start(pdev, PCI_64BIT_BAR4))) {
James Smart2fcee4b2010-12-15 17:57:46 -05008293 /*
8294 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
8295 * virtual address and setup the registers.
8296 */
James Smartf5ca6f22013-09-06 12:21:09 -04008297 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
8298 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
James Smart2fcee4b2010-12-15 17:57:46 -05008299 phba->sli4_hba.drbl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008300 ioremap(phba->pci_bar2_map, bar2map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008301 if (!phba->sli4_hba.drbl_regs_memmap_p) {
8302 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04008303 "ioremap failed for SLI4 HBA doorbell registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008304 goto out_iounmap_ctrl;
8305 }
James Smartf5ca6f22013-09-06 12:21:09 -04008306 phba->pci_bar4_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008307 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
8308 if (error)
8309 goto out_iounmap_all;
James Smartda0436e2009-05-22 14:51:39 -04008310 }
8311
James Smartda0436e2009-05-22 14:51:39 -04008312 return 0;
8313
8314out_iounmap_all:
8315 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
8316out_iounmap_ctrl:
8317 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
8318out_iounmap_conf:
8319 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8320out:
8321 return error;
8322}
8323
8324/**
8325 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
8326 * @phba: pointer to lpfc hba data structure.
8327 *
8328 * This routine is invoked to unset the PCI device memory space for device
8329 * with SLI-4 interface spec.
8330 **/
8331static void
8332lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
8333{
James Smart2e90f4b2011-12-13 13:22:37 -05008334 uint32_t if_type;
8335 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -04008336
James Smart2e90f4b2011-12-13 13:22:37 -05008337 switch (if_type) {
8338 case LPFC_SLI_INTF_IF_TYPE_0:
8339 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
8340 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
8341 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8342 break;
8343 case LPFC_SLI_INTF_IF_TYPE_2:
8344 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8345 break;
8346 case LPFC_SLI_INTF_IF_TYPE_1:
8347 default:
8348 dev_printk(KERN_ERR, &phba->pcidev->dev,
8349 "FATAL - unsupported SLI4 interface type - %d\n",
8350 if_type);
8351 break;
8352 }
James Smartda0436e2009-05-22 14:51:39 -04008353}
8354
8355/**
James Smart3772a992009-05-22 14:50:54 -04008356 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
8357 * @phba: pointer to lpfc hba data structure.
8358 *
8359 * This routine is invoked to enable the MSI-X interrupt vectors to device
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008360 * with SLI-3 interface specs. The kernel function pci_enable_msix_exact()
8361 * is called to enable the MSI-X vectors. Note that pci_enable_msix_exact(),
8362 * once invoked, enables either all or nothing, depending on the current
James Smart3772a992009-05-22 14:50:54 -04008363 * availability of PCI vector resources. The device driver is responsible
8364 * for calling the individual request_irq() to register each MSI-X vector
8365 * with a interrupt handler, which is done in this function. Note that
8366 * later when device is unloading, the driver should always call free_irq()
8367 * on all MSI-X vectors it has done request_irq() on before calling
8368 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
8369 * will be left with MSI-X enabled and leaks its vectors.
8370 *
8371 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008372 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008373 * other values - error
8374 **/
8375static int
8376lpfc_sli_enable_msix(struct lpfc_hba *phba)
8377{
8378 int rc, i;
8379 LPFC_MBOXQ_t *pmb;
8380
8381 /* Set up MSI-X multi-message vectors */
8382 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8383 phba->msix_entries[i].entry = i;
8384
8385 /* Configure MSI-X capability structure */
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008386 rc = pci_enable_msix_exact(phba->pcidev, phba->msix_entries,
8387 LPFC_MSIX_VECTORS);
James Smart3772a992009-05-22 14:50:54 -04008388 if (rc) {
8389 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8390 "0420 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02008391 goto vec_fail_out;
James Smart3772a992009-05-22 14:50:54 -04008392 }
8393 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8394 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8395 "0477 MSI-X entry[%d]: vector=x%x "
8396 "message=%d\n", i,
8397 phba->msix_entries[i].vector,
8398 phba->msix_entries[i].entry);
8399 /*
8400 * Assign MSI-X vectors to interrupt handlers
8401 */
8402
8403 /* vector-0 is associated to slow-path handler */
8404 rc = request_irq(phba->msix_entries[0].vector,
James Smarted243d32015-05-21 13:55:25 -04008405 &lpfc_sli_sp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04008406 LPFC_SP_DRIVER_HANDLER_NAME, phba);
8407 if (rc) {
8408 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8409 "0421 MSI-X slow-path request_irq failed "
8410 "(%d)\n", rc);
8411 goto msi_fail_out;
8412 }
8413
8414 /* vector-1 is associated to fast-path handler */
8415 rc = request_irq(phba->msix_entries[1].vector,
James Smarted243d32015-05-21 13:55:25 -04008416 &lpfc_sli_fp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04008417 LPFC_FP_DRIVER_HANDLER_NAME, phba);
8418
8419 if (rc) {
8420 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8421 "0429 MSI-X fast-path request_irq failed "
8422 "(%d)\n", rc);
8423 goto irq_fail_out;
8424 }
8425
8426 /*
8427 * Configure HBA MSI-X attention conditions to messages
8428 */
8429 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8430
8431 if (!pmb) {
8432 rc = -ENOMEM;
8433 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8434 "0474 Unable to allocate memory for issuing "
8435 "MBOX_CONFIG_MSI command\n");
8436 goto mem_fail_out;
8437 }
8438 rc = lpfc_config_msi(phba, pmb);
8439 if (rc)
8440 goto mbx_fail_out;
8441 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
8442 if (rc != MBX_SUCCESS) {
8443 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
8444 "0351 Config MSI mailbox command failed, "
8445 "mbxCmd x%x, mbxStatus x%x\n",
8446 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
8447 goto mbx_fail_out;
8448 }
8449
8450 /* Free memory allocated for mailbox command */
8451 mempool_free(pmb, phba->mbox_mem_pool);
8452 return rc;
8453
8454mbx_fail_out:
8455 /* Free memory allocated for mailbox command */
8456 mempool_free(pmb, phba->mbox_mem_pool);
8457
8458mem_fail_out:
8459 /* free the irq already requested */
8460 free_irq(phba->msix_entries[1].vector, phba);
8461
8462irq_fail_out:
8463 /* free the irq already requested */
8464 free_irq(phba->msix_entries[0].vector, phba);
8465
8466msi_fail_out:
8467 /* Unconfigure MSI-X capability structure */
8468 pci_disable_msix(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02008469
8470vec_fail_out:
James Smart3772a992009-05-22 14:50:54 -04008471 return rc;
8472}
8473
8474/**
8475 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
8476 * @phba: pointer to lpfc hba data structure.
8477 *
8478 * This routine is invoked to release the MSI-X vectors and then disable the
8479 * MSI-X interrupt mode to device with SLI-3 interface spec.
8480 **/
8481static void
8482lpfc_sli_disable_msix(struct lpfc_hba *phba)
8483{
8484 int i;
8485
8486 /* Free up MSI-X multi-message vectors */
8487 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8488 free_irq(phba->msix_entries[i].vector, phba);
8489 /* Disable MSI-X */
8490 pci_disable_msix(phba->pcidev);
8491
8492 return;
8493}
8494
8495/**
8496 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
8497 * @phba: pointer to lpfc hba data structure.
8498 *
8499 * This routine is invoked to enable the MSI interrupt mode to device with
8500 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
8501 * enable the MSI vector. The device driver is responsible for calling the
8502 * request_irq() to register MSI vector with a interrupt the handler, which
8503 * is done in this function.
8504 *
8505 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008506 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008507 * other values - error
8508 */
8509static int
8510lpfc_sli_enable_msi(struct lpfc_hba *phba)
8511{
8512 int rc;
8513
8514 rc = pci_enable_msi(phba->pcidev);
8515 if (!rc)
8516 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8517 "0462 PCI enable MSI mode success.\n");
8518 else {
8519 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8520 "0471 PCI enable MSI mode failed (%d)\n", rc);
8521 return rc;
8522 }
8523
8524 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04008525 0, LPFC_DRIVER_NAME, phba);
James Smart3772a992009-05-22 14:50:54 -04008526 if (rc) {
8527 pci_disable_msi(phba->pcidev);
8528 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8529 "0478 MSI request_irq failed (%d)\n", rc);
8530 }
8531 return rc;
8532}
8533
8534/**
8535 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
8536 * @phba: pointer to lpfc hba data structure.
8537 *
8538 * This routine is invoked to disable the MSI interrupt mode to device with
8539 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
8540 * done request_irq() on before calling pci_disable_msi(). Failure to do so
8541 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
8542 * its vector.
8543 */
8544static void
8545lpfc_sli_disable_msi(struct lpfc_hba *phba)
8546{
8547 free_irq(phba->pcidev->irq, phba);
8548 pci_disable_msi(phba->pcidev);
8549 return;
8550}
8551
8552/**
8553 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
8554 * @phba: pointer to lpfc hba data structure.
8555 *
8556 * This routine is invoked to enable device interrupt and associate driver's
8557 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
8558 * spec. Depends on the interrupt mode configured to the driver, the driver
8559 * will try to fallback from the configured interrupt mode to an interrupt
8560 * mode which is supported by the platform, kernel, and device in the order
8561 * of:
8562 * MSI-X -> MSI -> IRQ.
8563 *
8564 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008565 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008566 * other values - error
8567 **/
8568static uint32_t
8569lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
8570{
8571 uint32_t intr_mode = LPFC_INTR_ERROR;
8572 int retval;
8573
8574 if (cfg_mode == 2) {
8575 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
8576 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
8577 if (!retval) {
8578 /* Now, try to enable MSI-X interrupt mode */
8579 retval = lpfc_sli_enable_msix(phba);
8580 if (!retval) {
8581 /* Indicate initialization to MSI-X mode */
8582 phba->intr_type = MSIX;
8583 intr_mode = 2;
8584 }
8585 }
8586 }
8587
8588 /* Fallback to MSI if MSI-X initialization failed */
8589 if (cfg_mode >= 1 && phba->intr_type == NONE) {
8590 retval = lpfc_sli_enable_msi(phba);
8591 if (!retval) {
8592 /* Indicate initialization to MSI mode */
8593 phba->intr_type = MSI;
8594 intr_mode = 1;
8595 }
8596 }
8597
8598 /* Fallback to INTx if both MSI-X/MSI initalization failed */
8599 if (phba->intr_type == NONE) {
8600 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
8601 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8602 if (!retval) {
8603 /* Indicate initialization to INTx mode */
8604 phba->intr_type = INTx;
8605 intr_mode = 0;
8606 }
8607 }
8608 return intr_mode;
8609}
8610
8611/**
8612 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
8613 * @phba: pointer to lpfc hba data structure.
8614 *
8615 * This routine is invoked to disable device interrupt and disassociate the
8616 * driver's interrupt handler(s) from interrupt vector(s) to device with
8617 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
8618 * release the interrupt vector(s) for the message signaled interrupt.
8619 **/
8620static void
8621lpfc_sli_disable_intr(struct lpfc_hba *phba)
8622{
8623 /* Disable the currently initialized interrupt mode */
8624 if (phba->intr_type == MSIX)
8625 lpfc_sli_disable_msix(phba);
8626 else if (phba->intr_type == MSI)
8627 lpfc_sli_disable_msi(phba);
8628 else if (phba->intr_type == INTx)
8629 free_irq(phba->pcidev->irq, phba);
8630
8631 /* Reset interrupt management states */
8632 phba->intr_type = NONE;
8633 phba->sli.slistat.sli_intr = 0;
8634
8635 return;
8636}
8637
8638/**
James Smart7bb03bb2013-04-17 20:19:16 -04008639 * lpfc_find_next_cpu - Find next available CPU that matches the phys_id
8640 * @phba: pointer to lpfc hba data structure.
8641 *
8642 * Find next available CPU to use for IRQ to CPU affinity.
8643 */
8644static int
8645lpfc_find_next_cpu(struct lpfc_hba *phba, uint32_t phys_id)
8646{
8647 struct lpfc_vector_map_info *cpup;
8648 int cpu;
8649
8650 cpup = phba->sli4_hba.cpu_map;
8651 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8652 /* CPU must be online */
8653 if (cpu_online(cpu)) {
8654 if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
8655 (lpfc_used_cpu[cpu] == LPFC_VECTOR_MAP_EMPTY) &&
8656 (cpup->phys_id == phys_id)) {
8657 return cpu;
8658 }
8659 }
8660 cpup++;
8661 }
8662
8663 /*
8664 * If we get here, we have used ALL CPUs for the specific
8665 * phys_id. Now we need to clear out lpfc_used_cpu and start
8666 * reusing CPUs.
8667 */
8668
8669 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8670 if (lpfc_used_cpu[cpu] == phys_id)
8671 lpfc_used_cpu[cpu] = LPFC_VECTOR_MAP_EMPTY;
8672 }
8673
8674 cpup = phba->sli4_hba.cpu_map;
8675 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8676 /* CPU must be online */
8677 if (cpu_online(cpu)) {
8678 if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
8679 (cpup->phys_id == phys_id)) {
8680 return cpu;
8681 }
8682 }
8683 cpup++;
8684 }
8685 return LPFC_VECTOR_MAP_EMPTY;
8686}
8687
8688/**
8689 * lpfc_sli4_set_affinity - Set affinity for HBA IRQ vectors
8690 * @phba: pointer to lpfc hba data structure.
8691 * @vectors: number of HBA vectors
8692 *
8693 * Affinitize MSIX IRQ vectors to CPUs. Try to equally spread vector
8694 * affinization across multple physical CPUs (numa nodes).
8695 * In addition, this routine will assign an IO channel for each CPU
8696 * to use when issuing I/Os.
8697 */
8698static int
8699lpfc_sli4_set_affinity(struct lpfc_hba *phba, int vectors)
8700{
8701 int i, idx, saved_chann, used_chann, cpu, phys_id;
James Smartec2087a2013-09-06 12:20:36 -04008702 int max_phys_id, min_phys_id;
8703 int num_io_channel, first_cpu, chan;
James Smart7bb03bb2013-04-17 20:19:16 -04008704 struct lpfc_vector_map_info *cpup;
8705#ifdef CONFIG_X86
8706 struct cpuinfo_x86 *cpuinfo;
8707#endif
James Smart7bb03bb2013-04-17 20:19:16 -04008708 uint8_t chann[LPFC_FCP_IO_CHAN_MAX+1];
8709
8710 /* If there is no mapping, just return */
8711 if (!phba->cfg_fcp_cpu_map)
8712 return 1;
8713
8714 /* Init cpu_map array */
8715 memset(phba->sli4_hba.cpu_map, 0xff,
8716 (sizeof(struct lpfc_vector_map_info) *
8717 phba->sli4_hba.num_present_cpu));
8718
8719 max_phys_id = 0;
James Smartec2087a2013-09-06 12:20:36 -04008720 min_phys_id = 0xff;
James Smart7bb03bb2013-04-17 20:19:16 -04008721 phys_id = 0;
8722 num_io_channel = 0;
8723 first_cpu = LPFC_VECTOR_MAP_EMPTY;
8724
8725 /* Update CPU map with physical id and core id of each CPU */
8726 cpup = phba->sli4_hba.cpu_map;
8727 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8728#ifdef CONFIG_X86
8729 cpuinfo = &cpu_data(cpu);
8730 cpup->phys_id = cpuinfo->phys_proc_id;
8731 cpup->core_id = cpuinfo->cpu_core_id;
8732#else
8733 /* No distinction between CPUs for other platforms */
8734 cpup->phys_id = 0;
8735 cpup->core_id = 0;
8736#endif
8737
8738 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8739 "3328 CPU physid %d coreid %d\n",
8740 cpup->phys_id, cpup->core_id);
8741
8742 if (cpup->phys_id > max_phys_id)
8743 max_phys_id = cpup->phys_id;
James Smartec2087a2013-09-06 12:20:36 -04008744 if (cpup->phys_id < min_phys_id)
8745 min_phys_id = cpup->phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008746 cpup++;
8747 }
8748
James Smartec2087a2013-09-06 12:20:36 -04008749 phys_id = min_phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008750 /* Now associate the HBA vectors with specific CPUs */
8751 for (idx = 0; idx < vectors; idx++) {
8752 cpup = phba->sli4_hba.cpu_map;
8753 cpu = lpfc_find_next_cpu(phba, phys_id);
8754 if (cpu == LPFC_VECTOR_MAP_EMPTY) {
8755
8756 /* Try for all phys_id's */
8757 for (i = 1; i < max_phys_id; i++) {
8758 phys_id++;
8759 if (phys_id > max_phys_id)
James Smartec2087a2013-09-06 12:20:36 -04008760 phys_id = min_phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008761 cpu = lpfc_find_next_cpu(phba, phys_id);
8762 if (cpu == LPFC_VECTOR_MAP_EMPTY)
8763 continue;
8764 goto found;
8765 }
8766
James Smartec2087a2013-09-06 12:20:36 -04008767 /* Use round robin for scheduling */
8768 phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_ROUND_ROBIN;
8769 chan = 0;
8770 cpup = phba->sli4_hba.cpu_map;
8771 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
8772 cpup->channel_id = chan;
8773 cpup++;
8774 chan++;
8775 if (chan >= phba->cfg_fcp_io_channel)
8776 chan = 0;
8777 }
8778
James Smart7bb03bb2013-04-17 20:19:16 -04008779 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8780 "3329 Cannot set affinity:"
8781 "Error mapping vector %d (%d)\n",
8782 idx, vectors);
8783 return 0;
8784 }
8785found:
8786 cpup += cpu;
8787 if (phba->cfg_fcp_cpu_map == LPFC_DRIVER_CPU_MAP)
8788 lpfc_used_cpu[cpu] = phys_id;
8789
8790 /* Associate vector with selected CPU */
8791 cpup->irq = phba->sli4_hba.msix_entries[idx].vector;
8792
8793 /* Associate IO channel with selected CPU */
8794 cpup->channel_id = idx;
8795 num_io_channel++;
8796
8797 if (first_cpu == LPFC_VECTOR_MAP_EMPTY)
8798 first_cpu = cpu;
8799
8800 /* Now affinitize to the selected CPU */
James Smart7bb03bb2013-04-17 20:19:16 -04008801 i = irq_set_affinity_hint(phba->sli4_hba.msix_entries[idx].
Ian Mitchellc0365c02015-08-31 16:48:12 -04008802 vector, get_cpu_mask(cpu));
James Smart7bb03bb2013-04-17 20:19:16 -04008803
8804 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8805 "3330 Set Affinity: CPU %d channel %d "
8806 "irq %d (%x)\n",
8807 cpu, cpup->channel_id,
8808 phba->sli4_hba.msix_entries[idx].vector, i);
8809
8810 /* Spread vector mapping across multple physical CPU nodes */
8811 phys_id++;
8812 if (phys_id > max_phys_id)
James Smartec2087a2013-09-06 12:20:36 -04008813 phys_id = min_phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008814 }
8815
8816 /*
8817 * Finally fill in the IO channel for any remaining CPUs.
8818 * At this point, all IO channels have been assigned to a specific
8819 * MSIx vector, mapped to a specific CPU.
8820 * Base the remaining IO channel assigned, to IO channels already
8821 * assigned to other CPUs on the same phys_id.
8822 */
James Smartec2087a2013-09-06 12:20:36 -04008823 for (i = min_phys_id; i <= max_phys_id; i++) {
James Smart7bb03bb2013-04-17 20:19:16 -04008824 /*
8825 * If there are no io channels already mapped to
8826 * this phys_id, just round robin thru the io_channels.
8827 * Setup chann[] for round robin.
8828 */
8829 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
8830 chann[idx] = idx;
8831
8832 saved_chann = 0;
8833 used_chann = 0;
8834
8835 /*
8836 * First build a list of IO channels already assigned
8837 * to this phys_id before reassigning the same IO
8838 * channels to the remaining CPUs.
8839 */
8840 cpup = phba->sli4_hba.cpu_map;
8841 cpu = first_cpu;
8842 cpup += cpu;
8843 for (idx = 0; idx < phba->sli4_hba.num_present_cpu;
8844 idx++) {
8845 if (cpup->phys_id == i) {
8846 /*
8847 * Save any IO channels that are
8848 * already mapped to this phys_id.
8849 */
8850 if (cpup->irq != LPFC_VECTOR_MAP_EMPTY) {
James Smart6690e0d2015-12-16 18:11:56 -05008851 if (saved_chann <=
8852 LPFC_FCP_IO_CHAN_MAX) {
8853 chann[saved_chann] =
8854 cpup->channel_id;
8855 saved_chann++;
8856 }
James Smart7bb03bb2013-04-17 20:19:16 -04008857 goto out;
8858 }
8859
8860 /* See if we are using round-robin */
8861 if (saved_chann == 0)
8862 saved_chann =
8863 phba->cfg_fcp_io_channel;
8864
8865 /* Associate next IO channel with CPU */
8866 cpup->channel_id = chann[used_chann];
8867 num_io_channel++;
8868 used_chann++;
8869 if (used_chann == saved_chann)
8870 used_chann = 0;
8871
8872 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8873 "3331 Set IO_CHANN "
8874 "CPU %d channel %d\n",
8875 idx, cpup->channel_id);
8876 }
8877out:
8878 cpu++;
8879 if (cpu >= phba->sli4_hba.num_present_cpu) {
8880 cpup = phba->sli4_hba.cpu_map;
8881 cpu = 0;
8882 } else {
8883 cpup++;
8884 }
8885 }
8886 }
8887
8888 if (phba->sli4_hba.num_online_cpu != phba->sli4_hba.num_present_cpu) {
8889 cpup = phba->sli4_hba.cpu_map;
8890 for (idx = 0; idx < phba->sli4_hba.num_present_cpu; idx++) {
8891 if (cpup->channel_id == LPFC_VECTOR_MAP_EMPTY) {
8892 cpup->channel_id = 0;
8893 num_io_channel++;
8894
8895 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8896 "3332 Assign IO_CHANN "
8897 "CPU %d channel %d\n",
8898 idx, cpup->channel_id);
8899 }
8900 cpup++;
8901 }
8902 }
8903
8904 /* Sanity check */
8905 if (num_io_channel != phba->sli4_hba.num_present_cpu)
8906 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8907 "3333 Set affinity mismatch:"
James Smartec2087a2013-09-06 12:20:36 -04008908 "%d chann != %d cpus: %d vectors\n",
James Smart7bb03bb2013-04-17 20:19:16 -04008909 num_io_channel, phba->sli4_hba.num_present_cpu,
8910 vectors);
8911
James Smartec2087a2013-09-06 12:20:36 -04008912 /* Enable using cpu affinity for scheduling */
James Smart7bb03bb2013-04-17 20:19:16 -04008913 phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_BY_CPU;
8914 return 1;
8915}
8916
8917
8918/**
James Smartda0436e2009-05-22 14:51:39 -04008919 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
8920 * @phba: pointer to lpfc hba data structure.
8921 *
8922 * This routine is invoked to enable the MSI-X interrupt vectors to device
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008923 * with SLI-4 interface spec. The kernel function pci_enable_msix_range()
8924 * is called to enable the MSI-X vectors. The device driver is responsible
8925 * for calling the individual request_irq() to register each MSI-X vector
8926 * with a interrupt handler, which is done in this function. Note that
8927 * later when device is unloading, the driver should always call free_irq()
8928 * on all MSI-X vectors it has done request_irq() on before calling
8929 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
8930 * will be left with MSI-X enabled and leaks its vectors.
James Smartda0436e2009-05-22 14:51:39 -04008931 *
8932 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008933 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008934 * other values - error
8935 **/
8936static int
8937lpfc_sli4_enable_msix(struct lpfc_hba *phba)
8938{
James Smart75baf692010-06-08 18:31:21 -04008939 int vectors, rc, index;
James Smartda0436e2009-05-22 14:51:39 -04008940
8941 /* Set up MSI-X multi-message vectors */
James Smart82c3e9b2012-09-29 11:29:50 -04008942 for (index = 0; index < phba->cfg_fcp_io_channel; index++)
James Smartda0436e2009-05-22 14:51:39 -04008943 phba->sli4_hba.msix_entries[index].entry = index;
8944
8945 /* Configure MSI-X capability structure */
James Smart82c3e9b2012-09-29 11:29:50 -04008946 vectors = phba->cfg_fcp_io_channel;
James Smart1ba981f2014-02-20 09:56:45 -05008947 if (phba->cfg_fof) {
8948 phba->sli4_hba.msix_entries[index].entry = index;
8949 vectors++;
8950 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008951 rc = pci_enable_msix_range(phba->pcidev, phba->sli4_hba.msix_entries,
8952 2, vectors);
8953 if (rc < 0) {
James Smartda0436e2009-05-22 14:51:39 -04008954 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8955 "0484 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02008956 goto vec_fail_out;
James Smartda0436e2009-05-22 14:51:39 -04008957 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008958 vectors = rc;
James Smart75baf692010-06-08 18:31:21 -04008959
James Smartda0436e2009-05-22 14:51:39 -04008960 /* Log MSI-X vector assignment */
James Smart75baf692010-06-08 18:31:21 -04008961 for (index = 0; index < vectors; index++)
James Smartda0436e2009-05-22 14:51:39 -04008962 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8963 "0489 MSI-X entry[%d]: vector=x%x "
8964 "message=%d\n", index,
8965 phba->sli4_hba.msix_entries[index].vector,
8966 phba->sli4_hba.msix_entries[index].entry);
James Smart67d12732012-08-03 12:36:13 -04008967
James Smart7bb03bb2013-04-17 20:19:16 -04008968 /* Assign MSI-X vectors to interrupt handlers */
James Smart67d12732012-08-03 12:36:13 -04008969 for (index = 0; index < vectors; index++) {
James Smart4305f182012-08-03 12:36:33 -04008970 memset(&phba->sli4_hba.handler_name[index], 0, 16);
James Smarta2fc4aef2014-09-03 12:57:55 -04008971 snprintf((char *)&phba->sli4_hba.handler_name[index],
8972 LPFC_SLI4_HANDLER_NAME_SZ,
James Smart4305f182012-08-03 12:36:33 -04008973 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -04008974
James Smart67d12732012-08-03 12:36:13 -04008975 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
8976 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
James Smartba20c852012-08-03 12:36:52 -04008977 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].fcp_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -05008978 if (phba->cfg_fof && (index == (vectors - 1)))
8979 rc = request_irq(
8980 phba->sli4_hba.msix_entries[index].vector,
James Smarted243d32015-05-21 13:55:25 -04008981 &lpfc_sli4_fof_intr_handler, 0,
James Smart1ba981f2014-02-20 09:56:45 -05008982 (char *)&phba->sli4_hba.handler_name[index],
8983 &phba->sli4_hba.fcp_eq_hdl[index]);
8984 else
8985 rc = request_irq(
8986 phba->sli4_hba.msix_entries[index].vector,
James Smarted243d32015-05-21 13:55:25 -04008987 &lpfc_sli4_hba_intr_handler, 0,
James Smart4305f182012-08-03 12:36:33 -04008988 (char *)&phba->sli4_hba.handler_name[index],
James Smart67d12732012-08-03 12:36:13 -04008989 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -04008990 if (rc) {
8991 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8992 "0486 MSI-X fast-path (%d) "
8993 "request_irq failed (%d)\n", index, rc);
8994 goto cfg_fail_out;
8995 }
8996 }
8997
James Smart1ba981f2014-02-20 09:56:45 -05008998 if (phba->cfg_fof)
8999 vectors--;
9000
James Smart82c3e9b2012-09-29 11:29:50 -04009001 if (vectors != phba->cfg_fcp_io_channel) {
9002 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9003 "3238 Reducing IO channels to match number of "
9004 "MSI-X vectors, requested %d got %d\n",
9005 phba->cfg_fcp_io_channel, vectors);
9006 phba->cfg_fcp_io_channel = vectors;
9007 }
James Smart7bb03bb2013-04-17 20:19:16 -04009008
James Smart8b0dff12015-05-22 10:42:38 -04009009 if (!shost_use_blk_mq(lpfc_shost_from_vport(phba->pport)))
9010 lpfc_sli4_set_affinity(phba, vectors);
James Smartda0436e2009-05-22 14:51:39 -04009011 return rc;
9012
9013cfg_fail_out:
9014 /* free the irq already requested */
James Smartacbd8612013-09-06 12:21:19 -04009015 for (--index; index >= 0; index--) {
9016 irq_set_affinity_hint(phba->sli4_hba.msix_entries[index].
9017 vector, NULL);
James Smart67d12732012-08-03 12:36:13 -04009018 free_irq(phba->sli4_hba.msix_entries[index].vector,
9019 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartacbd8612013-09-06 12:21:19 -04009020 }
James Smartda0436e2009-05-22 14:51:39 -04009021
James Smartda0436e2009-05-22 14:51:39 -04009022 /* Unconfigure MSI-X capability structure */
9023 pci_disable_msix(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009024
9025vec_fail_out:
James Smartda0436e2009-05-22 14:51:39 -04009026 return rc;
9027}
9028
9029/**
9030 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
9031 * @phba: pointer to lpfc hba data structure.
9032 *
9033 * This routine is invoked to release the MSI-X vectors and then disable the
9034 * MSI-X interrupt mode to device with SLI-4 interface spec.
9035 **/
9036static void
9037lpfc_sli4_disable_msix(struct lpfc_hba *phba)
9038{
9039 int index;
9040
9041 /* Free up MSI-X multi-message vectors */
James Smartacbd8612013-09-06 12:21:19 -04009042 for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
9043 irq_set_affinity_hint(phba->sli4_hba.msix_entries[index].
9044 vector, NULL);
James Smartda0436e2009-05-22 14:51:39 -04009045 free_irq(phba->sli4_hba.msix_entries[index].vector,
James Smart67d12732012-08-03 12:36:13 -04009046 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartacbd8612013-09-06 12:21:19 -04009047 }
James Smart1ba981f2014-02-20 09:56:45 -05009048 if (phba->cfg_fof) {
9049 free_irq(phba->sli4_hba.msix_entries[index].vector,
9050 &phba->sli4_hba.fcp_eq_hdl[index]);
9051 }
James Smartda0436e2009-05-22 14:51:39 -04009052 /* Disable MSI-X */
9053 pci_disable_msix(phba->pcidev);
9054
9055 return;
9056}
9057
9058/**
9059 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
9060 * @phba: pointer to lpfc hba data structure.
9061 *
9062 * This routine is invoked to enable the MSI interrupt mode to device with
9063 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
9064 * to enable the MSI vector. The device driver is responsible for calling
9065 * the request_irq() to register MSI vector with a interrupt the handler,
9066 * which is done in this function.
9067 *
9068 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009069 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009070 * other values - error
9071 **/
9072static int
9073lpfc_sli4_enable_msi(struct lpfc_hba *phba)
9074{
9075 int rc, index;
9076
9077 rc = pci_enable_msi(phba->pcidev);
9078 if (!rc)
9079 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9080 "0487 PCI enable MSI mode success.\n");
9081 else {
9082 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9083 "0488 PCI enable MSI mode failed (%d)\n", rc);
9084 return rc;
9085 }
9086
9087 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04009088 0, LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -04009089 if (rc) {
9090 pci_disable_msi(phba->pcidev);
9091 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9092 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -04009093 return rc;
James Smartda0436e2009-05-22 14:51:39 -04009094 }
9095
James Smart67d12732012-08-03 12:36:13 -04009096 for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
James Smartda0436e2009-05-22 14:51:39 -04009097 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9098 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9099 }
9100
James Smart1ba981f2014-02-20 09:56:45 -05009101 if (phba->cfg_fof) {
9102 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9103 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9104 }
James Smart75baf692010-06-08 18:31:21 -04009105 return 0;
James Smartda0436e2009-05-22 14:51:39 -04009106}
9107
9108/**
9109 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
9110 * @phba: pointer to lpfc hba data structure.
9111 *
9112 * This routine is invoked to disable the MSI interrupt mode to device with
9113 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
9114 * done request_irq() on before calling pci_disable_msi(). Failure to do so
9115 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
9116 * its vector.
9117 **/
9118static void
9119lpfc_sli4_disable_msi(struct lpfc_hba *phba)
9120{
9121 free_irq(phba->pcidev->irq, phba);
9122 pci_disable_msi(phba->pcidev);
9123 return;
9124}
9125
9126/**
9127 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
9128 * @phba: pointer to lpfc hba data structure.
9129 *
9130 * This routine is invoked to enable device interrupt and associate driver's
9131 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
9132 * interface spec. Depends on the interrupt mode configured to the driver,
9133 * the driver will try to fallback from the configured interrupt mode to an
9134 * interrupt mode which is supported by the platform, kernel, and device in
9135 * the order of:
9136 * MSI-X -> MSI -> IRQ.
9137 *
9138 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009139 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009140 * other values - error
9141 **/
9142static uint32_t
9143lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9144{
9145 uint32_t intr_mode = LPFC_INTR_ERROR;
9146 int retval, index;
9147
9148 if (cfg_mode == 2) {
9149 /* Preparation before conf_msi mbox cmd */
9150 retval = 0;
9151 if (!retval) {
9152 /* Now, try to enable MSI-X interrupt mode */
9153 retval = lpfc_sli4_enable_msix(phba);
9154 if (!retval) {
9155 /* Indicate initialization to MSI-X mode */
9156 phba->intr_type = MSIX;
9157 intr_mode = 2;
9158 }
9159 }
9160 }
9161
9162 /* Fallback to MSI if MSI-X initialization failed */
9163 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9164 retval = lpfc_sli4_enable_msi(phba);
9165 if (!retval) {
9166 /* Indicate initialization to MSI mode */
9167 phba->intr_type = MSI;
9168 intr_mode = 1;
9169 }
9170 }
9171
9172 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9173 if (phba->intr_type == NONE) {
9174 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
9175 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9176 if (!retval) {
9177 /* Indicate initialization to INTx mode */
9178 phba->intr_type = INTx;
9179 intr_mode = 0;
James Smart67d12732012-08-03 12:36:13 -04009180 for (index = 0; index < phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04009181 index++) {
9182 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9183 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
James Smartba20c852012-08-03 12:36:52 -04009184 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
9185 fcp_eq_in_use, 1);
James Smartda0436e2009-05-22 14:51:39 -04009186 }
James Smart1ba981f2014-02-20 09:56:45 -05009187 if (phba->cfg_fof) {
9188 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9189 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9190 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
9191 fcp_eq_in_use, 1);
9192 }
James Smartda0436e2009-05-22 14:51:39 -04009193 }
9194 }
9195 return intr_mode;
9196}
9197
9198/**
9199 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
9200 * @phba: pointer to lpfc hba data structure.
9201 *
9202 * This routine is invoked to disable device interrupt and disassociate
9203 * the driver's interrupt handler(s) from interrupt vector(s) to device
9204 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
9205 * will release the interrupt vector(s) for the message signaled interrupt.
9206 **/
9207static void
9208lpfc_sli4_disable_intr(struct lpfc_hba *phba)
9209{
9210 /* Disable the currently initialized interrupt mode */
9211 if (phba->intr_type == MSIX)
9212 lpfc_sli4_disable_msix(phba);
9213 else if (phba->intr_type == MSI)
9214 lpfc_sli4_disable_msi(phba);
9215 else if (phba->intr_type == INTx)
9216 free_irq(phba->pcidev->irq, phba);
9217
9218 /* Reset interrupt management states */
9219 phba->intr_type = NONE;
9220 phba->sli.slistat.sli_intr = 0;
9221
9222 return;
9223}
9224
9225/**
James Smart3772a992009-05-22 14:50:54 -04009226 * lpfc_unset_hba - Unset SLI3 hba device initialization
9227 * @phba: pointer to lpfc hba data structure.
9228 *
9229 * This routine is invoked to unset the HBA device initialization steps to
9230 * a device with SLI-3 interface spec.
9231 **/
9232static void
9233lpfc_unset_hba(struct lpfc_hba *phba)
9234{
9235 struct lpfc_vport *vport = phba->pport;
9236 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9237
9238 spin_lock_irq(shost->host_lock);
9239 vport->load_flag |= FC_UNLOADING;
9240 spin_unlock_irq(shost->host_lock);
9241
James Smart72859902012-01-18 16:25:38 -05009242 kfree(phba->vpi_bmask);
9243 kfree(phba->vpi_ids);
9244
James Smart3772a992009-05-22 14:50:54 -04009245 lpfc_stop_hba_timers(phba);
9246
9247 phba->pport->work_port_events = 0;
9248
9249 lpfc_sli_hba_down(phba);
9250
9251 lpfc_sli_brdrestart(phba);
9252
9253 lpfc_sli_disable_intr(phba);
9254
9255 return;
9256}
9257
9258/**
James Smart5af5eee2010-10-22 11:06:38 -04009259 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
9260 * @phba: Pointer to HBA context object.
9261 *
9262 * This function is called in the SLI4 code path to wait for completion
9263 * of device's XRIs exchange busy. It will check the XRI exchange busy
9264 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
9265 * that, it will check the XRI exchange busy on outstanding FCP and ELS
9266 * I/Os every 30 seconds, log error message, and wait forever. Only when
9267 * all XRI exchange busy complete, the driver unload shall proceed with
9268 * invoking the function reset ioctl mailbox command to the CNA and the
9269 * the rest of the driver unload resource release.
9270 **/
9271static void
9272lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
9273{
9274 int wait_time = 0;
9275 int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
9276 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9277
9278 while (!fcp_xri_cmpl || !els_xri_cmpl) {
9279 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
9280 if (!fcp_xri_cmpl)
9281 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9282 "2877 FCP XRI exchange busy "
9283 "wait time: %d seconds.\n",
9284 wait_time/1000);
9285 if (!els_xri_cmpl)
9286 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9287 "2878 ELS XRI exchange busy "
9288 "wait time: %d seconds.\n",
9289 wait_time/1000);
9290 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
9291 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
9292 } else {
9293 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
9294 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
9295 }
9296 fcp_xri_cmpl =
9297 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
9298 els_xri_cmpl =
9299 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9300 }
9301}
9302
9303/**
James Smartda0436e2009-05-22 14:51:39 -04009304 * lpfc_sli4_hba_unset - Unset the fcoe hba
9305 * @phba: Pointer to HBA context object.
9306 *
9307 * This function is called in the SLI4 code path to reset the HBA's FCoE
9308 * function. The caller is not required to hold any lock. This routine
9309 * issues PCI function reset mailbox command to reset the FCoE function.
9310 * At the end of the function, it calls lpfc_hba_down_post function to
9311 * free any pending commands.
9312 **/
9313static void
9314lpfc_sli4_hba_unset(struct lpfc_hba *phba)
9315{
9316 int wait_cnt = 0;
9317 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -04009318 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -04009319
9320 lpfc_stop_hba_timers(phba);
9321 phba->sli4_hba.intr_enable = 0;
9322
9323 /*
9324 * Gracefully wait out the potential current outstanding asynchronous
9325 * mailbox command.
9326 */
9327
9328 /* First, block any pending async mailbox command from posted */
9329 spin_lock_irq(&phba->hbalock);
9330 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
9331 spin_unlock_irq(&phba->hbalock);
9332 /* Now, trying to wait it out if we can */
9333 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9334 msleep(10);
9335 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
9336 break;
9337 }
9338 /* Forcefully release the outstanding mailbox command if timed out */
9339 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9340 spin_lock_irq(&phba->hbalock);
9341 mboxq = phba->sli.mbox_active;
9342 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
9343 __lpfc_mbox_cmpl_put(phba, mboxq);
9344 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9345 phba->sli.mbox_active = NULL;
9346 spin_unlock_irq(&phba->hbalock);
9347 }
9348
James Smart5af5eee2010-10-22 11:06:38 -04009349 /* Abort all iocbs associated with the hba */
9350 lpfc_sli_hba_iocb_abort(phba);
9351
9352 /* Wait for completion of device XRI exchange busy */
9353 lpfc_sli4_xri_exchange_busy_wait(phba);
9354
James Smartda0436e2009-05-22 14:51:39 -04009355 /* Disable PCI subsystem interrupt */
9356 lpfc_sli4_disable_intr(phba);
9357
James Smart912e3ac2011-05-24 11:42:11 -04009358 /* Disable SR-IOV if enabled */
9359 if (phba->cfg_sriov_nr_virtfn)
9360 pci_disable_sriov(pdev);
9361
James Smartda0436e2009-05-22 14:51:39 -04009362 /* Stop kthread signal shall trigger work_done one more time */
9363 kthread_stop(phba->worker_thread);
9364
James Smart3677a3a2010-09-29 11:19:14 -04009365 /* Reset SLI4 HBA FCoE function */
9366 lpfc_pci_function_reset(phba);
James Smart5350d872011-10-10 21:33:49 -04009367 lpfc_sli4_queue_destroy(phba);
James Smart3677a3a2010-09-29 11:19:14 -04009368
James Smartda0436e2009-05-22 14:51:39 -04009369 /* Stop the SLI4 device port */
9370 phba->pport->work_port_events = 0;
9371}
9372
James Smart28baac72010-02-12 14:42:03 -05009373 /**
9374 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
9375 * @phba: Pointer to HBA context object.
9376 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9377 *
9378 * This function is called in the SLI4 code path to read the port's
9379 * sli4 capabilities.
9380 *
9381 * This function may be be called from any context that can block-wait
9382 * for the completion. The expectation is that this routine is called
9383 * typically from probe_one or from the online routine.
9384 **/
9385int
9386lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9387{
9388 int rc;
9389 struct lpfc_mqe *mqe;
9390 struct lpfc_pc_sli4_params *sli4_params;
9391 uint32_t mbox_tmo;
9392
9393 rc = 0;
9394 mqe = &mboxq->u.mqe;
9395
9396 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -05009397 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -05009398 if (!phba->sli4_hba.intr_enable)
9399 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9400 else {
James Smarta183a152011-10-10 21:32:43 -04009401 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -05009402 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
9403 }
9404
9405 if (unlikely(rc))
9406 return 1;
9407
9408 sli4_params = &phba->sli4_hba.pc_sli4_params;
9409 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
9410 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
9411 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
9412 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
9413 &mqe->un.sli4_params);
9414 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
9415 &mqe->un.sli4_params);
9416 sli4_params->proto_types = mqe->un.sli4_params.word3;
9417 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
9418 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
9419 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
9420 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
9421 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
9422 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
9423 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
9424 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
9425 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
9426 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
9427 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
9428 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
9429 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
9430 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
9431 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
9432 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
9433 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
9434 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
9435 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
9436 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -04009437
9438 /* Make sure that sge_supp_len can be handled by the driver */
9439 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
9440 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
9441
James Smart28baac72010-02-12 14:42:03 -05009442 return rc;
9443}
9444
James Smartda0436e2009-05-22 14:51:39 -04009445/**
James Smartfedd3b72011-02-16 12:39:24 -05009446 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
9447 * @phba: Pointer to HBA context object.
9448 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9449 *
9450 * This function is called in the SLI4 code path to read the port's
9451 * sli4 capabilities.
9452 *
9453 * This function may be be called from any context that can block-wait
9454 * for the completion. The expectation is that this routine is called
9455 * typically from probe_one or from the online routine.
9456 **/
9457int
9458lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9459{
9460 int rc;
9461 struct lpfc_mqe *mqe = &mboxq->u.mqe;
9462 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -04009463 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -05009464 int length;
9465 struct lpfc_sli4_parameters *mbx_sli4_parameters;
9466
James Smart6d368e52011-05-24 11:44:12 -04009467 /*
9468 * By default, the driver assumes the SLI4 port requires RPI
9469 * header postings. The SLI4_PARAM response will correct this
9470 * assumption.
9471 */
9472 phba->sli4_hba.rpi_hdrs_in_use = 1;
9473
James Smartfedd3b72011-02-16 12:39:24 -05009474 /* Read the port's SLI4 Config Parameters */
9475 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
9476 sizeof(struct lpfc_sli4_cfg_mhdr));
9477 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9478 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
9479 length, LPFC_SLI4_MBX_EMBED);
9480 if (!phba->sli4_hba.intr_enable)
9481 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -04009482 else {
9483 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
9484 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
9485 }
James Smartfedd3b72011-02-16 12:39:24 -05009486 if (unlikely(rc))
9487 return rc;
9488 sli4_params = &phba->sli4_hba.pc_sli4_params;
9489 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
9490 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
9491 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
9492 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
9493 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
9494 mbx_sli4_parameters);
9495 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
9496 mbx_sli4_parameters);
9497 if (bf_get(cfg_phwq, mbx_sli4_parameters))
9498 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
9499 else
9500 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
9501 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
9502 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
James Smart1ba981f2014-02-20 09:56:45 -05009503 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -05009504 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
9505 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
9506 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
9507 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
James Smart0c651872013-07-15 18:33:23 -04009508 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -05009509 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
9510 mbx_sli4_parameters);
9511 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
9512 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -04009513 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
9514 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart05580562011-05-24 11:40:48 -04009515
9516 /* Make sure that sge_supp_len can be handled by the driver */
9517 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
9518 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
9519
James Smartfedd3b72011-02-16 12:39:24 -05009520 return 0;
9521}
9522
9523/**
James Smart3772a992009-05-22 14:50:54 -04009524 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
9525 * @pdev: pointer to PCI device
9526 * @pid: pointer to PCI device identifier
9527 *
9528 * This routine is to be called to attach a device with SLI-3 interface spec
9529 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9530 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
9531 * information of the device and driver to see if the driver state that it can
9532 * support this kind of device. If the match is successful, the driver core
9533 * invokes this routine. If this routine determines it can claim the HBA, it
9534 * does all the initialization that it needs to do to handle the HBA properly.
9535 *
9536 * Return code
9537 * 0 - driver can claim the device
9538 * negative value - driver can not claim the device
9539 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009540static int
James Smart3772a992009-05-22 14:50:54 -04009541lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
9542{
9543 struct lpfc_hba *phba;
9544 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -04009545 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -04009546 int error;
9547 uint32_t cfg_mode, intr_mode;
9548
9549 /* Allocate memory for HBA structure */
9550 phba = lpfc_hba_alloc(pdev);
9551 if (!phba)
9552 return -ENOMEM;
9553
9554 /* Perform generic PCI device enabling operation */
9555 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -04009556 if (error)
James Smart3772a992009-05-22 14:50:54 -04009557 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -04009558
9559 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
9560 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
9561 if (error)
9562 goto out_disable_pci_dev;
9563
9564 /* Set up SLI-3 specific device PCI memory space */
9565 error = lpfc_sli_pci_mem_setup(phba);
9566 if (error) {
9567 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9568 "1402 Failed to set up pci memory space.\n");
9569 goto out_disable_pci_dev;
9570 }
9571
9572 /* Set up phase-1 common device driver resources */
9573 error = lpfc_setup_driver_resource_phase1(phba);
9574 if (error) {
9575 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9576 "1403 Failed to set up driver resource.\n");
9577 goto out_unset_pci_mem_s3;
9578 }
9579
9580 /* Set up SLI-3 specific device driver resources */
9581 error = lpfc_sli_driver_resource_setup(phba);
9582 if (error) {
9583 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9584 "1404 Failed to set up driver resource.\n");
9585 goto out_unset_pci_mem_s3;
9586 }
9587
9588 /* Initialize and populate the iocb list per host */
9589 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
9590 if (error) {
9591 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9592 "1405 Failed to initialize iocb list.\n");
9593 goto out_unset_driver_resource_s3;
9594 }
9595
9596 /* Set up common device driver resources */
9597 error = lpfc_setup_driver_resource_phase2(phba);
9598 if (error) {
9599 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9600 "1406 Failed to set up driver resource.\n");
9601 goto out_free_iocb_list;
9602 }
9603
James Smart079b5c92011-08-21 21:48:49 -04009604 /* Get the default values for Model Name and Description */
9605 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
9606
James Smart3772a992009-05-22 14:50:54 -04009607 /* Create SCSI host to the physical port */
9608 error = lpfc_create_shost(phba);
9609 if (error) {
9610 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9611 "1407 Failed to create scsi host.\n");
9612 goto out_unset_driver_resource;
9613 }
9614
9615 /* Configure sysfs attributes */
9616 vport = phba->pport;
9617 error = lpfc_alloc_sysfs_attr(vport);
9618 if (error) {
9619 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9620 "1476 Failed to allocate sysfs attr\n");
9621 goto out_destroy_shost;
9622 }
9623
James Smart6669f9b2009-10-02 15:16:45 -04009624 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -04009625 /* Now, trying to enable interrupt and bring up the device */
9626 cfg_mode = phba->cfg_use_msi;
9627 while (true) {
9628 /* Put device to a known state before enabling interrupt */
9629 lpfc_stop_port(phba);
9630 /* Configure and enable interrupt */
9631 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
9632 if (intr_mode == LPFC_INTR_ERROR) {
9633 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9634 "0431 Failed to enable interrupt.\n");
9635 error = -ENODEV;
9636 goto out_free_sysfs_attr;
9637 }
9638 /* SLI-3 HBA setup */
9639 if (lpfc_sli_hba_setup(phba)) {
9640 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9641 "1477 Failed to set up hba\n");
9642 error = -ENODEV;
9643 goto out_remove_device;
9644 }
9645
9646 /* Wait 50ms for the interrupts of previous mailbox commands */
9647 msleep(50);
9648 /* Check active interrupts on message signaled interrupts */
9649 if (intr_mode == 0 ||
9650 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
9651 /* Log the current active interrupt mode */
9652 phba->intr_mode = intr_mode;
9653 lpfc_log_intr_mode(phba, intr_mode);
9654 break;
9655 } else {
9656 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9657 "0447 Configure interrupt mode (%d) "
9658 "failed active interrupt test.\n",
9659 intr_mode);
9660 /* Disable the current interrupt mode */
9661 lpfc_sli_disable_intr(phba);
9662 /* Try next level of interrupt mode */
9663 cfg_mode = --intr_mode;
9664 }
9665 }
9666
9667 /* Perform post initialization setup */
9668 lpfc_post_init_setup(phba);
9669
9670 /* Check if there are static vports to be created. */
9671 lpfc_create_static_vport(phba);
9672
9673 return 0;
9674
9675out_remove_device:
9676 lpfc_unset_hba(phba);
9677out_free_sysfs_attr:
9678 lpfc_free_sysfs_attr(vport);
9679out_destroy_shost:
9680 lpfc_destroy_shost(phba);
9681out_unset_driver_resource:
9682 lpfc_unset_driver_resource_phase2(phba);
9683out_free_iocb_list:
9684 lpfc_free_iocb_list(phba);
9685out_unset_driver_resource_s3:
9686 lpfc_sli_driver_resource_unset(phba);
9687out_unset_pci_mem_s3:
9688 lpfc_sli_pci_mem_unset(phba);
9689out_disable_pci_dev:
9690 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -04009691 if (shost)
9692 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -04009693out_free_phba:
9694 lpfc_hba_free(phba);
9695 return error;
9696}
9697
9698/**
9699 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -04009700 * @pdev: pointer to PCI device
9701 *
James Smart3772a992009-05-22 14:50:54 -04009702 * This routine is to be called to disattach a device with SLI-3 interface
9703 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9704 * removed from PCI bus, it performs all the necessary cleanup for the HBA
9705 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -04009706 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009707static void
James Smart3772a992009-05-22 14:50:54 -04009708lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -05009709{
James Smart2e0fef82007-06-17 19:56:36 -05009710 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9711 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -05009712 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -05009713 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -05009714 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05009715 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
9716
James Smart549e55c2007-08-02 11:09:51 -04009717 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04009718 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04009719 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05009720
James Smart858c9f62007-06-17 19:56:39 -05009721 lpfc_free_sysfs_attr(vport);
9722
James Smarteada2722008-12-04 22:39:13 -05009723 /* Release all the vports against this physical port */
9724 vports = lpfc_create_vport_work_array(phba);
9725 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -04009726 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9727 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
9728 continue;
James Smarteada2722008-12-04 22:39:13 -05009729 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -04009730 }
James Smarteada2722008-12-04 22:39:13 -05009731 lpfc_destroy_vport_work_array(phba, vports);
9732
9733 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -05009734 fc_remove_host(shost);
9735 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04009736 lpfc_cleanup(vport);
9737
James Smart2e0fef82007-06-17 19:56:36 -05009738 /*
9739 * Bring down the SLI Layer. This step disable all interrupts,
9740 * clears the rings, discards all mailbox commands, and resets
9741 * the HBA.
9742 */
James Smarta257bf92009-04-06 18:48:10 -04009743
Justin P. Mattock48e34d02010-12-30 15:07:58 -08009744 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -05009745 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -04009746 /* Stop kthread signal shall trigger work_done one more time */
9747 kthread_stop(phba->worker_thread);
9748 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -05009749 lpfc_sli_brdrestart(phba);
9750
James Smart72859902012-01-18 16:25:38 -05009751 kfree(phba->vpi_bmask);
9752 kfree(phba->vpi_ids);
9753
James Smart3772a992009-05-22 14:50:54 -04009754 lpfc_stop_hba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05009755 spin_lock_irq(&phba->hbalock);
9756 list_del_init(&vport->listentry);
9757 spin_unlock_irq(&phba->hbalock);
9758
James Smart858c9f62007-06-17 19:56:39 -05009759 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05009760
James Smart912e3ac2011-05-24 11:42:11 -04009761 /* Disable SR-IOV if enabled */
9762 if (phba->cfg_sriov_nr_virtfn)
9763 pci_disable_sriov(pdev);
9764
James Smart5b75da22008-12-04 22:39:35 -05009765 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009766 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -05009767
James Smart858c9f62007-06-17 19:56:39 -05009768 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05009769
9770 /*
9771 * Call scsi_free before mem_free since scsi bufs are released to their
9772 * corresponding pools here.
9773 */
9774 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -04009775 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -05009776
James Smart34b02dc2008-08-24 21:49:55 -04009777 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
9778 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -05009779
James Smart2e0fef82007-06-17 19:56:36 -05009780 /* Free resources associated with SLI2 interface */
9781 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -04009782 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -05009783
9784 /* unmap adapter SLIM and Control Registers */
9785 iounmap(phba->ctrl_regs_memmap_p);
9786 iounmap(phba->slim_memmap_p);
9787
James Smart3772a992009-05-22 14:50:54 -04009788 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -05009789
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05009790 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05009791 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05009792}
9793
Linas Vepstas8d63f372007-02-14 14:28:36 -06009794/**
James Smart3772a992009-05-22 14:50:54 -04009795 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05009796 * @pdev: pointer to PCI device
9797 * @msg: power management message
9798 *
James Smart3772a992009-05-22 14:50:54 -04009799 * This routine is to be called from the kernel's PCI subsystem to support
9800 * system Power Management (PM) to device with SLI-3 interface spec. When
9801 * PM invokes this method, it quiesces the device by stopping the driver's
9802 * worker thread for the device, turning off device's interrupt and DMA,
9803 * and bring the device offline. Note that as the driver implements the
9804 * minimum PM requirements to a power-aware driver's PM support for the
9805 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
9806 * to the suspend() method call will be treated as SUSPEND and the driver will
9807 * fully reinitialize its device during resume() method call, the driver will
9808 * set device to PCI_D3hot state in PCI config space instead of setting it
9809 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -05009810 *
9811 * Return code
James Smart3772a992009-05-22 14:50:54 -04009812 * 0 - driver suspended the device
9813 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05009814 **/
9815static int
James Smart3772a992009-05-22 14:50:54 -04009816lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -05009817{
9818 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9819 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9820
9821 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9822 "0473 PCI device Power Management suspend.\n");
9823
9824 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -04009825 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -05009826 lpfc_offline(phba);
9827 kthread_stop(phba->worker_thread);
9828
9829 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -04009830 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -05009831
9832 /* Save device state to PCI config space */
9833 pci_save_state(pdev);
9834 pci_set_power_state(pdev, PCI_D3hot);
9835
9836 return 0;
9837}
9838
9839/**
James Smart3772a992009-05-22 14:50:54 -04009840 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05009841 * @pdev: pointer to PCI device
9842 *
James Smart3772a992009-05-22 14:50:54 -04009843 * This routine is to be called from the kernel's PCI subsystem to support
9844 * system Power Management (PM) to device with SLI-3 interface spec. When PM
9845 * invokes this method, it restores the device's PCI config space state and
9846 * fully reinitializes the device and brings it online. Note that as the
9847 * driver implements the minimum PM requirements to a power-aware driver's
9848 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
9849 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
9850 * driver will fully reinitialize its device during resume() method call,
9851 * the device will be set to PCI_D0 directly in PCI config space before
9852 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -05009853 *
9854 * Return code
James Smart3772a992009-05-22 14:50:54 -04009855 * 0 - driver suspended the device
9856 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05009857 **/
9858static int
James Smart3772a992009-05-22 14:50:54 -04009859lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -05009860{
9861 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9862 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -05009863 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05009864 int error;
9865
9866 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9867 "0452 PCI device Power Management resume.\n");
9868
9869 /* Restore device state from PCI config space */
9870 pci_set_power_state(pdev, PCI_D0);
9871 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -04009872
James Smart1dfb5a42010-02-12 14:40:50 -05009873 /*
9874 * As the new kernel behavior of pci_restore_state() API call clears
9875 * device saved_state flag, need to save the restored state again.
9876 */
9877 pci_save_state(pdev);
9878
James Smart3a55b532008-12-04 22:38:54 -05009879 if (pdev->is_busmaster)
9880 pci_set_master(pdev);
9881
9882 /* Startup the kernel thread for this host adapter. */
9883 phba->worker_thread = kthread_run(lpfc_do_work, phba,
9884 "lpfc_worker_%d", phba->brd_no);
9885 if (IS_ERR(phba->worker_thread)) {
9886 error = PTR_ERR(phba->worker_thread);
9887 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9888 "0434 PM resume failed to start worker "
9889 "thread: error=x%x.\n", error);
9890 return error;
9891 }
9892
James Smart5b75da22008-12-04 22:39:35 -05009893 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009894 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05009895 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -05009896 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -05009897 "0430 PM resume Failed to enable interrupt\n");
9898 return -EIO;
9899 } else
9900 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05009901
9902 /* Restart HBA and bring it online */
9903 lpfc_sli_brdrestart(phba);
9904 lpfc_online(phba);
9905
James Smart5b75da22008-12-04 22:39:35 -05009906 /* Log the current active interrupt mode */
9907 lpfc_log_intr_mode(phba, phba->intr_mode);
9908
James Smart3a55b532008-12-04 22:38:54 -05009909 return 0;
9910}
9911
9912/**
James Smart891478a2009-11-18 15:40:23 -05009913 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
9914 * @phba: pointer to lpfc hba data structure.
9915 *
9916 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -04009917 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -05009918 **/
9919static void
9920lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
9921{
9922 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9923 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -04009924
9925 /*
9926 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
9927 * and let the SCSI mid-layer to retry them to recover.
9928 */
James Smartdb55fba2014-04-04 13:52:02 -04009929 lpfc_sli_abort_fcp_rings(phba);
James Smart891478a2009-11-18 15:40:23 -05009930}
9931
9932/**
James Smart0d878412009-10-02 15:16:56 -04009933 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
9934 * @phba: pointer to lpfc hba data structure.
9935 *
9936 * This routine is called to prepare the SLI3 device for PCI slot reset. It
9937 * disables the device interrupt and pci device, and aborts the internal FCP
9938 * pending I/Os.
9939 **/
9940static void
9941lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
9942{
James Smart0d878412009-10-02 15:16:56 -04009943 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -05009944 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -04009945
James Smart75baf692010-06-08 18:31:21 -04009946 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -04009947 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -04009948
James Smarte2af0d22010-03-15 11:25:32 -04009949 /* Block all SCSI devices' I/Os on the host */
9950 lpfc_scsi_dev_block(phba);
9951
James Smartea714f32013-04-17 20:18:47 -04009952 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9953 lpfc_sli_flush_fcp_rings(phba);
9954
James Smarte2af0d22010-03-15 11:25:32 -04009955 /* stop all timers */
9956 lpfc_stop_hba_timers(phba);
9957
James Smart0d878412009-10-02 15:16:56 -04009958 /* Disable interrupt and pci device */
9959 lpfc_sli_disable_intr(phba);
9960 pci_disable_device(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -04009961}
9962
9963/**
9964 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
9965 * @phba: pointer to lpfc hba data structure.
9966 *
9967 * This routine is called to prepare the SLI3 device for PCI slot permanently
9968 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
9969 * pending I/Os.
9970 **/
9971static void
James Smart75baf692010-06-08 18:31:21 -04009972lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -04009973{
9974 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -05009975 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -04009976 /* Block all SCSI devices' I/Os on the host */
9977 lpfc_scsi_dev_block(phba);
9978
9979 /* stop all timers */
9980 lpfc_stop_hba_timers(phba);
9981
James Smart0d878412009-10-02 15:16:56 -04009982 /* Clean up all driver's outstanding SCSI I/Os */
9983 lpfc_sli_flush_fcp_rings(phba);
9984}
9985
9986/**
James Smart3772a992009-05-22 14:50:54 -04009987 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -04009988 * @pdev: pointer to PCI device.
9989 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -06009990 *
James Smart3772a992009-05-22 14:50:54 -04009991 * This routine is called from the PCI subsystem for I/O error handling to
9992 * device with SLI-3 interface spec. This function is called by the PCI
9993 * subsystem after a PCI bus error affecting this device has been detected.
9994 * When this function is invoked, it will need to stop all the I/Os and
9995 * interrupt(s) to the device. Once that is done, it will return
9996 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
9997 * as desired.
James Smarte59058c2008-08-24 21:49:00 -04009998 *
9999 * Return codes
James Smart0d878412009-10-02 15:16:56 -040010000 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -040010001 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10002 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -040010003 **/
James Smart3772a992009-05-22 14:50:54 -040010004static pci_ers_result_t
10005lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010006{
James Smart51ef4c22007-08-02 11:10:31 -040010007 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10008 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010009
James Smart0d878412009-10-02 15:16:56 -040010010 switch (state) {
10011 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -050010012 /* Non-fatal error, prepare for recovery */
10013 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -040010014 return PCI_ERS_RESULT_CAN_RECOVER;
10015 case pci_channel_io_frozen:
10016 /* Fatal error, prepare for slot reset */
10017 lpfc_sli_prep_dev_for_reset(phba);
10018 return PCI_ERS_RESULT_NEED_RESET;
10019 case pci_channel_io_perm_failure:
10020 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -040010021 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010022 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -040010023 default:
10024 /* Unknown state, prepare and request slot reset */
10025 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10026 "0472 Unknown PCI error state: x%x\n", state);
10027 lpfc_sli_prep_dev_for_reset(phba);
10028 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -040010029 }
Linas Vepstas8d63f372007-02-14 14:28:36 -060010030}
10031
10032/**
James Smart3772a992009-05-22 14:50:54 -040010033 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -040010034 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010035 *
James Smart3772a992009-05-22 14:50:54 -040010036 * This routine is called from the PCI subsystem for error handling to
10037 * device with SLI-3 interface spec. This is called after PCI bus has been
10038 * reset to restart the PCI card from scratch, as if from a cold-boot.
10039 * During the PCI subsystem error recovery, after driver returns
10040 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10041 * recovery and then call this routine before calling the .resume method
10042 * to recover the device. This function will initialize the HBA device,
10043 * enable the interrupt, but it will just put the HBA to offline state
10044 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -040010045 *
10046 * Return codes
James Smart3772a992009-05-22 14:50:54 -040010047 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10048 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -060010049 */
James Smart3772a992009-05-22 14:50:54 -040010050static pci_ers_result_t
10051lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010052{
James Smart51ef4c22007-08-02 11:10:31 -040010053 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10054 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010055 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -050010056 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010057
10058 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +110010059 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -060010060 printk(KERN_ERR "lpfc: Cannot re-enable "
10061 "PCI device after reset.\n");
10062 return PCI_ERS_RESULT_DISCONNECT;
10063 }
10064
James Smart97207482008-12-04 22:39:19 -050010065 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050010066
10067 /*
10068 * As the new kernel behavior of pci_restore_state() API call clears
10069 * device saved_state flag, need to save the restored state again.
10070 */
10071 pci_save_state(pdev);
10072
James Smart97207482008-12-04 22:39:19 -050010073 if (pdev->is_busmaster)
10074 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010075
James Smart92d7f7b2007-06-17 19:56:38 -050010076 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040010077 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -050010078 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010079
James Smart5b75da22008-12-04 22:39:35 -050010080 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040010081 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050010082 if (intr_mode == LPFC_INTR_ERROR) {
10083 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10084 "0427 Cannot re-enable interrupt after "
10085 "slot reset.\n");
10086 return PCI_ERS_RESULT_DISCONNECT;
10087 } else
10088 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010089
James Smart75baf692010-06-08 18:31:21 -040010090 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -040010091 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010092 lpfc_offline(phba);
10093 lpfc_sli_brdrestart(phba);
10094
James Smart5b75da22008-12-04 22:39:35 -050010095 /* Log the current active interrupt mode */
10096 lpfc_log_intr_mode(phba, phba->intr_mode);
10097
Linas Vepstas8d63f372007-02-14 14:28:36 -060010098 return PCI_ERS_RESULT_RECOVERED;
10099}
10100
10101/**
James Smart3772a992009-05-22 14:50:54 -040010102 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -040010103 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -060010104 *
James Smart3772a992009-05-22 14:50:54 -040010105 * This routine is called from the PCI subsystem for error handling to device
10106 * with SLI-3 interface spec. It is called when kernel error recovery tells
10107 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10108 * error recovery. After this call, traffic can start to flow from this device
10109 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010110 */
James Smart3772a992009-05-22 14:50:54 -040010111static void
10112lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010113{
James Smart51ef4c22007-08-02 11:10:31 -040010114 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10115 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010116
James Smarte2af0d22010-03-15 11:25:32 -040010117 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -040010118 lpfc_online(phba);
James Smart0d878412009-10-02 15:16:56 -040010119
10120 /* Clean up Advanced Error Reporting (AER) if needed */
10121 if (phba->hba_flag & HBA_AER_ENABLED)
10122 pci_cleanup_aer_uncorrect_error_status(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010123}
10124
James Smart3772a992009-05-22 14:50:54 -040010125/**
James Smartda0436e2009-05-22 14:51:39 -040010126 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
10127 * @phba: pointer to lpfc hba data structure.
10128 *
10129 * returns the number of ELS/CT IOCBs to reserve
10130 **/
10131int
10132lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
10133{
10134 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
10135
James Smartf1126682009-06-10 17:22:44 -040010136 if (phba->sli_rev == LPFC_SLI_REV4) {
10137 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -040010138 return 10;
James Smartf1126682009-06-10 17:22:44 -040010139 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -040010140 return 25;
James Smartf1126682009-06-10 17:22:44 -040010141 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -040010142 return 50;
James Smartf1126682009-06-10 17:22:44 -040010143 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -040010144 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -040010145 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -040010146 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -040010147 else if (max_xri <= 2048)
10148 return 200;
10149 else
10150 return 250;
James Smartf1126682009-06-10 17:22:44 -040010151 } else
10152 return 0;
James Smartda0436e2009-05-22 14:51:39 -040010153}
10154
10155/**
James Smart52d52442011-05-24 11:42:45 -040010156 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -040010157 * @fw: pointer to firmware image returned from request_firmware.
James Smartce396282012-09-29 11:30:56 -040010158 * @phba: pointer to lpfc hba data structure.
James Smart52d52442011-05-24 11:42:45 -040010159 *
James Smart52d52442011-05-24 11:42:45 -040010160 **/
James Smartce396282012-09-29 11:30:56 -040010161static void
10162lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -040010163{
James Smartce396282012-09-29 11:30:56 -040010164 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -050010165 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -040010166 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -040010167 struct list_head dma_buffer_list;
10168 int i, rc = 0;
10169 struct lpfc_dmabuf *dmabuf, *next;
10170 uint32_t offset = 0, temp_offset = 0;
10171
James Smartc71ab862012-10-31 14:44:33 -040010172 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -040010173 if (!fw) {
10174 rc = -ENXIO;
10175 goto out;
10176 }
10177 image = (struct lpfc_grp_hdr *)fw->data;
10178
James Smart52d52442011-05-24 11:42:45 -040010179 INIT_LIST_HEAD(&dma_buffer_list);
James Smart079b5c92011-08-21 21:48:49 -040010180 if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) ||
10181 (bf_get_be32(lpfc_grp_hdr_file_type, image) !=
10182 LPFC_FILE_TYPE_GROUP) ||
10183 (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) ||
10184 (be32_to_cpu(image->size) != fw->size)) {
James Smart52d52442011-05-24 11:42:45 -040010185 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10186 "3022 Invalid FW image found. "
James Smart079b5c92011-08-21 21:48:49 -040010187 "Magic:%x Type:%x ID:%x\n",
10188 be32_to_cpu(image->magic_number),
10189 bf_get_be32(lpfc_grp_hdr_file_type, image),
10190 bf_get_be32(lpfc_grp_hdr_id, image));
James Smartce396282012-09-29 11:30:56 -040010191 rc = -EINVAL;
10192 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010193 }
10194 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -040010195 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -040010196 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartce396282012-09-29 11:30:56 -040010197 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -040010198 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -040010199 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -040010200 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
10201 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
10202 GFP_KERNEL);
10203 if (!dmabuf) {
10204 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040010205 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010206 }
10207 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
10208 SLI4_PAGE_SIZE,
10209 &dmabuf->phys,
10210 GFP_KERNEL);
10211 if (!dmabuf->virt) {
10212 kfree(dmabuf);
10213 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040010214 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010215 }
10216 list_add_tail(&dmabuf->list, &dma_buffer_list);
10217 }
10218 while (offset < fw->size) {
10219 temp_offset = offset;
10220 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -040010221 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -040010222 memcpy(dmabuf->virt,
10223 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -040010224 fw->size - temp_offset);
10225 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -040010226 break;
10227 }
James Smart52d52442011-05-24 11:42:45 -040010228 memcpy(dmabuf->virt, fw->data + temp_offset,
10229 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -040010230 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -040010231 }
10232 rc = lpfc_wr_object(phba, &dma_buffer_list,
10233 (fw->size - offset), &offset);
James Smartce396282012-09-29 11:30:56 -040010234 if (rc)
10235 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010236 }
10237 rc = offset;
10238 }
James Smartce396282012-09-29 11:30:56 -040010239
10240release_out:
James Smart52d52442011-05-24 11:42:45 -040010241 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
10242 list_del(&dmabuf->list);
10243 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
10244 dmabuf->virt, dmabuf->phys);
10245 kfree(dmabuf);
10246 }
James Smartce396282012-09-29 11:30:56 -040010247 release_firmware(fw);
10248out:
10249 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc71ab862012-10-31 14:44:33 -040010250 "3024 Firmware update done: %d.\n", rc);
James Smartce396282012-09-29 11:30:56 -040010251 return;
James Smart52d52442011-05-24 11:42:45 -040010252}
10253
10254/**
James Smartc71ab862012-10-31 14:44:33 -040010255 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
10256 * @phba: pointer to lpfc hba data structure.
10257 *
10258 * This routine is called to perform Linux generic firmware upgrade on device
10259 * that supports such feature.
10260 **/
10261int
10262lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
10263{
10264 uint8_t file_name[ELX_MODEL_NAME_SIZE];
10265 int ret;
10266 const struct firmware *fw;
10267
10268 /* Only supported on SLI4 interface type 2 for now */
10269 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
10270 LPFC_SLI_INTF_IF_TYPE_2)
10271 return -EPERM;
10272
10273 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
10274
10275 if (fw_upgrade == INT_FW_UPGRADE) {
10276 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
10277 file_name, &phba->pcidev->dev,
10278 GFP_KERNEL, (void *)phba,
10279 lpfc_write_firmware);
10280 } else if (fw_upgrade == RUN_FW_UPGRADE) {
10281 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
10282 if (!ret)
10283 lpfc_write_firmware(fw, (void *)phba);
10284 } else {
10285 ret = -EINVAL;
10286 }
10287
10288 return ret;
10289}
10290
10291/**
James Smartda0436e2009-05-22 14:51:39 -040010292 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
10293 * @pdev: pointer to PCI device
10294 * @pid: pointer to PCI device identifier
10295 *
10296 * This routine is called from the kernel's PCI subsystem to device with
10297 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10298 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10299 * information of the device and driver to see if the driver state that it
10300 * can support this kind of device. If the match is successful, the driver
10301 * core invokes this routine. If this routine determines it can claim the HBA,
10302 * it does all the initialization that it needs to do to handle the HBA
10303 * properly.
10304 *
10305 * Return code
10306 * 0 - driver can claim the device
10307 * negative value - driver can not claim the device
10308 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010309static int
James Smartda0436e2009-05-22 14:51:39 -040010310lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
10311{
10312 struct lpfc_hba *phba;
10313 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040010314 struct Scsi_Host *shost = NULL;
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040010315 int error;
James Smartda0436e2009-05-22 14:51:39 -040010316 uint32_t cfg_mode, intr_mode;
James Smart67d12732012-08-03 12:36:13 -040010317 int adjusted_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -040010318
10319 /* Allocate memory for HBA structure */
10320 phba = lpfc_hba_alloc(pdev);
10321 if (!phba)
10322 return -ENOMEM;
10323
10324 /* Perform generic PCI device enabling operation */
10325 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040010326 if (error)
James Smartda0436e2009-05-22 14:51:39 -040010327 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -040010328
10329 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
10330 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
10331 if (error)
10332 goto out_disable_pci_dev;
10333
10334 /* Set up SLI-4 specific device PCI memory space */
10335 error = lpfc_sli4_pci_mem_setup(phba);
10336 if (error) {
10337 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10338 "1410 Failed to set up pci memory space.\n");
10339 goto out_disable_pci_dev;
10340 }
10341
10342 /* Set up phase-1 common device driver resources */
10343 error = lpfc_setup_driver_resource_phase1(phba);
10344 if (error) {
10345 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10346 "1411 Failed to set up driver resource.\n");
10347 goto out_unset_pci_mem_s4;
10348 }
10349
10350 /* Set up SLI-4 Specific device driver resources */
10351 error = lpfc_sli4_driver_resource_setup(phba);
10352 if (error) {
10353 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10354 "1412 Failed to set up driver resource.\n");
10355 goto out_unset_pci_mem_s4;
10356 }
10357
10358 /* Initialize and populate the iocb list per host */
James Smart2a9bf3d2010-06-07 15:24:45 -040010359
10360 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10361 "2821 initialize iocb list %d.\n",
10362 phba->cfg_iocb_cnt*1024);
10363 error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
10364
James Smartda0436e2009-05-22 14:51:39 -040010365 if (error) {
10366 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10367 "1413 Failed to initialize iocb list.\n");
10368 goto out_unset_driver_resource_s4;
10369 }
10370
James Smart19ca7602010-11-20 23:11:55 -050010371 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -040010372 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -050010373
James Smartda0436e2009-05-22 14:51:39 -040010374 /* Set up common device driver resources */
10375 error = lpfc_setup_driver_resource_phase2(phba);
10376 if (error) {
10377 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10378 "1414 Failed to set up driver resource.\n");
10379 goto out_free_iocb_list;
10380 }
10381
James Smart079b5c92011-08-21 21:48:49 -040010382 /* Get the default values for Model Name and Description */
10383 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
10384
James Smartda0436e2009-05-22 14:51:39 -040010385 /* Create SCSI host to the physical port */
10386 error = lpfc_create_shost(phba);
10387 if (error) {
10388 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10389 "1415 Failed to create scsi host.\n");
10390 goto out_unset_driver_resource;
10391 }
10392
10393 /* Configure sysfs attributes */
10394 vport = phba->pport;
10395 error = lpfc_alloc_sysfs_attr(vport);
10396 if (error) {
10397 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10398 "1416 Failed to allocate sysfs attr\n");
10399 goto out_destroy_shost;
10400 }
10401
James Smart6669f9b2009-10-02 15:16:45 -040010402 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -040010403 /* Now, trying to enable interrupt and bring up the device */
10404 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -040010405
James Smart7b15db32013-01-03 15:43:29 -050010406 /* Put device to a known state before enabling interrupt */
10407 lpfc_stop_port(phba);
10408 /* Configure and enable interrupt */
10409 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
10410 if (intr_mode == LPFC_INTR_ERROR) {
10411 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10412 "0426 Failed to enable interrupt.\n");
10413 error = -ENODEV;
10414 goto out_free_sysfs_attr;
James Smartda0436e2009-05-22 14:51:39 -040010415 }
James Smart7b15db32013-01-03 15:43:29 -050010416 /* Default to single EQ for non-MSI-X */
10417 if (phba->intr_type != MSIX)
10418 adjusted_fcp_io_channel = 1;
10419 else
10420 adjusted_fcp_io_channel = phba->cfg_fcp_io_channel;
10421 phba->cfg_fcp_io_channel = adjusted_fcp_io_channel;
10422 /* Set up SLI-4 HBA */
10423 if (lpfc_sli4_hba_setup(phba)) {
10424 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10425 "1421 Failed to set up hba\n");
10426 error = -ENODEV;
10427 goto out_disable_intr;
10428 }
10429
10430 /* Log the current active interrupt mode */
10431 phba->intr_mode = intr_mode;
10432 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -040010433
10434 /* Perform post initialization setup */
10435 lpfc_post_init_setup(phba);
10436
James Smartc71ab862012-10-31 14:44:33 -040010437 /* check for firmware upgrade or downgrade */
10438 if (phba->cfg_request_firmware_upgrade)
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040010439 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -040010440
James Smart1c6834a2009-07-19 10:01:26 -040010441 /* Check if there are static vports to be created. */
10442 lpfc_create_static_vport(phba);
James Smartda0436e2009-05-22 14:51:39 -040010443 return 0;
10444
10445out_disable_intr:
10446 lpfc_sli4_disable_intr(phba);
10447out_free_sysfs_attr:
10448 lpfc_free_sysfs_attr(vport);
10449out_destroy_shost:
10450 lpfc_destroy_shost(phba);
10451out_unset_driver_resource:
10452 lpfc_unset_driver_resource_phase2(phba);
10453out_free_iocb_list:
10454 lpfc_free_iocb_list(phba);
10455out_unset_driver_resource_s4:
10456 lpfc_sli4_driver_resource_unset(phba);
10457out_unset_pci_mem_s4:
10458 lpfc_sli4_pci_mem_unset(phba);
10459out_disable_pci_dev:
10460 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040010461 if (shost)
10462 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -040010463out_free_phba:
10464 lpfc_hba_free(phba);
10465 return error;
10466}
10467
10468/**
10469 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
10470 * @pdev: pointer to PCI device
10471 *
10472 * This routine is called from the kernel's PCI subsystem to device with
10473 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10474 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10475 * device to be removed from the PCI subsystem properly.
10476 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010477static void
James Smartda0436e2009-05-22 14:51:39 -040010478lpfc_pci_remove_one_s4(struct pci_dev *pdev)
10479{
10480 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10481 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
10482 struct lpfc_vport **vports;
10483 struct lpfc_hba *phba = vport->phba;
10484 int i;
10485
10486 /* Mark the device unloading flag */
10487 spin_lock_irq(&phba->hbalock);
10488 vport->load_flag |= FC_UNLOADING;
10489 spin_unlock_irq(&phba->hbalock);
10490
10491 /* Free the HBA sysfs attributes */
10492 lpfc_free_sysfs_attr(vport);
10493
10494 /* Release all the vports against this physical port */
10495 vports = lpfc_create_vport_work_array(phba);
10496 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040010497 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10498 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
10499 continue;
James Smartda0436e2009-05-22 14:51:39 -040010500 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040010501 }
James Smartda0436e2009-05-22 14:51:39 -040010502 lpfc_destroy_vport_work_array(phba, vports);
10503
10504 /* Remove FC host and then SCSI host with the physical port */
10505 fc_remove_host(shost);
10506 scsi_remove_host(shost);
10507
10508 /* Perform cleanup on the physical port */
10509 lpfc_cleanup(vport);
10510
10511 /*
10512 * Bring down the SLI Layer. This step disables all interrupts,
10513 * clears the rings, discards all mailbox commands, and resets
10514 * the HBA FCoE function.
10515 */
10516 lpfc_debugfs_terminate(vport);
10517 lpfc_sli4_hba_unset(phba);
10518
10519 spin_lock_irq(&phba->hbalock);
10520 list_del_init(&vport->listentry);
10521 spin_unlock_irq(&phba->hbalock);
10522
James Smart3677a3a2010-09-29 11:19:14 -040010523 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -040010524 * buffers are released to their corresponding pools here.
10525 */
10526 lpfc_scsi_free(phba);
James Smart67d12732012-08-03 12:36:13 -040010527
James Smartda0436e2009-05-22 14:51:39 -040010528 lpfc_sli4_driver_resource_unset(phba);
10529
10530 /* Unmap adapter Control and Doorbell registers */
10531 lpfc_sli4_pci_mem_unset(phba);
10532
10533 /* Release PCI resources and disable device's PCI function */
10534 scsi_host_put(shost);
10535 lpfc_disable_pci_dev(phba);
10536
10537 /* Finally, free the driver's device data structure */
10538 lpfc_hba_free(phba);
10539
10540 return;
10541}
10542
10543/**
10544 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
10545 * @pdev: pointer to PCI device
10546 * @msg: power management message
10547 *
10548 * This routine is called from the kernel's PCI subsystem to support system
10549 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
10550 * this method, it quiesces the device by stopping the driver's worker
10551 * thread for the device, turning off device's interrupt and DMA, and bring
10552 * the device offline. Note that as the driver implements the minimum PM
10553 * requirements to a power-aware driver's PM support for suspend/resume -- all
10554 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
10555 * method call will be treated as SUSPEND and the driver will fully
10556 * reinitialize its device during resume() method call, the driver will set
10557 * device to PCI_D3hot state in PCI config space instead of setting it
10558 * according to the @msg provided by the PM.
10559 *
10560 * Return code
10561 * 0 - driver suspended the device
10562 * Error otherwise
10563 **/
10564static int
10565lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
10566{
10567 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10568 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10569
10570 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -040010571 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -040010572
10573 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040010574 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -040010575 lpfc_offline(phba);
10576 kthread_stop(phba->worker_thread);
10577
10578 /* Disable interrupt from device */
10579 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040010580 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040010581
10582 /* Save device state to PCI config space */
10583 pci_save_state(pdev);
10584 pci_set_power_state(pdev, PCI_D3hot);
10585
10586 return 0;
10587}
10588
10589/**
10590 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
10591 * @pdev: pointer to PCI device
10592 *
10593 * This routine is called from the kernel's PCI subsystem to support system
10594 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
10595 * this method, it restores the device's PCI config space state and fully
10596 * reinitializes the device and brings it online. Note that as the driver
10597 * implements the minimum PM requirements to a power-aware driver's PM for
10598 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10599 * to the suspend() method call will be treated as SUSPEND and the driver
10600 * will fully reinitialize its device during resume() method call, the device
10601 * will be set to PCI_D0 directly in PCI config space before restoring the
10602 * state.
10603 *
10604 * Return code
10605 * 0 - driver suspended the device
10606 * Error otherwise
10607 **/
10608static int
10609lpfc_pci_resume_one_s4(struct pci_dev *pdev)
10610{
10611 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10612 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10613 uint32_t intr_mode;
10614 int error;
10615
10616 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10617 "0292 PCI device Power Management resume.\n");
10618
10619 /* Restore device state from PCI config space */
10620 pci_set_power_state(pdev, PCI_D0);
10621 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050010622
10623 /*
10624 * As the new kernel behavior of pci_restore_state() API call clears
10625 * device saved_state flag, need to save the restored state again.
10626 */
10627 pci_save_state(pdev);
10628
James Smartda0436e2009-05-22 14:51:39 -040010629 if (pdev->is_busmaster)
10630 pci_set_master(pdev);
10631
10632 /* Startup the kernel thread for this host adapter. */
10633 phba->worker_thread = kthread_run(lpfc_do_work, phba,
10634 "lpfc_worker_%d", phba->brd_no);
10635 if (IS_ERR(phba->worker_thread)) {
10636 error = PTR_ERR(phba->worker_thread);
10637 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10638 "0293 PM resume failed to start worker "
10639 "thread: error=x%x.\n", error);
10640 return error;
10641 }
10642
10643 /* Configure and enable interrupt */
10644 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
10645 if (intr_mode == LPFC_INTR_ERROR) {
10646 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10647 "0294 PM resume Failed to enable interrupt\n");
10648 return -EIO;
10649 } else
10650 phba->intr_mode = intr_mode;
10651
10652 /* Restart HBA and bring it online */
10653 lpfc_sli_brdrestart(phba);
10654 lpfc_online(phba);
10655
10656 /* Log the current active interrupt mode */
10657 lpfc_log_intr_mode(phba, phba->intr_mode);
10658
10659 return 0;
10660}
10661
10662/**
James Smart75baf692010-06-08 18:31:21 -040010663 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
10664 * @phba: pointer to lpfc hba data structure.
10665 *
10666 * This routine is called to prepare the SLI4 device for PCI slot recover. It
10667 * aborts all the outstanding SCSI I/Os to the pci device.
10668 **/
10669static void
10670lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
10671{
James Smart75baf692010-06-08 18:31:21 -040010672 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10673 "2828 PCI channel I/O abort preparing for recovery\n");
10674 /*
10675 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10676 * and let the SCSI mid-layer to retry them to recover.
10677 */
James Smartdb55fba2014-04-04 13:52:02 -040010678 lpfc_sli_abort_fcp_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040010679}
10680
10681/**
10682 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
10683 * @phba: pointer to lpfc hba data structure.
10684 *
10685 * This routine is called to prepare the SLI4 device for PCI slot reset. It
10686 * disables the device interrupt and pci device, and aborts the internal FCP
10687 * pending I/Os.
10688 **/
10689static void
10690lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
10691{
10692 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10693 "2826 PCI channel disable preparing for reset\n");
10694
10695 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040010696 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010697
10698 /* Block all SCSI devices' I/Os on the host */
10699 lpfc_scsi_dev_block(phba);
10700
James Smartea714f32013-04-17 20:18:47 -040010701 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10702 lpfc_sli_flush_fcp_rings(phba);
10703
James Smart75baf692010-06-08 18:31:21 -040010704 /* stop all timers */
10705 lpfc_stop_hba_timers(phba);
10706
10707 /* Disable interrupt and pci device */
10708 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040010709 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -040010710 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -040010711}
10712
10713/**
10714 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
10715 * @phba: pointer to lpfc hba data structure.
10716 *
10717 * This routine is called to prepare the SLI4 device for PCI slot permanently
10718 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10719 * pending I/Os.
10720 **/
10721static void
10722lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
10723{
10724 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10725 "2827 PCI channel permanent disable for failure\n");
10726
10727 /* Block all SCSI devices' I/Os on the host */
10728 lpfc_scsi_dev_block(phba);
10729
10730 /* stop all timers */
10731 lpfc_stop_hba_timers(phba);
10732
10733 /* Clean up all driver's outstanding SCSI I/Os */
10734 lpfc_sli_flush_fcp_rings(phba);
10735}
10736
10737/**
James Smartda0436e2009-05-22 14:51:39 -040010738 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
10739 * @pdev: pointer to PCI device.
10740 * @state: the current PCI connection state.
10741 *
10742 * This routine is called from the PCI subsystem for error handling to device
10743 * with SLI-4 interface spec. This function is called by the PCI subsystem
10744 * after a PCI bus error affecting this device has been detected. When this
10745 * function is invoked, it will need to stop all the I/Os and interrupt(s)
10746 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
10747 * for the PCI subsystem to perform proper recovery as desired.
10748 *
10749 * Return codes
10750 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10751 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10752 **/
10753static pci_ers_result_t
10754lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
10755{
James Smart75baf692010-06-08 18:31:21 -040010756 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10757 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10758
10759 switch (state) {
10760 case pci_channel_io_normal:
10761 /* Non-fatal error, prepare for recovery */
10762 lpfc_sli4_prep_dev_for_recover(phba);
10763 return PCI_ERS_RESULT_CAN_RECOVER;
10764 case pci_channel_io_frozen:
10765 /* Fatal error, prepare for slot reset */
10766 lpfc_sli4_prep_dev_for_reset(phba);
10767 return PCI_ERS_RESULT_NEED_RESET;
10768 case pci_channel_io_perm_failure:
10769 /* Permanent failure, prepare for device down */
10770 lpfc_sli4_prep_dev_for_perm_failure(phba);
10771 return PCI_ERS_RESULT_DISCONNECT;
10772 default:
10773 /* Unknown state, prepare and request slot reset */
10774 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10775 "2825 Unknown PCI error state: x%x\n", state);
10776 lpfc_sli4_prep_dev_for_reset(phba);
10777 return PCI_ERS_RESULT_NEED_RESET;
10778 }
James Smartda0436e2009-05-22 14:51:39 -040010779}
10780
10781/**
10782 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
10783 * @pdev: pointer to PCI device.
10784 *
10785 * This routine is called from the PCI subsystem for error handling to device
10786 * with SLI-4 interface spec. It is called after PCI bus has been reset to
10787 * restart the PCI card from scratch, as if from a cold-boot. During the
10788 * PCI subsystem error recovery, after the driver returns
10789 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10790 * recovery and then call this routine before calling the .resume method to
10791 * recover the device. This function will initialize the HBA device, enable
10792 * the interrupt, but it will just put the HBA to offline state without
10793 * passing any I/O traffic.
10794 *
10795 * Return codes
10796 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10797 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10798 */
10799static pci_ers_result_t
10800lpfc_io_slot_reset_s4(struct pci_dev *pdev)
10801{
James Smart75baf692010-06-08 18:31:21 -040010802 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10803 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10804 struct lpfc_sli *psli = &phba->sli;
10805 uint32_t intr_mode;
10806
10807 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
10808 if (pci_enable_device_mem(pdev)) {
10809 printk(KERN_ERR "lpfc: Cannot re-enable "
10810 "PCI device after reset.\n");
10811 return PCI_ERS_RESULT_DISCONNECT;
10812 }
10813
10814 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040010815
10816 /*
10817 * As the new kernel behavior of pci_restore_state() API call clears
10818 * device saved_state flag, need to save the restored state again.
10819 */
10820 pci_save_state(pdev);
10821
James Smart75baf692010-06-08 18:31:21 -040010822 if (pdev->is_busmaster)
10823 pci_set_master(pdev);
10824
10825 spin_lock_irq(&phba->hbalock);
10826 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
10827 spin_unlock_irq(&phba->hbalock);
10828
10829 /* Configure and enable interrupt */
10830 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
10831 if (intr_mode == LPFC_INTR_ERROR) {
10832 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10833 "2824 Cannot re-enable interrupt after "
10834 "slot reset.\n");
10835 return PCI_ERS_RESULT_DISCONNECT;
10836 } else
10837 phba->intr_mode = intr_mode;
10838
10839 /* Log the current active interrupt mode */
10840 lpfc_log_intr_mode(phba, phba->intr_mode);
10841
James Smartda0436e2009-05-22 14:51:39 -040010842 return PCI_ERS_RESULT_RECOVERED;
10843}
10844
10845/**
10846 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
10847 * @pdev: pointer to PCI device
10848 *
10849 * This routine is called from the PCI subsystem for error handling to device
10850 * with SLI-4 interface spec. It is called when kernel error recovery tells
10851 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10852 * error recovery. After this call, traffic can start to flow from this device
10853 * again.
10854 **/
10855static void
10856lpfc_io_resume_s4(struct pci_dev *pdev)
10857{
James Smart75baf692010-06-08 18:31:21 -040010858 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10859 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10860
10861 /*
10862 * In case of slot reset, as function reset is performed through
10863 * mailbox command which needs DMA to be enabled, this operation
10864 * has to be moved to the io resume phase. Taking device offline
10865 * will perform the necessary cleanup.
10866 */
10867 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
10868 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040010869 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010870 lpfc_offline(phba);
10871 lpfc_sli_brdrestart(phba);
10872 /* Bring the device back online */
10873 lpfc_online(phba);
10874 }
10875
10876 /* Clean up Advanced Error Reporting (AER) if needed */
10877 if (phba->hba_flag & HBA_AER_ENABLED)
10878 pci_cleanup_aer_uncorrect_error_status(pdev);
James Smartda0436e2009-05-22 14:51:39 -040010879}
10880
10881/**
James Smart3772a992009-05-22 14:50:54 -040010882 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
10883 * @pdev: pointer to PCI device
10884 * @pid: pointer to PCI device identifier
10885 *
10886 * This routine is to be registered to the kernel's PCI subsystem. When an
10887 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
10888 * at PCI device-specific information of the device and driver to see if the
10889 * driver state that it can support this kind of device. If the match is
10890 * successful, the driver core invokes this routine. This routine dispatches
10891 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
10892 * do all the initialization that it needs to do to handle the HBA device
10893 * properly.
10894 *
10895 * Return code
10896 * 0 - driver can claim the device
10897 * negative value - driver can not claim the device
10898 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010899static int
James Smart3772a992009-05-22 14:50:54 -040010900lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
10901{
10902 int rc;
James Smart8fa38512009-07-19 10:01:03 -040010903 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040010904
James Smart28baac72010-02-12 14:42:03 -050010905 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040010906 return -ENODEV;
10907
James Smart8fa38512009-07-19 10:01:03 -040010908 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050010909 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040010910 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040010911 else
James Smart3772a992009-05-22 14:50:54 -040010912 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040010913
James Smart3772a992009-05-22 14:50:54 -040010914 return rc;
10915}
10916
10917/**
10918 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
10919 * @pdev: pointer to PCI device
10920 *
10921 * This routine is to be registered to the kernel's PCI subsystem. When an
10922 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
10923 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
10924 * remove routine, which will perform all the necessary cleanup for the
10925 * device to be removed from the PCI subsystem properly.
10926 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010927static void
James Smart3772a992009-05-22 14:50:54 -040010928lpfc_pci_remove_one(struct pci_dev *pdev)
10929{
10930 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10931 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10932
10933 switch (phba->pci_dev_grp) {
10934 case LPFC_PCI_DEV_LP:
10935 lpfc_pci_remove_one_s3(pdev);
10936 break;
James Smartda0436e2009-05-22 14:51:39 -040010937 case LPFC_PCI_DEV_OC:
10938 lpfc_pci_remove_one_s4(pdev);
10939 break;
James Smart3772a992009-05-22 14:50:54 -040010940 default:
10941 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10942 "1424 Invalid PCI device group: 0x%x\n",
10943 phba->pci_dev_grp);
10944 break;
10945 }
10946 return;
10947}
10948
10949/**
10950 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
10951 * @pdev: pointer to PCI device
10952 * @msg: power management message
10953 *
10954 * This routine is to be registered to the kernel's PCI subsystem to support
10955 * system Power Management (PM). When PM invokes this method, it dispatches
10956 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
10957 * suspend the device.
10958 *
10959 * Return code
10960 * 0 - driver suspended the device
10961 * Error otherwise
10962 **/
10963static int
10964lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
10965{
10966 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10967 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10968 int rc = -ENODEV;
10969
10970 switch (phba->pci_dev_grp) {
10971 case LPFC_PCI_DEV_LP:
10972 rc = lpfc_pci_suspend_one_s3(pdev, msg);
10973 break;
James Smartda0436e2009-05-22 14:51:39 -040010974 case LPFC_PCI_DEV_OC:
10975 rc = lpfc_pci_suspend_one_s4(pdev, msg);
10976 break;
James Smart3772a992009-05-22 14:50:54 -040010977 default:
10978 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10979 "1425 Invalid PCI device group: 0x%x\n",
10980 phba->pci_dev_grp);
10981 break;
10982 }
10983 return rc;
10984}
10985
10986/**
10987 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
10988 * @pdev: pointer to PCI device
10989 *
10990 * This routine is to be registered to the kernel's PCI subsystem to support
10991 * system Power Management (PM). When PM invokes this method, it dispatches
10992 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
10993 * resume the device.
10994 *
10995 * Return code
10996 * 0 - driver suspended the device
10997 * Error otherwise
10998 **/
10999static int
11000lpfc_pci_resume_one(struct pci_dev *pdev)
11001{
11002 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11003 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11004 int rc = -ENODEV;
11005
11006 switch (phba->pci_dev_grp) {
11007 case LPFC_PCI_DEV_LP:
11008 rc = lpfc_pci_resume_one_s3(pdev);
11009 break;
James Smartda0436e2009-05-22 14:51:39 -040011010 case LPFC_PCI_DEV_OC:
11011 rc = lpfc_pci_resume_one_s4(pdev);
11012 break;
James Smart3772a992009-05-22 14:50:54 -040011013 default:
11014 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11015 "1426 Invalid PCI device group: 0x%x\n",
11016 phba->pci_dev_grp);
11017 break;
11018 }
11019 return rc;
11020}
11021
11022/**
11023 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
11024 * @pdev: pointer to PCI device.
11025 * @state: the current PCI connection state.
11026 *
11027 * This routine is registered to the PCI subsystem for error handling. This
11028 * function is called by the PCI subsystem after a PCI bus error affecting
11029 * this device has been detected. When this routine is invoked, it dispatches
11030 * the action to the proper SLI-3 or SLI-4 device error detected handling
11031 * routine, which will perform the proper error detected operation.
11032 *
11033 * Return codes
11034 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11035 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11036 **/
11037static pci_ers_result_t
11038lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
11039{
11040 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11041 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11042 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11043
11044 switch (phba->pci_dev_grp) {
11045 case LPFC_PCI_DEV_LP:
11046 rc = lpfc_io_error_detected_s3(pdev, state);
11047 break;
James Smartda0436e2009-05-22 14:51:39 -040011048 case LPFC_PCI_DEV_OC:
11049 rc = lpfc_io_error_detected_s4(pdev, state);
11050 break;
James Smart3772a992009-05-22 14:50:54 -040011051 default:
11052 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11053 "1427 Invalid PCI device group: 0x%x\n",
11054 phba->pci_dev_grp);
11055 break;
11056 }
11057 return rc;
11058}
11059
11060/**
11061 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
11062 * @pdev: pointer to PCI device.
11063 *
11064 * This routine is registered to the PCI subsystem for error handling. This
11065 * function is called after PCI bus has been reset to restart the PCI card
11066 * from scratch, as if from a cold-boot. When this routine is invoked, it
11067 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
11068 * routine, which will perform the proper device reset.
11069 *
11070 * Return codes
11071 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11072 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11073 **/
11074static pci_ers_result_t
11075lpfc_io_slot_reset(struct pci_dev *pdev)
11076{
11077 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11078 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11079 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11080
11081 switch (phba->pci_dev_grp) {
11082 case LPFC_PCI_DEV_LP:
11083 rc = lpfc_io_slot_reset_s3(pdev);
11084 break;
James Smartda0436e2009-05-22 14:51:39 -040011085 case LPFC_PCI_DEV_OC:
11086 rc = lpfc_io_slot_reset_s4(pdev);
11087 break;
James Smart3772a992009-05-22 14:50:54 -040011088 default:
11089 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11090 "1428 Invalid PCI device group: 0x%x\n",
11091 phba->pci_dev_grp);
11092 break;
11093 }
11094 return rc;
11095}
11096
11097/**
11098 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
11099 * @pdev: pointer to PCI device
11100 *
11101 * This routine is registered to the PCI subsystem for error handling. It
11102 * is called when kernel error recovery tells the lpfc driver that it is
11103 * OK to resume normal PCI operation after PCI bus error recovery. When
11104 * this routine is invoked, it dispatches the action to the proper SLI-3
11105 * or SLI-4 device io_resume routine, which will resume the device operation.
11106 **/
11107static void
11108lpfc_io_resume(struct pci_dev *pdev)
11109{
11110 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11111 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11112
11113 switch (phba->pci_dev_grp) {
11114 case LPFC_PCI_DEV_LP:
11115 lpfc_io_resume_s3(pdev);
11116 break;
James Smartda0436e2009-05-22 14:51:39 -040011117 case LPFC_PCI_DEV_OC:
11118 lpfc_io_resume_s4(pdev);
11119 break;
James Smart3772a992009-05-22 14:50:54 -040011120 default:
11121 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11122 "1429 Invalid PCI device group: 0x%x\n",
11123 phba->pci_dev_grp);
11124 break;
11125 }
11126 return;
11127}
11128
James Smart1ba981f2014-02-20 09:56:45 -050011129/**
11130 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
11131 * @phba: pointer to lpfc hba data structure.
11132 *
11133 * This routine checks to see if OAS is supported for this adapter. If
11134 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
11135 * the enable oas flag is cleared and the pool created for OAS device data
11136 * is destroyed.
11137 *
11138 **/
11139void
11140lpfc_sli4_oas_verify(struct lpfc_hba *phba)
11141{
11142
11143 if (!phba->cfg_EnableXLane)
11144 return;
11145
11146 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
11147 phba->cfg_fof = 1;
11148 } else {
James Smartf38fa0b2014-04-04 13:52:21 -040011149 phba->cfg_fof = 0;
James Smart1ba981f2014-02-20 09:56:45 -050011150 if (phba->device_data_mem_pool)
11151 mempool_destroy(phba->device_data_mem_pool);
11152 phba->device_data_mem_pool = NULL;
11153 }
11154
11155 return;
11156}
11157
11158/**
11159 * lpfc_fof_queue_setup - Set up all the fof queues
11160 * @phba: pointer to lpfc hba data structure.
11161 *
11162 * This routine is invoked to set up all the fof queues for the FC HBA
11163 * operation.
11164 *
11165 * Return codes
11166 * 0 - successful
11167 * -ENOMEM - No available memory
11168 **/
11169int
11170lpfc_fof_queue_setup(struct lpfc_hba *phba)
11171{
11172 struct lpfc_sli *psli = &phba->sli;
11173 int rc;
11174
11175 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
11176 if (rc)
11177 return -ENOMEM;
11178
James Smartf38fa0b2014-04-04 13:52:21 -040011179 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050011180
11181 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
11182 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
11183 if (rc)
11184 goto out_oas_cq;
11185
11186 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
11187 phba->sli4_hba.oas_cq, LPFC_FCP);
11188 if (rc)
11189 goto out_oas_wq;
11190
11191 phba->sli4_hba.oas_cq->pring = &psli->ring[LPFC_FCP_OAS_RING];
11192 phba->sli4_hba.oas_ring = &psli->ring[LPFC_FCP_OAS_RING];
11193 }
11194
11195 return 0;
11196
11197out_oas_wq:
James Smartf38fa0b2014-04-04 13:52:21 -040011198 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
James Smart1ba981f2014-02-20 09:56:45 -050011199out_oas_cq:
11200 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
11201 return rc;
11202
11203}
11204
11205/**
11206 * lpfc_fof_queue_create - Create all the fof queues
11207 * @phba: pointer to lpfc hba data structure.
11208 *
11209 * This routine is invoked to allocate all the fof queues for the FC HBA
11210 * operation. For each SLI4 queue type, the parameters such as queue entry
11211 * count (queue depth) shall be taken from the module parameter. For now,
11212 * we just use some constant number as place holder.
11213 *
11214 * Return codes
11215 * 0 - successful
11216 * -ENOMEM - No availble memory
11217 * -EIO - The mailbox failed to complete successfully.
11218 **/
11219int
11220lpfc_fof_queue_create(struct lpfc_hba *phba)
11221{
11222 struct lpfc_queue *qdesc;
11223
11224 /* Create FOF EQ */
11225 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
11226 phba->sli4_hba.eq_ecount);
11227 if (!qdesc)
11228 goto out_error;
11229
11230 phba->sli4_hba.fof_eq = qdesc;
11231
James Smartf38fa0b2014-04-04 13:52:21 -040011232 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050011233
11234 /* Create OAS CQ */
11235 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
11236 phba->sli4_hba.cq_ecount);
11237 if (!qdesc)
11238 goto out_error;
11239
11240 phba->sli4_hba.oas_cq = qdesc;
11241
11242 /* Create OAS WQ */
11243 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
11244 phba->sli4_hba.wq_ecount);
11245 if (!qdesc)
11246 goto out_error;
11247
11248 phba->sli4_hba.oas_wq = qdesc;
11249
11250 }
11251 return 0;
11252
11253out_error:
11254 lpfc_fof_queue_destroy(phba);
11255 return -ENOMEM;
11256}
11257
11258/**
11259 * lpfc_fof_queue_destroy - Destroy all the fof queues
11260 * @phba: pointer to lpfc hba data structure.
11261 *
11262 * This routine is invoked to release all the SLI4 queues with the FC HBA
11263 * operation.
11264 *
11265 * Return codes
11266 * 0 - successful
11267 **/
11268int
11269lpfc_fof_queue_destroy(struct lpfc_hba *phba)
11270{
11271 /* Release FOF Event queue */
11272 if (phba->sli4_hba.fof_eq != NULL) {
11273 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
11274 phba->sli4_hba.fof_eq = NULL;
11275 }
11276
11277 /* Release OAS Completion queue */
11278 if (phba->sli4_hba.oas_cq != NULL) {
11279 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
11280 phba->sli4_hba.oas_cq = NULL;
11281 }
11282
11283 /* Release OAS Work queue */
11284 if (phba->sli4_hba.oas_wq != NULL) {
11285 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
11286 phba->sli4_hba.oas_wq = NULL;
11287 }
11288 return 0;
11289}
11290
dea31012005-04-17 16:05:31 -050011291static struct pci_device_id lpfc_id_table[] = {
11292 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
11293 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -040011294 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
11295 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011296 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
11297 PCI_ANY_ID, PCI_ANY_ID, },
11298 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
11299 PCI_ANY_ID, PCI_ANY_ID, },
11300 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
11301 PCI_ANY_ID, PCI_ANY_ID, },
11302 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
11303 PCI_ANY_ID, PCI_ANY_ID, },
11304 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
11305 PCI_ANY_ID, PCI_ANY_ID, },
11306 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
11307 PCI_ANY_ID, PCI_ANY_ID, },
11308 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
11309 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011310 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
11311 PCI_ANY_ID, PCI_ANY_ID, },
11312 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
11313 PCI_ANY_ID, PCI_ANY_ID, },
11314 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
11315 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011316 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
11317 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011318 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
11319 PCI_ANY_ID, PCI_ANY_ID, },
11320 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
11321 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011322 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
11323 PCI_ANY_ID, PCI_ANY_ID, },
11324 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
11325 PCI_ANY_ID, PCI_ANY_ID, },
11326 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
11327 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -040011328 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
11329 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011330 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
11331 PCI_ANY_ID, PCI_ANY_ID, },
11332 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
11333 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011334 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
11335 PCI_ANY_ID, PCI_ANY_ID, },
11336 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
11337 PCI_ANY_ID, PCI_ANY_ID, },
11338 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
11339 PCI_ANY_ID, PCI_ANY_ID, },
11340 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
11341 PCI_ANY_ID, PCI_ANY_ID, },
11342 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
11343 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011344 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
11345 PCI_ANY_ID, PCI_ANY_ID, },
11346 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
11347 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -040011348 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
11349 PCI_ANY_ID, PCI_ANY_ID, },
11350 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
11351 PCI_ANY_ID, PCI_ANY_ID, },
11352 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
11353 PCI_ANY_ID, PCI_ANY_ID, },
11354 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
11355 PCI_ANY_ID, PCI_ANY_ID, },
11356 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
11357 PCI_ANY_ID, PCI_ANY_ID, },
11358 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
11359 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -040011360 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
11361 PCI_ANY_ID, PCI_ANY_ID, },
11362 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
11363 PCI_ANY_ID, PCI_ANY_ID, },
11364 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
11365 PCI_ANY_ID, PCI_ANY_ID, },
James Smart3772a992009-05-22 14:50:54 -040011366 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
11367 PCI_ANY_ID, PCI_ANY_ID, },
James Smarta747c9c2009-11-18 15:41:10 -050011368 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT,
11369 PCI_ANY_ID, PCI_ANY_ID, },
11370 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON,
James Smart6669f9b2009-10-02 15:16:45 -040011371 PCI_ANY_ID, PCI_ANY_ID, },
James Smart98fc5dd2010-06-07 15:24:29 -040011372 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS,
11373 PCI_ANY_ID, PCI_ANY_ID, },
James Smart085c6472010-11-20 23:11:37 -050011374 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC,
11375 PCI_ANY_ID, PCI_ANY_ID, },
11376 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE,
11377 PCI_ANY_ID, PCI_ANY_ID, },
James Smartc0c11512011-05-24 11:41:34 -040011378 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF,
11379 PCI_ANY_ID, PCI_ANY_ID, },
11380 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF,
11381 PCI_ANY_ID, PCI_ANY_ID, },
James Smartd38dd522015-08-31 16:48:17 -040011382 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_G6_FC,
11383 PCI_ANY_ID, PCI_ANY_ID, },
James Smartf8cafd32012-08-03 12:42:51 -040011384 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK,
11385 PCI_ANY_ID, PCI_ANY_ID, },
11386 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF,
11387 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011388 { 0 }
11389};
11390
11391MODULE_DEVICE_TABLE(pci, lpfc_id_table);
11392
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070011393static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060011394 .error_detected = lpfc_io_error_detected,
11395 .slot_reset = lpfc_io_slot_reset,
11396 .resume = lpfc_io_resume,
11397};
11398
dea31012005-04-17 16:05:31 -050011399static struct pci_driver lpfc_driver = {
11400 .name = LPFC_DRIVER_NAME,
11401 .id_table = lpfc_id_table,
11402 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011403 .remove = lpfc_pci_remove_one,
James Smart3a55b532008-12-04 22:38:54 -050011404 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040011405 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050011406 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050011407};
11408
James Smart3ef6d242012-01-18 16:23:48 -050011409static const struct file_operations lpfc_mgmt_fop = {
Al Viro858feac2013-04-14 22:39:37 -040011410 .owner = THIS_MODULE,
James Smart3ef6d242012-01-18 16:23:48 -050011411};
11412
11413static struct miscdevice lpfc_mgmt_dev = {
11414 .minor = MISC_DYNAMIC_MINOR,
11415 .name = "lpfcmgmt",
11416 .fops = &lpfc_mgmt_fop,
11417};
11418
James Smarte59058c2008-08-24 21:49:00 -040011419/**
James Smart3621a712009-04-06 18:47:14 -040011420 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040011421 *
11422 * This routine is to be invoked when the lpfc module is loaded into the
11423 * kernel. The special kernel macro module_init() is used to indicate the
11424 * role of this routine to the kernel as lpfc module entry point.
11425 *
11426 * Return codes
11427 * 0 - successful
11428 * -ENOMEM - FC attach transport failed
11429 * all others - failed
11430 */
dea31012005-04-17 16:05:31 -050011431static int __init
11432lpfc_init(void)
11433{
James Smart7bb03bb2013-04-17 20:19:16 -040011434 int cpu;
dea31012005-04-17 16:05:31 -050011435 int error = 0;
11436
11437 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040011438 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050011439
James Smart3ef6d242012-01-18 16:23:48 -050011440 error = misc_register(&lpfc_mgmt_dev);
11441 if (error)
11442 printk(KERN_ERR "Could not register lpfcmgmt device, "
11443 "misc_register returned with status %d", error);
11444
James Smart7ee5d432007-10-27 13:37:17 -040011445 if (lpfc_enable_npiv) {
11446 lpfc_transport_functions.vport_create = lpfc_vport_create;
11447 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
11448 }
dea31012005-04-17 16:05:31 -050011449 lpfc_transport_template =
11450 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040011451 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050011452 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040011453 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -040011454 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -040011455 fc_attach_transport(&lpfc_vport_transport_functions);
11456 if (lpfc_vport_transport_template == NULL) {
11457 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040011458 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -040011459 }
James Smart7ee5d432007-10-27 13:37:17 -040011460 }
James Smart7bb03bb2013-04-17 20:19:16 -040011461
11462 /* Initialize in case vector mapping is needed */
James Smartb246de12013-05-31 17:03:07 -040011463 lpfc_used_cpu = NULL;
11464 lpfc_present_cpu = 0;
11465 for_each_present_cpu(cpu)
11466 lpfc_present_cpu++;
James Smart7bb03bb2013-04-17 20:19:16 -040011467
dea31012005-04-17 16:05:31 -050011468 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050011469 if (error) {
dea31012005-04-17 16:05:31 -050011470 fc_release_transport(lpfc_transport_template);
James Smartd7c255b2008-08-24 21:50:00 -040011471 if (lpfc_enable_npiv)
11472 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050011473 }
dea31012005-04-17 16:05:31 -050011474
11475 return error;
11476}
11477
James Smarte59058c2008-08-24 21:49:00 -040011478/**
James Smart3621a712009-04-06 18:47:14 -040011479 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040011480 *
11481 * This routine is invoked when the lpfc module is removed from the kernel.
11482 * The special kernel macro module_exit() is used to indicate the role of
11483 * this routine to the kernel as lpfc module exit point.
11484 */
dea31012005-04-17 16:05:31 -050011485static void __exit
11486lpfc_exit(void)
11487{
James Smart3ef6d242012-01-18 16:23:48 -050011488 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050011489 pci_unregister_driver(&lpfc_driver);
11490 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040011491 if (lpfc_enable_npiv)
11492 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050011493 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040011494 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
11495 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050011496 (1L << _dump_buf_data_order), _dump_buf_data);
11497 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
11498 }
11499
11500 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040011501 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
11502 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050011503 (1L << _dump_buf_dif_order), _dump_buf_dif);
11504 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
11505 }
James Smartb246de12013-05-31 17:03:07 -040011506 kfree(lpfc_used_cpu);
Johannes Thumshirn79739672015-08-31 16:48:11 -040011507 idr_destroy(&lpfc_hba_index);
dea31012005-04-17 16:05:31 -050011508}
11509
11510module_init(lpfc_init);
11511module_exit(lpfc_exit);
11512MODULE_LICENSE("GPL");
11513MODULE_DESCRIPTION(LPFC_MODULE_DESC);
11514MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
11515MODULE_VERSION("0:" LPFC_DRIVER_VERSION);