blob: b43f7ac9812c3473b0bb04c227bfc7c38e09175e [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 Smart50611572016-03-31 14:12:34 -07004 * Copyright (C) 2004-2016 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);
Arnd Bergmannaeb66412016-03-14 15:29:44 +01002863 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 }
Arnd Bergmannaeb66412016-03-14 15:29:44 +01002880 }
2881 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002882
James Smart46fa3112007-04-25 09:51:45 -04002883 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002884 return 0;
2885}
2886
James Smarte59058c2008-08-24 21:49:00 -04002887/**
James Smart3621a712009-04-06 18:47:14 -04002888 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04002889 * @phba: pointer to lpfc hba data structure.
2890 *
2891 * This routine marks a HBA's management interface as not blocked. Once the
2892 * HBA's management interface is marked as not blocked, all the user space
2893 * access to the HBA, whether they are from sysfs interface or libdfc
2894 * interface will be allowed. The HBA is set to block the management interface
2895 * when the driver prepares the HBA interface for online or offline and then
2896 * set to unblock the management interface afterwards.
2897 **/
James Smart46fa3112007-04-25 09:51:45 -04002898void
James Smart46fa3112007-04-25 09:51:45 -04002899lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
2900{
2901 unsigned long iflag;
2902
James Smart2e0fef82007-06-17 19:56:36 -05002903 spin_lock_irqsave(&phba->hbalock, iflag);
2904 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
2905 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04002906}
2907
James Smarte59058c2008-08-24 21:49:00 -04002908/**
James Smart3621a712009-04-06 18:47:14 -04002909 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04002910 * @phba: pointer to lpfc hba data structure.
2911 *
2912 * This routine is invoked to prepare a HBA to be brought offline. It performs
2913 * unregistration login to all the nodes on all vports and flushes the mailbox
2914 * queue to make it ready to be brought offline.
2915 **/
James Smart46fa3112007-04-25 09:51:45 -04002916void
James Smart618a5232012-06-12 13:54:36 -04002917lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04002918{
James Smart2e0fef82007-06-17 19:56:36 -05002919 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04002920 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04002921 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05002922 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04002923 int i;
dea31012005-04-17 16:05:31 -05002924
James Smart2e0fef82007-06-17 19:56:36 -05002925 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002926 return;
dea31012005-04-17 16:05:31 -05002927
James Smart618a5232012-06-12 13:54:36 -04002928 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05002929
2930 lpfc_linkdown(phba);
2931
James Smart87af33f2007-10-27 13:37:43 -04002932 /* Issue an unreg_login to all nodes on all vports */
2933 vports = lpfc_create_vport_work_array(phba);
2934 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04002935 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04002936 if (vports[i]->load_flag & FC_UNLOADING)
2937 continue;
James Smart72100cc2010-02-12 14:43:01 -05002938 shost = lpfc_shost_from_vport(vports[i]);
2939 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05002940 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002941 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2942 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05002943 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05002944
James Smart87af33f2007-10-27 13:37:43 -04002945 shost = lpfc_shost_from_vport(vports[i]);
2946 list_for_each_entry_safe(ndlp, next_ndlp,
2947 &vports[i]->fc_nodes,
2948 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002949 if (!NLP_CHK_NODE_ACT(ndlp))
2950 continue;
James Smart87af33f2007-10-27 13:37:43 -04002951 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2952 continue;
2953 if (ndlp->nlp_type & NLP_FABRIC) {
2954 lpfc_disc_state_machine(vports[i], ndlp,
2955 NULL, NLP_EVT_DEVICE_RECOVERY);
2956 lpfc_disc_state_machine(vports[i], ndlp,
2957 NULL, NLP_EVT_DEVICE_RM);
2958 }
2959 spin_lock_irq(shost->host_lock);
2960 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart401ee0c2012-03-01 22:35:34 -05002961 spin_unlock_irq(shost->host_lock);
James Smart6b5151f2012-01-18 16:24:06 -05002962 /*
2963 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05002964 * RPI. Get a new RPI when the adapter port
2965 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05002966 */
James Smartbe6bb942015-04-07 15:07:22 -04002967 if (phba->sli_rev == LPFC_SLI_REV4) {
2968 lpfc_printf_vlog(ndlp->vport,
2969 KERN_INFO, LOG_NODE,
2970 "0011 lpfc_offline: "
2971 "ndlp:x%p did %x "
2972 "usgmap:x%x rpi:%x\n",
2973 ndlp, ndlp->nlp_DID,
2974 ndlp->nlp_usg_map,
2975 ndlp->nlp_rpi);
2976
James Smart6b5151f2012-01-18 16:24:06 -05002977 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smartbe6bb942015-04-07 15:07:22 -04002978 }
James Smart87af33f2007-10-27 13:37:43 -04002979 lpfc_unreg_rpi(vports[i], ndlp);
2980 }
2981 }
2982 }
James Smart09372822008-01-11 01:52:54 -05002983 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002984
James Smart618a5232012-06-12 13:54:36 -04002985 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
James Smart46fa3112007-04-25 09:51:45 -04002986}
2987
James Smarte59058c2008-08-24 21:49:00 -04002988/**
James Smart3621a712009-04-06 18:47:14 -04002989 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04002990 * @phba: pointer to lpfc hba data structure.
2991 *
2992 * This routine actually brings a HBA offline. It stops all the timers
2993 * associated with the HBA, brings down the SLI layer, and eventually
2994 * marks the HBA as in offline state for the upper layer protocol.
2995 **/
James Smart46fa3112007-04-25 09:51:45 -04002996void
James Smart2e0fef82007-06-17 19:56:36 -05002997lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04002998{
James Smart549e55c2007-08-02 11:09:51 -04002999 struct Scsi_Host *shost;
3000 struct lpfc_vport **vports;
3001 int i;
James Smart46fa3112007-04-25 09:51:45 -04003002
James Smart549e55c2007-08-02 11:09:51 -04003003 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003004 return;
James Smart688a8862006-07-06 15:49:56 -04003005
James Smartda0436e2009-05-22 14:51:39 -04003006 /* stop port and all timers associated with this hba */
3007 lpfc_stop_port(phba);
James Smart51ef4c22007-08-02 11:10:31 -04003008 vports = lpfc_create_vport_work_array(phba);
3009 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003010 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04003011 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05003012 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05003013 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003014 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05003015 /* Bring down the SLI Layer and cleanup. The HBA is offline
3016 now. */
3017 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003018 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04003019 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003020 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04003021 vports = lpfc_create_vport_work_array(phba);
3022 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003023 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003024 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04003025 spin_lock_irq(shost->host_lock);
3026 vports[i]->work_port_events = 0;
3027 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3028 spin_unlock_irq(shost->host_lock);
3029 }
James Smart09372822008-01-11 01:52:54 -05003030 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003031}
3032
James Smarte59058c2008-08-24 21:49:00 -04003033/**
James Smart3621a712009-04-06 18:47:14 -04003034 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04003035 * @phba: pointer to lpfc hba data structure.
3036 *
3037 * This routine is to free all the SCSI buffers and IOCBs from the driver
3038 * list back to kernel. It is called from lpfc_pci_remove_one to free
3039 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04003040 **/
James Smart8a9d2e82012-05-09 21:16:12 -04003041static void
James Smart2e0fef82007-06-17 19:56:36 -05003042lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003043{
3044 struct lpfc_scsi_buf *sb, *sb_next;
3045 struct lpfc_iocbq *io, *io_next;
3046
James Smart2e0fef82007-06-17 19:56:36 -05003047 spin_lock_irq(&phba->hbalock);
James Smarta40fc5f2013-04-17 20:17:40 -04003048
dea31012005-04-17 16:05:31 -05003049 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smarta40fc5f2013-04-17 20:17:40 -04003050
3051 spin_lock(&phba->scsi_buf_list_put_lock);
3052 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3053 list) {
dea31012005-04-17 16:05:31 -05003054 list_del(&sb->list);
3055 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05003056 sb->dma_handle);
dea31012005-04-17 16:05:31 -05003057 kfree(sb);
3058 phba->total_scsi_bufs--;
3059 }
James Smarta40fc5f2013-04-17 20:17:40 -04003060 spin_unlock(&phba->scsi_buf_list_put_lock);
3061
3062 spin_lock(&phba->scsi_buf_list_get_lock);
3063 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3064 list) {
3065 list_del(&sb->list);
3066 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
3067 sb->dma_handle);
3068 kfree(sb);
3069 phba->total_scsi_bufs--;
3070 }
3071 spin_unlock(&phba->scsi_buf_list_get_lock);
dea31012005-04-17 16:05:31 -05003072
3073 /* Release all the lpfc_iocbq entries maintained by this host. */
3074 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
3075 list_del(&io->list);
3076 kfree(io);
3077 phba->total_iocbq_bufs--;
3078 }
James Smart6d368e52011-05-24 11:44:12 -04003079
James Smart2e0fef82007-06-17 19:56:36 -05003080 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003081}
3082
3083/**
3084 * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping
3085 * @phba: pointer to lpfc hba data structure.
3086 *
3087 * This routine first calculates the sizes of the current els and allocated
3088 * scsi sgl lists, and then goes through all sgls to updates the physical
3089 * XRIs assigned due to port function reset. During port initialization, the
3090 * current els and allocated scsi sgl lists are 0s.
3091 *
3092 * Return codes
3093 * 0 - successful (for now, it always returns 0)
3094 **/
3095int
3096lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba)
3097{
3098 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3099 struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL;
3100 uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt;
3101 LIST_HEAD(els_sgl_list);
3102 LIST_HEAD(scsi_sgl_list);
3103 int rc;
James Smartdafe8ce2014-09-03 12:56:40 -04003104 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart8a9d2e82012-05-09 21:16:12 -04003105
3106 /*
3107 * update on pci function's els xri-sgl list
3108 */
3109 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3110 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3111 /* els xri-sgl expanded */
3112 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3113 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3114 "3157 ELS xri-sgl count increased from "
3115 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3116 els_xri_cnt);
3117 /* allocate the additional els sgls */
3118 for (i = 0; i < xri_cnt; i++) {
3119 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3120 GFP_KERNEL);
3121 if (sglq_entry == NULL) {
3122 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3123 "2562 Failure to allocate an "
3124 "ELS sgl entry:%d\n", i);
3125 rc = -ENOMEM;
3126 goto out_free_mem;
3127 }
3128 sglq_entry->buff_type = GEN_BUFF_TYPE;
3129 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3130 &sglq_entry->phys);
3131 if (sglq_entry->virt == NULL) {
3132 kfree(sglq_entry);
3133 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3134 "2563 Failure to allocate an "
3135 "ELS mbuf:%d\n", i);
3136 rc = -ENOMEM;
3137 goto out_free_mem;
3138 }
3139 sglq_entry->sgl = sglq_entry->virt;
3140 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3141 sglq_entry->state = SGL_FREED;
3142 list_add_tail(&sglq_entry->list, &els_sgl_list);
3143 }
James Smart38c20672013-03-01 16:37:44 -05003144 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04003145 spin_lock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003146 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04003147 spin_unlock(&pring->ring_lock);
James Smart38c20672013-03-01 16:37:44 -05003148 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003149 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3150 /* els xri-sgl shrinked */
3151 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3152 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3153 "3158 ELS xri-sgl count decreased from "
3154 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3155 els_xri_cnt);
3156 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04003157 spin_lock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003158 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04003159 spin_unlock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003160 spin_unlock_irq(&phba->hbalock);
3161 /* release extra els sgls from list */
3162 for (i = 0; i < xri_cnt; i++) {
3163 list_remove_head(&els_sgl_list,
3164 sglq_entry, struct lpfc_sglq, list);
3165 if (sglq_entry) {
3166 lpfc_mbuf_free(phba, sglq_entry->virt,
3167 sglq_entry->phys);
3168 kfree(sglq_entry);
3169 }
3170 }
3171 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04003172 spin_lock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003173 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04003174 spin_unlock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003175 spin_unlock_irq(&phba->hbalock);
3176 } else
3177 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3178 "3163 ELS xri-sgl count unchanged: %d\n",
3179 els_xri_cnt);
3180 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3181
3182 /* update xris to els sgls on the list */
3183 sglq_entry = NULL;
3184 sglq_entry_next = NULL;
3185 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3186 &phba->sli4_hba.lpfc_sgl_list, list) {
3187 lxri = lpfc_sli4_next_xritag(phba);
3188 if (lxri == NO_XRI) {
3189 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3190 "2400 Failed to allocate xri for "
3191 "ELS sgl\n");
3192 rc = -ENOMEM;
3193 goto out_free_mem;
3194 }
3195 sglq_entry->sli4_lxritag = lxri;
3196 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3197 }
3198
3199 /*
3200 * update on pci function's allocated scsi xri-sgl list
3201 */
3202 phba->total_scsi_bufs = 0;
3203
3204 /* maximum number of xris available for scsi buffers */
3205 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3206 els_xri_cnt;
3207
3208 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3209 "2401 Current allocated SCSI xri-sgl count:%d, "
3210 "maximum SCSI xri count:%d\n",
3211 phba->sli4_hba.scsi_xri_cnt,
3212 phba->sli4_hba.scsi_xri_max);
3213
James Smarta40fc5f2013-04-17 20:17:40 -04003214 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003215 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003216 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3217 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
James Smart164cecd2013-09-06 12:22:38 -04003218 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003219 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003220
3221 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3222 /* max scsi xri shrinked below the allocated scsi buffers */
3223 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3224 phba->sli4_hba.scsi_xri_max;
3225 /* release the extra allocated scsi buffers */
3226 for (i = 0; i < scsi_xri_cnt; i++) {
3227 list_remove_head(&scsi_sgl_list, psb,
3228 struct lpfc_scsi_buf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04003229 if (psb) {
3230 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
3231 psb->data, psb->dma_handle);
3232 kfree(psb);
3233 }
James Smart8a9d2e82012-05-09 21:16:12 -04003234 }
James Smarta40fc5f2013-04-17 20:17:40 -04003235 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003236 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
James Smarta40fc5f2013-04-17 20:17:40 -04003237 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003238 }
3239
3240 /* update xris associated to remaining allocated scsi buffers */
3241 psb = NULL;
3242 psb_next = NULL;
3243 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3244 lxri = lpfc_sli4_next_xritag(phba);
3245 if (lxri == NO_XRI) {
3246 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3247 "2560 Failed to allocate xri for "
3248 "scsi buffer\n");
3249 rc = -ENOMEM;
3250 goto out_free_mem;
3251 }
3252 psb->cur_iocbq.sli4_lxritag = lxri;
3253 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3254 }
James Smarta40fc5f2013-04-17 20:17:40 -04003255 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003256 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003257 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3258 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
James Smart164cecd2013-09-06 12:22:38 -04003259 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003260 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003261
dea31012005-04-17 16:05:31 -05003262 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003263
3264out_free_mem:
3265 lpfc_free_els_sgl_list(phba);
3266 lpfc_scsi_free(phba);
3267 return rc;
dea31012005-04-17 16:05:31 -05003268}
3269
James Smarte59058c2008-08-24 21:49:00 -04003270/**
James Smart3621a712009-04-06 18:47:14 -04003271 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04003272 * @phba: pointer to lpfc hba data structure.
3273 * @instance: a unique integer ID to this FC port.
3274 * @dev: pointer to the device data structure.
3275 *
3276 * This routine creates a FC port for the upper layer protocol. The FC port
3277 * can be created on top of either a physical port or a virtual port provided
3278 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3279 * and associates the FC port created before adding the shost into the SCSI
3280 * layer.
3281 *
3282 * Return codes
3283 * @vport - pointer to the virtual N_Port data structure.
3284 * NULL - port create failed.
3285 **/
James Smart2e0fef82007-06-17 19:56:36 -05003286struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04003287lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04003288{
James Smart2e0fef82007-06-17 19:56:36 -05003289 struct lpfc_vport *vport;
3290 struct Scsi_Host *shost;
3291 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04003292
James Smartea4142f2015-04-07 15:07:13 -04003293 if (dev != &phba->pcidev->dev) {
James Smart3de2a652007-08-02 11:09:59 -04003294 shost = scsi_host_alloc(&lpfc_vport_template,
3295 sizeof(struct lpfc_vport));
James Smartea4142f2015-04-07 15:07:13 -04003296 } else {
3297 if (phba->sli_rev == LPFC_SLI_REV4)
3298 shost = scsi_host_alloc(&lpfc_template,
James Smart3de2a652007-08-02 11:09:59 -04003299 sizeof(struct lpfc_vport));
James Smartea4142f2015-04-07 15:07:13 -04003300 else
3301 shost = scsi_host_alloc(&lpfc_template_s3,
3302 sizeof(struct lpfc_vport));
3303 }
James Smart2e0fef82007-06-17 19:56:36 -05003304 if (!shost)
3305 goto out;
James Smart47a86172007-04-25 09:53:22 -04003306
James Smart2e0fef82007-06-17 19:56:36 -05003307 vport = (struct lpfc_vport *) shost->hostdata;
3308 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05003309 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05003310 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05003311 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04003312
James Smart3de2a652007-08-02 11:09:59 -04003313 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05003314 shost->unique_id = instance;
3315 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04003316 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05003317 shost->this_id = -1;
3318 shost->max_cmd_len = 16;
James Smart8b0dff12015-05-22 10:42:38 -04003319 shost->nr_hw_queues = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04003320 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05003321 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04003322 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smartda0436e2009-05-22 14:51:39 -04003323 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
3324 }
James Smart81301a92008-12-04 22:39:46 -05003325
James Smart47a86172007-04-25 09:53:22 -04003326 /*
James Smart2e0fef82007-06-17 19:56:36 -05003327 * Set initial can_queue value since 0 is no longer supported and
3328 * scsi_add_host will fail. This will be adjusted later based on the
3329 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04003330 */
James Smart2e0fef82007-06-17 19:56:36 -05003331 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04003332 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05003333 shost->transportt = lpfc_vport_transport_template;
3334 vport->port_type = LPFC_NPIV_PORT;
3335 } else {
3336 shost->transportt = lpfc_transport_template;
3337 vport->port_type = LPFC_PHYSICAL_PORT;
3338 }
James Smart47a86172007-04-25 09:53:22 -04003339
James Smart2e0fef82007-06-17 19:56:36 -05003340 /* Initialize all internally managed lists. */
3341 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04003342 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05003343 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04003344
James Smart2e0fef82007-06-17 19:56:36 -05003345 init_timer(&vport->fc_disctmo);
3346 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003347 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04003348
James Smart2e0fef82007-06-17 19:56:36 -05003349 init_timer(&vport->els_tmofunc);
3350 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003351 vport->els_tmofunc.data = (unsigned long)vport;
James Smart92494142011-02-16 12:39:44 -05003352
3353 init_timer(&vport->delayed_disc_tmo);
3354 vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
3355 vport->delayed_disc_tmo.data = (unsigned long)vport;
3356
James Bottomleyd139b9b2009-11-05 13:33:12 -06003357 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05003358 if (error)
3359 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04003360
James Smart549e55c2007-08-02 11:09:51 -04003361 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003362 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04003363 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003364 return vport;
James Smart47a86172007-04-25 09:53:22 -04003365
James Smart2e0fef82007-06-17 19:56:36 -05003366out_put_shost:
3367 scsi_host_put(shost);
3368out:
3369 return NULL;
James Smart47a86172007-04-25 09:53:22 -04003370}
3371
James Smarte59058c2008-08-24 21:49:00 -04003372/**
James Smart3621a712009-04-06 18:47:14 -04003373 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04003374 * @vport: pointer to an lpfc virtual N_Port data structure.
3375 *
3376 * This routine destroys a FC port from the upper layer protocol. All the
3377 * resources associated with the port are released.
3378 **/
James Smart2e0fef82007-06-17 19:56:36 -05003379void
3380destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04003381{
James Smart92d7f7b2007-06-17 19:56:38 -05003382 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3383 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003384
James Smart858c9f62007-06-17 19:56:39 -05003385 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05003386 fc_remove_host(shost);
3387 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04003388
James Smart92d7f7b2007-06-17 19:56:38 -05003389 spin_lock_irq(&phba->hbalock);
3390 list_del_init(&vport->listentry);
3391 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04003392
James Smart92d7f7b2007-06-17 19:56:38 -05003393 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04003394 return;
James Smart47a86172007-04-25 09:53:22 -04003395}
3396
James Smarte59058c2008-08-24 21:49:00 -04003397/**
James Smart3621a712009-04-06 18:47:14 -04003398 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04003399 *
3400 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3401 * uses the kernel idr facility to perform the task.
3402 *
3403 * Return codes:
3404 * instance - a unique integer ID allocated as the new instance.
3405 * -1 - lpfc get instance failed.
3406 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003407int
3408lpfc_get_instance(void)
3409{
Tejun Heoab516032013-02-27 17:04:44 -08003410 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003411
Tejun Heoab516032013-02-27 17:04:44 -08003412 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
3413 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003414}
3415
James Smarte59058c2008-08-24 21:49:00 -04003416/**
James Smart3621a712009-04-06 18:47:14 -04003417 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04003418 * @shost: pointer to SCSI host data structure.
3419 * @time: elapsed time of the scan in jiffies.
3420 *
3421 * This routine is called by the SCSI layer with a SCSI host to determine
3422 * whether the scan host is finished.
3423 *
3424 * Note: there is no scan_start function as adapter initialization will have
3425 * asynchronously kicked off the link initialization.
3426 *
3427 * Return codes
3428 * 0 - SCSI host scan is not over yet.
3429 * 1 - SCSI host scan is over.
3430 **/
James Smart47a86172007-04-25 09:53:22 -04003431int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
3432{
James Smart2e0fef82007-06-17 19:56:36 -05003433 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3434 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05003435 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04003436
James Smart858c9f62007-06-17 19:56:39 -05003437 spin_lock_irq(shost->host_lock);
3438
James Smart51ef4c22007-08-02 11:10:31 -04003439 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05003440 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003441 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05003442 }
James Smart256ec0d2013-04-17 20:14:58 -04003443 if (time >= msecs_to_jiffies(30 * 1000)) {
James Smart2e0fef82007-06-17 19:56:36 -05003444 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003445 "0461 Scanning longer than 30 "
3446 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003447 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003448 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003449 }
James Smart256ec0d2013-04-17 20:14:58 -04003450 if (time >= msecs_to_jiffies(15 * 1000) &&
3451 phba->link_state <= LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05003452 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003453 "0465 Link down longer than 15 "
3454 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003455 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05003456 goto finished;
James Smart47a86172007-04-25 09:53:22 -04003457 }
3458
James Smart2e0fef82007-06-17 19:56:36 -05003459 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05003460 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003461 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05003462 goto finished;
James Smart256ec0d2013-04-17 20:14:58 -04003463 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
James Smart858c9f62007-06-17 19:56:39 -05003464 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003465 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05003466 goto finished;
3467
3468 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003469
3470finished:
James Smart858c9f62007-06-17 19:56:39 -05003471 spin_unlock_irq(shost->host_lock);
3472 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003473}
3474
James Smarte59058c2008-08-24 21:49:00 -04003475/**
James Smart3621a712009-04-06 18:47:14 -04003476 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04003477 * @shost: pointer to SCSI host data structure.
3478 *
3479 * This routine initializes a given SCSI host attributes on a FC port. The
3480 * SCSI host can be either on top of a physical port or a virtual port.
3481 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003482void lpfc_host_attrib_init(struct Scsi_Host *shost)
3483{
3484 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3485 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003486 /*
James Smart2e0fef82007-06-17 19:56:36 -05003487 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04003488 */
3489
James Smart2e0fef82007-06-17 19:56:36 -05003490 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
3491 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04003492 fc_host_supported_classes(shost) = FC_COS_CLASS3;
3493
3494 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003495 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003496 fc_host_supported_fc4s(shost)[2] = 1;
3497 fc_host_supported_fc4s(shost)[7] = 1;
3498
James Smart92d7f7b2007-06-17 19:56:38 -05003499 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
3500 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04003501
3502 fc_host_supported_speeds(shost) = 0;
James Smartd38dd522015-08-31 16:48:17 -04003503 if (phba->lmt & LMT_32Gb)
3504 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
James Smart88a2cfb2011-07-22 18:36:33 -04003505 if (phba->lmt & LMT_16Gb)
3506 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
James Smart47a86172007-04-25 09:53:22 -04003507 if (phba->lmt & LMT_10Gb)
3508 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04003509 if (phba->lmt & LMT_8Gb)
3510 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04003511 if (phba->lmt & LMT_4Gb)
3512 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
3513 if (phba->lmt & LMT_2Gb)
3514 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
3515 if (phba->lmt & LMT_1Gb)
3516 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
3517
3518 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05003519 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
3520 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04003521
Mike Christie0af5d702010-09-15 16:52:31 -05003522 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
3523
James Smart47a86172007-04-25 09:53:22 -04003524 /* This value is also unchanging */
3525 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003526 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003527 fc_host_active_fc4s(shost)[2] = 1;
3528 fc_host_active_fc4s(shost)[7] = 1;
3529
James Smart92d7f7b2007-06-17 19:56:38 -05003530 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04003531 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04003532 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04003533 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04003534}
dea31012005-04-17 16:05:31 -05003535
James Smarte59058c2008-08-24 21:49:00 -04003536/**
James Smartda0436e2009-05-22 14:51:39 -04003537 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04003538 * @phba: pointer to lpfc hba data structure.
3539 *
James Smartda0436e2009-05-22 14:51:39 -04003540 * This routine is invoked to stop an SLI3 device port, it stops the device
3541 * from generating interrupts and stops the device driver's timers for the
3542 * device.
James Smarte59058c2008-08-24 21:49:00 -04003543 **/
James Smartdb2378e2008-02-08 18:49:51 -05003544static void
James Smartda0436e2009-05-22 14:51:39 -04003545lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05003546{
James Smartda0436e2009-05-22 14:51:39 -04003547 /* Clear all interrupt enable conditions */
3548 writel(0, phba->HCregaddr);
3549 readl(phba->HCregaddr); /* flush */
3550 /* Clear all pending interrupts */
3551 writel(0xffffffff, phba->HAregaddr);
3552 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04003553
James Smartda0436e2009-05-22 14:51:39 -04003554 /* Reset some HBA SLI setup states */
3555 lpfc_stop_hba_timers(phba);
3556 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05003557}
3558
James Smarte59058c2008-08-24 21:49:00 -04003559/**
James Smartda0436e2009-05-22 14:51:39 -04003560 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05003561 * @phba: pointer to lpfc hba data structure.
3562 *
James Smartda0436e2009-05-22 14:51:39 -04003563 * This routine is invoked to stop an SLI4 device port, it stops the device
3564 * from generating interrupts and stops the device driver's timers for the
3565 * device.
3566 **/
3567static void
3568lpfc_stop_port_s4(struct lpfc_hba *phba)
3569{
3570 /* Reset some HBA SLI4 setup states */
3571 lpfc_stop_hba_timers(phba);
3572 phba->pport->work_port_events = 0;
3573 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04003574}
3575
3576/**
3577 * lpfc_stop_port - Wrapper function for stopping hba port
3578 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05003579 *
James Smartda0436e2009-05-22 14:51:39 -04003580 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3581 * the API jump table function pointer from the lpfc_hba struct.
3582 **/
3583void
3584lpfc_stop_port(struct lpfc_hba *phba)
3585{
3586 phba->lpfc_stop_port(phba);
3587}
3588
3589/**
James Smartecfd03c2010-02-12 14:41:27 -05003590 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3591 * @phba: Pointer to hba for which this call is being executed.
3592 *
3593 * This routine starts the timer waiting for the FCF rediscovery to complete.
3594 **/
3595void
3596lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
3597{
3598 unsigned long fcf_redisc_wait_tmo =
3599 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
3600 /* Start fcf rediscovery wait period timer */
3601 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
3602 spin_lock_irq(&phba->hbalock);
3603 /* Allow action to new fcf asynchronous event */
3604 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
3605 /* Mark the FCF rediscovery pending state */
3606 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
3607 spin_unlock_irq(&phba->hbalock);
3608}
3609
3610/**
3611 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
3612 * @ptr: Map to lpfc_hba data structure pointer.
3613 *
3614 * This routine is invoked when waiting for FCF table rediscover has been
3615 * timed out. If new FCF record(s) has (have) been discovered during the
3616 * wait period, a new FCF event shall be added to the FCOE async event
3617 * list, and then worker thread shall be waked up for processing from the
3618 * worker thread context.
3619 **/
Rashika Kheriae399b222014-09-03 12:55:28 -04003620static void
James Smartecfd03c2010-02-12 14:41:27 -05003621lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
3622{
3623 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
3624
3625 /* Don't send FCF rediscovery event if timer cancelled */
3626 spin_lock_irq(&phba->hbalock);
3627 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
3628 spin_unlock_irq(&phba->hbalock);
3629 return;
3630 }
3631 /* Clear FCF rediscovery timer pending flag */
3632 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
3633 /* FCF rediscovery event to worker thread */
3634 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
3635 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003636 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04003637 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05003638 /* wake up worker thread */
3639 lpfc_worker_wake_up(phba);
3640}
3641
3642/**
James Smartda0436e2009-05-22 14:51:39 -04003643 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
3644 * @phba: pointer to lpfc hba data structure.
3645 * @acqe_link: pointer to the async link completion queue entry.
3646 *
3647 * This routine is to parse the SLI4 link-attention link fault code and
3648 * translate it into the base driver's read link attention mailbox command
3649 * status.
3650 *
3651 * Return: Link-attention status in terms of base driver's coding.
3652 **/
3653static uint16_t
3654lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
3655 struct lpfc_acqe_link *acqe_link)
3656{
3657 uint16_t latt_fault;
3658
3659 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
3660 case LPFC_ASYNC_LINK_FAULT_NONE:
3661 case LPFC_ASYNC_LINK_FAULT_LOCAL:
3662 case LPFC_ASYNC_LINK_FAULT_REMOTE:
3663 latt_fault = 0;
3664 break;
3665 default:
3666 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3667 "0398 Invalid link fault code: x%x\n",
3668 bf_get(lpfc_acqe_link_fault, acqe_link));
3669 latt_fault = MBXERR_ERROR;
3670 break;
3671 }
3672 return latt_fault;
3673}
3674
3675/**
3676 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
3677 * @phba: pointer to lpfc hba data structure.
3678 * @acqe_link: pointer to the async link completion queue entry.
3679 *
3680 * This routine is to parse the SLI4 link attention type and translate it
3681 * into the base driver's link attention type coding.
3682 *
3683 * Return: Link attention type in terms of base driver's coding.
3684 **/
3685static uint8_t
3686lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
3687 struct lpfc_acqe_link *acqe_link)
3688{
3689 uint8_t att_type;
3690
3691 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
3692 case LPFC_ASYNC_LINK_STATUS_DOWN:
3693 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05003694 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04003695 break;
3696 case LPFC_ASYNC_LINK_STATUS_UP:
3697 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05003698 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003699 break;
3700 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05003701 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04003702 break;
3703 default:
3704 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3705 "0399 Invalid link attention type: x%x\n",
3706 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003707 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003708 break;
3709 }
3710 return att_type;
3711}
3712
3713/**
James Smart8b68cd52012-09-29 11:32:37 -04003714 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
3715 * @phba: pointer to lpfc hba data structure.
3716 *
3717 * This routine is to get an SLI3 FC port's link speed in Mbps.
3718 *
3719 * Return: link speed in terms of Mbps.
3720 **/
3721uint32_t
3722lpfc_sli_port_speed_get(struct lpfc_hba *phba)
3723{
3724 uint32_t link_speed;
3725
3726 if (!lpfc_is_link_up(phba))
3727 return 0;
3728
James Smarta085e872015-12-16 18:12:02 -05003729 if (phba->sli_rev <= LPFC_SLI_REV3) {
3730 switch (phba->fc_linkspeed) {
3731 case LPFC_LINK_SPEED_1GHZ:
3732 link_speed = 1000;
3733 break;
3734 case LPFC_LINK_SPEED_2GHZ:
3735 link_speed = 2000;
3736 break;
3737 case LPFC_LINK_SPEED_4GHZ:
3738 link_speed = 4000;
3739 break;
3740 case LPFC_LINK_SPEED_8GHZ:
3741 link_speed = 8000;
3742 break;
3743 case LPFC_LINK_SPEED_10GHZ:
3744 link_speed = 10000;
3745 break;
3746 case LPFC_LINK_SPEED_16GHZ:
3747 link_speed = 16000;
3748 break;
3749 default:
3750 link_speed = 0;
3751 }
3752 } else {
3753 if (phba->sli4_hba.link_state.logical_speed)
3754 link_speed =
3755 phba->sli4_hba.link_state.logical_speed;
3756 else
3757 link_speed = phba->sli4_hba.link_state.speed;
James Smart8b68cd52012-09-29 11:32:37 -04003758 }
3759 return link_speed;
3760}
3761
3762/**
3763 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
3764 * @phba: pointer to lpfc hba data structure.
3765 * @evt_code: asynchronous event code.
3766 * @speed_code: asynchronous event link speed code.
3767 *
3768 * This routine is to parse the giving SLI4 async event link speed code into
3769 * value of Mbps for the link speed.
3770 *
3771 * Return: link speed in terms of Mbps.
3772 **/
3773static uint32_t
3774lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
3775 uint8_t speed_code)
3776{
3777 uint32_t port_speed;
3778
3779 switch (evt_code) {
3780 case LPFC_TRAILER_CODE_LINK:
3781 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04003782 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smart8b68cd52012-09-29 11:32:37 -04003783 port_speed = 0;
3784 break;
James Smart26d830e2015-04-07 15:07:17 -04003785 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04003786 port_speed = 10;
3787 break;
James Smart26d830e2015-04-07 15:07:17 -04003788 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04003789 port_speed = 100;
3790 break;
James Smart26d830e2015-04-07 15:07:17 -04003791 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04003792 port_speed = 1000;
3793 break;
James Smart26d830e2015-04-07 15:07:17 -04003794 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04003795 port_speed = 10000;
3796 break;
James Smart26d830e2015-04-07 15:07:17 -04003797 case LPFC_ASYNC_LINK_SPEED_20GBPS:
3798 port_speed = 20000;
3799 break;
3800 case LPFC_ASYNC_LINK_SPEED_25GBPS:
3801 port_speed = 25000;
3802 break;
3803 case LPFC_ASYNC_LINK_SPEED_40GBPS:
3804 port_speed = 40000;
3805 break;
James Smart8b68cd52012-09-29 11:32:37 -04003806 default:
3807 port_speed = 0;
3808 }
3809 break;
3810 case LPFC_TRAILER_CODE_FC:
3811 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04003812 case LPFC_FC_LA_SPEED_UNKNOWN:
James Smart8b68cd52012-09-29 11:32:37 -04003813 port_speed = 0;
3814 break;
James Smart26d830e2015-04-07 15:07:17 -04003815 case LPFC_FC_LA_SPEED_1G:
James Smart8b68cd52012-09-29 11:32:37 -04003816 port_speed = 1000;
3817 break;
James Smart26d830e2015-04-07 15:07:17 -04003818 case LPFC_FC_LA_SPEED_2G:
James Smart8b68cd52012-09-29 11:32:37 -04003819 port_speed = 2000;
3820 break;
James Smart26d830e2015-04-07 15:07:17 -04003821 case LPFC_FC_LA_SPEED_4G:
James Smart8b68cd52012-09-29 11:32:37 -04003822 port_speed = 4000;
3823 break;
James Smart26d830e2015-04-07 15:07:17 -04003824 case LPFC_FC_LA_SPEED_8G:
James Smart8b68cd52012-09-29 11:32:37 -04003825 port_speed = 8000;
3826 break;
James Smart26d830e2015-04-07 15:07:17 -04003827 case LPFC_FC_LA_SPEED_10G:
James Smart8b68cd52012-09-29 11:32:37 -04003828 port_speed = 10000;
3829 break;
James Smart26d830e2015-04-07 15:07:17 -04003830 case LPFC_FC_LA_SPEED_16G:
James Smart8b68cd52012-09-29 11:32:37 -04003831 port_speed = 16000;
3832 break;
James Smartd38dd522015-08-31 16:48:17 -04003833 case LPFC_FC_LA_SPEED_32G:
3834 port_speed = 32000;
3835 break;
James Smart8b68cd52012-09-29 11:32:37 -04003836 default:
3837 port_speed = 0;
3838 }
3839 break;
3840 default:
3841 port_speed = 0;
3842 }
3843 return port_speed;
3844}
3845
3846/**
James Smart70f3c072010-12-15 17:57:33 -05003847 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04003848 * @phba: pointer to lpfc hba data structure.
3849 * @acqe_link: pointer to the async link completion queue entry.
3850 *
James Smart70f3c072010-12-15 17:57:33 -05003851 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04003852 **/
3853static void
3854lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
3855 struct lpfc_acqe_link *acqe_link)
3856{
3857 struct lpfc_dmabuf *mp;
3858 LPFC_MBOXQ_t *pmb;
3859 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05003860 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04003861 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05003862 int rc;
James Smartda0436e2009-05-22 14:51:39 -04003863
3864 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05003865 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04003866 return;
James Smart32b97932009-07-19 10:01:21 -04003867 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04003868 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3869 if (!pmb) {
3870 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3871 "0395 The mboxq allocation failed\n");
3872 return;
3873 }
3874 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3875 if (!mp) {
3876 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3877 "0396 The lpfc_dmabuf allocation failed\n");
3878 goto out_free_pmb;
3879 }
3880 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
3881 if (!mp->virt) {
3882 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3883 "0397 The mbuf allocation failed\n");
3884 goto out_free_dmabuf;
3885 }
3886
3887 /* Cleanup any outstanding ELS commands */
3888 lpfc_els_flush_all_cmd(phba);
3889
3890 /* Block ELS IOCBs until we have done process link event */
3891 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
3892
3893 /* Update link event statistics */
3894 phba->sli.slistat.link_event++;
3895
James Smart76a95d72010-11-20 23:11:48 -05003896 /* Create lpfc_handle_latt mailbox command from link ACQE */
3897 lpfc_read_topology(phba, pmb, mp);
3898 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04003899 pmb->vport = phba->pport;
3900
James Smartda0436e2009-05-22 14:51:39 -04003901 /* Keep the link status for extra SLI4 state machine reference */
3902 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04003903 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
3904 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04003905 phba->sli4_hba.link_state.duplex =
3906 bf_get(lpfc_acqe_link_duplex, acqe_link);
3907 phba->sli4_hba.link_state.status =
3908 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05003909 phba->sli4_hba.link_state.type =
3910 bf_get(lpfc_acqe_link_type, acqe_link);
3911 phba->sli4_hba.link_state.number =
3912 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04003913 phba->sli4_hba.link_state.fault =
3914 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05003915 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04003916 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
3917
James Smart70f3c072010-12-15 17:57:33 -05003918 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04003919 "2900 Async FC/FCoE Link event - Speed:%dGBit "
3920 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
3921 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05003922 phba->sli4_hba.link_state.speed,
3923 phba->sli4_hba.link_state.topology,
3924 phba->sli4_hba.link_state.status,
3925 phba->sli4_hba.link_state.type,
3926 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04003927 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05003928 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05003929 /*
3930 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
3931 * topology info. Note: Optional for non FC-AL ports.
3932 */
3933 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3934 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3935 if (rc == MBX_NOT_FINISHED)
3936 goto out_free_dmabuf;
3937 return;
3938 }
3939 /*
3940 * For FCoE Mode: fill in all the topology information we need and call
3941 * the READ_TOPOLOGY completion routine to continue without actually
3942 * sending the READ_TOPOLOGY mailbox command to the port.
3943 */
3944 /* Parse and translate status field */
3945 mb = &pmb->u.mb;
3946 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
3947
3948 /* Parse and translate link attention fields */
3949 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3950 la->eventTag = acqe_link->event_tag;
3951 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
3952 bf_set(lpfc_mbx_read_top_link_spd, la,
James Smarta085e872015-12-16 18:12:02 -05003953 (bf_get(lpfc_acqe_link_speed, acqe_link)));
James Smart76a95d72010-11-20 23:11:48 -05003954
3955 /* Fake the the following irrelvant fields */
3956 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
3957 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
3958 bf_set(lpfc_mbx_read_top_il, la, 0);
3959 bf_set(lpfc_mbx_read_top_pb, la, 0);
3960 bf_set(lpfc_mbx_read_top_fa, la, 0);
3961 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04003962
3963 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05003964 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04003965
3966 return;
3967
3968out_free_dmabuf:
3969 kfree(mp);
3970out_free_pmb:
3971 mempool_free(pmb, phba->mbox_mem_pool);
3972}
3973
3974/**
James Smart70f3c072010-12-15 17:57:33 -05003975 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
3976 * @phba: pointer to lpfc hba data structure.
3977 * @acqe_fc: pointer to the async fc completion queue entry.
3978 *
3979 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
3980 * that the event was received and then issue a read_topology mailbox command so
3981 * that the rest of the driver will treat it the same as SLI3.
3982 **/
3983static void
3984lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
3985{
3986 struct lpfc_dmabuf *mp;
3987 LPFC_MBOXQ_t *pmb;
3988 int rc;
3989
3990 if (bf_get(lpfc_trailer_type, acqe_fc) !=
3991 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
3992 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3993 "2895 Non FC link Event detected.(%d)\n",
3994 bf_get(lpfc_trailer_type, acqe_fc));
3995 return;
3996 }
3997 /* Keep the link status for extra SLI4 state machine reference */
3998 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04003999 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
4000 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05004001 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
4002 phba->sli4_hba.link_state.topology =
4003 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
4004 phba->sli4_hba.link_state.status =
4005 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
4006 phba->sli4_hba.link_state.type =
4007 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
4008 phba->sli4_hba.link_state.number =
4009 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
4010 phba->sli4_hba.link_state.fault =
4011 bf_get(lpfc_acqe_link_fault, acqe_fc);
4012 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004013 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart70f3c072010-12-15 17:57:33 -05004014 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4015 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4016 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4017 "%dMbps Fault:%d\n",
4018 phba->sli4_hba.link_state.speed,
4019 phba->sli4_hba.link_state.topology,
4020 phba->sli4_hba.link_state.status,
4021 phba->sli4_hba.link_state.type,
4022 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004023 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004024 phba->sli4_hba.link_state.fault);
4025 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4026 if (!pmb) {
4027 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4028 "2897 The mboxq allocation failed\n");
4029 return;
4030 }
4031 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4032 if (!mp) {
4033 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4034 "2898 The lpfc_dmabuf allocation failed\n");
4035 goto out_free_pmb;
4036 }
4037 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4038 if (!mp->virt) {
4039 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4040 "2899 The mbuf allocation failed\n");
4041 goto out_free_dmabuf;
4042 }
4043
4044 /* Cleanup any outstanding ELS commands */
4045 lpfc_els_flush_all_cmd(phba);
4046
4047 /* Block ELS IOCBs until we have done process link event */
4048 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
4049
4050 /* Update link event statistics */
4051 phba->sli.slistat.link_event++;
4052
4053 /* Create lpfc_handle_latt mailbox command from link ACQE */
4054 lpfc_read_topology(phba, pmb, mp);
4055 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4056 pmb->vport = phba->pport;
4057
4058 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4059 if (rc == MBX_NOT_FINISHED)
4060 goto out_free_dmabuf;
4061 return;
4062
4063out_free_dmabuf:
4064 kfree(mp);
4065out_free_pmb:
4066 mempool_free(pmb, phba->mbox_mem_pool);
4067}
4068
4069/**
4070 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4071 * @phba: pointer to lpfc hba data structure.
4072 * @acqe_fc: pointer to the async SLI completion queue entry.
4073 *
4074 * This routine is to handle the SLI4 asynchronous SLI events.
4075 **/
4076static void
4077lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
4078{
James Smart4b8bae02012-06-12 13:55:07 -04004079 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04004080 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04004081 uint8_t status;
James Smart946727d2015-04-07 15:07:09 -04004082 uint8_t evt_type;
James Smart448193b2015-12-16 18:12:05 -05004083 uint8_t operational = 0;
James Smart946727d2015-04-07 15:07:09 -04004084 struct temp_event temp_event_data;
James Smart4b8bae02012-06-12 13:55:07 -04004085 struct lpfc_acqe_misconfigured_event *misconfigured;
James Smart946727d2015-04-07 15:07:09 -04004086 struct Scsi_Host *shost;
James Smart4b8bae02012-06-12 13:55:07 -04004087
James Smart946727d2015-04-07 15:07:09 -04004088 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
4089
James Smart448193b2015-12-16 18:12:05 -05004090 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4091 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4092 "x%08x SLI Event Type:%d\n",
4093 acqe_sli->event_data1, acqe_sli->event_data2,
4094 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004095
4096 port_name = phba->Port[0];
4097 if (port_name == 0x00)
4098 port_name = '?'; /* get port name is empty */
4099
James Smart946727d2015-04-07 15:07:09 -04004100 switch (evt_type) {
4101 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
4102 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4103 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
4104 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4105
4106 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4107 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4108 acqe_sli->event_data1, port_name);
4109
4110 shost = lpfc_shost_from_vport(phba->pport);
4111 fc_host_post_vendor_event(shost, fc_get_event_number(),
4112 sizeof(temp_event_data),
4113 (char *)&temp_event_data,
4114 SCSI_NL_VID_TYPE_PCI
4115 | PCI_VENDOR_ID_EMULEX);
4116 break;
4117 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
4118 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4119 temp_event_data.event_code = LPFC_NORMAL_TEMP;
4120 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4121
4122 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4123 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4124 acqe_sli->event_data1, port_name);
4125
4126 shost = lpfc_shost_from_vport(phba->pport);
4127 fc_host_post_vendor_event(shost, fc_get_event_number(),
4128 sizeof(temp_event_data),
4129 (char *)&temp_event_data,
4130 SCSI_NL_VID_TYPE_PCI
4131 | PCI_VENDOR_ID_EMULEX);
4132 break;
4133 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
4134 misconfigured = (struct lpfc_acqe_misconfigured_event *)
James Smart4b8bae02012-06-12 13:55:07 -04004135 &acqe_sli->event_data1;
4136
James Smart946727d2015-04-07 15:07:09 -04004137 /* fetch the status for this port */
4138 switch (phba->sli4_hba.lnk_info.lnk_no) {
4139 case LPFC_LINK_NUMBER_0:
James Smart448193b2015-12-16 18:12:05 -05004140 status = bf_get(lpfc_sli_misconfigured_port0_state,
4141 &misconfigured->theEvent);
4142 operational = bf_get(lpfc_sli_misconfigured_port0_op,
James Smart4b8bae02012-06-12 13:55:07 -04004143 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004144 break;
4145 case LPFC_LINK_NUMBER_1:
James Smart448193b2015-12-16 18:12:05 -05004146 status = bf_get(lpfc_sli_misconfigured_port1_state,
4147 &misconfigured->theEvent);
4148 operational = bf_get(lpfc_sli_misconfigured_port1_op,
James Smart4b8bae02012-06-12 13:55:07 -04004149 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004150 break;
4151 case LPFC_LINK_NUMBER_2:
James Smart448193b2015-12-16 18:12:05 -05004152 status = bf_get(lpfc_sli_misconfigured_port2_state,
4153 &misconfigured->theEvent);
4154 operational = bf_get(lpfc_sli_misconfigured_port2_op,
James Smart4b8bae02012-06-12 13:55:07 -04004155 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004156 break;
4157 case LPFC_LINK_NUMBER_3:
James Smart448193b2015-12-16 18:12:05 -05004158 status = bf_get(lpfc_sli_misconfigured_port3_state,
4159 &misconfigured->theEvent);
4160 operational = bf_get(lpfc_sli_misconfigured_port3_op,
James Smart4b8bae02012-06-12 13:55:07 -04004161 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004162 break;
4163 default:
James Smart448193b2015-12-16 18:12:05 -05004164 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4165 "3296 "
4166 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
4167 "event: Invalid link %d",
4168 phba->sli4_hba.lnk_info.lnk_no);
4169 return;
James Smart946727d2015-04-07 15:07:09 -04004170 }
James Smart4b8bae02012-06-12 13:55:07 -04004171
James Smart448193b2015-12-16 18:12:05 -05004172 /* Skip if optic state unchanged */
4173 if (phba->sli4_hba.lnk_info.optic_state == status)
4174 return;
4175
James Smart946727d2015-04-07 15:07:09 -04004176 switch (status) {
4177 case LPFC_SLI_EVENT_STATUS_VALID:
James Smart448193b2015-12-16 18:12:05 -05004178 sprintf(message, "Physical Link is functional");
4179 break;
James Smart946727d2015-04-07 15:07:09 -04004180 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
4181 sprintf(message, "Optics faulted/incorrectly "
4182 "installed/not installed - Reseat optics, "
4183 "if issue not resolved, replace.");
4184 break;
4185 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
4186 sprintf(message,
4187 "Optics of two types installed - Remove one "
4188 "optic or install matching pair of optics.");
4189 break;
4190 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
4191 sprintf(message, "Incompatible optics - Replace with "
James Smart292098b2012-09-29 11:31:41 -04004192 "compatible optics for card to function.");
James Smart946727d2015-04-07 15:07:09 -04004193 break;
James Smart448193b2015-12-16 18:12:05 -05004194 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
4195 sprintf(message, "Unqualified optics - Replace with "
4196 "Avago optics for Warranty and Technical "
4197 "Support - Link is%s operational",
4198 (operational) ? "" : " not");
4199 break;
4200 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
4201 sprintf(message, "Uncertified optics - Replace with "
4202 "Avago-certified optics to enable link "
4203 "operation - Link is%s operational",
4204 (operational) ? "" : " not");
4205 break;
James Smart946727d2015-04-07 15:07:09 -04004206 default:
4207 /* firmware is reporting a status we don't know about */
4208 sprintf(message, "Unknown event status x%02x", status);
4209 break;
4210 }
James Smart448193b2015-12-16 18:12:05 -05004211 phba->sli4_hba.lnk_info.optic_state = status;
James Smart946727d2015-04-07 15:07:09 -04004212 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart448193b2015-12-16 18:12:05 -05004213 "3176 Port Name %c %s\n", port_name, message);
James Smart946727d2015-04-07 15:07:09 -04004214 break;
4215 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
4216 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4217 "3192 Remote DPort Test Initiated - "
4218 "Event Data1:x%08x Event Data2: x%08x\n",
4219 acqe_sli->event_data1, acqe_sli->event_data2);
James Smart4b8bae02012-06-12 13:55:07 -04004220 break;
4221 default:
James Smart946727d2015-04-07 15:07:09 -04004222 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4223 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
4224 "x%08x SLI Event Type:%d\n",
4225 acqe_sli->event_data1, acqe_sli->event_data2,
4226 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004227 break;
4228 }
James Smart70f3c072010-12-15 17:57:33 -05004229}
4230
4231/**
James Smartfc2b9892010-02-26 14:15:29 -05004232 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
4233 * @vport: pointer to vport data structure.
4234 *
4235 * This routine is to perform Clear Virtual Link (CVL) on a vport in
4236 * response to a CVL event.
4237 *
4238 * Return the pointer to the ndlp with the vport if successful, otherwise
4239 * return NULL.
4240 **/
4241static struct lpfc_nodelist *
4242lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
4243{
4244 struct lpfc_nodelist *ndlp;
4245 struct Scsi_Host *shost;
4246 struct lpfc_hba *phba;
4247
4248 if (!vport)
4249 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05004250 phba = vport->phba;
4251 if (!phba)
4252 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04004253 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4254 if (!ndlp) {
4255 /* Cannot find existing Fabric ndlp, so allocate a new one */
4256 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4257 if (!ndlp)
4258 return 0;
4259 lpfc_nlp_init(vport, ndlp, Fabric_DID);
4260 /* Set the node type */
4261 ndlp->nlp_type |= NLP_FABRIC;
4262 /* Put ndlp onto node list */
4263 lpfc_enqueue_node(vport, ndlp);
4264 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4265 /* re-setup ndlp without removing from node list */
4266 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4267 if (!ndlp)
4268 return 0;
4269 }
James Smart63e801c2010-11-20 23:14:19 -05004270 if ((phba->pport->port_state < LPFC_FLOGI) &&
4271 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004272 return NULL;
4273 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05004274 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
4275 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004276 return NULL;
4277 shost = lpfc_shost_from_vport(vport);
4278 if (!shost)
4279 return NULL;
4280 lpfc_linkdown_port(vport);
4281 lpfc_cleanup_pending_mbox(vport);
4282 spin_lock_irq(shost->host_lock);
4283 vport->fc_flag |= FC_VPORT_CVL_RCVD;
4284 spin_unlock_irq(shost->host_lock);
4285
4286 return ndlp;
4287}
4288
4289/**
4290 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4291 * @vport: pointer to lpfc hba data structure.
4292 *
4293 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4294 * response to a FCF dead event.
4295 **/
4296static void
4297lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
4298{
4299 struct lpfc_vport **vports;
4300 int i;
4301
4302 vports = lpfc_create_vport_work_array(phba);
4303 if (vports)
4304 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4305 lpfc_sli4_perform_vport_cvl(vports[i]);
4306 lpfc_destroy_vport_work_array(phba, vports);
4307}
4308
4309/**
James Smart76a95d72010-11-20 23:11:48 -05004310 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04004311 * @phba: pointer to lpfc hba data structure.
4312 * @acqe_link: pointer to the async fcoe completion queue entry.
4313 *
4314 * This routine is to handle the SLI4 asynchronous fcoe event.
4315 **/
4316static void
James Smart76a95d72010-11-20 23:11:48 -05004317lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05004318 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04004319{
James Smart70f3c072010-12-15 17:57:33 -05004320 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004321 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04004322 struct lpfc_vport *vport;
4323 struct lpfc_nodelist *ndlp;
4324 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05004325 int active_vlink_present;
4326 struct lpfc_vport **vports;
4327 int i;
James Smartda0436e2009-05-22 14:51:39 -04004328
James Smart70f3c072010-12-15 17:57:33 -05004329 phba->fc_eventTag = acqe_fip->event_tag;
4330 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004331 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05004332 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
4333 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
4334 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04004335 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4336 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004337 "2546 New FCF event, evt_tag:x%x, "
4338 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004339 acqe_fip->event_tag,
4340 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04004341 else
4342 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
4343 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004344 "2788 FCF param modified event, "
4345 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004346 acqe_fip->event_tag,
4347 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04004348 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004349 /*
4350 * During period of FCF discovery, read the FCF
4351 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04004352 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05004353 */
4354 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4355 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004356 "2779 Read FCF (x%x) for updating "
4357 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05004358 acqe_fip->index);
4359 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004360 }
James Smart38b92ef2010-08-04 16:11:39 -04004361
4362 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04004363 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04004364 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04004365 spin_unlock_irq(&phba->hbalock);
4366 break;
4367 }
4368 /* If fast FCF failover rescan event is pending, do nothing */
4369 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
4370 spin_unlock_irq(&phba->hbalock);
4371 break;
4372 }
4373
James Smartc2b97122013-05-31 17:05:36 -04004374 /* If the FCF has been in discovered state, do nothing. */
4375 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
James Smart3804dc82010-07-14 15:31:37 -04004376 spin_unlock_irq(&phba->hbalock);
4377 break;
4378 }
4379 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04004380
James Smart0c9ab6f2010-02-26 14:15:57 -05004381 /* Otherwise, scan the entire FCF table and re-discover SAN */
4382 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004383 "2770 Start FCF table scan per async FCF "
4384 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004385 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004386 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
4387 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04004388 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004389 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4390 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04004391 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04004392 break;
4393
James Smart70f3c072010-12-15 17:57:33 -05004394 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04004395 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04004396 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004397 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
4398 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004399 break;
4400
James Smart70f3c072010-12-15 17:57:33 -05004401 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05004402 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004403 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004404 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05004405 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04004406 /*
4407 * If we are in the middle of FCF failover process, clear
4408 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04004409 */
James Smartfc2b9892010-02-26 14:15:29 -05004410 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004411 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05004412 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004413 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05004414 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004415 break;
4416 }
James Smart38b92ef2010-08-04 16:11:39 -04004417 spin_unlock_irq(&phba->hbalock);
4418
4419 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05004420 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04004421 break;
4422
4423 /*
4424 * Otherwise, request the port to rediscover the entire FCF
4425 * table for a fast recovery from case that the current FCF
4426 * is no longer valid as we are not in the middle of FCF
4427 * failover process already.
4428 */
James Smartc2b97122013-05-31 17:05:36 -04004429 spin_lock_irq(&phba->hbalock);
4430 /* Mark the fast failover process in progress */
4431 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
4432 spin_unlock_irq(&phba->hbalock);
4433
4434 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
4435 "2771 Start FCF fast failover process due to "
4436 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
4437 "\n", acqe_fip->event_tag, acqe_fip->index);
4438 rc = lpfc_sli4_redisc_fcf_table(phba);
4439 if (rc) {
4440 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4441 LOG_DISCOVERY,
4442 "2772 Issue FCF rediscover mabilbox "
4443 "command failed, fail through to FCF "
4444 "dead event\n");
4445 spin_lock_irq(&phba->hbalock);
4446 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
4447 spin_unlock_irq(&phba->hbalock);
4448 /*
4449 * Last resort will fail over by treating this
4450 * as a link down to FCF registration.
4451 */
4452 lpfc_sli4_fcf_dead_failthrough(phba);
4453 } else {
4454 /* Reset FCF roundrobin bmask for new discovery */
4455 lpfc_sli4_clear_fcf_rr_bmask(phba);
4456 /*
4457 * Handling fast FCF failover to a DEAD FCF event is
4458 * considered equalivant to receiving CVL to all vports.
4459 */
4460 lpfc_sli4_perform_all_vport_cvl(phba);
4461 }
James Smartda0436e2009-05-22 14:51:39 -04004462 break;
James Smart70f3c072010-12-15 17:57:33 -05004463 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05004464 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004465 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04004466 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05004467 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04004468
James Smart6669f9b2009-10-02 15:16:45 -04004469 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04004470 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004471 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004472 if (!ndlp)
4473 break;
James Smart695a8142010-01-26 23:08:03 -05004474 active_vlink_present = 0;
4475
4476 vports = lpfc_create_vport_work_array(phba);
4477 if (vports) {
4478 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
4479 i++) {
4480 if ((!(vports[i]->fc_flag &
4481 FC_VPORT_CVL_RCVD)) &&
4482 (vports[i]->port_state > LPFC_FDISC)) {
4483 active_vlink_present = 1;
4484 break;
4485 }
4486 }
4487 lpfc_destroy_vport_work_array(phba, vports);
4488 }
4489
James Smartcc823552015-05-21 13:55:26 -04004490 /*
4491 * Don't re-instantiate if vport is marked for deletion.
4492 * If we are here first then vport_delete is going to wait
4493 * for discovery to complete.
4494 */
4495 if (!(vport->load_flag & FC_UNLOADING) &&
4496 active_vlink_present) {
James Smart695a8142010-01-26 23:08:03 -05004497 /*
4498 * If there are other active VLinks present,
4499 * re-instantiate the Vlink using FDISC.
4500 */
James Smart256ec0d2013-04-17 20:14:58 -04004501 mod_timer(&ndlp->nlp_delayfunc,
4502 jiffies + msecs_to_jiffies(1000));
James Smartfc2b9892010-02-26 14:15:29 -05004503 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004504 spin_lock_irq(shost->host_lock);
4505 ndlp->nlp_flag |= NLP_DELAY_TMO;
4506 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05004507 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
4508 vport->port_state = LPFC_FDISC;
4509 } else {
James Smartecfd03c2010-02-12 14:41:27 -05004510 /*
4511 * Otherwise, we request port to rediscover
4512 * the entire FCF table for a fast recovery
4513 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05004514 * is no longer valid if we are not already
4515 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05004516 */
James Smartfc2b9892010-02-26 14:15:29 -05004517 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004518 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05004519 spin_unlock_irq(&phba->hbalock);
4520 break;
4521 }
4522 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05004523 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004524 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004525 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4526 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004527 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05004528 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05004529 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05004530 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004531 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4532 LOG_DISCOVERY,
4533 "2774 Issue FCF rediscover "
4534 "mabilbox command failed, "
4535 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05004536 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004537 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004538 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05004539 /*
4540 * Last resort will be re-try on the
4541 * the current registered FCF entry.
4542 */
4543 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04004544 } else
4545 /*
4546 * Reset FCF roundrobin bmask for new
4547 * discovery.
4548 */
James Smart7d791df2011-07-22 18:37:52 -04004549 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04004550 }
4551 break;
James Smartda0436e2009-05-22 14:51:39 -04004552 default:
4553 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4554 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05004555 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004556 break;
4557 }
4558}
4559
4560/**
4561 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
4562 * @phba: pointer to lpfc hba data structure.
4563 * @acqe_link: pointer to the async dcbx completion queue entry.
4564 *
4565 * This routine is to handle the SLI4 asynchronous dcbx event.
4566 **/
4567static void
4568lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
4569 struct lpfc_acqe_dcbx *acqe_dcbx)
4570{
James Smart4d9ab992009-10-02 15:16:39 -04004571 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004572 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4573 "0290 The SLI4 DCBX asynchronous event is not "
4574 "handled yet\n");
4575}
4576
4577/**
James Smartb19a0612010-04-06 14:48:51 -04004578 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
4579 * @phba: pointer to lpfc hba data structure.
4580 * @acqe_link: pointer to the async grp5 completion queue entry.
4581 *
4582 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
4583 * is an asynchronous notified of a logical link speed change. The Port
4584 * reports the logical link speed in units of 10Mbps.
4585 **/
4586static void
4587lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
4588 struct lpfc_acqe_grp5 *acqe_grp5)
4589{
4590 uint16_t prev_ll_spd;
4591
4592 phba->fc_eventTag = acqe_grp5->event_tag;
4593 phba->fcoe_eventtag = acqe_grp5->event_tag;
4594 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
4595 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004596 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04004597 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4598 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04004599 "from %dMbps to %dMbps\n", prev_ll_spd,
4600 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04004601}
4602
4603/**
James Smartda0436e2009-05-22 14:51:39 -04004604 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
4605 * @phba: pointer to lpfc hba data structure.
4606 *
4607 * This routine is invoked by the worker thread to process all the pending
4608 * SLI4 asynchronous events.
4609 **/
4610void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
4611{
4612 struct lpfc_cq_event *cq_event;
4613
4614 /* First, declare the async event has been handled */
4615 spin_lock_irq(&phba->hbalock);
4616 phba->hba_flag &= ~ASYNC_EVENT;
4617 spin_unlock_irq(&phba->hbalock);
4618 /* Now, handle all the async events */
4619 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
4620 /* Get the first event from the head of the event queue */
4621 spin_lock_irq(&phba->hbalock);
4622 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
4623 cq_event, struct lpfc_cq_event, list);
4624 spin_unlock_irq(&phba->hbalock);
4625 /* Process the asynchronous event */
4626 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
4627 case LPFC_TRAILER_CODE_LINK:
4628 lpfc_sli4_async_link_evt(phba,
4629 &cq_event->cqe.acqe_link);
4630 break;
4631 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05004632 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004633 break;
4634 case LPFC_TRAILER_CODE_DCBX:
4635 lpfc_sli4_async_dcbx_evt(phba,
4636 &cq_event->cqe.acqe_dcbx);
4637 break;
James Smartb19a0612010-04-06 14:48:51 -04004638 case LPFC_TRAILER_CODE_GRP5:
4639 lpfc_sli4_async_grp5_evt(phba,
4640 &cq_event->cqe.acqe_grp5);
4641 break;
James Smart70f3c072010-12-15 17:57:33 -05004642 case LPFC_TRAILER_CODE_FC:
4643 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
4644 break;
4645 case LPFC_TRAILER_CODE_SLI:
4646 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
4647 break;
James Smartda0436e2009-05-22 14:51:39 -04004648 default:
4649 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4650 "1804 Invalid asynchrous event code: "
4651 "x%x\n", bf_get(lpfc_trailer_code,
4652 &cq_event->cqe.mcqe_cmpl));
4653 break;
4654 }
4655 /* Free the completion event processed to the free pool */
4656 lpfc_sli4_cq_event_release(phba, cq_event);
4657 }
4658}
4659
4660/**
James Smartecfd03c2010-02-12 14:41:27 -05004661 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
4662 * @phba: pointer to lpfc hba data structure.
4663 *
4664 * This routine is invoked by the worker thread to process FCF table
4665 * rediscovery pending completion event.
4666 **/
4667void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
4668{
4669 int rc;
4670
4671 spin_lock_irq(&phba->hbalock);
4672 /* Clear FCF rediscovery timeout event */
4673 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
4674 /* Clear driver fast failover FCF record flag */
4675 phba->fcf.failover_rec.flag = 0;
4676 /* Set state for FCF fast failover */
4677 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
4678 spin_unlock_irq(&phba->hbalock);
4679
4680 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05004681 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004682 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05004683 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05004684 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004685 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4686 "2747 Issue FCF scan read FCF mailbox "
4687 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05004688}
4689
4690/**
James Smartda0436e2009-05-22 14:51:39 -04004691 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
4692 * @phba: pointer to lpfc hba data structure.
4693 * @dev_grp: The HBA PCI-Device group number.
4694 *
4695 * This routine is invoked to set up the per HBA PCI-Device group function
4696 * API jump table entries.
4697 *
4698 * Return: 0 if success, otherwise -ENODEV
4699 **/
4700int
4701lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05004702{
4703 int rc;
4704
James Smartda0436e2009-05-22 14:51:39 -04004705 /* Set up lpfc PCI-device group */
4706 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05004707
James Smartda0436e2009-05-22 14:51:39 -04004708 /* The LPFC_PCI_DEV_OC uses SLI4 */
4709 if (dev_grp == LPFC_PCI_DEV_OC)
4710 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05004711
James Smartda0436e2009-05-22 14:51:39 -04004712 /* Set up device INIT API function jump table */
4713 rc = lpfc_init_api_table_setup(phba, dev_grp);
4714 if (rc)
4715 return -ENODEV;
4716 /* Set up SCSI API function jump table */
4717 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
4718 if (rc)
4719 return -ENODEV;
4720 /* Set up SLI API function jump table */
4721 rc = lpfc_sli_api_table_setup(phba, dev_grp);
4722 if (rc)
4723 return -ENODEV;
4724 /* Set up MBOX API function jump table */
4725 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
4726 if (rc)
4727 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05004728
James Smartda0436e2009-05-22 14:51:39 -04004729 return 0;
James Smart5b75da22008-12-04 22:39:35 -05004730}
4731
4732/**
James Smart3621a712009-04-06 18:47:14 -04004733 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05004734 * @phba: pointer to lpfc hba data structure.
4735 * @intr_mode: active interrupt mode adopted.
4736 *
4737 * This routine it invoked to log the currently used active interrupt mode
4738 * to the device.
James Smart3772a992009-05-22 14:50:54 -04004739 **/
4740static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05004741{
4742 switch (intr_mode) {
4743 case 0:
4744 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4745 "0470 Enable INTx interrupt mode.\n");
4746 break;
4747 case 1:
4748 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4749 "0481 Enabled MSI interrupt mode.\n");
4750 break;
4751 case 2:
4752 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4753 "0480 Enabled MSI-X interrupt mode.\n");
4754 break;
4755 default:
4756 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4757 "0482 Illegal interrupt mode.\n");
4758 break;
4759 }
4760 return;
4761}
4762
James Smart5b75da22008-12-04 22:39:35 -05004763/**
James Smart3772a992009-05-22 14:50:54 -04004764 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05004765 * @phba: pointer to lpfc hba data structure.
4766 *
James Smart3772a992009-05-22 14:50:54 -04004767 * This routine is invoked to enable the PCI device that is common to all
4768 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05004769 *
4770 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004771 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004772 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05004773 **/
James Smart3772a992009-05-22 14:50:54 -04004774static int
4775lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05004776{
James Smart3772a992009-05-22 14:50:54 -04004777 struct pci_dev *pdev;
James Smart079b5c92011-08-21 21:48:49 -04004778 int bars = 0;
James Smart5b75da22008-12-04 22:39:35 -05004779
James Smart3772a992009-05-22 14:50:54 -04004780 /* Obtain PCI device reference */
4781 if (!phba->pcidev)
4782 goto out_error;
4783 else
4784 pdev = phba->pcidev;
4785 /* Select PCI BARs */
4786 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4787 /* Enable PCI device */
4788 if (pci_enable_device_mem(pdev))
4789 goto out_error;
4790 /* Request PCI resource for the device */
4791 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
4792 goto out_disable_device;
4793 /* Set up device as PCI master and save state for EEH */
4794 pci_set_master(pdev);
4795 pci_try_set_mwi(pdev);
4796 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05004797
James Smart05580562011-05-24 11:40:48 -04004798 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
Jon Mason453193e2013-09-11 15:38:13 -07004799 if (pci_is_pcie(pdev))
James Smart05580562011-05-24 11:40:48 -04004800 pdev->needs_freset = 1;
4801
James Smart3772a992009-05-22 14:50:54 -04004802 return 0;
James Smart5b75da22008-12-04 22:39:35 -05004803
James Smart3772a992009-05-22 14:50:54 -04004804out_disable_device:
4805 pci_disable_device(pdev);
4806out_error:
James Smart079b5c92011-08-21 21:48:49 -04004807 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4808 "1401 Failed to enable pci device, bars:x%x\n", bars);
James Smart3772a992009-05-22 14:50:54 -04004809 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05004810}
4811
4812/**
James Smart3772a992009-05-22 14:50:54 -04004813 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05004814 * @phba: pointer to lpfc hba data structure.
4815 *
James Smart3772a992009-05-22 14:50:54 -04004816 * This routine is invoked to disable the PCI device that is common to all
4817 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05004818 **/
4819static void
James Smart3772a992009-05-22 14:50:54 -04004820lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05004821{
James Smart3772a992009-05-22 14:50:54 -04004822 struct pci_dev *pdev;
4823 int bars;
James Smart5b75da22008-12-04 22:39:35 -05004824
James Smart3772a992009-05-22 14:50:54 -04004825 /* Obtain PCI device reference */
4826 if (!phba->pcidev)
4827 return;
4828 else
4829 pdev = phba->pcidev;
4830 /* Select PCI BARs */
4831 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4832 /* Release PCI resource and disable PCI device */
4833 pci_release_selected_regions(pdev, bars);
4834 pci_disable_device(pdev);
James Smart5b75da22008-12-04 22:39:35 -05004835
4836 return;
4837}
4838
4839/**
James Smart3772a992009-05-22 14:50:54 -04004840 * lpfc_reset_hba - Reset a hba
4841 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04004842 *
James Smart3772a992009-05-22 14:50:54 -04004843 * This routine is invoked to reset a hba device. It brings the HBA
4844 * offline, performs a board restart, and then brings the board back
4845 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
4846 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04004847 **/
James Smart3772a992009-05-22 14:50:54 -04004848void
4849lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05004850{
James Smart3772a992009-05-22 14:50:54 -04004851 /* If resets are disabled then set error state and return. */
4852 if (!phba->cfg_enable_hba_reset) {
4853 phba->link_state = LPFC_HBA_ERROR;
4854 return;
4855 }
James Smartee620212014-04-04 13:51:53 -04004856 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
4857 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
4858 else
4859 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart3772a992009-05-22 14:50:54 -04004860 lpfc_offline(phba);
4861 lpfc_sli_brdrestart(phba);
4862 lpfc_online(phba);
4863 lpfc_unblock_mgmt_io(phba);
4864}
dea31012005-04-17 16:05:31 -05004865
James Smart3772a992009-05-22 14:50:54 -04004866/**
James Smart0a96e972011-07-22 18:37:28 -04004867 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
4868 * @phba: pointer to lpfc hba data structure.
4869 *
4870 * This function enables the PCI SR-IOV virtual functions to a physical
4871 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4872 * enable the number of virtual functions to the physical function. As
4873 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4874 * API call does not considered as an error condition for most of the device.
4875 **/
4876uint16_t
4877lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
4878{
4879 struct pci_dev *pdev = phba->pcidev;
4880 uint16_t nr_virtfn;
4881 int pos;
4882
James Smart0a96e972011-07-22 18:37:28 -04004883 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4884 if (pos == 0)
4885 return 0;
4886
4887 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
4888 return nr_virtfn;
4889}
4890
4891/**
James Smart912e3ac2011-05-24 11:42:11 -04004892 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
4893 * @phba: pointer to lpfc hba data structure.
4894 * @nr_vfn: number of virtual functions to be enabled.
4895 *
4896 * This function enables the PCI SR-IOV virtual functions to a physical
4897 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4898 * enable the number of virtual functions to the physical function. As
4899 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4900 * API call does not considered as an error condition for most of the device.
4901 **/
4902int
4903lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
4904{
4905 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04004906 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04004907 int rc;
4908
James Smart0a96e972011-07-22 18:37:28 -04004909 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
4910 if (nr_vfn > max_nr_vfn) {
4911 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4912 "3057 Requested vfs (%d) greater than "
4913 "supported vfs (%d)", nr_vfn, max_nr_vfn);
4914 return -EINVAL;
4915 }
4916
James Smart912e3ac2011-05-24 11:42:11 -04004917 rc = pci_enable_sriov(pdev, nr_vfn);
4918 if (rc) {
4919 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4920 "2806 Failed to enable sriov on this device "
4921 "with vfn number nr_vf:%d, rc:%d\n",
4922 nr_vfn, rc);
4923 } else
4924 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4925 "2807 Successful enable sriov on this device "
4926 "with vfn number nr_vf:%d\n", nr_vfn);
4927 return rc;
4928}
4929
4930/**
James Smart3772a992009-05-22 14:50:54 -04004931 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
4932 * @phba: pointer to lpfc hba data structure.
4933 *
4934 * This routine is invoked to set up the driver internal resources specific to
4935 * support the SLI-3 HBA device it attached to.
4936 *
4937 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004938 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004939 * other values - error
4940 **/
4941static int
4942lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
4943{
4944 struct lpfc_sli *psli;
James Smart912e3ac2011-05-24 11:42:11 -04004945 int rc;
dea31012005-04-17 16:05:31 -05004946
James Smart3772a992009-05-22 14:50:54 -04004947 /*
4948 * Initialize timers used by driver
4949 */
dea31012005-04-17 16:05:31 -05004950
James Smart3772a992009-05-22 14:50:54 -04004951 /* Heartbeat timer */
4952 init_timer(&phba->hb_tmofunc);
4953 phba->hb_tmofunc.function = lpfc_hb_timeout;
4954 phba->hb_tmofunc.data = (unsigned long)phba;
4955
4956 psli = &phba->sli;
4957 /* MBOX heartbeat timer */
4958 init_timer(&psli->mbox_tmo);
4959 psli->mbox_tmo.function = lpfc_mbox_timeout;
4960 psli->mbox_tmo.data = (unsigned long) phba;
4961 /* FCP polling mode timer */
4962 init_timer(&phba->fcp_poll_timer);
4963 phba->fcp_poll_timer.function = lpfc_poll_timeout;
4964 phba->fcp_poll_timer.data = (unsigned long) phba;
4965 /* Fabric block timer */
4966 init_timer(&phba->fabric_block_timer);
4967 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
4968 phba->fabric_block_timer.data = (unsigned long) phba;
4969 /* EA polling mode timer */
4970 init_timer(&phba->eratt_poll);
4971 phba->eratt_poll.function = lpfc_poll_eratt;
4972 phba->eratt_poll.data = (unsigned long) phba;
4973
4974 /* Host attention work mask setup */
4975 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
4976 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
4977
4978 /* Get all the module params for configuring this host */
4979 lpfc_get_cfgparam(phba);
James Smart49198b32010-04-06 15:04:33 -04004980 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
4981 phba->menlo_flag |= HBA_MENLO_SUPPORT;
4982 /* check for menlo minimum sg count */
4983 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
4984 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
4985 }
4986
James Smart2a76a282012-08-03 12:35:54 -04004987 if (!phba->sli.ring)
Firo Yangc6cb9b42015-08-31 16:48:09 -04004988 phba->sli.ring = kzalloc(LPFC_SLI3_MAX_RING *
James Smart2a76a282012-08-03 12:35:54 -04004989 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
4990 if (!phba->sli.ring)
4991 return -ENOMEM;
4992
James Smart3772a992009-05-22 14:50:54 -04004993 /*
James Smart96f70772013-04-17 20:16:15 -04004994 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smart3772a992009-05-22 14:50:54 -04004995 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart3772a992009-05-22 14:50:54 -04004996 */
James Smart3772a992009-05-22 14:50:54 -04004997
James Smart96f70772013-04-17 20:16:15 -04004998 /* Initialize the host templates the configured values. */
James Smart3772a992009-05-22 14:50:54 -04004999 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
Bodo Stroesser5f406fa2015-08-31 16:48:10 -04005000 lpfc_template_s3.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart3772a992009-05-22 14:50:54 -04005001
James Smart96f70772013-04-17 20:16:15 -04005002 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
5003 if (phba->cfg_enable_bg) {
5004 /*
5005 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5006 * the FCP rsp, and a BDE for each. Sice we have no control
5007 * over how many protection data segments the SCSI Layer
5008 * will hand us (ie: there could be one for every block
5009 * in the IO), we just allocate enough BDEs to accomidate
5010 * our max amount and we need to limit lpfc_sg_seg_cnt to
5011 * minimize the risk of running out.
5012 */
5013 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5014 sizeof(struct fcp_rsp) +
5015 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
5016
5017 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
5018 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
5019
5020 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
5021 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
5022 } else {
5023 /*
5024 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5025 * the FCP rsp, a BDE for each, and a BDE for up to
5026 * cfg_sg_seg_cnt data segments.
5027 */
5028 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5029 sizeof(struct fcp_rsp) +
5030 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
5031
5032 /* Total BDEs in BPL for scsi_sg_list */
5033 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5034 }
5035
5036 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5037 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
5038 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5039 phba->cfg_total_seg_cnt);
5040
James Smart3772a992009-05-22 14:50:54 -04005041 phba->max_vpi = LPFC_MAX_VPI;
5042 /* This will be set to correct value after config_port mbox */
5043 phba->max_vports = 0;
5044
5045 /*
5046 * Initialize the SLI Layer to run with lpfc HBAs.
5047 */
5048 lpfc_sli_setup(phba);
5049 lpfc_sli_queue_setup(phba);
5050
5051 /* Allocate device driver memory */
5052 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
5053 return -ENOMEM;
5054
James Smart912e3ac2011-05-24 11:42:11 -04005055 /*
5056 * Enable sr-iov virtual functions if supported and configured
5057 * through the module parameter.
5058 */
5059 if (phba->cfg_sriov_nr_virtfn > 0) {
5060 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5061 phba->cfg_sriov_nr_virtfn);
5062 if (rc) {
5063 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5064 "2808 Requested number of SR-IOV "
5065 "virtual functions (%d) is not "
5066 "supported\n",
5067 phba->cfg_sriov_nr_virtfn);
5068 phba->cfg_sriov_nr_virtfn = 0;
5069 }
5070 }
5071
James Smart3772a992009-05-22 14:50:54 -04005072 return 0;
5073}
5074
5075/**
5076 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
5077 * @phba: pointer to lpfc hba data structure.
5078 *
5079 * This routine is invoked to unset the driver internal resources set up
5080 * specific for supporting the SLI-3 HBA device it attached to.
5081 **/
5082static void
5083lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
5084{
5085 /* Free device driver memory allocated */
5086 lpfc_mem_free_all(phba);
5087
5088 return;
5089}
5090
5091/**
James Smartda0436e2009-05-22 14:51:39 -04005092 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
5093 * @phba: pointer to lpfc hba data structure.
5094 *
5095 * This routine is invoked to set up the driver internal resources specific to
5096 * support the SLI-4 HBA device it attached to.
5097 *
5098 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005099 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04005100 * other values - error
5101 **/
5102static int
5103lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5104{
James Smart7bb03bb2013-04-17 20:19:16 -04005105 struct lpfc_vector_map_info *cpup;
James Smartda0436e2009-05-22 14:51:39 -04005106 struct lpfc_sli *psli;
James Smart28baac72010-02-12 14:42:03 -05005107 LPFC_MBOXQ_t *mboxq;
James Smart96f70772013-04-17 20:16:15 -04005108 int rc, i, hbq_count, max_buf_size;
James Smart28baac72010-02-12 14:42:03 -05005109 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
5110 struct lpfc_mqe *mqe;
James Smart09294d42013-04-17 20:16:05 -04005111 int longs;
James Smart1ba981f2014-02-20 09:56:45 -05005112 int fof_vectors = 0;
James Smartda0436e2009-05-22 14:51:39 -04005113
James Smart716d3bc2013-09-06 12:18:28 -04005114 /* Get all the module params for configuring this host */
5115 lpfc_get_cfgparam(phba);
5116
James Smartda0436e2009-05-22 14:51:39 -04005117 /* Before proceed, wait for POST done and device ready */
5118 rc = lpfc_sli4_post_status_check(phba);
5119 if (rc)
5120 return -ENODEV;
5121
5122 /*
5123 * Initialize timers used by driver
5124 */
5125
5126 /* Heartbeat timer */
5127 init_timer(&phba->hb_tmofunc);
5128 phba->hb_tmofunc.function = lpfc_hb_timeout;
5129 phba->hb_tmofunc.data = (unsigned long)phba;
James Smart19ca7602010-11-20 23:11:55 -05005130 init_timer(&phba->rrq_tmr);
5131 phba->rrq_tmr.function = lpfc_rrq_timeout;
5132 phba->rrq_tmr.data = (unsigned long)phba;
James Smartda0436e2009-05-22 14:51:39 -04005133
5134 psli = &phba->sli;
5135 /* MBOX heartbeat timer */
5136 init_timer(&psli->mbox_tmo);
5137 psli->mbox_tmo.function = lpfc_mbox_timeout;
5138 psli->mbox_tmo.data = (unsigned long) phba;
5139 /* Fabric block timer */
5140 init_timer(&phba->fabric_block_timer);
5141 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
5142 phba->fabric_block_timer.data = (unsigned long) phba;
5143 /* EA polling mode timer */
5144 init_timer(&phba->eratt_poll);
5145 phba->eratt_poll.function = lpfc_poll_eratt;
5146 phba->eratt_poll.data = (unsigned long) phba;
James Smartecfd03c2010-02-12 14:41:27 -05005147 /* FCF rediscover timer */
5148 init_timer(&phba->fcf.redisc_wait);
5149 phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
5150 phba->fcf.redisc_wait.data = (unsigned long)phba;
5151
James Smartda0436e2009-05-22 14:51:39 -04005152 /*
James Smart7ad20aa2011-05-24 11:44:28 -04005153 * Control structure for handling external multi-buffer mailbox
5154 * command pass-through.
5155 */
5156 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
5157 sizeof(struct lpfc_mbox_ext_buf_ctx));
5158 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
5159
James Smartda0436e2009-05-22 14:51:39 -04005160 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04005161
James Smartda0436e2009-05-22 14:51:39 -04005162 /* This will be set to correct value after the read_config mbox */
5163 phba->max_vports = 0;
5164
5165 /* Program the default value of vlan_id and fc_map */
5166 phba->valid_vlan = 0;
5167 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5168 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5169 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5170
5171 /*
James Smart2a76a282012-08-03 12:35:54 -04005172 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
5173 * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple.
5174 */
5175 if (!phba->sli.ring)
5176 phba->sli.ring = kzalloc(
James Smart67d12732012-08-03 12:36:13 -04005177 (LPFC_SLI3_MAX_RING + phba->cfg_fcp_io_channel) *
James Smart2a76a282012-08-03 12:35:54 -04005178 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
5179 if (!phba->sli.ring)
5180 return -ENOMEM;
James Smart085c6472010-11-20 23:11:37 -05005181
James Smart09294d42013-04-17 20:16:05 -04005182 /*
5183 * It doesn't matter what family our adapter is in, we are
5184 * limited to 2 Pages, 512 SGEs, for our SGL.
5185 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
5186 */
5187 max_buf_size = (2 * SLI4_PAGE_SIZE);
5188 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2)
5189 phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2;
James Smart09294d42013-04-17 20:16:05 -04005190
James Smartda0436e2009-05-22 14:51:39 -04005191 /*
James Smart96f70772013-04-17 20:16:15 -04005192 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smartda0436e2009-05-22 14:51:39 -04005193 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart28baac72010-02-12 14:42:03 -05005194 */
James Smart085c6472010-11-20 23:11:37 -05005195
James Smart96f70772013-04-17 20:16:15 -04005196 if (phba->cfg_enable_bg) {
5197 /*
5198 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5199 * the FCP rsp, and a SGE for each. Sice we have no control
5200 * over how many protection data segments the SCSI Layer
5201 * will hand us (ie: there could be one for every block
5202 * in the IO), we just allocate enough SGEs to accomidate
5203 * our max amount and we need to limit lpfc_sg_seg_cnt to
5204 * minimize the risk of running out.
5205 */
5206 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5207 sizeof(struct fcp_rsp) + max_buf_size;
5208
5209 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
5210 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
5211
5212 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
5213 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
5214 } else {
5215 /*
5216 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5217 * the FCP rsp, a SGE for each, and a SGE for up to
5218 * cfg_sg_seg_cnt data segments.
5219 */
5220 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5221 sizeof(struct fcp_rsp) +
5222 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge));
5223
5224 /* Total SGEs for scsi_sg_list */
5225 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5226 /*
5227 * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only need
5228 * to post 1 page for the SGL.
5229 */
James Smart085c6472010-11-20 23:11:37 -05005230 }
James Smartacd68592012-01-18 16:25:09 -05005231
James Smart96f70772013-04-17 20:16:15 -04005232 /* Initialize the host templates with the updated values. */
5233 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5234 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5235
5236 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
5237 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
5238 else
5239 phba->cfg_sg_dma_buf_size =
5240 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
5241
5242 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5243 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
5244 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5245 phba->cfg_total_seg_cnt);
James Smartda0436e2009-05-22 14:51:39 -04005246
5247 /* Initialize buffer queue management fields */
5248 hbq_count = lpfc_sli_hbq_count();
5249 for (i = 0; i < hbq_count; ++i)
5250 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
5251 INIT_LIST_HEAD(&phba->rb_pend_list);
5252 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
5253 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
5254
5255 /*
5256 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
5257 */
5258 /* Initialize the Abort scsi buffer list used by driver */
5259 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
5260 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
5261 /* This abort list used by worker thread */
5262 spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
5263
5264 /*
James Smart6d368e52011-05-24 11:44:12 -04005265 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04005266 */
5267
5268 /* Driver internel slow-path CQ Event pool */
5269 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
5270 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04005271 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04005272 /* Asynchronous event CQ Event work queue list */
5273 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
5274 /* Fast-path XRI aborted CQ Event work queue list */
5275 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
5276 /* Slow-path XRI aborted CQ Event work queue list */
5277 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
5278 /* Receive queue CQ Event work queue list */
5279 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
5280
James Smart6d368e52011-05-24 11:44:12 -04005281 /* Initialize extent block lists. */
5282 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
5283 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
5284 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
5285 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
5286
James Smart448193b2015-12-16 18:12:05 -05005287 /* initialize optic_state to 0xFF */
5288 phba->sli4_hba.lnk_info.optic_state = 0xff;
5289
James Smartda0436e2009-05-22 14:51:39 -04005290 /* Initialize the driver internal SLI layer lists. */
5291 lpfc_sli_setup(phba);
5292 lpfc_sli_queue_setup(phba);
5293
5294 /* Allocate device driver memory */
5295 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
5296 if (rc)
5297 return -ENOMEM;
5298
James Smart2fcee4b2010-12-15 17:57:46 -05005299 /* IF Type 2 ports get initialized now. */
5300 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5301 LPFC_SLI_INTF_IF_TYPE_2) {
5302 rc = lpfc_pci_function_reset(phba);
5303 if (unlikely(rc))
5304 return -ENODEV;
James Smart946727d2015-04-07 15:07:09 -04005305 phba->temp_sensor_support = 1;
James Smart2fcee4b2010-12-15 17:57:46 -05005306 }
5307
James Smartda0436e2009-05-22 14:51:39 -04005308 /* Create the bootstrap mailbox command */
5309 rc = lpfc_create_bootstrap_mbox(phba);
5310 if (unlikely(rc))
5311 goto out_free_mem;
5312
5313 /* Set up the host's endian order with the device. */
5314 rc = lpfc_setup_endian_order(phba);
5315 if (unlikely(rc))
5316 goto out_free_bsmbx;
5317
5318 /* Set up the hba's configuration parameters. */
5319 rc = lpfc_sli4_read_config(phba);
5320 if (unlikely(rc))
5321 goto out_free_bsmbx;
James Smartcff261f2013-12-17 20:29:47 -05005322 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
5323 if (unlikely(rc))
5324 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005325
James Smart2fcee4b2010-12-15 17:57:46 -05005326 /* IF Type 0 ports get initialized now. */
5327 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5328 LPFC_SLI_INTF_IF_TYPE_0) {
5329 rc = lpfc_pci_function_reset(phba);
5330 if (unlikely(rc))
5331 goto out_free_bsmbx;
5332 }
James Smartda0436e2009-05-22 14:51:39 -04005333
James Smartcb5172e2010-03-15 11:25:07 -04005334 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
5335 GFP_KERNEL);
5336 if (!mboxq) {
5337 rc = -ENOMEM;
5338 goto out_free_bsmbx;
5339 }
5340
James Smartfedd3b72011-02-16 12:39:24 -05005341 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04005342 lpfc_supported_pages(mboxq);
5343 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05005344 if (!rc) {
5345 mqe = &mboxq->u.mqe;
5346 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
5347 LPFC_MAX_SUPPORTED_PAGES);
5348 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
5349 switch (pn_page[i]) {
5350 case LPFC_SLI4_PARAMETERS:
5351 phba->sli4_hba.pc_sli4_params.supported = 1;
5352 break;
5353 default:
5354 break;
5355 }
5356 }
5357 /* Read the port's SLI4 Parameters capabilities if supported. */
5358 if (phba->sli4_hba.pc_sli4_params.supported)
5359 rc = lpfc_pc_sli4_params_get(phba, mboxq);
5360 if (rc) {
5361 mempool_free(mboxq, phba->mbox_mem_pool);
5362 rc = -EIO;
5363 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04005364 }
5365 }
James Smartfedd3b72011-02-16 12:39:24 -05005366 /*
5367 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04005368 * If this call fails, it isn't critical unless the SLI4 parameters come
5369 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05005370 */
James Smart6d368e52011-05-24 11:44:12 -04005371 rc = lpfc_get_sli4_parameters(phba, mboxq);
5372 if (rc) {
5373 if (phba->sli4_hba.extents_in_use &&
5374 phba->sli4_hba.rpi_hdrs_in_use) {
5375 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5376 "2999 Unsupported SLI4 Parameters "
5377 "Extents and RPI headers enabled.\n");
5378 goto out_free_bsmbx;
5379 }
5380 }
James Smartcb5172e2010-03-15 11:25:07 -04005381 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -05005382
5383 /* Verify OAS is supported */
5384 lpfc_sli4_oas_verify(phba);
5385 if (phba->cfg_fof)
5386 fof_vectors = 1;
5387
James Smart5350d872011-10-10 21:33:49 -04005388 /* Verify all the SLI4 queues */
5389 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04005390 if (rc)
5391 goto out_free_bsmbx;
5392
5393 /* Create driver internal CQE event pool */
5394 rc = lpfc_sli4_cq_event_pool_create(phba);
5395 if (rc)
James Smart5350d872011-10-10 21:33:49 -04005396 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005397
James Smart8a9d2e82012-05-09 21:16:12 -04005398 /* Initialize sgl lists per host */
5399 lpfc_init_sgl_list(phba);
5400
5401 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04005402 rc = lpfc_init_active_sgl_array(phba);
5403 if (rc) {
5404 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5405 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04005406 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04005407 }
James Smartda0436e2009-05-22 14:51:39 -04005408 rc = lpfc_sli4_init_rpi_hdrs(phba);
5409 if (rc) {
5410 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5411 "1432 Failed to initialize rpi headers.\n");
5412 goto out_free_active_sgl;
5413 }
5414
James Smarta93ff372010-10-22 11:06:08 -04005415 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05005416 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
5417 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
5418 GFP_KERNEL);
5419 if (!phba->fcf.fcf_rr_bmask) {
5420 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5421 "2759 Failed allocate memory for FCF round "
5422 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04005423 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05005424 goto out_remove_rpi_hdrs;
5425 }
5426
James Smart67d12732012-08-03 12:36:13 -04005427 phba->sli4_hba.fcp_eq_hdl =
5428 kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
James Smart1ba981f2014-02-20 09:56:45 -05005429 (fof_vectors + phba->cfg_fcp_io_channel)),
5430 GFP_KERNEL);
James Smart67d12732012-08-03 12:36:13 -04005431 if (!phba->sli4_hba.fcp_eq_hdl) {
5432 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5433 "2572 Failed allocate memory for "
5434 "fast-path per-EQ handle array\n");
5435 rc = -ENOMEM;
5436 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04005437 }
5438
5439 phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
James Smart1ba981f2014-02-20 09:56:45 -05005440 (fof_vectors +
5441 phba->cfg_fcp_io_channel)), GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04005442 if (!phba->sli4_hba.msix_entries) {
5443 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5444 "2573 Failed allocate memory for msi-x "
5445 "interrupt vector entries\n");
James Smart05580562011-05-24 11:40:48 -04005446 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04005447 goto out_free_fcp_eq_hdl;
5448 }
5449
James Smart7bb03bb2013-04-17 20:19:16 -04005450 phba->sli4_hba.cpu_map = kzalloc((sizeof(struct lpfc_vector_map_info) *
5451 phba->sli4_hba.num_present_cpu),
5452 GFP_KERNEL);
5453 if (!phba->sli4_hba.cpu_map) {
5454 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5455 "3327 Failed allocate memory for msi-x "
5456 "interrupt vector mapping\n");
5457 rc = -ENOMEM;
5458 goto out_free_msix;
5459 }
James Smartb246de12013-05-31 17:03:07 -04005460 if (lpfc_used_cpu == NULL) {
5461 lpfc_used_cpu = kzalloc((sizeof(uint16_t) * lpfc_present_cpu),
5462 GFP_KERNEL);
5463 if (!lpfc_used_cpu) {
5464 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5465 "3335 Failed allocate memory for msi-x "
5466 "interrupt vector mapping\n");
5467 kfree(phba->sli4_hba.cpu_map);
5468 rc = -ENOMEM;
5469 goto out_free_msix;
5470 }
5471 for (i = 0; i < lpfc_present_cpu; i++)
5472 lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
5473 }
5474
James Smart7bb03bb2013-04-17 20:19:16 -04005475 /* Initialize io channels for round robin */
5476 cpup = phba->sli4_hba.cpu_map;
5477 rc = 0;
5478 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
5479 cpup->channel_id = rc;
5480 rc++;
5481 if (rc >= phba->cfg_fcp_io_channel)
5482 rc = 0;
5483 }
5484
James Smart912e3ac2011-05-24 11:42:11 -04005485 /*
5486 * Enable sr-iov virtual functions if supported and configured
5487 * through the module parameter.
5488 */
5489 if (phba->cfg_sriov_nr_virtfn > 0) {
5490 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5491 phba->cfg_sriov_nr_virtfn);
5492 if (rc) {
5493 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5494 "3020 Requested number of SR-IOV "
5495 "virtual functions (%d) is not "
5496 "supported\n",
5497 phba->cfg_sriov_nr_virtfn);
5498 phba->cfg_sriov_nr_virtfn = 0;
5499 }
5500 }
5501
James Smart5248a742011-07-22 18:37:06 -04005502 return 0;
James Smartda0436e2009-05-22 14:51:39 -04005503
James Smart7bb03bb2013-04-17 20:19:16 -04005504out_free_msix:
5505 kfree(phba->sli4_hba.msix_entries);
James Smartda0436e2009-05-22 14:51:39 -04005506out_free_fcp_eq_hdl:
5507 kfree(phba->sli4_hba.fcp_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05005508out_free_fcf_rr_bmask:
5509 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04005510out_remove_rpi_hdrs:
5511 lpfc_sli4_remove_rpi_hdrs(phba);
5512out_free_active_sgl:
5513 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04005514out_destroy_cq_event_pool:
5515 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04005516out_free_bsmbx:
5517 lpfc_destroy_bootstrap_mbox(phba);
5518out_free_mem:
5519 lpfc_mem_free(phba);
5520 return rc;
5521}
5522
5523/**
5524 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
5525 * @phba: pointer to lpfc hba data structure.
5526 *
5527 * This routine is invoked to unset the driver internal resources set up
5528 * specific for supporting the SLI-4 HBA device it attached to.
5529 **/
5530static void
5531lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
5532{
5533 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
5534
James Smart7bb03bb2013-04-17 20:19:16 -04005535 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
5536 kfree(phba->sli4_hba.cpu_map);
5537 phba->sli4_hba.num_present_cpu = 0;
5538 phba->sli4_hba.num_online_cpu = 0;
James Smart76fd07a2014-02-20 09:57:18 -05005539 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04005540
James Smartda0436e2009-05-22 14:51:39 -04005541 /* Free memory allocated for msi-x interrupt vector entries */
5542 kfree(phba->sli4_hba.msix_entries);
5543
5544 /* Free memory allocated for fast-path work queue handles */
5545 kfree(phba->sli4_hba.fcp_eq_hdl);
5546
5547 /* Free the allocated rpi headers. */
5548 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04005549 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04005550
James Smart0c9ab6f2010-02-26 14:15:57 -05005551 /* Free eligible FCF index bmask */
5552 kfree(phba->fcf.fcf_rr_bmask);
5553
James Smartda0436e2009-05-22 14:51:39 -04005554 /* Free the ELS sgl list */
5555 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04005556 lpfc_free_els_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04005557
James Smartda0436e2009-05-22 14:51:39 -04005558 /* Free the completion queue EQ event pool */
5559 lpfc_sli4_cq_event_release_all(phba);
5560 lpfc_sli4_cq_event_pool_destroy(phba);
5561
James Smart6d368e52011-05-24 11:44:12 -04005562 /* Release resource identifiers. */
5563 lpfc_sli4_dealloc_resource_identifiers(phba);
5564
James Smartda0436e2009-05-22 14:51:39 -04005565 /* Free the bsmbx region. */
5566 lpfc_destroy_bootstrap_mbox(phba);
5567
5568 /* Free the SLI Layer memory with SLI4 HBAs */
5569 lpfc_mem_free_all(phba);
5570
5571 /* Free the current connect table */
5572 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04005573 &phba->fcf_conn_rec_list, list) {
5574 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04005575 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04005576 }
James Smartda0436e2009-05-22 14:51:39 -04005577
5578 return;
5579}
5580
5581/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005582 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04005583 * @phba: The hba struct for which this call is being executed.
5584 * @dev_grp: The HBA PCI-Device group number.
5585 *
5586 * This routine sets up the device INIT interface API function jump table
5587 * in @phba struct.
5588 *
5589 * Returns: 0 - success, -ENODEV - failure.
5590 **/
5591int
5592lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5593{
James Smart84d1b002010-02-12 14:42:33 -05005594 phba->lpfc_hba_init_link = lpfc_hba_init_link;
5595 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05005596 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04005597 switch (dev_grp) {
5598 case LPFC_PCI_DEV_LP:
5599 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
5600 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
5601 phba->lpfc_stop_port = lpfc_stop_port_s3;
5602 break;
James Smartda0436e2009-05-22 14:51:39 -04005603 case LPFC_PCI_DEV_OC:
5604 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
5605 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
5606 phba->lpfc_stop_port = lpfc_stop_port_s4;
5607 break;
James Smart3772a992009-05-22 14:50:54 -04005608 default:
5609 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5610 "1431 Invalid HBA PCI-device group: 0x%x\n",
5611 dev_grp);
5612 return -ENODEV;
5613 break;
5614 }
5615 return 0;
5616}
5617
5618/**
5619 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
5620 * @phba: pointer to lpfc hba data structure.
5621 *
5622 * This routine is invoked to set up the driver internal resources before the
5623 * device specific resource setup to support the HBA device it attached to.
5624 *
5625 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005626 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005627 * other values - error
5628 **/
5629static int
5630lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
5631{
5632 /*
5633 * Driver resources common to all SLI revisions
5634 */
James Smartea2151b2008-09-07 11:52:10 -04005635 atomic_set(&phba->fast_event_count, 0);
James Smart2e0fef82007-06-17 19:56:36 -05005636 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005637
James Smarte47c9092008-02-08 18:49:26 -05005638 /* Initialize ndlp management spinlock */
5639 spin_lock_init(&phba->ndlp_lock);
5640
James Smart2e0fef82007-06-17 19:56:36 -05005641 INIT_LIST_HEAD(&phba->port_list);
James Smart3772a992009-05-22 14:50:54 -04005642 INIT_LIST_HEAD(&phba->work_list);
James Smart84774a42008-08-24 21:50:06 -04005643 init_waitqueue_head(&phba->wait_4_mlo_m_q);
dea31012005-04-17 16:05:31 -05005644
James Smart3772a992009-05-22 14:50:54 -04005645 /* Initialize the wait queue head for the kernel thread */
5646 init_waitqueue_head(&phba->work_waitq);
James Smart858c9f62007-06-17 19:56:39 -05005647
James Smart3772a992009-05-22 14:50:54 -04005648 /* Initialize the scsi buffer list used by driver for scsi IO */
James Smarta40fc5f2013-04-17 20:17:40 -04005649 spin_lock_init(&phba->scsi_buf_list_get_lock);
5650 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5651 spin_lock_init(&phba->scsi_buf_list_put_lock);
5652 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
dea31012005-04-17 16:05:31 -05005653
James Smart3772a992009-05-22 14:50:54 -04005654 /* Initialize the fabric iocb list */
5655 INIT_LIST_HEAD(&phba->fabric_iocb_list);
dea31012005-04-17 16:05:31 -05005656
James Smart3772a992009-05-22 14:50:54 -04005657 /* Initialize list to save ELS buffers */
5658 INIT_LIST_HEAD(&phba->elsbuf);
dea31012005-04-17 16:05:31 -05005659
James Smart3772a992009-05-22 14:50:54 -04005660 /* Initialize FCF connection rec list */
5661 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
dea31012005-04-17 16:05:31 -05005662
James Smart1ba981f2014-02-20 09:56:45 -05005663 /* Initialize OAS configuration list */
5664 spin_lock_init(&phba->devicelock);
5665 INIT_LIST_HEAD(&phba->luns);
5666
James Smart3772a992009-05-22 14:50:54 -04005667 return 0;
5668}
dea31012005-04-17 16:05:31 -05005669
James Smart3772a992009-05-22 14:50:54 -04005670/**
5671 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
5672 * @phba: pointer to lpfc hba data structure.
5673 *
5674 * This routine is invoked to set up the driver internal resources after the
5675 * device specific resource setup to support the HBA device it attached to.
5676 *
5677 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005678 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005679 * other values - error
5680 **/
5681static int
5682lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
5683{
5684 int error;
5685
5686 /* Startup the kernel thread for this host adapter. */
5687 phba->worker_thread = kthread_run(lpfc_do_work, phba,
5688 "lpfc_worker_%d", phba->brd_no);
5689 if (IS_ERR(phba->worker_thread)) {
5690 error = PTR_ERR(phba->worker_thread);
5691 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005692 }
5693
James Smart3772a992009-05-22 14:50:54 -04005694 return 0;
5695}
5696
5697/**
5698 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
5699 * @phba: pointer to lpfc hba data structure.
5700 *
5701 * This routine is invoked to unset the driver internal resources set up after
5702 * the device specific resource setup for supporting the HBA device it
5703 * attached to.
5704 **/
5705static void
5706lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
5707{
5708 /* Stop kernel worker thread */
5709 kthread_stop(phba->worker_thread);
5710}
5711
5712/**
5713 * lpfc_free_iocb_list - Free iocb list.
5714 * @phba: pointer to lpfc hba data structure.
5715 *
5716 * This routine is invoked to free the driver's IOCB list and memory.
5717 **/
5718static void
5719lpfc_free_iocb_list(struct lpfc_hba *phba)
5720{
5721 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
5722
5723 spin_lock_irq(&phba->hbalock);
5724 list_for_each_entry_safe(iocbq_entry, iocbq_next,
5725 &phba->lpfc_iocb_list, list) {
5726 list_del(&iocbq_entry->list);
5727 kfree(iocbq_entry);
5728 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005729 }
James Smart3772a992009-05-22 14:50:54 -04005730 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005731
James Smart3772a992009-05-22 14:50:54 -04005732 return;
5733}
dea31012005-04-17 16:05:31 -05005734
James Smart3772a992009-05-22 14:50:54 -04005735/**
5736 * lpfc_init_iocb_list - Allocate and initialize iocb list.
5737 * @phba: pointer to lpfc hba data structure.
5738 *
5739 * This routine is invoked to allocate and initizlize the driver's IOCB
5740 * list and set up the IOCB tag array accordingly.
5741 *
5742 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005743 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005744 * other values - error
5745 **/
5746static int
5747lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
5748{
5749 struct lpfc_iocbq *iocbq_entry = NULL;
5750 uint16_t iotag;
5751 int i;
dea31012005-04-17 16:05:31 -05005752
5753 /* Initialize and populate the iocb list per host. */
5754 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04005755 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07005756 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05005757 if (iocbq_entry == NULL) {
5758 printk(KERN_ERR "%s: only allocated %d iocbs of "
5759 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07005760 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05005761 goto out_free_iocbq;
5762 }
5763
James Bottomley604a3e32005-10-29 10:28:33 -05005764 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
5765 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04005766 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05005767 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04005768 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05005769 goto out_free_iocbq;
5770 }
James Smart6d368e52011-05-24 11:44:12 -04005771 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04005772 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05005773
5774 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005775 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
5776 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05005777 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005778 }
5779
James Smart3772a992009-05-22 14:50:54 -04005780 return 0;
5781
5782out_free_iocbq:
5783 lpfc_free_iocb_list(phba);
5784
5785 return -ENOMEM;
5786}
5787
5788/**
James Smart8a9d2e82012-05-09 21:16:12 -04005789 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04005790 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04005791 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04005792 *
James Smart8a9d2e82012-05-09 21:16:12 -04005793 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04005794 **/
James Smart8a9d2e82012-05-09 21:16:12 -04005795void
5796lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04005797{
5798 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04005799
5800 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
5801 list_del(&sglq_entry->list);
5802 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
5803 kfree(sglq_entry);
5804 }
5805}
5806
5807/**
5808 * lpfc_free_els_sgl_list - Free els sgl list.
5809 * @phba: pointer to lpfc hba data structure.
5810 *
5811 * This routine is invoked to free the driver's els sgl list and memory.
5812 **/
5813static void
5814lpfc_free_els_sgl_list(struct lpfc_hba *phba)
5815{
James Smartda0436e2009-05-22 14:51:39 -04005816 LIST_HEAD(sglq_list);
James Smartdafe8ce2014-09-03 12:56:40 -04005817 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smartda0436e2009-05-22 14:51:39 -04005818
James Smart8a9d2e82012-05-09 21:16:12 -04005819 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04005820 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04005821 spin_lock(&pring->ring_lock);
James Smartda0436e2009-05-22 14:51:39 -04005822 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
James Smartdafe8ce2014-09-03 12:56:40 -04005823 spin_unlock(&pring->ring_lock);
James Smartda0436e2009-05-22 14:51:39 -04005824 spin_unlock_irq(&phba->hbalock);
5825
James Smart8a9d2e82012-05-09 21:16:12 -04005826 /* Now free the sgl list */
5827 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04005828}
5829
5830/**
5831 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
5832 * @phba: pointer to lpfc hba data structure.
5833 *
5834 * This routine is invoked to allocate the driver's active sgl memory.
5835 * This array will hold the sglq_entry's for active IOs.
5836 **/
5837static int
5838lpfc_init_active_sgl_array(struct lpfc_hba *phba)
5839{
5840 int size;
5841 size = sizeof(struct lpfc_sglq *);
5842 size *= phba->sli4_hba.max_cfg_param.max_xri;
5843
5844 phba->sli4_hba.lpfc_sglq_active_list =
5845 kzalloc(size, GFP_KERNEL);
5846 if (!phba->sli4_hba.lpfc_sglq_active_list)
5847 return -ENOMEM;
5848 return 0;
5849}
5850
5851/**
5852 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
5853 * @phba: pointer to lpfc hba data structure.
5854 *
5855 * This routine is invoked to walk through the array of active sglq entries
5856 * and free all of the resources.
5857 * This is just a place holder for now.
5858 **/
5859static void
5860lpfc_free_active_sgl(struct lpfc_hba *phba)
5861{
5862 kfree(phba->sli4_hba.lpfc_sglq_active_list);
5863}
5864
5865/**
5866 * lpfc_init_sgl_list - Allocate and initialize sgl list.
5867 * @phba: pointer to lpfc hba data structure.
5868 *
5869 * This routine is invoked to allocate and initizlize the driver's sgl
5870 * list and set up the sgl xritag tag array accordingly.
5871 *
James Smartda0436e2009-05-22 14:51:39 -04005872 **/
James Smart8a9d2e82012-05-09 21:16:12 -04005873static void
James Smartda0436e2009-05-22 14:51:39 -04005874lpfc_init_sgl_list(struct lpfc_hba *phba)
5875{
James Smartda0436e2009-05-22 14:51:39 -04005876 /* Initialize and populate the sglq list per host/VF. */
5877 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
5878 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
5879
James Smart8a9d2e82012-05-09 21:16:12 -04005880 /* els xri-sgl book keeping */
5881 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04005882
James Smart8a9d2e82012-05-09 21:16:12 -04005883 /* scsi xri-buffer book keeping */
James Smartda0436e2009-05-22 14:51:39 -04005884 phba->sli4_hba.scsi_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04005885}
5886
5887/**
5888 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
5889 * @phba: pointer to lpfc hba data structure.
5890 *
5891 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04005892 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04005893 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04005894 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
5895 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04005896 *
5897 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005898 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04005899 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04005900 **/
5901int
5902lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
5903{
5904 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04005905 struct lpfc_rpi_hdr *rpi_hdr;
5906
5907 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05005908 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04005909 return rc;
James Smart6d368e52011-05-24 11:44:12 -04005910 if (phba->sli4_hba.extents_in_use)
5911 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04005912
5913 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
5914 if (!rpi_hdr) {
5915 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5916 "0391 Error during rpi post operation\n");
5917 lpfc_sli4_remove_rpis(phba);
5918 rc = -ENODEV;
5919 }
5920
5921 return rc;
5922}
5923
5924/**
5925 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
5926 * @phba: pointer to lpfc hba data structure.
5927 *
5928 * This routine is invoked to allocate a single 4KB memory region to
5929 * support rpis and stores them in the phba. This single region
5930 * provides support for up to 64 rpis. The region is used globally
5931 * by the device.
5932 *
5933 * Returns:
5934 * A valid rpi hdr on success.
5935 * A NULL pointer on any failure.
5936 **/
5937struct lpfc_rpi_hdr *
5938lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
5939{
5940 uint16_t rpi_limit, curr_rpi_range;
5941 struct lpfc_dmabuf *dmabuf;
5942 struct lpfc_rpi_hdr *rpi_hdr;
James Smart9589b0622011-04-16 11:03:17 -04005943 uint32_t rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04005944
James Smart6d368e52011-05-24 11:44:12 -04005945 /*
5946 * If the SLI4 port supports extents, posting the rpi header isn't
5947 * required. Set the expected maximum count and let the actual value
5948 * get set when extents are fully allocated.
5949 */
5950 if (!phba->sli4_hba.rpi_hdrs_in_use)
5951 return NULL;
5952 if (phba->sli4_hba.extents_in_use)
5953 return NULL;
5954
5955 /* The limit on the logical index is just the max_rpi count. */
James Smartda0436e2009-05-22 14:51:39 -04005956 rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
James Smart6d368e52011-05-24 11:44:12 -04005957 phba->sli4_hba.max_cfg_param.max_rpi - 1;
James Smartda0436e2009-05-22 14:51:39 -04005958
5959 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04005960 /*
5961 * Establish the starting RPI in this header block. The starting
5962 * rpi is normalized to a zero base because the physical rpi is
5963 * port based.
5964 */
James Smart97f2ecf2012-03-01 22:35:23 -05005965 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04005966 spin_unlock_irq(&phba->hbalock);
5967
5968 /*
5969 * The port has a limited number of rpis. The increment here
5970 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
5971 * and to allow the full max_rpi range per port.
5972 */
5973 if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
James Smart9589b0622011-04-16 11:03:17 -04005974 rpi_count = rpi_limit - curr_rpi_range;
5975 else
5976 rpi_count = LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04005977
James Smart6d368e52011-05-24 11:44:12 -04005978 if (!rpi_count)
5979 return NULL;
James Smartda0436e2009-05-22 14:51:39 -04005980 /*
5981 * First allocate the protocol header region for the port. The
5982 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
5983 */
5984 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5985 if (!dmabuf)
5986 return NULL;
5987
Joe Perches1aee3832014-09-03 12:56:12 -04005988 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
5989 LPFC_HDR_TEMPLATE_SIZE,
5990 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04005991 if (!dmabuf->virt) {
5992 rpi_hdr = NULL;
5993 goto err_free_dmabuf;
5994 }
5995
James Smartda0436e2009-05-22 14:51:39 -04005996 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
5997 rpi_hdr = NULL;
5998 goto err_free_coherent;
5999 }
6000
6001 /* Save the rpi header data for cleanup later. */
6002 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
6003 if (!rpi_hdr)
6004 goto err_free_coherent;
6005
6006 rpi_hdr->dmabuf = dmabuf;
6007 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
6008 rpi_hdr->page_count = 1;
6009 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006010
6011 /* The rpi_hdr stores the logical index only. */
6012 rpi_hdr->start_rpi = curr_rpi_range;
James Smartda0436e2009-05-22 14:51:39 -04006013 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
6014
6015 /*
James Smart6d368e52011-05-24 11:44:12 -04006016 * The next_rpi stores the next logical module-64 rpi value used
6017 * to post physical rpis in subsequent rpi postings.
James Smartda0436e2009-05-22 14:51:39 -04006018 */
James Smart9589b0622011-04-16 11:03:17 -04006019 phba->sli4_hba.next_rpi += rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04006020 spin_unlock_irq(&phba->hbalock);
6021 return rpi_hdr;
6022
6023 err_free_coherent:
6024 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
6025 dmabuf->virt, dmabuf->phys);
6026 err_free_dmabuf:
6027 kfree(dmabuf);
6028 return NULL;
6029}
6030
6031/**
6032 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
6033 * @phba: pointer to lpfc hba data structure.
6034 *
6035 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04006036 * to support rpis for SLI4 ports not supporting extents. This routine
6037 * presumes the caller has released all rpis consumed by fabric or port
6038 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04006039 **/
6040void
6041lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
6042{
6043 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
6044
James Smart6d368e52011-05-24 11:44:12 -04006045 if (!phba->sli4_hba.rpi_hdrs_in_use)
6046 goto exit;
6047
James Smartda0436e2009-05-22 14:51:39 -04006048 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
6049 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
6050 list_del(&rpi_hdr->list);
6051 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
6052 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
6053 kfree(rpi_hdr->dmabuf);
6054 kfree(rpi_hdr);
6055 }
James Smart6d368e52011-05-24 11:44:12 -04006056 exit:
6057 /* There are no rpis available to the port now. */
6058 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04006059}
6060
6061/**
James Smart3772a992009-05-22 14:50:54 -04006062 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
6063 * @pdev: pointer to pci device data structure.
6064 *
6065 * This routine is invoked to allocate the driver hba data structure for an
6066 * HBA device. If the allocation is successful, the phba reference to the
6067 * PCI device data structure is set.
6068 *
6069 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006070 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04006071 * NULL - error
6072 **/
6073static struct lpfc_hba *
6074lpfc_hba_alloc(struct pci_dev *pdev)
6075{
6076 struct lpfc_hba *phba;
6077
6078 /* Allocate memory for HBA structure */
6079 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
6080 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02006081 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04006082 return NULL;
6083 }
6084
6085 /* Set reference to PCI device in HBA structure */
6086 phba->pcidev = pdev;
6087
6088 /* Assign an unused board number */
6089 phba->brd_no = lpfc_get_instance();
6090 if (phba->brd_no < 0) {
6091 kfree(phba);
6092 return NULL;
6093 }
6094
James Smart4fede782010-01-26 23:08:55 -05006095 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04006096 INIT_LIST_HEAD(&phba->ct_ev_waiters);
6097
James Smart3772a992009-05-22 14:50:54 -04006098 return phba;
6099}
6100
6101/**
6102 * lpfc_hba_free - Free driver hba data structure with a device.
6103 * @phba: pointer to lpfc hba data structure.
6104 *
6105 * This routine is invoked to free the driver hba data structure with an
6106 * HBA device.
6107 **/
6108static void
6109lpfc_hba_free(struct lpfc_hba *phba)
6110{
6111 /* Release the driver assigned board number */
6112 idr_remove(&lpfc_hba_index, phba->brd_no);
6113
James Smart2a76a282012-08-03 12:35:54 -04006114 /* Free memory allocated with sli rings */
6115 kfree(phba->sli.ring);
6116 phba->sli.ring = NULL;
6117
James Smart3772a992009-05-22 14:50:54 -04006118 kfree(phba);
6119 return;
6120}
6121
6122/**
6123 * lpfc_create_shost - Create hba physical port with associated scsi host.
6124 * @phba: pointer to lpfc hba data structure.
6125 *
6126 * This routine is invoked to create HBA physical port and associate a SCSI
6127 * host with it.
6128 *
6129 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006130 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006131 * other values - error
6132 **/
6133static int
6134lpfc_create_shost(struct lpfc_hba *phba)
6135{
6136 struct lpfc_vport *vport;
6137 struct Scsi_Host *shost;
6138
6139 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05006140 phba->fc_edtov = FF_DEF_EDTOV;
6141 phba->fc_ratov = FF_DEF_RATOV;
6142 phba->fc_altov = FF_DEF_ALTOV;
6143 phba->fc_arbtov = FF_DEF_ARBTOV;
6144
James Smartd7c47992010-06-08 18:31:54 -04006145 atomic_set(&phba->sdev_cnt, 0);
James Smart3de2a652007-08-02 11:09:59 -04006146 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05006147 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04006148 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05006149
6150 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05006151 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05006152 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04006153 /* Put reference to SCSI host to driver's device private data */
6154 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05006155
James Smart4258e982015-12-16 18:11:58 -05006156 /*
6157 * At this point we are fully registered with PSA. In addition,
6158 * any initial discovery should be completed.
6159 */
6160 vport->load_flag |= FC_ALLOW_FDMI;
James Smart8663cbb2016-03-31 14:12:33 -07006161 if (phba->cfg_enable_SmartSAN ||
6162 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -05006163
6164 /* Setup appropriate attribute masks */
6165 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -07006166 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -05006167 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
6168 else
6169 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
6170 }
James Smart3772a992009-05-22 14:50:54 -04006171 return 0;
6172}
dea31012005-04-17 16:05:31 -05006173
James Smart3772a992009-05-22 14:50:54 -04006174/**
6175 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
6176 * @phba: pointer to lpfc hba data structure.
6177 *
6178 * This routine is invoked to destroy HBA physical port and the associated
6179 * SCSI host.
6180 **/
6181static void
6182lpfc_destroy_shost(struct lpfc_hba *phba)
6183{
6184 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04006185
James Smart3772a992009-05-22 14:50:54 -04006186 /* Destroy physical port that associated with the SCSI host */
6187 destroy_port(vport);
6188
6189 return;
6190}
6191
6192/**
6193 * lpfc_setup_bg - Setup Block guard structures and debug areas.
6194 * @phba: pointer to lpfc hba data structure.
6195 * @shost: the shost to be used to detect Block guard settings.
6196 *
6197 * This routine sets up the local Block guard protocol settings for @shost.
6198 * This routine also allocates memory for debugging bg buffers.
6199 **/
6200static void
6201lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
6202{
James Smartbbeb79b2012-06-12 13:54:27 -04006203 uint32_t old_mask;
6204 uint32_t old_guard;
6205
James Smart3772a992009-05-22 14:50:54 -04006206 int pagecnt = 10;
6207 if (lpfc_prot_mask && lpfc_prot_guard) {
6208 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6209 "1478 Registering BlockGuard with the "
6210 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04006211
6212 old_mask = lpfc_prot_mask;
6213 old_guard = lpfc_prot_guard;
6214
6215 /* Only allow supported values */
6216 lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
6217 SHOST_DIX_TYPE0_PROTECTION |
6218 SHOST_DIX_TYPE1_PROTECTION);
6219 lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC);
6220
6221 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
6222 if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
6223 lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
6224
6225 if (lpfc_prot_mask && lpfc_prot_guard) {
6226 if ((old_mask != lpfc_prot_mask) ||
6227 (old_guard != lpfc_prot_guard))
6228 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6229 "1475 Registering BlockGuard with the "
6230 "SCSI layer: mask %d guard %d\n",
6231 lpfc_prot_mask, lpfc_prot_guard);
6232
6233 scsi_host_set_prot(shost, lpfc_prot_mask);
6234 scsi_host_set_guard(shost, lpfc_prot_guard);
6235 } else
6236 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6237 "1479 Not Registering BlockGuard with the SCSI "
6238 "layer, Bad protection parameters: %d %d\n",
6239 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04006240 }
James Smartbbeb79b2012-06-12 13:54:27 -04006241
James Smart81301a92008-12-04 22:39:46 -05006242 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05006243 while (pagecnt) {
6244 spin_lock_init(&_dump_buf_lock);
6245 _dump_buf_data =
6246 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6247 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04006248 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6249 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04006250 "_dump_buf_data at 0x%p\n",
6251 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05006252 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04006253 memset(_dump_buf_data, 0,
6254 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05006255 break;
James Smart3772a992009-05-22 14:50:54 -04006256 } else
James Smart81301a92008-12-04 22:39:46 -05006257 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05006258 }
James Smart81301a92008-12-04 22:39:46 -05006259 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04006260 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6261 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04006262 "memory for hexdump\n");
6263 } else
James Smart6a9c52c2009-10-02 15:16:51 -04006264 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6265 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05006266 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05006267 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05006268 while (pagecnt) {
6269 _dump_buf_dif =
6270 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6271 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04006272 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6273 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04006274 "_dump_buf_dif at 0x%p\n",
6275 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05006276 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04006277 memset(_dump_buf_dif, 0,
6278 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05006279 break;
James Smart3772a992009-05-22 14:50:54 -04006280 } else
James Smart81301a92008-12-04 22:39:46 -05006281 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05006282 }
James Smart81301a92008-12-04 22:39:46 -05006283 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04006284 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6285 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04006286 "memory for hexdump\n");
6287 } else
James Smart6a9c52c2009-10-02 15:16:51 -04006288 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6289 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04006290 _dump_buf_dif);
6291}
6292
6293/**
6294 * lpfc_post_init_setup - Perform necessary device post initialization setup.
6295 * @phba: pointer to lpfc hba data structure.
6296 *
6297 * This routine is invoked to perform all the necessary post initialization
6298 * setup for the device.
6299 **/
6300static void
6301lpfc_post_init_setup(struct lpfc_hba *phba)
6302{
6303 struct Scsi_Host *shost;
6304 struct lpfc_adapter_event_header adapter_event;
6305
6306 /* Get the default values for Model Name and Description */
6307 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
6308
6309 /*
6310 * hba setup may have changed the hba_queue_depth so we need to
6311 * adjust the value of can_queue.
6312 */
6313 shost = pci_get_drvdata(phba->pcidev);
6314 shost->can_queue = phba->cfg_hba_queue_depth - 10;
6315 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
6316 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05006317
6318 lpfc_host_attrib_init(shost);
6319
James Smart2e0fef82007-06-17 19:56:36 -05006320 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
6321 spin_lock_irq(shost->host_lock);
6322 lpfc_poll_start_timer(phba);
6323 spin_unlock_irq(shost->host_lock);
6324 }
James Smart8f6d98d2006-08-01 07:34:00 -04006325
James Smart93996272008-08-24 21:50:30 -04006326 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6327 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04006328 /* Send board arrival event to upper layer */
6329 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
6330 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
6331 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04006332 sizeof(adapter_event),
6333 (char *) &adapter_event,
6334 LPFC_NL_VENDOR_ID);
6335 return;
6336}
6337
6338/**
6339 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
6340 * @phba: pointer to lpfc hba data structure.
6341 *
6342 * This routine is invoked to set up the PCI device memory space for device
6343 * with SLI-3 interface spec.
6344 *
6345 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006346 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006347 * other values - error
6348 **/
6349static int
6350lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
6351{
6352 struct pci_dev *pdev;
6353 unsigned long bar0map_len, bar2map_len;
6354 int i, hbq_count;
6355 void *ptr;
6356 int error = -ENODEV;
6357
6358 /* Obtain PCI device reference */
6359 if (!phba->pcidev)
6360 return error;
6361 else
6362 pdev = phba->pcidev;
6363
6364 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05006365 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
6366 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
6367 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
6368 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smart3772a992009-05-22 14:50:54 -04006369 return error;
Michael Reed8e685972009-09-18 12:02:05 -05006370 }
6371 }
James Smart3772a992009-05-22 14:50:54 -04006372
6373 /* Get the bus address of Bar0 and Bar2 and the number of bytes
6374 * required by each mapping.
6375 */
6376 phba->pci_bar0_map = pci_resource_start(pdev, 0);
6377 bar0map_len = pci_resource_len(pdev, 0);
6378
6379 phba->pci_bar2_map = pci_resource_start(pdev, 2);
6380 bar2map_len = pci_resource_len(pdev, 2);
6381
6382 /* Map HBA SLIM to a kernel virtual address. */
6383 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
6384 if (!phba->slim_memmap_p) {
6385 dev_printk(KERN_ERR, &pdev->dev,
6386 "ioremap failed for SLIM memory.\n");
6387 goto out;
6388 }
6389
6390 /* Map HBA Control Registers to a kernel virtual address. */
6391 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
6392 if (!phba->ctrl_regs_memmap_p) {
6393 dev_printk(KERN_ERR, &pdev->dev,
6394 "ioremap failed for HBA control registers.\n");
6395 goto out_iounmap_slim;
6396 }
6397
6398 /* Allocate memory for SLI-2 structures */
Joe Perches1aee3832014-09-03 12:56:12 -04006399 phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6400 &phba->slim2p.phys, GFP_KERNEL);
James Smart3772a992009-05-22 14:50:54 -04006401 if (!phba->slim2p.virt)
6402 goto out_iounmap;
6403
James Smart3772a992009-05-22 14:50:54 -04006404 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04006405 phba->mbox_ext = (phba->slim2p.virt +
6406 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04006407 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
6408 phba->IOCBs = (phba->slim2p.virt +
6409 offsetof(struct lpfc_sli2_slim, IOCBs));
6410
6411 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
6412 lpfc_sli_hbq_size(),
6413 &phba->hbqslimp.phys,
6414 GFP_KERNEL);
6415 if (!phba->hbqslimp.virt)
6416 goto out_free_slim;
6417
6418 hbq_count = lpfc_sli_hbq_count();
6419 ptr = phba->hbqslimp.virt;
6420 for (i = 0; i < hbq_count; ++i) {
6421 phba->hbqs[i].hbq_virt = ptr;
6422 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
6423 ptr += (lpfc_hbq_defs[i]->entry_count *
6424 sizeof(struct lpfc_hbq_entry));
6425 }
6426 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
6427 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
6428
6429 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
6430
6431 INIT_LIST_HEAD(&phba->rb_pend_list);
6432
6433 phba->MBslimaddr = phba->slim_memmap_p;
6434 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
6435 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
6436 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
6437 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04006438
dea31012005-04-17 16:05:31 -05006439 return 0;
6440
dea31012005-04-17 16:05:31 -05006441out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04006442 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6443 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05006444out_iounmap:
6445 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006446out_iounmap_slim:
dea31012005-04-17 16:05:31 -05006447 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05006448out:
6449 return error;
6450}
6451
James Smarte59058c2008-08-24 21:49:00 -04006452/**
James Smart3772a992009-05-22 14:50:54 -04006453 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
6454 * @phba: pointer to lpfc hba data structure.
6455 *
6456 * This routine is invoked to unset the PCI device memory space for device
6457 * with SLI-3 interface spec.
6458 **/
6459static void
6460lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
6461{
6462 struct pci_dev *pdev;
6463
6464 /* Obtain PCI device reference */
6465 if (!phba->pcidev)
6466 return;
6467 else
6468 pdev = phba->pcidev;
6469
6470 /* Free coherent DMA memory allocated */
6471 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
6472 phba->hbqslimp.virt, phba->hbqslimp.phys);
6473 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6474 phba->slim2p.virt, phba->slim2p.phys);
6475
6476 /* I/O memory unmap */
6477 iounmap(phba->ctrl_regs_memmap_p);
6478 iounmap(phba->slim_memmap_p);
6479
6480 return;
6481}
6482
6483/**
James Smartda0436e2009-05-22 14:51:39 -04006484 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
6485 * @phba: pointer to lpfc hba data structure.
6486 *
6487 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
6488 * done and check status.
6489 *
6490 * Return 0 if successful, otherwise -ENODEV.
6491 **/
6492int
6493lpfc_sli4_post_status_check(struct lpfc_hba *phba)
6494{
James Smart2fcee4b2010-12-15 17:57:46 -05006495 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
6496 struct lpfc_register reg_data;
6497 int i, port_error = 0;
6498 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04006499
James Smart9940b972011-03-11 16:06:12 -05006500 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
6501 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05006502 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04006503 return -ENODEV;
6504
James Smartda0436e2009-05-22 14:51:39 -04006505 /* Wait up to 30 seconds for the SLI Port POST done and ready */
6506 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05006507 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
6508 &portsmphr_reg.word0) ||
6509 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006510 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04006511 port_error = -ENODEV;
6512 break;
6513 }
James Smart2fcee4b2010-12-15 17:57:46 -05006514 if (LPFC_POST_STAGE_PORT_READY ==
6515 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04006516 break;
James Smartda0436e2009-05-22 14:51:39 -04006517 msleep(10);
6518 }
6519
James Smart2fcee4b2010-12-15 17:57:46 -05006520 /*
6521 * If there was a port error during POST, then don't proceed with
6522 * other register reads as the data may not be valid. Just exit.
6523 */
6524 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04006525 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006526 "1408 Port Failed POST - portsmphr=0x%x, "
6527 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
6528 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
6529 portsmphr_reg.word0,
6530 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
6531 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
6532 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
6533 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
6534 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
6535 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
6536 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
6537 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
6538 } else {
James Smart28baac72010-02-12 14:42:03 -05006539 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006540 "2534 Device Info: SLIFamily=0x%x, "
6541 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
6542 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05006543 bf_get(lpfc_sli_intf_sli_family,
6544 &phba->sli4_hba.sli_intf),
6545 bf_get(lpfc_sli_intf_slirev,
6546 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006547 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05006548 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006549 bf_get(lpfc_sli_intf_sli_hint1,
6550 &phba->sli4_hba.sli_intf),
6551 bf_get(lpfc_sli_intf_sli_hint2,
6552 &phba->sli4_hba.sli_intf),
6553 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05006554 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05006555 /*
6556 * Check for other Port errors during the initialization
6557 * process. Fail the load if the port did not come up
6558 * correctly.
6559 */
6560 if_type = bf_get(lpfc_sli_intf_if_type,
6561 &phba->sli4_hba.sli_intf);
6562 switch (if_type) {
6563 case LPFC_SLI_INTF_IF_TYPE_0:
6564 phba->sli4_hba.ue_mask_lo =
6565 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
6566 phba->sli4_hba.ue_mask_hi =
6567 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
6568 uerrlo_reg.word0 =
6569 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
6570 uerrhi_reg.word0 =
6571 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
6572 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
6573 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
6574 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6575 "1422 Unrecoverable Error "
6576 "Detected during POST "
6577 "uerr_lo_reg=0x%x, "
6578 "uerr_hi_reg=0x%x, "
6579 "ue_mask_lo_reg=0x%x, "
6580 "ue_mask_hi_reg=0x%x\n",
6581 uerrlo_reg.word0,
6582 uerrhi_reg.word0,
6583 phba->sli4_hba.ue_mask_lo,
6584 phba->sli4_hba.ue_mask_hi);
6585 port_error = -ENODEV;
6586 }
6587 break;
6588 case LPFC_SLI_INTF_IF_TYPE_2:
6589 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05006590 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
6591 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04006592 (bf_get(lpfc_sliport_status_err, &reg_data) &&
6593 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006594 phba->work_status[0] =
6595 readl(phba->sli4_hba.u.if_type2.
6596 ERR1regaddr);
6597 phba->work_status[1] =
6598 readl(phba->sli4_hba.u.if_type2.
6599 ERR2regaddr);
6600 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05006601 "2888 Unrecoverable port error "
6602 "following POST: port status reg "
6603 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05006604 "error 1=0x%x, error 2=0x%x\n",
6605 reg_data.word0,
6606 portsmphr_reg.word0,
6607 phba->work_status[0],
6608 phba->work_status[1]);
6609 port_error = -ENODEV;
6610 }
6611 break;
6612 case LPFC_SLI_INTF_IF_TYPE_1:
6613 default:
6614 break;
6615 }
James Smart28baac72010-02-12 14:42:03 -05006616 }
James Smartda0436e2009-05-22 14:51:39 -04006617 return port_error;
6618}
6619
6620/**
6621 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
6622 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05006623 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04006624 *
6625 * This routine is invoked to set up SLI4 BAR0 PCI config space register
6626 * memory map.
6627 **/
6628static void
James Smart2fcee4b2010-12-15 17:57:46 -05006629lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04006630{
James Smart2fcee4b2010-12-15 17:57:46 -05006631 switch (if_type) {
6632 case LPFC_SLI_INTF_IF_TYPE_0:
6633 phba->sli4_hba.u.if_type0.UERRLOregaddr =
6634 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
6635 phba->sli4_hba.u.if_type0.UERRHIregaddr =
6636 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
6637 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
6638 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
6639 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
6640 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
6641 phba->sli4_hba.SLIINTFregaddr =
6642 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6643 break;
6644 case LPFC_SLI_INTF_IF_TYPE_2:
6645 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006646 phba->sli4_hba.conf_regs_memmap_p +
6647 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006648 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006649 phba->sli4_hba.conf_regs_memmap_p +
6650 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006651 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006652 phba->sli4_hba.conf_regs_memmap_p +
6653 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006654 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006655 phba->sli4_hba.conf_regs_memmap_p +
6656 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006657 phba->sli4_hba.SLIINTFregaddr =
6658 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6659 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006660 phba->sli4_hba.conf_regs_memmap_p +
6661 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006662 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006663 phba->sli4_hba.conf_regs_memmap_p +
6664 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006665 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006666 phba->sli4_hba.conf_regs_memmap_p +
6667 LPFC_ULP0_WQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006668 phba->sli4_hba.EQCQDBregaddr =
6669 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
6670 phba->sli4_hba.MQDBregaddr =
6671 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
6672 phba->sli4_hba.BMBXregaddr =
6673 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
6674 break;
6675 case LPFC_SLI_INTF_IF_TYPE_1:
6676 default:
6677 dev_printk(KERN_ERR, &phba->pcidev->dev,
6678 "FATAL - unsupported SLI4 interface type - %d\n",
6679 if_type);
6680 break;
6681 }
James Smartda0436e2009-05-22 14:51:39 -04006682}
6683
6684/**
6685 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
6686 * @phba: pointer to lpfc hba data structure.
6687 *
6688 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
6689 * memory map.
6690 **/
6691static void
6692lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
6693{
James Smart2fcee4b2010-12-15 17:57:46 -05006694 phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
6695 LPFC_SLIPORT_IF0_SMPHR;
James Smartda0436e2009-05-22 14:51:39 -04006696 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006697 LPFC_HST_ISR0;
James Smartda0436e2009-05-22 14:51:39 -04006698 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006699 LPFC_HST_IMR0;
James Smartda0436e2009-05-22 14:51:39 -04006700 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006701 LPFC_HST_ISCR0;
James Smartda0436e2009-05-22 14:51:39 -04006702}
6703
6704/**
6705 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
6706 * @phba: pointer to lpfc hba data structure.
6707 * @vf: virtual function number
6708 *
6709 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
6710 * based on the given viftual function number, @vf.
6711 *
6712 * Return 0 if successful, otherwise -ENODEV.
6713 **/
6714static int
6715lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
6716{
6717 if (vf > LPFC_VIR_FUNC_MAX)
6718 return -ENODEV;
6719
6720 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05006721 vf * LPFC_VFR_PAGE_SIZE +
6722 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04006723 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05006724 vf * LPFC_VFR_PAGE_SIZE +
6725 LPFC_ULP0_WQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04006726 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6727 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
6728 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6729 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
6730 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6731 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
6732 return 0;
6733}
6734
6735/**
6736 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
6737 * @phba: pointer to lpfc hba data structure.
6738 *
6739 * This routine is invoked to create the bootstrap mailbox
6740 * region consistent with the SLI-4 interface spec. This
6741 * routine allocates all memory necessary to communicate
6742 * mailbox commands to the port and sets up all alignment
6743 * needs. No locks are expected to be held when calling
6744 * this routine.
6745 *
6746 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006747 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04006748 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04006749 **/
6750static int
6751lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
6752{
6753 uint32_t bmbx_size;
6754 struct lpfc_dmabuf *dmabuf;
6755 struct dma_address *dma_address;
6756 uint32_t pa_addr;
6757 uint64_t phys_addr;
6758
6759 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6760 if (!dmabuf)
6761 return -ENOMEM;
6762
6763 /*
6764 * The bootstrap mailbox region is comprised of 2 parts
6765 * plus an alignment restriction of 16 bytes.
6766 */
6767 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
Joe Perches1aee3832014-09-03 12:56:12 -04006768 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
6769 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04006770 if (!dmabuf->virt) {
6771 kfree(dmabuf);
6772 return -ENOMEM;
6773 }
James Smartda0436e2009-05-22 14:51:39 -04006774
6775 /*
6776 * Initialize the bootstrap mailbox pointers now so that the register
6777 * operations are simple later. The mailbox dma address is required
6778 * to be 16-byte aligned. Also align the virtual memory as each
6779 * maibox is copied into the bmbx mailbox region before issuing the
6780 * command to the port.
6781 */
6782 phba->sli4_hba.bmbx.dmabuf = dmabuf;
6783 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
6784
6785 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
6786 LPFC_ALIGN_16_BYTE);
6787 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
6788 LPFC_ALIGN_16_BYTE);
6789
6790 /*
6791 * Set the high and low physical addresses now. The SLI4 alignment
6792 * requirement is 16 bytes and the mailbox is posted to the port
6793 * as two 30-bit addresses. The other data is a bit marking whether
6794 * the 30-bit address is the high or low address.
6795 * Upcast bmbx aphys to 64bits so shift instruction compiles
6796 * clean on 32 bit machines.
6797 */
6798 dma_address = &phba->sli4_hba.bmbx.dma_address;
6799 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
6800 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
6801 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
6802 LPFC_BMBX_BIT1_ADDR_HI);
6803
6804 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
6805 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
6806 LPFC_BMBX_BIT1_ADDR_LO);
6807 return 0;
6808}
6809
6810/**
6811 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
6812 * @phba: pointer to lpfc hba data structure.
6813 *
6814 * This routine is invoked to teardown the bootstrap mailbox
6815 * region and release all host resources. This routine requires
6816 * the caller to ensure all mailbox commands recovered, no
6817 * additional mailbox comands are sent, and interrupts are disabled
6818 * before calling this routine.
6819 *
6820 **/
6821static void
6822lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
6823{
6824 dma_free_coherent(&phba->pcidev->dev,
6825 phba->sli4_hba.bmbx.bmbx_size,
6826 phba->sli4_hba.bmbx.dmabuf->virt,
6827 phba->sli4_hba.bmbx.dmabuf->phys);
6828
6829 kfree(phba->sli4_hba.bmbx.dmabuf);
6830 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
6831}
6832
6833/**
6834 * lpfc_sli4_read_config - Get the config parameters.
6835 * @phba: pointer to lpfc hba data structure.
6836 *
6837 * This routine is invoked to read the configuration parameters from the HBA.
6838 * The configuration parameters are used to set the base and maximum values
6839 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
6840 * allocation for the port.
6841 *
6842 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006843 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006844 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006845 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006846 **/
James Smartff78d8f2011-12-13 13:21:35 -05006847int
James Smartda0436e2009-05-22 14:51:39 -04006848lpfc_sli4_read_config(struct lpfc_hba *phba)
6849{
6850 LPFC_MBOXQ_t *pmb;
6851 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04006852 union lpfc_sli4_cfg_shdr *shdr;
6853 uint32_t shdr_status, shdr_add_status;
6854 struct lpfc_mbx_get_func_cfg *get_func_cfg;
6855 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04006856 char *pdesc_0;
James Smart8aa134a2012-08-14 14:25:29 -04006857 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04006858
6859 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6860 if (!pmb) {
6861 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6862 "2011 Unable to allocate memory for issuing "
6863 "SLI_CONFIG_SPECIAL mailbox command\n");
6864 return -ENOMEM;
6865 }
6866
6867 lpfc_read_config(phba, pmb);
6868
6869 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
6870 if (rc != MBX_SUCCESS) {
6871 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6872 "2012 Mailbox failed , mbxCmd x%x "
6873 "READ_CONFIG, mbxStatus x%x\n",
6874 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6875 bf_get(lpfc_mqe_status, &pmb->u.mqe));
6876 rc = -EIO;
6877 } else {
6878 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05006879 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
6880 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
6881 phba->sli4_hba.lnk_info.lnk_tp =
6882 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
6883 phba->sli4_hba.lnk_info.lnk_no =
6884 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
6885 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6886 "3081 lnk_type:%d, lnk_numb:%d\n",
6887 phba->sli4_hba.lnk_info.lnk_tp,
6888 phba->sli4_hba.lnk_info.lnk_no);
6889 } else
6890 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6891 "3082 Mailbox (x%x) returned ldv:x0\n",
6892 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart6d368e52011-05-24 11:44:12 -04006893 phba->sli4_hba.extents_in_use =
6894 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04006895 phba->sli4_hba.max_cfg_param.max_xri =
6896 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
6897 phba->sli4_hba.max_cfg_param.xri_base =
6898 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
6899 phba->sli4_hba.max_cfg_param.max_vpi =
6900 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
6901 phba->sli4_hba.max_cfg_param.vpi_base =
6902 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
6903 phba->sli4_hba.max_cfg_param.max_rpi =
6904 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
6905 phba->sli4_hba.max_cfg_param.rpi_base =
6906 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
6907 phba->sli4_hba.max_cfg_param.max_vfi =
6908 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
6909 phba->sli4_hba.max_cfg_param.vfi_base =
6910 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
6911 phba->sli4_hba.max_cfg_param.max_fcfi =
6912 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04006913 phba->sli4_hba.max_cfg_param.max_eq =
6914 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
6915 phba->sli4_hba.max_cfg_param.max_rq =
6916 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
6917 phba->sli4_hba.max_cfg_param.max_wq =
6918 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
6919 phba->sli4_hba.max_cfg_param.max_cq =
6920 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
6921 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
6922 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
6923 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
6924 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05006925 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
6926 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04006927 phba->max_vports = phba->max_vpi;
6928 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04006929 "2003 cfg params Extents? %d "
6930 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04006931 "VPI(B:%d M:%d) "
6932 "VFI(B:%d M:%d) "
6933 "RPI(B:%d M:%d) "
James Smart6d368e52011-05-24 11:44:12 -04006934 "FCFI(Count:%d)\n",
6935 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04006936 phba->sli4_hba.max_cfg_param.xri_base,
6937 phba->sli4_hba.max_cfg_param.max_xri,
6938 phba->sli4_hba.max_cfg_param.vpi_base,
6939 phba->sli4_hba.max_cfg_param.max_vpi,
6940 phba->sli4_hba.max_cfg_param.vfi_base,
6941 phba->sli4_hba.max_cfg_param.max_vfi,
6942 phba->sli4_hba.max_cfg_param.rpi_base,
6943 phba->sli4_hba.max_cfg_param.max_rpi,
James Smartda0436e2009-05-22 14:51:39 -04006944 phba->sli4_hba.max_cfg_param.max_fcfi);
6945 }
James Smart912e3ac2011-05-24 11:42:11 -04006946
6947 if (rc)
6948 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04006949
6950 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -04006951 length = phba->sli4_hba.max_cfg_param.max_xri -
6952 lpfc_sli4_get_els_iocb_cnt(phba);
6953 if (phba->cfg_hba_queue_depth > length) {
6954 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6955 "3361 HBA queue depth changed from %d to %d\n",
6956 phba->cfg_hba_queue_depth, length);
6957 phba->cfg_hba_queue_depth = length;
6958 }
James Smart912e3ac2011-05-24 11:42:11 -04006959
6960 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
6961 LPFC_SLI_INTF_IF_TYPE_2)
6962 goto read_cfg_out;
6963
6964 /* get the pf# and vf# for SLI4 if_type 2 port */
6965 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
6966 sizeof(struct lpfc_sli4_cfg_mhdr));
6967 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
6968 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
6969 length, LPFC_SLI4_MBX_EMBED);
6970
James Smart8aa134a2012-08-14 14:25:29 -04006971 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04006972 shdr = (union lpfc_sli4_cfg_shdr *)
6973 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
6974 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6975 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04006976 if (rc2 || shdr_status || shdr_add_status) {
James Smart912e3ac2011-05-24 11:42:11 -04006977 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6978 "3026 Mailbox failed , mbxCmd x%x "
6979 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
6980 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6981 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04006982 goto read_cfg_out;
6983 }
6984
6985 /* search for fc_fcoe resrouce descriptor */
6986 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
James Smart912e3ac2011-05-24 11:42:11 -04006987
James Smart8aa134a2012-08-14 14:25:29 -04006988 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
6989 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
6990 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
6991 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
6992 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
6993 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
6994 goto read_cfg_out;
6995
James Smart912e3ac2011-05-24 11:42:11 -04006996 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04006997 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04006998 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04006999 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04007000 phba->sli4_hba.iov.pf_number =
7001 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
7002 phba->sli4_hba.iov.vf_number =
7003 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
7004 break;
7005 }
7006 }
7007
7008 if (i < LPFC_RSRC_DESC_MAX_NUM)
7009 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7010 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
7011 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
7012 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04007013 else
James Smart912e3ac2011-05-24 11:42:11 -04007014 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7015 "3028 GET_FUNCTION_CONFIG: failed to find "
7016 "Resrouce Descriptor:x%x\n",
7017 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04007018
7019read_cfg_out:
7020 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04007021 return rc;
7022}
7023
7024/**
James Smart2fcee4b2010-12-15 17:57:46 -05007025 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04007026 * @phba: pointer to lpfc hba data structure.
7027 *
James Smart2fcee4b2010-12-15 17:57:46 -05007028 * This routine is invoked to setup the port-side endian order when
7029 * the port if_type is 0. This routine has no function for other
7030 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04007031 *
7032 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007033 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007034 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007035 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007036 **/
7037static int
7038lpfc_setup_endian_order(struct lpfc_hba *phba)
7039{
7040 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05007041 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04007042 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
7043 HOST_ENDIAN_HIGH_WORD1};
7044
James Smart2fcee4b2010-12-15 17:57:46 -05007045 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7046 switch (if_type) {
7047 case LPFC_SLI_INTF_IF_TYPE_0:
7048 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7049 GFP_KERNEL);
7050 if (!mboxq) {
7051 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7052 "0492 Unable to allocate memory for "
7053 "issuing SLI_CONFIG_SPECIAL mailbox "
7054 "command\n");
7055 return -ENOMEM;
7056 }
James Smartda0436e2009-05-22 14:51:39 -04007057
James Smart2fcee4b2010-12-15 17:57:46 -05007058 /*
7059 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
7060 * two words to contain special data values and no other data.
7061 */
7062 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
7063 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
7064 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7065 if (rc != MBX_SUCCESS) {
7066 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7067 "0493 SLI_CONFIG_SPECIAL mailbox "
7068 "failed with status x%x\n",
7069 rc);
7070 rc = -EIO;
7071 }
7072 mempool_free(mboxq, phba->mbox_mem_pool);
7073 break;
7074 case LPFC_SLI_INTF_IF_TYPE_2:
7075 case LPFC_SLI_INTF_IF_TYPE_1:
7076 default:
7077 break;
James Smartda0436e2009-05-22 14:51:39 -04007078 }
James Smartda0436e2009-05-22 14:51:39 -04007079 return rc;
7080}
7081
7082/**
James Smart5350d872011-10-10 21:33:49 -04007083 * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts
James Smartda0436e2009-05-22 14:51:39 -04007084 * @phba: pointer to lpfc hba data structure.
7085 *
James Smart5350d872011-10-10 21:33:49 -04007086 * This routine is invoked to check the user settable queue counts for EQs and
7087 * CQs. after this routine is called the counts will be set to valid values that
7088 * adhere to the constraints of the system's interrupt vectors and the port's
7089 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04007090 *
7091 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007092 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007093 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007094 **/
7095static int
James Smart5350d872011-10-10 21:33:49 -04007096lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04007097{
James Smart67d12732012-08-03 12:36:13 -04007098 int cfg_fcp_io_channel;
James Smart90695ee2012-08-14 14:25:36 -04007099 uint32_t cpu;
7100 uint32_t i = 0;
James Smart1ba981f2014-02-20 09:56:45 -05007101 int fof_vectors = phba->cfg_fof ? 1 : 0;
James Smartda0436e2009-05-22 14:51:39 -04007102
7103 /*
James Smart67d12732012-08-03 12:36:13 -04007104 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04007105 * device parameters
7106 */
7107
James Smart67d12732012-08-03 12:36:13 -04007108 /* Sanity check on HBA EQ parameters */
7109 cfg_fcp_io_channel = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04007110
James Smart7bb03bb2013-04-17 20:19:16 -04007111 /* It doesn't make sense to have more io channels then online CPUs */
7112 for_each_present_cpu(cpu) {
7113 if (cpu_online(cpu))
7114 i++;
James Smart90695ee2012-08-14 14:25:36 -04007115 }
James Smart7bb03bb2013-04-17 20:19:16 -04007116 phba->sli4_hba.num_online_cpu = i;
James Smartb246de12013-05-31 17:03:07 -04007117 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
James Smart76fd07a2014-02-20 09:57:18 -05007118 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04007119
James Smart90695ee2012-08-14 14:25:36 -04007120 if (i < cfg_fcp_io_channel) {
James Smart82c3e9b2012-09-29 11:29:50 -04007121 lpfc_printf_log(phba,
7122 KERN_ERR, LOG_INIT,
James Smart90695ee2012-08-14 14:25:36 -04007123 "3188 Reducing IO channels to match number of "
James Smart7bb03bb2013-04-17 20:19:16 -04007124 "online CPUs: from %d to %d\n",
7125 cfg_fcp_io_channel, i);
James Smart90695ee2012-08-14 14:25:36 -04007126 cfg_fcp_io_channel = i;
7127 }
7128
James Smart1ba981f2014-02-20 09:56:45 -05007129 if (cfg_fcp_io_channel + fof_vectors >
James Smart67d12732012-08-03 12:36:13 -04007130 phba->sli4_hba.max_cfg_param.max_eq) {
James Smart82c3e9b2012-09-29 11:29:50 -04007131 if (phba->sli4_hba.max_cfg_param.max_eq <
7132 LPFC_FCP_IO_CHAN_MIN) {
James Smartda0436e2009-05-22 14:51:39 -04007133 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7134 "2574 Not enough EQs (%d) from the "
7135 "pci function for supporting FCP "
7136 "EQs (%d)\n",
7137 phba->sli4_hba.max_cfg_param.max_eq,
James Smart67d12732012-08-03 12:36:13 -04007138 phba->cfg_fcp_io_channel);
James Smartda0436e2009-05-22 14:51:39 -04007139 goto out_error;
7140 }
James Smart82c3e9b2012-09-29 11:29:50 -04007141 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7142 "2575 Reducing IO channels to match number of "
7143 "available EQs: from %d to %d\n",
7144 cfg_fcp_io_channel,
7145 phba->sli4_hba.max_cfg_param.max_eq);
James Smart1ba981f2014-02-20 09:56:45 -05007146 cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq -
7147 fof_vectors;
James Smartda0436e2009-05-22 14:51:39 -04007148 }
James Smart67d12732012-08-03 12:36:13 -04007149
James Smartda0436e2009-05-22 14:51:39 -04007150 /* The actual number of FCP event queues adopted */
James Smart67d12732012-08-03 12:36:13 -04007151 phba->cfg_fcp_io_channel = cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04007152
James Smartda0436e2009-05-22 14:51:39 -04007153 /* Get EQ depth from module parameter, fake the default for now */
7154 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
7155 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
7156
James Smart5350d872011-10-10 21:33:49 -04007157 /* Get CQ depth from module parameter, fake the default for now */
7158 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
7159 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
7160
7161 return 0;
7162out_error:
7163 return -ENOMEM;
7164}
7165
7166/**
7167 * lpfc_sli4_queue_create - Create all the SLI4 queues
7168 * @phba: pointer to lpfc hba data structure.
7169 *
7170 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
7171 * operation. For each SLI4 queue type, the parameters such as queue entry
7172 * count (queue depth) shall be taken from the module parameter. For now,
7173 * we just use some constant number as place holder.
7174 *
7175 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07007176 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04007177 * -ENOMEM - No availble memory
7178 * -EIO - The mailbox failed to complete successfully.
7179 **/
7180int
7181lpfc_sli4_queue_create(struct lpfc_hba *phba)
7182{
7183 struct lpfc_queue *qdesc;
James Smart67d12732012-08-03 12:36:13 -04007184 int idx;
James Smart5350d872011-10-10 21:33:49 -04007185
7186 /*
James Smart67d12732012-08-03 12:36:13 -04007187 * Create HBA Record arrays.
James Smart5350d872011-10-10 21:33:49 -04007188 */
James Smart67d12732012-08-03 12:36:13 -04007189 if (!phba->cfg_fcp_io_channel)
7190 return -ERANGE;
James Smart5350d872011-10-10 21:33:49 -04007191
James Smart67d12732012-08-03 12:36:13 -04007192 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
7193 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
7194 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
7195 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
7196 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
7197 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
7198
7199 phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) *
7200 phba->cfg_fcp_io_channel), GFP_KERNEL);
7201 if (!phba->sli4_hba.hba_eq) {
James Smartda0436e2009-05-22 14:51:39 -04007202 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007203 "2576 Failed allocate memory for "
7204 "fast-path EQ record array\n");
James Smartda0436e2009-05-22 14:51:39 -04007205 goto out_error;
7206 }
James Smart67d12732012-08-03 12:36:13 -04007207
7208 phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
7209 phba->cfg_fcp_io_channel), GFP_KERNEL);
7210 if (!phba->sli4_hba.fcp_cq) {
7211 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7212 "2577 Failed allocate memory for fast-path "
7213 "CQ record array\n");
7214 goto out_error;
7215 }
7216
7217 phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
7218 phba->cfg_fcp_io_channel), GFP_KERNEL);
7219 if (!phba->sli4_hba.fcp_wq) {
7220 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7221 "2578 Failed allocate memory for fast-path "
7222 "WQ record array\n");
7223 goto out_error;
7224 }
James Smartda0436e2009-05-22 14:51:39 -04007225
James Smart5350d872011-10-10 21:33:49 -04007226 /*
James Smart67d12732012-08-03 12:36:13 -04007227 * Since the first EQ can have multiple CQs associated with it,
7228 * this array is used to quickly see if we have a FCP fast-path
7229 * CQ match.
James Smart5350d872011-10-10 21:33:49 -04007230 */
James Smart67d12732012-08-03 12:36:13 -04007231 phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) *
7232 phba->cfg_fcp_io_channel), GFP_KERNEL);
7233 if (!phba->sli4_hba.fcp_cq_map) {
7234 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7235 "2545 Failed allocate memory for fast-path "
7236 "CQ map\n");
7237 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007238 }
James Smart67d12732012-08-03 12:36:13 -04007239
7240 /*
7241 * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies
7242 * how many EQs to create.
7243 */
7244 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7245
7246 /* Create EQs */
James Smartda0436e2009-05-22 14:51:39 -04007247 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
7248 phba->sli4_hba.eq_ecount);
7249 if (!qdesc) {
7250 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007251 "0497 Failed allocate EQ (%d)\n", idx);
7252 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007253 }
James Smart67d12732012-08-03 12:36:13 -04007254 phba->sli4_hba.hba_eq[idx] = qdesc;
7255
7256 /* Create Fast Path FCP CQs */
7257 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7258 phba->sli4_hba.cq_ecount);
7259 if (!qdesc) {
7260 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7261 "0499 Failed allocate fast-path FCP "
7262 "CQ (%d)\n", idx);
7263 goto out_error;
7264 }
7265 phba->sli4_hba.fcp_cq[idx] = qdesc;
7266
7267 /* Create Fast Path FCP WQs */
James Smartb5c53952016-03-31 14:12:30 -07007268 if (phba->fcp_embed_io) {
7269 qdesc = lpfc_sli4_queue_alloc(phba,
7270 LPFC_WQE128_SIZE,
7271 LPFC_WQE128_DEF_COUNT);
7272 } else {
7273 qdesc = lpfc_sli4_queue_alloc(phba,
7274 phba->sli4_hba.wq_esize,
7275 phba->sli4_hba.wq_ecount);
7276 }
James Smart67d12732012-08-03 12:36:13 -04007277 if (!qdesc) {
7278 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7279 "0503 Failed allocate fast-path FCP "
7280 "WQ (%d)\n", idx);
7281 goto out_error;
7282 }
7283 phba->sli4_hba.fcp_wq[idx] = qdesc;
James Smartda0436e2009-05-22 14:51:39 -04007284 }
7285
James Smart67d12732012-08-03 12:36:13 -04007286
James Smartda0436e2009-05-22 14:51:39 -04007287 /*
James Smart67d12732012-08-03 12:36:13 -04007288 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04007289 */
7290
James Smartda0436e2009-05-22 14:51:39 -04007291 /* Create slow-path Mailbox Command Complete Queue */
7292 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7293 phba->sli4_hba.cq_ecount);
7294 if (!qdesc) {
7295 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7296 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04007297 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007298 }
7299 phba->sli4_hba.mbx_cq = qdesc;
7300
7301 /* Create slow-path ELS Complete Queue */
7302 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7303 phba->sli4_hba.cq_ecount);
7304 if (!qdesc) {
7305 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7306 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -04007307 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007308 }
7309 phba->sli4_hba.els_cq = qdesc;
7310
James Smartda0436e2009-05-22 14:51:39 -04007311
James Smart5350d872011-10-10 21:33:49 -04007312 /*
James Smart67d12732012-08-03 12:36:13 -04007313 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04007314 */
James Smartda0436e2009-05-22 14:51:39 -04007315
7316 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04007317
7318 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
7319 phba->sli4_hba.mq_ecount);
7320 if (!qdesc) {
7321 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7322 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04007323 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007324 }
7325 phba->sli4_hba.mbx_wq = qdesc;
7326
7327 /*
James Smart67d12732012-08-03 12:36:13 -04007328 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04007329 */
James Smartda0436e2009-05-22 14:51:39 -04007330
7331 /* Create slow-path ELS Work Queue */
7332 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
7333 phba->sli4_hba.wq_ecount);
7334 if (!qdesc) {
7335 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7336 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04007337 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007338 }
7339 phba->sli4_hba.els_wq = qdesc;
7340
James Smartda0436e2009-05-22 14:51:39 -04007341 /*
7342 * Create Receive Queue (RQ)
7343 */
James Smartda0436e2009-05-22 14:51:39 -04007344
7345 /* Create Receive Queue for header */
7346 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
7347 phba->sli4_hba.rq_ecount);
7348 if (!qdesc) {
7349 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7350 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04007351 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007352 }
7353 phba->sli4_hba.hdr_rq = qdesc;
7354
7355 /* Create Receive Queue for data */
7356 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
7357 phba->sli4_hba.rq_ecount);
7358 if (!qdesc) {
7359 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7360 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04007361 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007362 }
7363 phba->sli4_hba.dat_rq = qdesc;
7364
James Smart1ba981f2014-02-20 09:56:45 -05007365 /* Create the Queues needed for Flash Optimized Fabric operations */
7366 if (phba->cfg_fof)
7367 lpfc_fof_queue_create(phba);
James Smartda0436e2009-05-22 14:51:39 -04007368 return 0;
7369
James Smartda0436e2009-05-22 14:51:39 -04007370out_error:
James Smart67d12732012-08-03 12:36:13 -04007371 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04007372 return -ENOMEM;
7373}
7374
7375/**
7376 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
7377 * @phba: pointer to lpfc hba data structure.
7378 *
7379 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
7380 * operation.
7381 *
7382 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007383 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007384 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007385 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007386 **/
James Smart5350d872011-10-10 21:33:49 -04007387void
James Smartda0436e2009-05-22 14:51:39 -04007388lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
7389{
James Smart67d12732012-08-03 12:36:13 -04007390 int idx;
7391
James Smart1ba981f2014-02-20 09:56:45 -05007392 if (phba->cfg_fof)
7393 lpfc_fof_queue_destroy(phba);
7394
James Smart67d12732012-08-03 12:36:13 -04007395 if (phba->sli4_hba.hba_eq != NULL) {
7396 /* Release HBA event queue */
7397 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7398 if (phba->sli4_hba.hba_eq[idx] != NULL) {
7399 lpfc_sli4_queue_free(
7400 phba->sli4_hba.hba_eq[idx]);
7401 phba->sli4_hba.hba_eq[idx] = NULL;
7402 }
7403 }
7404 kfree(phba->sli4_hba.hba_eq);
7405 phba->sli4_hba.hba_eq = NULL;
7406 }
7407
7408 if (phba->sli4_hba.fcp_cq != NULL) {
7409 /* Release FCP completion queue */
7410 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7411 if (phba->sli4_hba.fcp_cq[idx] != NULL) {
7412 lpfc_sli4_queue_free(
7413 phba->sli4_hba.fcp_cq[idx]);
7414 phba->sli4_hba.fcp_cq[idx] = NULL;
7415 }
7416 }
7417 kfree(phba->sli4_hba.fcp_cq);
7418 phba->sli4_hba.fcp_cq = NULL;
7419 }
7420
7421 if (phba->sli4_hba.fcp_wq != NULL) {
7422 /* Release FCP work queue */
7423 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7424 if (phba->sli4_hba.fcp_wq[idx] != NULL) {
7425 lpfc_sli4_queue_free(
7426 phba->sli4_hba.fcp_wq[idx]);
7427 phba->sli4_hba.fcp_wq[idx] = NULL;
7428 }
7429 }
7430 kfree(phba->sli4_hba.fcp_wq);
7431 phba->sli4_hba.fcp_wq = NULL;
7432 }
7433
7434 /* Release FCP CQ mapping array */
7435 if (phba->sli4_hba.fcp_cq_map != NULL) {
7436 kfree(phba->sli4_hba.fcp_cq_map);
7437 phba->sli4_hba.fcp_cq_map = NULL;
7438 }
James Smartda0436e2009-05-22 14:51:39 -04007439
7440 /* Release mailbox command work queue */
James Smart67d12732012-08-03 12:36:13 -04007441 if (phba->sli4_hba.mbx_wq != NULL) {
7442 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
7443 phba->sli4_hba.mbx_wq = NULL;
7444 }
James Smartda0436e2009-05-22 14:51:39 -04007445
7446 /* Release ELS work queue */
James Smart67d12732012-08-03 12:36:13 -04007447 if (phba->sli4_hba.els_wq != NULL) {
7448 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
7449 phba->sli4_hba.els_wq = NULL;
7450 }
James Smartda0436e2009-05-22 14:51:39 -04007451
7452 /* Release unsolicited receive queue */
James Smart67d12732012-08-03 12:36:13 -04007453 if (phba->sli4_hba.hdr_rq != NULL) {
7454 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
7455 phba->sli4_hba.hdr_rq = NULL;
7456 }
7457 if (phba->sli4_hba.dat_rq != NULL) {
7458 lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
7459 phba->sli4_hba.dat_rq = NULL;
7460 }
James Smartda0436e2009-05-22 14:51:39 -04007461
James Smartda0436e2009-05-22 14:51:39 -04007462 /* Release ELS complete queue */
James Smart67d12732012-08-03 12:36:13 -04007463 if (phba->sli4_hba.els_cq != NULL) {
7464 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
7465 phba->sli4_hba.els_cq = NULL;
7466 }
James Smartda0436e2009-05-22 14:51:39 -04007467
7468 /* Release mailbox command complete queue */
James Smart67d12732012-08-03 12:36:13 -04007469 if (phba->sli4_hba.mbx_cq != NULL) {
7470 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
7471 phba->sli4_hba.mbx_cq = NULL;
7472 }
James Smartda0436e2009-05-22 14:51:39 -04007473
7474 return;
7475}
7476
7477/**
7478 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
7479 * @phba: pointer to lpfc hba data structure.
7480 *
7481 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
7482 * operation.
7483 *
7484 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007485 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007486 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007487 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007488 **/
7489int
7490lpfc_sli4_queue_setup(struct lpfc_hba *phba)
7491{
James Smart2a76a282012-08-03 12:35:54 -04007492 struct lpfc_sli *psli = &phba->sli;
7493 struct lpfc_sli_ring *pring;
James Smartda0436e2009-05-22 14:51:39 -04007494 int rc = -ENOMEM;
7495 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
7496 int fcp_cq_index = 0;
James Smart962bc512013-01-03 15:44:00 -05007497 uint32_t shdr_status, shdr_add_status;
7498 union lpfc_sli4_cfg_shdr *shdr;
7499 LPFC_MBOXQ_t *mboxq;
7500 uint32_t length;
7501
7502 /* Check for dual-ULP support */
7503 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7504 if (!mboxq) {
7505 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7506 "3249 Unable to allocate memory for "
7507 "QUERY_FW_CFG mailbox command\n");
7508 return -ENOMEM;
7509 }
7510 length = (sizeof(struct lpfc_mbx_query_fw_config) -
7511 sizeof(struct lpfc_sli4_cfg_mhdr));
7512 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
7513 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
7514 length, LPFC_SLI4_MBX_EMBED);
7515
7516 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7517
7518 shdr = (union lpfc_sli4_cfg_shdr *)
7519 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
7520 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7521 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7522 if (shdr_status || shdr_add_status || rc) {
7523 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7524 "3250 QUERY_FW_CFG mailbox failed with status "
7525 "x%x add_status x%x, mbx status x%x\n",
7526 shdr_status, shdr_add_status, rc);
7527 if (rc != MBX_TIMEOUT)
7528 mempool_free(mboxq, phba->mbox_mem_pool);
7529 rc = -ENXIO;
7530 goto out_error;
7531 }
7532
7533 phba->sli4_hba.fw_func_mode =
7534 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
7535 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
7536 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
James Smart8b017a32015-05-21 13:55:18 -04007537 phba->sli4_hba.physical_port =
7538 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
James Smart962bc512013-01-03 15:44:00 -05007539 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7540 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
7541 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
7542 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
7543
7544 if (rc != MBX_TIMEOUT)
7545 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04007546
7547 /*
James Smart67d12732012-08-03 12:36:13 -04007548 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04007549 */
7550
James Smart67d12732012-08-03 12:36:13 -04007551 /* Set up HBA event queue */
7552 if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) {
James Smart2e90f4b2011-12-13 13:22:37 -05007553 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7554 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007555 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007556 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05007557 }
James Smart67d12732012-08-03 12:36:13 -04007558 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
7559 if (!phba->sli4_hba.hba_eq[fcp_eqidx]) {
James Smartda0436e2009-05-22 14:51:39 -04007560 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7561 "0522 Fast-path EQ (%d) not "
7562 "allocated\n", fcp_eqidx);
James Smart1b511972011-12-13 13:23:09 -05007563 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007564 goto out_destroy_hba_eq;
James Smartda0436e2009-05-22 14:51:39 -04007565 }
James Smart67d12732012-08-03 12:36:13 -04007566 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx],
James Smartbf8dae82012-08-03 12:36:24 -04007567 (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel));
James Smartda0436e2009-05-22 14:51:39 -04007568 if (rc) {
7569 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7570 "0523 Failed setup of fast-path EQ "
James Smarta2fc4aef2014-09-03 12:57:55 -04007571 "(%d), rc = 0x%x\n", fcp_eqidx,
7572 (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007573 goto out_destroy_hba_eq;
James Smartda0436e2009-05-22 14:51:39 -04007574 }
7575 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007576 "2584 HBA EQ setup: "
James Smartda0436e2009-05-22 14:51:39 -04007577 "queue[%d]-id=%d\n", fcp_eqidx,
James Smart67d12732012-08-03 12:36:13 -04007578 phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007579 }
7580
James Smart67d12732012-08-03 12:36:13 -04007581 /* Set up fast-path FCP Response Complete Queue */
7582 if (!phba->sli4_hba.fcp_cq) {
7583 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7584 "3148 Fast-path FCP CQ array not "
7585 "allocated\n");
7586 rc = -ENOMEM;
7587 goto out_destroy_hba_eq;
7588 }
7589
7590 for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) {
7591 if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
7592 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7593 "0526 Fast-path FCP CQ (%d) not "
7594 "allocated\n", fcp_cqidx);
7595 rc = -ENOMEM;
7596 goto out_destroy_fcp_cq;
7597 }
7598 rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
7599 phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP);
7600 if (rc) {
7601 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7602 "0527 Failed setup of fast-path FCP "
James Smarta2fc4aef2014-09-03 12:57:55 -04007603 "CQ (%d), rc = 0x%x\n", fcp_cqidx,
7604 (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007605 goto out_destroy_fcp_cq;
7606 }
7607
7608 /* Setup fcp_cq_map for fast lookup */
7609 phba->sli4_hba.fcp_cq_map[fcp_cqidx] =
7610 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id;
7611
7612 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7613 "2588 FCP CQ setup: cq[%d]-id=%d, "
7614 "parent seq[%d]-id=%d\n",
7615 fcp_cqidx,
7616 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
7617 fcp_cqidx,
7618 phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id);
7619 }
7620
7621 /* Set up fast-path FCP Work Queue */
7622 if (!phba->sli4_hba.fcp_wq) {
7623 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7624 "3149 Fast-path FCP WQ array not "
7625 "allocated\n");
7626 rc = -ENOMEM;
7627 goto out_destroy_fcp_cq;
7628 }
7629
7630 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) {
7631 if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
7632 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7633 "0534 Fast-path FCP WQ (%d) not "
7634 "allocated\n", fcp_wqidx);
7635 rc = -ENOMEM;
7636 goto out_destroy_fcp_wq;
7637 }
7638 rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
7639 phba->sli4_hba.fcp_cq[fcp_wqidx],
7640 LPFC_FCP);
7641 if (rc) {
7642 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7643 "0535 Failed setup of fast-path FCP "
James Smarta2fc4aef2014-09-03 12:57:55 -04007644 "WQ (%d), rc = 0x%x\n", fcp_wqidx,
7645 (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007646 goto out_destroy_fcp_wq;
7647 }
7648
7649 /* Bind this WQ to the next FCP ring */
7650 pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx];
7651 pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx];
7652 phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring;
7653
7654 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7655 "2591 FCP WQ setup: wq[%d]-id=%d, "
7656 "parent cq[%d]-id=%d\n",
7657 fcp_wqidx,
7658 phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
7659 fcp_cq_index,
7660 phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id);
7661 }
James Smartda0436e2009-05-22 14:51:39 -04007662 /*
7663 * Set up Complete Queues (CQs)
7664 */
7665
7666 /* Set up slow-path MBOX Complete Queue as the first CQ */
7667 if (!phba->sli4_hba.mbx_cq) {
7668 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7669 "0528 Mailbox CQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007670 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007671 goto out_destroy_fcp_wq;
James Smartda0436e2009-05-22 14:51:39 -04007672 }
James Smart67d12732012-08-03 12:36:13 -04007673 rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq,
7674 phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04007675 if (rc) {
7676 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7677 "0529 Failed setup of slow-path mailbox CQ: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007678 "rc = 0x%x\n", (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007679 goto out_destroy_fcp_wq;
James Smartda0436e2009-05-22 14:51:39 -04007680 }
7681 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7682 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
7683 phba->sli4_hba.mbx_cq->queue_id,
James Smart67d12732012-08-03 12:36:13 -04007684 phba->sli4_hba.hba_eq[0]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007685
7686 /* Set up slow-path ELS Complete Queue */
7687 if (!phba->sli4_hba.els_cq) {
7688 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7689 "0530 ELS CQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007690 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007691 goto out_destroy_mbx_cq;
7692 }
James Smart67d12732012-08-03 12:36:13 -04007693 rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq,
7694 phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04007695 if (rc) {
7696 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7697 "0531 Failed setup of slow-path ELS CQ: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007698 "rc = 0x%x\n", (uint32_t)rc);
James Smartda0436e2009-05-22 14:51:39 -04007699 goto out_destroy_mbx_cq;
7700 }
7701 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7702 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
7703 phba->sli4_hba.els_cq->queue_id,
James Smart67d12732012-08-03 12:36:13 -04007704 phba->sli4_hba.hba_eq[0]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007705
7706 /*
7707 * Set up all the Work Queues (WQs)
7708 */
7709
7710 /* Set up Mailbox Command Queue */
7711 if (!phba->sli4_hba.mbx_wq) {
7712 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7713 "0538 Slow-path MQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007714 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007715 goto out_destroy_els_cq;
James Smartda0436e2009-05-22 14:51:39 -04007716 }
7717 rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
7718 phba->sli4_hba.mbx_cq, LPFC_MBOX);
7719 if (rc) {
7720 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7721 "0539 Failed setup of slow-path MQ: "
7722 "rc = 0x%x\n", rc);
James Smart67d12732012-08-03 12:36:13 -04007723 goto out_destroy_els_cq;
James Smartda0436e2009-05-22 14:51:39 -04007724 }
7725 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7726 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
7727 phba->sli4_hba.mbx_wq->queue_id,
7728 phba->sli4_hba.mbx_cq->queue_id);
7729
7730 /* Set up slow-path ELS Work Queue */
7731 if (!phba->sli4_hba.els_wq) {
7732 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7733 "0536 Slow-path ELS WQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007734 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007735 goto out_destroy_mbx_wq;
7736 }
7737 rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
7738 phba->sli4_hba.els_cq, LPFC_ELS);
7739 if (rc) {
7740 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7741 "0537 Failed setup of slow-path ELS WQ: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007742 "rc = 0x%x\n", (uint32_t)rc);
James Smartda0436e2009-05-22 14:51:39 -04007743 goto out_destroy_mbx_wq;
7744 }
James Smart2a76a282012-08-03 12:35:54 -04007745
7746 /* Bind this WQ to the ELS ring */
7747 pring = &psli->ring[LPFC_ELS_RING];
7748 pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq;
7749 phba->sli4_hba.els_cq->pring = pring;
7750
James Smartda0436e2009-05-22 14:51:39 -04007751 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7752 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
7753 phba->sli4_hba.els_wq->queue_id,
7754 phba->sli4_hba.els_cq->queue_id);
7755
James Smartda0436e2009-05-22 14:51:39 -04007756 /*
7757 * Create Receive Queue (RQ)
7758 */
7759 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
7760 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7761 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007762 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007763 goto out_destroy_els_wq;
James Smartda0436e2009-05-22 14:51:39 -04007764 }
James Smart73d91e52011-10-10 21:32:10 -04007765
7766 lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
7767 lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
7768
James Smartda0436e2009-05-22 14:51:39 -04007769 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04007770 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04007771 if (rc) {
7772 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7773 "0541 Failed setup of Receive Queue: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007774 "rc = 0x%x\n", (uint32_t)rc);
James Smartda0436e2009-05-22 14:51:39 -04007775 goto out_destroy_fcp_wq;
7776 }
James Smart73d91e52011-10-10 21:32:10 -04007777
James Smartda0436e2009-05-22 14:51:39 -04007778 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7779 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
7780 "parent cq-id=%d\n",
7781 phba->sli4_hba.hdr_rq->queue_id,
7782 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04007783 phba->sli4_hba.els_cq->queue_id);
James Smart1ba981f2014-02-20 09:56:45 -05007784
7785 if (phba->cfg_fof) {
7786 rc = lpfc_fof_queue_setup(phba);
7787 if (rc) {
7788 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7789 "0549 Failed setup of FOF Queues: "
7790 "rc = 0x%x\n", rc);
7791 goto out_destroy_els_rq;
7792 }
7793 }
James Smart2c9c5a02015-04-07 15:07:15 -04007794
7795 /*
7796 * Configure EQ delay multipier for interrupt coalescing using
7797 * MODIFY_EQ_DELAY for all EQs created, LPFC_MAX_EQ_DELAY at a time.
7798 */
7799 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel;
7800 fcp_eqidx += LPFC_MAX_EQ_DELAY)
7801 lpfc_modify_fcp_eq_delay(phba, fcp_eqidx);
James Smartda0436e2009-05-22 14:51:39 -04007802 return 0;
7803
James Smart1ba981f2014-02-20 09:56:45 -05007804out_destroy_els_rq:
7805 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
James Smart2e90f4b2011-12-13 13:22:37 -05007806out_destroy_els_wq:
James Smartda0436e2009-05-22 14:51:39 -04007807 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7808out_destroy_mbx_wq:
7809 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
James Smart2e90f4b2011-12-13 13:22:37 -05007810out_destroy_els_cq:
James Smartda0436e2009-05-22 14:51:39 -04007811 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
7812out_destroy_mbx_cq:
7813 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
James Smart67d12732012-08-03 12:36:13 -04007814out_destroy_fcp_wq:
7815 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
7816 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
7817out_destroy_fcp_cq:
7818 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
7819 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
7820out_destroy_hba_eq:
James Smartda0436e2009-05-22 14:51:39 -04007821 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
James Smart67d12732012-08-03 12:36:13 -04007822 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]);
James Smartda0436e2009-05-22 14:51:39 -04007823out_error:
7824 return rc;
7825}
7826
7827/**
7828 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
7829 * @phba: pointer to lpfc hba data structure.
7830 *
7831 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
7832 * operation.
7833 *
7834 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007835 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007836 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007837 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007838 **/
7839void
7840lpfc_sli4_queue_unset(struct lpfc_hba *phba)
7841{
7842 int fcp_qidx;
7843
James Smart1ba981f2014-02-20 09:56:45 -05007844 /* Unset the queues created for Flash Optimized Fabric operations */
7845 if (phba->cfg_fof)
7846 lpfc_fof_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04007847 /* Unset mailbox command work queue */
7848 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
7849 /* Unset ELS work queue */
7850 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7851 /* Unset unsolicited receive queue */
7852 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
7853 /* Unset FCP work queue */
James Smart67d12732012-08-03 12:36:13 -04007854 if (phba->sli4_hba.fcp_wq) {
7855 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
7856 fcp_qidx++)
7857 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
7858 }
James Smartda0436e2009-05-22 14:51:39 -04007859 /* Unset mailbox command complete queue */
7860 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
7861 /* Unset ELS complete queue */
7862 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
James Smartda0436e2009-05-22 14:51:39 -04007863 /* Unset FCP response complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05007864 if (phba->sli4_hba.fcp_cq) {
James Smart67d12732012-08-03 12:36:13 -04007865 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
7866 fcp_qidx++)
James Smart2e90f4b2011-12-13 13:22:37 -05007867 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
James Smart2e90f4b2011-12-13 13:22:37 -05007868 }
James Smartda0436e2009-05-22 14:51:39 -04007869 /* Unset fast-path event queue */
James Smart67d12732012-08-03 12:36:13 -04007870 if (phba->sli4_hba.hba_eq) {
7871 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
James Smart2e90f4b2011-12-13 13:22:37 -05007872 fcp_qidx++)
James Smart67d12732012-08-03 12:36:13 -04007873 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_qidx]);
James Smart2e90f4b2011-12-13 13:22:37 -05007874 }
James Smartda0436e2009-05-22 14:51:39 -04007875}
7876
7877/**
7878 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
7879 * @phba: pointer to lpfc hba data structure.
7880 *
7881 * This routine is invoked to allocate and set up a pool of completion queue
7882 * events. The body of the completion queue event is a completion queue entry
7883 * CQE. For now, this pool is used for the interrupt service routine to queue
7884 * the following HBA completion queue events for the worker thread to process:
7885 * - Mailbox asynchronous events
7886 * - Receive queue completion unsolicited events
7887 * Later, this can be used for all the slow-path events.
7888 *
7889 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007890 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007891 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007892 **/
7893static int
7894lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
7895{
7896 struct lpfc_cq_event *cq_event;
7897 int i;
7898
7899 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
7900 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
7901 if (!cq_event)
7902 goto out_pool_create_fail;
7903 list_add_tail(&cq_event->list,
7904 &phba->sli4_hba.sp_cqe_event_pool);
7905 }
7906 return 0;
7907
7908out_pool_create_fail:
7909 lpfc_sli4_cq_event_pool_destroy(phba);
7910 return -ENOMEM;
7911}
7912
7913/**
7914 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
7915 * @phba: pointer to lpfc hba data structure.
7916 *
7917 * This routine is invoked to free the pool of completion queue events at
7918 * driver unload time. Note that, it is the responsibility of the driver
7919 * cleanup routine to free all the outstanding completion-queue events
7920 * allocated from this pool back into the pool before invoking this routine
7921 * to destroy the pool.
7922 **/
7923static void
7924lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
7925{
7926 struct lpfc_cq_event *cq_event, *next_cq_event;
7927
7928 list_for_each_entry_safe(cq_event, next_cq_event,
7929 &phba->sli4_hba.sp_cqe_event_pool, list) {
7930 list_del(&cq_event->list);
7931 kfree(cq_event);
7932 }
7933}
7934
7935/**
7936 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7937 * @phba: pointer to lpfc hba data structure.
7938 *
7939 * This routine is the lock free version of the API invoked to allocate a
7940 * completion-queue event from the free pool.
7941 *
7942 * Return: Pointer to the newly allocated completion-queue event if successful
7943 * NULL otherwise.
7944 **/
7945struct lpfc_cq_event *
7946__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
7947{
7948 struct lpfc_cq_event *cq_event = NULL;
7949
7950 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
7951 struct lpfc_cq_event, list);
7952 return cq_event;
7953}
7954
7955/**
7956 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7957 * @phba: pointer to lpfc hba data structure.
7958 *
7959 * This routine is the lock version of the API invoked to allocate a
7960 * completion-queue event from the free pool.
7961 *
7962 * Return: Pointer to the newly allocated completion-queue event if successful
7963 * NULL otherwise.
7964 **/
7965struct lpfc_cq_event *
7966lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
7967{
7968 struct lpfc_cq_event *cq_event;
7969 unsigned long iflags;
7970
7971 spin_lock_irqsave(&phba->hbalock, iflags);
7972 cq_event = __lpfc_sli4_cq_event_alloc(phba);
7973 spin_unlock_irqrestore(&phba->hbalock, iflags);
7974 return cq_event;
7975}
7976
7977/**
7978 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7979 * @phba: pointer to lpfc hba data structure.
7980 * @cq_event: pointer to the completion queue event to be freed.
7981 *
7982 * This routine is the lock free version of the API invoked to release a
7983 * completion-queue event back into the free pool.
7984 **/
7985void
7986__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
7987 struct lpfc_cq_event *cq_event)
7988{
7989 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
7990}
7991
7992/**
7993 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7994 * @phba: pointer to lpfc hba data structure.
7995 * @cq_event: pointer to the completion queue event to be freed.
7996 *
7997 * This routine is the lock version of the API invoked to release a
7998 * completion-queue event back into the free pool.
7999 **/
8000void
8001lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
8002 struct lpfc_cq_event *cq_event)
8003{
8004 unsigned long iflags;
8005 spin_lock_irqsave(&phba->hbalock, iflags);
8006 __lpfc_sli4_cq_event_release(phba, cq_event);
8007 spin_unlock_irqrestore(&phba->hbalock, iflags);
8008}
8009
8010/**
8011 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
8012 * @phba: pointer to lpfc hba data structure.
8013 *
8014 * This routine is to free all the pending completion-queue events to the
8015 * back into the free pool for device reset.
8016 **/
8017static void
8018lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
8019{
8020 LIST_HEAD(cqelist);
8021 struct lpfc_cq_event *cqe;
8022 unsigned long iflags;
8023
8024 /* Retrieve all the pending WCQEs from pending WCQE lists */
8025 spin_lock_irqsave(&phba->hbalock, iflags);
8026 /* Pending FCP XRI abort events */
8027 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
8028 &cqelist);
8029 /* Pending ELS XRI abort events */
8030 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
8031 &cqelist);
8032 /* Pending asynnc events */
8033 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
8034 &cqelist);
8035 spin_unlock_irqrestore(&phba->hbalock, iflags);
8036
8037 while (!list_empty(&cqelist)) {
8038 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
8039 lpfc_sli4_cq_event_release(phba, cqe);
8040 }
8041}
8042
8043/**
8044 * lpfc_pci_function_reset - Reset pci function.
8045 * @phba: pointer to lpfc hba data structure.
8046 *
8047 * This routine is invoked to request a PCI function reset. It will destroys
8048 * all resources assigned to the PCI function which originates this request.
8049 *
8050 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008051 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008052 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008053 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008054 **/
8055int
8056lpfc_pci_function_reset(struct lpfc_hba *phba)
8057{
8058 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05008059 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04008060 uint32_t shdr_status, shdr_add_status;
James Smart2f6fa2c2014-09-03 12:57:08 -04008061 uint32_t rdy_chk;
8062 uint32_t port_reset = 0;
James Smartda0436e2009-05-22 14:51:39 -04008063 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05008064 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -05008065 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -04008066
James Smart2fcee4b2010-12-15 17:57:46 -05008067 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8068 switch (if_type) {
8069 case LPFC_SLI_INTF_IF_TYPE_0:
8070 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8071 GFP_KERNEL);
8072 if (!mboxq) {
8073 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8074 "0494 Unable to allocate memory for "
8075 "issuing SLI_FUNCTION_RESET mailbox "
8076 "command\n");
8077 return -ENOMEM;
8078 }
8079
8080 /* Setup PCI function reset mailbox-ioctl command */
8081 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8082 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
8083 LPFC_SLI4_MBX_EMBED);
8084 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8085 shdr = (union lpfc_sli4_cfg_shdr *)
8086 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
8087 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8088 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
8089 &shdr->response);
8090 if (rc != MBX_TIMEOUT)
8091 mempool_free(mboxq, phba->mbox_mem_pool);
8092 if (shdr_status || shdr_add_status || rc) {
8093 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8094 "0495 SLI_FUNCTION_RESET mailbox "
8095 "failed with status x%x add_status x%x,"
8096 " mbx status x%x\n",
8097 shdr_status, shdr_add_status, rc);
8098 rc = -ENXIO;
8099 }
8100 break;
8101 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2f6fa2c2014-09-03 12:57:08 -04008102wait:
8103 /*
8104 * Poll the Port Status Register and wait for RDY for
8105 * up to 30 seconds. If the port doesn't respond, treat
8106 * it as an error.
8107 */
James Smart77d093f2015-04-07 15:07:08 -04008108 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
James Smart2f6fa2c2014-09-03 12:57:08 -04008109 if (lpfc_readl(phba->sli4_hba.u.if_type2.
8110 STATUSregaddr, &reg_data.word0)) {
8111 rc = -ENODEV;
8112 goto out;
8113 }
8114 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
8115 break;
8116 msleep(20);
8117 }
8118
8119 if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
8120 phba->work_status[0] = readl(
8121 phba->sli4_hba.u.if_type2.ERR1regaddr);
8122 phba->work_status[1] = readl(
8123 phba->sli4_hba.u.if_type2.ERR2regaddr);
8124 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8125 "2890 Port not ready, port status reg "
8126 "0x%x error 1=0x%x, error 2=0x%x\n",
8127 reg_data.word0,
8128 phba->work_status[0],
8129 phba->work_status[1]);
8130 rc = -ENODEV;
8131 goto out;
8132 }
8133
8134 if (!port_reset) {
8135 /*
8136 * Reset the port now
8137 */
James Smart2fcee4b2010-12-15 17:57:46 -05008138 reg_data.word0 = 0;
8139 bf_set(lpfc_sliport_ctrl_end, &reg_data,
8140 LPFC_SLIPORT_LITTLE_ENDIAN);
8141 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
8142 LPFC_SLIPORT_INIT_PORT);
8143 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
8144 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -05008145 /* flush */
James Smart2b81f942012-03-01 22:37:18 -05008146 pci_read_config_word(phba->pcidev,
8147 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -05008148
James Smart2f6fa2c2014-09-03 12:57:08 -04008149 port_reset = 1;
8150 msleep(20);
8151 goto wait;
8152 } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
8153 rc = -ENODEV;
8154 goto out;
James Smart2fcee4b2010-12-15 17:57:46 -05008155 }
8156 break;
James Smart2f6fa2c2014-09-03 12:57:08 -04008157
James Smart2fcee4b2010-12-15 17:57:46 -05008158 case LPFC_SLI_INTF_IF_TYPE_1:
8159 default:
8160 break;
James Smartda0436e2009-05-22 14:51:39 -04008161 }
8162
James Smart73d91e52011-10-10 21:32:10 -04008163out:
James Smart2fcee4b2010-12-15 17:57:46 -05008164 /* Catch the not-ready port failure after a port reset. */
James Smart2f6fa2c2014-09-03 12:57:08 -04008165 if (rc) {
James Smart229adb02013-04-17 20:16:51 -04008166 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8167 "3317 HBA not functional: IP Reset Failed "
James Smart2f6fa2c2014-09-03 12:57:08 -04008168 "try: echo fw_reset > board_mode\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008169 rc = -ENODEV;
James Smart229adb02013-04-17 20:16:51 -04008170 }
James Smart2fcee4b2010-12-15 17:57:46 -05008171
James Smartda0436e2009-05-22 14:51:39 -04008172 return rc;
8173}
8174
8175/**
James Smartda0436e2009-05-22 14:51:39 -04008176 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
8177 * @phba: pointer to lpfc hba data structure.
8178 *
8179 * This routine is invoked to set up the PCI device memory space for device
8180 * with SLI-4 interface spec.
8181 *
8182 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008183 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008184 * other values - error
8185 **/
8186static int
8187lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
8188{
8189 struct pci_dev *pdev;
8190 unsigned long bar0map_len, bar1map_len, bar2map_len;
8191 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05008192 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04008193
8194 /* Obtain PCI device reference */
8195 if (!phba->pcidev)
8196 return error;
8197 else
8198 pdev = phba->pcidev;
8199
8200 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05008201 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
8202 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
8203 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
8204 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smartda0436e2009-05-22 14:51:39 -04008205 return error;
Michael Reed8e685972009-09-18 12:02:05 -05008206 }
8207 }
James Smartda0436e2009-05-22 14:51:39 -04008208
James Smart2fcee4b2010-12-15 17:57:46 -05008209 /*
8210 * The BARs and register set definitions and offset locations are
8211 * dependent on the if_type.
8212 */
8213 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
8214 &phba->sli4_hba.sli_intf.word0)) {
8215 return error;
8216 }
8217
8218 /* There is no SLI3 failback for SLI4 devices. */
8219 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
8220 LPFC_SLI_INTF_VALID) {
8221 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8222 "2894 SLI_INTF reg contents invalid "
8223 "sli_intf reg 0x%x\n",
8224 phba->sli4_hba.sli_intf.word0);
8225 return error;
8226 }
8227
8228 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8229 /*
8230 * Get the bus address of SLI4 device Bar regions and the
8231 * number of bytes required by each mapping. The mapping of the
8232 * particular PCI BARs regions is dependent on the type of
8233 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04008234 */
James Smartf5ca6f22013-09-06 12:21:09 -04008235 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
8236 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
8237 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
James Smart2fcee4b2010-12-15 17:57:46 -05008238
8239 /*
8240 * Map SLI4 PCI Config Space Register base to a kernel virtual
8241 * addr
8242 */
8243 phba->sli4_hba.conf_regs_memmap_p =
8244 ioremap(phba->pci_bar0_map, bar0map_len);
8245 if (!phba->sli4_hba.conf_regs_memmap_p) {
8246 dev_printk(KERN_ERR, &pdev->dev,
8247 "ioremap failed for SLI4 PCI config "
8248 "registers.\n");
8249 goto out;
8250 }
James Smartf5ca6f22013-09-06 12:21:09 -04008251 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008252 /* Set up BAR0 PCI config space register memory map */
8253 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05008254 } else {
8255 phba->pci_bar0_map = pci_resource_start(pdev, 1);
8256 bar0map_len = pci_resource_len(pdev, 1);
James Smart2fcee4b2010-12-15 17:57:46 -05008257 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
8258 dev_printk(KERN_ERR, &pdev->dev,
8259 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
8260 goto out;
8261 }
8262 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008263 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008264 if (!phba->sli4_hba.conf_regs_memmap_p) {
8265 dev_printk(KERN_ERR, &pdev->dev,
8266 "ioremap failed for SLI4 PCI config "
8267 "registers.\n");
8268 goto out;
8269 }
8270 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04008271 }
8272
James Smartc31098c2011-04-16 11:03:33 -04008273 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04008274 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
James Smart2fcee4b2010-12-15 17:57:46 -05008275 /*
8276 * Map SLI4 if type 0 HBA Control Register base to a kernel
8277 * virtual address and setup the registers.
8278 */
James Smartf5ca6f22013-09-06 12:21:09 -04008279 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
8280 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
James Smart2fcee4b2010-12-15 17:57:46 -05008281 phba->sli4_hba.ctrl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008282 ioremap(phba->pci_bar1_map, bar1map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008283 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
8284 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04008285 "ioremap failed for SLI4 HBA control registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008286 goto out_iounmap_conf;
8287 }
James Smartf5ca6f22013-09-06 12:21:09 -04008288 phba->pci_bar2_memmap_p = phba->sli4_hba.ctrl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008289 lpfc_sli4_bar1_register_memmap(phba);
James Smartda0436e2009-05-22 14:51:39 -04008290 }
8291
James Smartc31098c2011-04-16 11:03:33 -04008292 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04008293 (pci_resource_start(pdev, PCI_64BIT_BAR4))) {
James Smart2fcee4b2010-12-15 17:57:46 -05008294 /*
8295 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
8296 * virtual address and setup the registers.
8297 */
James Smartf5ca6f22013-09-06 12:21:09 -04008298 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
8299 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
James Smart2fcee4b2010-12-15 17:57:46 -05008300 phba->sli4_hba.drbl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008301 ioremap(phba->pci_bar2_map, bar2map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008302 if (!phba->sli4_hba.drbl_regs_memmap_p) {
8303 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04008304 "ioremap failed for SLI4 HBA doorbell registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008305 goto out_iounmap_ctrl;
8306 }
James Smartf5ca6f22013-09-06 12:21:09 -04008307 phba->pci_bar4_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008308 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
8309 if (error)
8310 goto out_iounmap_all;
James Smartda0436e2009-05-22 14:51:39 -04008311 }
8312
James Smartda0436e2009-05-22 14:51:39 -04008313 return 0;
8314
8315out_iounmap_all:
8316 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
8317out_iounmap_ctrl:
8318 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
8319out_iounmap_conf:
8320 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8321out:
8322 return error;
8323}
8324
8325/**
8326 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
8327 * @phba: pointer to lpfc hba data structure.
8328 *
8329 * This routine is invoked to unset the PCI device memory space for device
8330 * with SLI-4 interface spec.
8331 **/
8332static void
8333lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
8334{
James Smart2e90f4b2011-12-13 13:22:37 -05008335 uint32_t if_type;
8336 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -04008337
James Smart2e90f4b2011-12-13 13:22:37 -05008338 switch (if_type) {
8339 case LPFC_SLI_INTF_IF_TYPE_0:
8340 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
8341 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
8342 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8343 break;
8344 case LPFC_SLI_INTF_IF_TYPE_2:
8345 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8346 break;
8347 case LPFC_SLI_INTF_IF_TYPE_1:
8348 default:
8349 dev_printk(KERN_ERR, &phba->pcidev->dev,
8350 "FATAL - unsupported SLI4 interface type - %d\n",
8351 if_type);
8352 break;
8353 }
James Smartda0436e2009-05-22 14:51:39 -04008354}
8355
8356/**
James Smart3772a992009-05-22 14:50:54 -04008357 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
8358 * @phba: pointer to lpfc hba data structure.
8359 *
8360 * This routine is invoked to enable the MSI-X interrupt vectors to device
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008361 * with SLI-3 interface specs. The kernel function pci_enable_msix_exact()
8362 * is called to enable the MSI-X vectors. Note that pci_enable_msix_exact(),
8363 * once invoked, enables either all or nothing, depending on the current
James Smart3772a992009-05-22 14:50:54 -04008364 * availability of PCI vector resources. The device driver is responsible
8365 * for calling the individual request_irq() to register each MSI-X vector
8366 * with a interrupt handler, which is done in this function. Note that
8367 * later when device is unloading, the driver should always call free_irq()
8368 * on all MSI-X vectors it has done request_irq() on before calling
8369 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
8370 * will be left with MSI-X enabled and leaks its vectors.
8371 *
8372 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008373 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008374 * other values - error
8375 **/
8376static int
8377lpfc_sli_enable_msix(struct lpfc_hba *phba)
8378{
8379 int rc, i;
8380 LPFC_MBOXQ_t *pmb;
8381
8382 /* Set up MSI-X multi-message vectors */
8383 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8384 phba->msix_entries[i].entry = i;
8385
8386 /* Configure MSI-X capability structure */
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008387 rc = pci_enable_msix_exact(phba->pcidev, phba->msix_entries,
8388 LPFC_MSIX_VECTORS);
James Smart3772a992009-05-22 14:50:54 -04008389 if (rc) {
8390 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8391 "0420 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02008392 goto vec_fail_out;
James Smart3772a992009-05-22 14:50:54 -04008393 }
8394 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8395 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8396 "0477 MSI-X entry[%d]: vector=x%x "
8397 "message=%d\n", i,
8398 phba->msix_entries[i].vector,
8399 phba->msix_entries[i].entry);
8400 /*
8401 * Assign MSI-X vectors to interrupt handlers
8402 */
8403
8404 /* vector-0 is associated to slow-path handler */
8405 rc = request_irq(phba->msix_entries[0].vector,
James Smarted243d32015-05-21 13:55:25 -04008406 &lpfc_sli_sp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04008407 LPFC_SP_DRIVER_HANDLER_NAME, phba);
8408 if (rc) {
8409 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8410 "0421 MSI-X slow-path request_irq failed "
8411 "(%d)\n", rc);
8412 goto msi_fail_out;
8413 }
8414
8415 /* vector-1 is associated to fast-path handler */
8416 rc = request_irq(phba->msix_entries[1].vector,
James Smarted243d32015-05-21 13:55:25 -04008417 &lpfc_sli_fp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04008418 LPFC_FP_DRIVER_HANDLER_NAME, phba);
8419
8420 if (rc) {
8421 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8422 "0429 MSI-X fast-path request_irq failed "
8423 "(%d)\n", rc);
8424 goto irq_fail_out;
8425 }
8426
8427 /*
8428 * Configure HBA MSI-X attention conditions to messages
8429 */
8430 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8431
8432 if (!pmb) {
8433 rc = -ENOMEM;
8434 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8435 "0474 Unable to allocate memory for issuing "
8436 "MBOX_CONFIG_MSI command\n");
8437 goto mem_fail_out;
8438 }
8439 rc = lpfc_config_msi(phba, pmb);
8440 if (rc)
8441 goto mbx_fail_out;
8442 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
8443 if (rc != MBX_SUCCESS) {
8444 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
8445 "0351 Config MSI mailbox command failed, "
8446 "mbxCmd x%x, mbxStatus x%x\n",
8447 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
8448 goto mbx_fail_out;
8449 }
8450
8451 /* Free memory allocated for mailbox command */
8452 mempool_free(pmb, phba->mbox_mem_pool);
8453 return rc;
8454
8455mbx_fail_out:
8456 /* Free memory allocated for mailbox command */
8457 mempool_free(pmb, phba->mbox_mem_pool);
8458
8459mem_fail_out:
8460 /* free the irq already requested */
8461 free_irq(phba->msix_entries[1].vector, phba);
8462
8463irq_fail_out:
8464 /* free the irq already requested */
8465 free_irq(phba->msix_entries[0].vector, phba);
8466
8467msi_fail_out:
8468 /* Unconfigure MSI-X capability structure */
8469 pci_disable_msix(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02008470
8471vec_fail_out:
James Smart3772a992009-05-22 14:50:54 -04008472 return rc;
8473}
8474
8475/**
8476 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
8477 * @phba: pointer to lpfc hba data structure.
8478 *
8479 * This routine is invoked to release the MSI-X vectors and then disable the
8480 * MSI-X interrupt mode to device with SLI-3 interface spec.
8481 **/
8482static void
8483lpfc_sli_disable_msix(struct lpfc_hba *phba)
8484{
8485 int i;
8486
8487 /* Free up MSI-X multi-message vectors */
8488 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8489 free_irq(phba->msix_entries[i].vector, phba);
8490 /* Disable MSI-X */
8491 pci_disable_msix(phba->pcidev);
8492
8493 return;
8494}
8495
8496/**
8497 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
8498 * @phba: pointer to lpfc hba data structure.
8499 *
8500 * This routine is invoked to enable the MSI interrupt mode to device with
8501 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
8502 * enable the MSI vector. The device driver is responsible for calling the
8503 * request_irq() to register MSI vector with a interrupt the handler, which
8504 * is done in this function.
8505 *
8506 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008507 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008508 * other values - error
8509 */
8510static int
8511lpfc_sli_enable_msi(struct lpfc_hba *phba)
8512{
8513 int rc;
8514
8515 rc = pci_enable_msi(phba->pcidev);
8516 if (!rc)
8517 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8518 "0462 PCI enable MSI mode success.\n");
8519 else {
8520 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8521 "0471 PCI enable MSI mode failed (%d)\n", rc);
8522 return rc;
8523 }
8524
8525 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04008526 0, LPFC_DRIVER_NAME, phba);
James Smart3772a992009-05-22 14:50:54 -04008527 if (rc) {
8528 pci_disable_msi(phba->pcidev);
8529 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8530 "0478 MSI request_irq failed (%d)\n", rc);
8531 }
8532 return rc;
8533}
8534
8535/**
8536 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
8537 * @phba: pointer to lpfc hba data structure.
8538 *
8539 * This routine is invoked to disable the MSI interrupt mode to device with
8540 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
8541 * done request_irq() on before calling pci_disable_msi(). Failure to do so
8542 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
8543 * its vector.
8544 */
8545static void
8546lpfc_sli_disable_msi(struct lpfc_hba *phba)
8547{
8548 free_irq(phba->pcidev->irq, phba);
8549 pci_disable_msi(phba->pcidev);
8550 return;
8551}
8552
8553/**
8554 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
8555 * @phba: pointer to lpfc hba data structure.
8556 *
8557 * This routine is invoked to enable device interrupt and associate driver's
8558 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
8559 * spec. Depends on the interrupt mode configured to the driver, the driver
8560 * will try to fallback from the configured interrupt mode to an interrupt
8561 * mode which is supported by the platform, kernel, and device in the order
8562 * of:
8563 * MSI-X -> MSI -> IRQ.
8564 *
8565 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008566 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008567 * other values - error
8568 **/
8569static uint32_t
8570lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
8571{
8572 uint32_t intr_mode = LPFC_INTR_ERROR;
8573 int retval;
8574
8575 if (cfg_mode == 2) {
8576 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
8577 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
8578 if (!retval) {
8579 /* Now, try to enable MSI-X interrupt mode */
8580 retval = lpfc_sli_enable_msix(phba);
8581 if (!retval) {
8582 /* Indicate initialization to MSI-X mode */
8583 phba->intr_type = MSIX;
8584 intr_mode = 2;
8585 }
8586 }
8587 }
8588
8589 /* Fallback to MSI if MSI-X initialization failed */
8590 if (cfg_mode >= 1 && phba->intr_type == NONE) {
8591 retval = lpfc_sli_enable_msi(phba);
8592 if (!retval) {
8593 /* Indicate initialization to MSI mode */
8594 phba->intr_type = MSI;
8595 intr_mode = 1;
8596 }
8597 }
8598
8599 /* Fallback to INTx if both MSI-X/MSI initalization failed */
8600 if (phba->intr_type == NONE) {
8601 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
8602 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8603 if (!retval) {
8604 /* Indicate initialization to INTx mode */
8605 phba->intr_type = INTx;
8606 intr_mode = 0;
8607 }
8608 }
8609 return intr_mode;
8610}
8611
8612/**
8613 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
8614 * @phba: pointer to lpfc hba data structure.
8615 *
8616 * This routine is invoked to disable device interrupt and disassociate the
8617 * driver's interrupt handler(s) from interrupt vector(s) to device with
8618 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
8619 * release the interrupt vector(s) for the message signaled interrupt.
8620 **/
8621static void
8622lpfc_sli_disable_intr(struct lpfc_hba *phba)
8623{
8624 /* Disable the currently initialized interrupt mode */
8625 if (phba->intr_type == MSIX)
8626 lpfc_sli_disable_msix(phba);
8627 else if (phba->intr_type == MSI)
8628 lpfc_sli_disable_msi(phba);
8629 else if (phba->intr_type == INTx)
8630 free_irq(phba->pcidev->irq, phba);
8631
8632 /* Reset interrupt management states */
8633 phba->intr_type = NONE;
8634 phba->sli.slistat.sli_intr = 0;
8635
8636 return;
8637}
8638
8639/**
James Smart7bb03bb2013-04-17 20:19:16 -04008640 * lpfc_find_next_cpu - Find next available CPU that matches the phys_id
8641 * @phba: pointer to lpfc hba data structure.
8642 *
8643 * Find next available CPU to use for IRQ to CPU affinity.
8644 */
8645static int
8646lpfc_find_next_cpu(struct lpfc_hba *phba, uint32_t phys_id)
8647{
8648 struct lpfc_vector_map_info *cpup;
8649 int cpu;
8650
8651 cpup = phba->sli4_hba.cpu_map;
8652 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8653 /* CPU must be online */
8654 if (cpu_online(cpu)) {
8655 if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
8656 (lpfc_used_cpu[cpu] == LPFC_VECTOR_MAP_EMPTY) &&
8657 (cpup->phys_id == phys_id)) {
8658 return cpu;
8659 }
8660 }
8661 cpup++;
8662 }
8663
8664 /*
8665 * If we get here, we have used ALL CPUs for the specific
8666 * phys_id. Now we need to clear out lpfc_used_cpu and start
8667 * reusing CPUs.
8668 */
8669
8670 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8671 if (lpfc_used_cpu[cpu] == phys_id)
8672 lpfc_used_cpu[cpu] = LPFC_VECTOR_MAP_EMPTY;
8673 }
8674
8675 cpup = phba->sli4_hba.cpu_map;
8676 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8677 /* CPU must be online */
8678 if (cpu_online(cpu)) {
8679 if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
8680 (cpup->phys_id == phys_id)) {
8681 return cpu;
8682 }
8683 }
8684 cpup++;
8685 }
8686 return LPFC_VECTOR_MAP_EMPTY;
8687}
8688
8689/**
8690 * lpfc_sli4_set_affinity - Set affinity for HBA IRQ vectors
8691 * @phba: pointer to lpfc hba data structure.
8692 * @vectors: number of HBA vectors
8693 *
8694 * Affinitize MSIX IRQ vectors to CPUs. Try to equally spread vector
8695 * affinization across multple physical CPUs (numa nodes).
8696 * In addition, this routine will assign an IO channel for each CPU
8697 * to use when issuing I/Os.
8698 */
8699static int
8700lpfc_sli4_set_affinity(struct lpfc_hba *phba, int vectors)
8701{
8702 int i, idx, saved_chann, used_chann, cpu, phys_id;
James Smartec2087a2013-09-06 12:20:36 -04008703 int max_phys_id, min_phys_id;
8704 int num_io_channel, first_cpu, chan;
James Smart7bb03bb2013-04-17 20:19:16 -04008705 struct lpfc_vector_map_info *cpup;
8706#ifdef CONFIG_X86
8707 struct cpuinfo_x86 *cpuinfo;
8708#endif
James Smart7bb03bb2013-04-17 20:19:16 -04008709 uint8_t chann[LPFC_FCP_IO_CHAN_MAX+1];
8710
8711 /* If there is no mapping, just return */
8712 if (!phba->cfg_fcp_cpu_map)
8713 return 1;
8714
8715 /* Init cpu_map array */
8716 memset(phba->sli4_hba.cpu_map, 0xff,
8717 (sizeof(struct lpfc_vector_map_info) *
8718 phba->sli4_hba.num_present_cpu));
8719
8720 max_phys_id = 0;
James Smartec2087a2013-09-06 12:20:36 -04008721 min_phys_id = 0xff;
James Smart7bb03bb2013-04-17 20:19:16 -04008722 phys_id = 0;
8723 num_io_channel = 0;
8724 first_cpu = LPFC_VECTOR_MAP_EMPTY;
8725
8726 /* Update CPU map with physical id and core id of each CPU */
8727 cpup = phba->sli4_hba.cpu_map;
8728 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8729#ifdef CONFIG_X86
8730 cpuinfo = &cpu_data(cpu);
8731 cpup->phys_id = cpuinfo->phys_proc_id;
8732 cpup->core_id = cpuinfo->cpu_core_id;
8733#else
8734 /* No distinction between CPUs for other platforms */
8735 cpup->phys_id = 0;
8736 cpup->core_id = 0;
8737#endif
8738
8739 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8740 "3328 CPU physid %d coreid %d\n",
8741 cpup->phys_id, cpup->core_id);
8742
8743 if (cpup->phys_id > max_phys_id)
8744 max_phys_id = cpup->phys_id;
James Smartec2087a2013-09-06 12:20:36 -04008745 if (cpup->phys_id < min_phys_id)
8746 min_phys_id = cpup->phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008747 cpup++;
8748 }
8749
James Smartec2087a2013-09-06 12:20:36 -04008750 phys_id = min_phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008751 /* Now associate the HBA vectors with specific CPUs */
8752 for (idx = 0; idx < vectors; idx++) {
8753 cpup = phba->sli4_hba.cpu_map;
8754 cpu = lpfc_find_next_cpu(phba, phys_id);
8755 if (cpu == LPFC_VECTOR_MAP_EMPTY) {
8756
8757 /* Try for all phys_id's */
8758 for (i = 1; i < max_phys_id; i++) {
8759 phys_id++;
8760 if (phys_id > max_phys_id)
James Smartec2087a2013-09-06 12:20:36 -04008761 phys_id = min_phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008762 cpu = lpfc_find_next_cpu(phba, phys_id);
8763 if (cpu == LPFC_VECTOR_MAP_EMPTY)
8764 continue;
8765 goto found;
8766 }
8767
James Smartec2087a2013-09-06 12:20:36 -04008768 /* Use round robin for scheduling */
8769 phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_ROUND_ROBIN;
8770 chan = 0;
8771 cpup = phba->sli4_hba.cpu_map;
8772 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
8773 cpup->channel_id = chan;
8774 cpup++;
8775 chan++;
8776 if (chan >= phba->cfg_fcp_io_channel)
8777 chan = 0;
8778 }
8779
James Smart7bb03bb2013-04-17 20:19:16 -04008780 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8781 "3329 Cannot set affinity:"
8782 "Error mapping vector %d (%d)\n",
8783 idx, vectors);
8784 return 0;
8785 }
8786found:
8787 cpup += cpu;
8788 if (phba->cfg_fcp_cpu_map == LPFC_DRIVER_CPU_MAP)
8789 lpfc_used_cpu[cpu] = phys_id;
8790
8791 /* Associate vector with selected CPU */
8792 cpup->irq = phba->sli4_hba.msix_entries[idx].vector;
8793
8794 /* Associate IO channel with selected CPU */
8795 cpup->channel_id = idx;
8796 num_io_channel++;
8797
8798 if (first_cpu == LPFC_VECTOR_MAP_EMPTY)
8799 first_cpu = cpu;
8800
8801 /* Now affinitize to the selected CPU */
James Smart7bb03bb2013-04-17 20:19:16 -04008802 i = irq_set_affinity_hint(phba->sli4_hba.msix_entries[idx].
Ian Mitchellc0365c02015-08-31 16:48:12 -04008803 vector, get_cpu_mask(cpu));
James Smart7bb03bb2013-04-17 20:19:16 -04008804
8805 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8806 "3330 Set Affinity: CPU %d channel %d "
8807 "irq %d (%x)\n",
8808 cpu, cpup->channel_id,
8809 phba->sli4_hba.msix_entries[idx].vector, i);
8810
8811 /* Spread vector mapping across multple physical CPU nodes */
8812 phys_id++;
8813 if (phys_id > max_phys_id)
James Smartec2087a2013-09-06 12:20:36 -04008814 phys_id = min_phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008815 }
8816
8817 /*
8818 * Finally fill in the IO channel for any remaining CPUs.
8819 * At this point, all IO channels have been assigned to a specific
8820 * MSIx vector, mapped to a specific CPU.
8821 * Base the remaining IO channel assigned, to IO channels already
8822 * assigned to other CPUs on the same phys_id.
8823 */
James Smartec2087a2013-09-06 12:20:36 -04008824 for (i = min_phys_id; i <= max_phys_id; i++) {
James Smart7bb03bb2013-04-17 20:19:16 -04008825 /*
8826 * If there are no io channels already mapped to
8827 * this phys_id, just round robin thru the io_channels.
8828 * Setup chann[] for round robin.
8829 */
8830 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
8831 chann[idx] = idx;
8832
8833 saved_chann = 0;
8834 used_chann = 0;
8835
8836 /*
8837 * First build a list of IO channels already assigned
8838 * to this phys_id before reassigning the same IO
8839 * channels to the remaining CPUs.
8840 */
8841 cpup = phba->sli4_hba.cpu_map;
8842 cpu = first_cpu;
8843 cpup += cpu;
8844 for (idx = 0; idx < phba->sli4_hba.num_present_cpu;
8845 idx++) {
8846 if (cpup->phys_id == i) {
8847 /*
8848 * Save any IO channels that are
8849 * already mapped to this phys_id.
8850 */
8851 if (cpup->irq != LPFC_VECTOR_MAP_EMPTY) {
James Smart6690e0d2015-12-16 18:11:56 -05008852 if (saved_chann <=
8853 LPFC_FCP_IO_CHAN_MAX) {
8854 chann[saved_chann] =
8855 cpup->channel_id;
8856 saved_chann++;
8857 }
James Smart7bb03bb2013-04-17 20:19:16 -04008858 goto out;
8859 }
8860
8861 /* See if we are using round-robin */
8862 if (saved_chann == 0)
8863 saved_chann =
8864 phba->cfg_fcp_io_channel;
8865
8866 /* Associate next IO channel with CPU */
8867 cpup->channel_id = chann[used_chann];
8868 num_io_channel++;
8869 used_chann++;
8870 if (used_chann == saved_chann)
8871 used_chann = 0;
8872
8873 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8874 "3331 Set IO_CHANN "
8875 "CPU %d channel %d\n",
8876 idx, cpup->channel_id);
8877 }
8878out:
8879 cpu++;
8880 if (cpu >= phba->sli4_hba.num_present_cpu) {
8881 cpup = phba->sli4_hba.cpu_map;
8882 cpu = 0;
8883 } else {
8884 cpup++;
8885 }
8886 }
8887 }
8888
8889 if (phba->sli4_hba.num_online_cpu != phba->sli4_hba.num_present_cpu) {
8890 cpup = phba->sli4_hba.cpu_map;
8891 for (idx = 0; idx < phba->sli4_hba.num_present_cpu; idx++) {
8892 if (cpup->channel_id == LPFC_VECTOR_MAP_EMPTY) {
8893 cpup->channel_id = 0;
8894 num_io_channel++;
8895
8896 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8897 "3332 Assign IO_CHANN "
8898 "CPU %d channel %d\n",
8899 idx, cpup->channel_id);
8900 }
8901 cpup++;
8902 }
8903 }
8904
8905 /* Sanity check */
8906 if (num_io_channel != phba->sli4_hba.num_present_cpu)
8907 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8908 "3333 Set affinity mismatch:"
James Smartec2087a2013-09-06 12:20:36 -04008909 "%d chann != %d cpus: %d vectors\n",
James Smart7bb03bb2013-04-17 20:19:16 -04008910 num_io_channel, phba->sli4_hba.num_present_cpu,
8911 vectors);
8912
James Smartec2087a2013-09-06 12:20:36 -04008913 /* Enable using cpu affinity for scheduling */
James Smart7bb03bb2013-04-17 20:19:16 -04008914 phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_BY_CPU;
8915 return 1;
8916}
8917
8918
8919/**
James Smartda0436e2009-05-22 14:51:39 -04008920 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
8921 * @phba: pointer to lpfc hba data structure.
8922 *
8923 * This routine is invoked to enable the MSI-X interrupt vectors to device
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008924 * with SLI-4 interface spec. The kernel function pci_enable_msix_range()
8925 * is called to enable the MSI-X vectors. The device driver is responsible
8926 * for calling the individual request_irq() to register each MSI-X vector
8927 * with a interrupt handler, which is done in this function. Note that
8928 * later when device is unloading, the driver should always call free_irq()
8929 * on all MSI-X vectors it has done request_irq() on before calling
8930 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
8931 * will be left with MSI-X enabled and leaks its vectors.
James Smartda0436e2009-05-22 14:51:39 -04008932 *
8933 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008934 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008935 * other values - error
8936 **/
8937static int
8938lpfc_sli4_enable_msix(struct lpfc_hba *phba)
8939{
James Smart75baf692010-06-08 18:31:21 -04008940 int vectors, rc, index;
James Smartda0436e2009-05-22 14:51:39 -04008941
8942 /* Set up MSI-X multi-message vectors */
James Smart82c3e9b2012-09-29 11:29:50 -04008943 for (index = 0; index < phba->cfg_fcp_io_channel; index++)
James Smartda0436e2009-05-22 14:51:39 -04008944 phba->sli4_hba.msix_entries[index].entry = index;
8945
8946 /* Configure MSI-X capability structure */
James Smart82c3e9b2012-09-29 11:29:50 -04008947 vectors = phba->cfg_fcp_io_channel;
James Smart1ba981f2014-02-20 09:56:45 -05008948 if (phba->cfg_fof) {
8949 phba->sli4_hba.msix_entries[index].entry = index;
8950 vectors++;
8951 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008952 rc = pci_enable_msix_range(phba->pcidev, phba->sli4_hba.msix_entries,
8953 2, vectors);
8954 if (rc < 0) {
James Smartda0436e2009-05-22 14:51:39 -04008955 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8956 "0484 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02008957 goto vec_fail_out;
James Smartda0436e2009-05-22 14:51:39 -04008958 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008959 vectors = rc;
James Smart75baf692010-06-08 18:31:21 -04008960
James Smartda0436e2009-05-22 14:51:39 -04008961 /* Log MSI-X vector assignment */
James Smart75baf692010-06-08 18:31:21 -04008962 for (index = 0; index < vectors; index++)
James Smartda0436e2009-05-22 14:51:39 -04008963 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8964 "0489 MSI-X entry[%d]: vector=x%x "
8965 "message=%d\n", index,
8966 phba->sli4_hba.msix_entries[index].vector,
8967 phba->sli4_hba.msix_entries[index].entry);
James Smart67d12732012-08-03 12:36:13 -04008968
James Smart7bb03bb2013-04-17 20:19:16 -04008969 /* Assign MSI-X vectors to interrupt handlers */
James Smart67d12732012-08-03 12:36:13 -04008970 for (index = 0; index < vectors; index++) {
James Smart4305f182012-08-03 12:36:33 -04008971 memset(&phba->sli4_hba.handler_name[index], 0, 16);
James Smarta2fc4aef2014-09-03 12:57:55 -04008972 snprintf((char *)&phba->sli4_hba.handler_name[index],
8973 LPFC_SLI4_HANDLER_NAME_SZ,
James Smart4305f182012-08-03 12:36:33 -04008974 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -04008975
James Smart67d12732012-08-03 12:36:13 -04008976 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
8977 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
James Smartba20c852012-08-03 12:36:52 -04008978 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].fcp_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -05008979 if (phba->cfg_fof && (index == (vectors - 1)))
8980 rc = request_irq(
8981 phba->sli4_hba.msix_entries[index].vector,
James Smarted243d32015-05-21 13:55:25 -04008982 &lpfc_sli4_fof_intr_handler, 0,
James Smart1ba981f2014-02-20 09:56:45 -05008983 (char *)&phba->sli4_hba.handler_name[index],
8984 &phba->sli4_hba.fcp_eq_hdl[index]);
8985 else
8986 rc = request_irq(
8987 phba->sli4_hba.msix_entries[index].vector,
James Smarted243d32015-05-21 13:55:25 -04008988 &lpfc_sli4_hba_intr_handler, 0,
James Smart4305f182012-08-03 12:36:33 -04008989 (char *)&phba->sli4_hba.handler_name[index],
James Smart67d12732012-08-03 12:36:13 -04008990 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -04008991 if (rc) {
8992 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8993 "0486 MSI-X fast-path (%d) "
8994 "request_irq failed (%d)\n", index, rc);
8995 goto cfg_fail_out;
8996 }
8997 }
8998
James Smart1ba981f2014-02-20 09:56:45 -05008999 if (phba->cfg_fof)
9000 vectors--;
9001
James Smart82c3e9b2012-09-29 11:29:50 -04009002 if (vectors != phba->cfg_fcp_io_channel) {
9003 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9004 "3238 Reducing IO channels to match number of "
9005 "MSI-X vectors, requested %d got %d\n",
9006 phba->cfg_fcp_io_channel, vectors);
9007 phba->cfg_fcp_io_channel = vectors;
9008 }
James Smart7bb03bb2013-04-17 20:19:16 -04009009
James Smart8b0dff12015-05-22 10:42:38 -04009010 if (!shost_use_blk_mq(lpfc_shost_from_vport(phba->pport)))
9011 lpfc_sli4_set_affinity(phba, vectors);
James Smartda0436e2009-05-22 14:51:39 -04009012 return rc;
9013
9014cfg_fail_out:
9015 /* free the irq already requested */
James Smartacbd8612013-09-06 12:21:19 -04009016 for (--index; index >= 0; index--) {
9017 irq_set_affinity_hint(phba->sli4_hba.msix_entries[index].
9018 vector, NULL);
James Smart67d12732012-08-03 12:36:13 -04009019 free_irq(phba->sli4_hba.msix_entries[index].vector,
9020 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartacbd8612013-09-06 12:21:19 -04009021 }
James Smartda0436e2009-05-22 14:51:39 -04009022
James Smartda0436e2009-05-22 14:51:39 -04009023 /* Unconfigure MSI-X capability structure */
9024 pci_disable_msix(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009025
9026vec_fail_out:
James Smartda0436e2009-05-22 14:51:39 -04009027 return rc;
9028}
9029
9030/**
9031 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
9032 * @phba: pointer to lpfc hba data structure.
9033 *
9034 * This routine is invoked to release the MSI-X vectors and then disable the
9035 * MSI-X interrupt mode to device with SLI-4 interface spec.
9036 **/
9037static void
9038lpfc_sli4_disable_msix(struct lpfc_hba *phba)
9039{
9040 int index;
9041
9042 /* Free up MSI-X multi-message vectors */
James Smartacbd8612013-09-06 12:21:19 -04009043 for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
9044 irq_set_affinity_hint(phba->sli4_hba.msix_entries[index].
9045 vector, NULL);
James Smartda0436e2009-05-22 14:51:39 -04009046 free_irq(phba->sli4_hba.msix_entries[index].vector,
James Smart67d12732012-08-03 12:36:13 -04009047 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartacbd8612013-09-06 12:21:19 -04009048 }
James Smart1ba981f2014-02-20 09:56:45 -05009049 if (phba->cfg_fof) {
9050 free_irq(phba->sli4_hba.msix_entries[index].vector,
9051 &phba->sli4_hba.fcp_eq_hdl[index]);
9052 }
James Smartda0436e2009-05-22 14:51:39 -04009053 /* Disable MSI-X */
9054 pci_disable_msix(phba->pcidev);
9055
9056 return;
9057}
9058
9059/**
9060 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
9061 * @phba: pointer to lpfc hba data structure.
9062 *
9063 * This routine is invoked to enable the MSI interrupt mode to device with
9064 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
9065 * to enable the MSI vector. The device driver is responsible for calling
9066 * the request_irq() to register MSI vector with a interrupt the handler,
9067 * which is done in this function.
9068 *
9069 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009070 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009071 * other values - error
9072 **/
9073static int
9074lpfc_sli4_enable_msi(struct lpfc_hba *phba)
9075{
9076 int rc, index;
9077
9078 rc = pci_enable_msi(phba->pcidev);
9079 if (!rc)
9080 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9081 "0487 PCI enable MSI mode success.\n");
9082 else {
9083 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9084 "0488 PCI enable MSI mode failed (%d)\n", rc);
9085 return rc;
9086 }
9087
9088 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04009089 0, LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -04009090 if (rc) {
9091 pci_disable_msi(phba->pcidev);
9092 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9093 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -04009094 return rc;
James Smartda0436e2009-05-22 14:51:39 -04009095 }
9096
James Smart67d12732012-08-03 12:36:13 -04009097 for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
James Smartda0436e2009-05-22 14:51:39 -04009098 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9099 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9100 }
9101
James Smart1ba981f2014-02-20 09:56:45 -05009102 if (phba->cfg_fof) {
9103 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9104 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9105 }
James Smart75baf692010-06-08 18:31:21 -04009106 return 0;
James Smartda0436e2009-05-22 14:51:39 -04009107}
9108
9109/**
9110 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
9111 * @phba: pointer to lpfc hba data structure.
9112 *
9113 * This routine is invoked to disable the MSI interrupt mode to device with
9114 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
9115 * done request_irq() on before calling pci_disable_msi(). Failure to do so
9116 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
9117 * its vector.
9118 **/
9119static void
9120lpfc_sli4_disable_msi(struct lpfc_hba *phba)
9121{
9122 free_irq(phba->pcidev->irq, phba);
9123 pci_disable_msi(phba->pcidev);
9124 return;
9125}
9126
9127/**
9128 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
9129 * @phba: pointer to lpfc hba data structure.
9130 *
9131 * This routine is invoked to enable device interrupt and associate driver's
9132 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
9133 * interface spec. Depends on the interrupt mode configured to the driver,
9134 * the driver will try to fallback from the configured interrupt mode to an
9135 * interrupt mode which is supported by the platform, kernel, and device in
9136 * the order of:
9137 * MSI-X -> MSI -> IRQ.
9138 *
9139 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009140 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009141 * other values - error
9142 **/
9143static uint32_t
9144lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9145{
9146 uint32_t intr_mode = LPFC_INTR_ERROR;
9147 int retval, index;
9148
9149 if (cfg_mode == 2) {
9150 /* Preparation before conf_msi mbox cmd */
9151 retval = 0;
9152 if (!retval) {
9153 /* Now, try to enable MSI-X interrupt mode */
9154 retval = lpfc_sli4_enable_msix(phba);
9155 if (!retval) {
9156 /* Indicate initialization to MSI-X mode */
9157 phba->intr_type = MSIX;
9158 intr_mode = 2;
9159 }
9160 }
9161 }
9162
9163 /* Fallback to MSI if MSI-X initialization failed */
9164 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9165 retval = lpfc_sli4_enable_msi(phba);
9166 if (!retval) {
9167 /* Indicate initialization to MSI mode */
9168 phba->intr_type = MSI;
9169 intr_mode = 1;
9170 }
9171 }
9172
9173 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9174 if (phba->intr_type == NONE) {
9175 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
9176 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9177 if (!retval) {
9178 /* Indicate initialization to INTx mode */
9179 phba->intr_type = INTx;
9180 intr_mode = 0;
James Smart67d12732012-08-03 12:36:13 -04009181 for (index = 0; index < phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04009182 index++) {
9183 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9184 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
James Smartba20c852012-08-03 12:36:52 -04009185 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
9186 fcp_eq_in_use, 1);
James Smartda0436e2009-05-22 14:51:39 -04009187 }
James Smart1ba981f2014-02-20 09:56:45 -05009188 if (phba->cfg_fof) {
9189 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9190 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9191 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
9192 fcp_eq_in_use, 1);
9193 }
James Smartda0436e2009-05-22 14:51:39 -04009194 }
9195 }
9196 return intr_mode;
9197}
9198
9199/**
9200 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
9201 * @phba: pointer to lpfc hba data structure.
9202 *
9203 * This routine is invoked to disable device interrupt and disassociate
9204 * the driver's interrupt handler(s) from interrupt vector(s) to device
9205 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
9206 * will release the interrupt vector(s) for the message signaled interrupt.
9207 **/
9208static void
9209lpfc_sli4_disable_intr(struct lpfc_hba *phba)
9210{
9211 /* Disable the currently initialized interrupt mode */
9212 if (phba->intr_type == MSIX)
9213 lpfc_sli4_disable_msix(phba);
9214 else if (phba->intr_type == MSI)
9215 lpfc_sli4_disable_msi(phba);
9216 else if (phba->intr_type == INTx)
9217 free_irq(phba->pcidev->irq, phba);
9218
9219 /* Reset interrupt management states */
9220 phba->intr_type = NONE;
9221 phba->sli.slistat.sli_intr = 0;
9222
9223 return;
9224}
9225
9226/**
James Smart3772a992009-05-22 14:50:54 -04009227 * lpfc_unset_hba - Unset SLI3 hba device initialization
9228 * @phba: pointer to lpfc hba data structure.
9229 *
9230 * This routine is invoked to unset the HBA device initialization steps to
9231 * a device with SLI-3 interface spec.
9232 **/
9233static void
9234lpfc_unset_hba(struct lpfc_hba *phba)
9235{
9236 struct lpfc_vport *vport = phba->pport;
9237 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9238
9239 spin_lock_irq(shost->host_lock);
9240 vport->load_flag |= FC_UNLOADING;
9241 spin_unlock_irq(shost->host_lock);
9242
James Smart72859902012-01-18 16:25:38 -05009243 kfree(phba->vpi_bmask);
9244 kfree(phba->vpi_ids);
9245
James Smart3772a992009-05-22 14:50:54 -04009246 lpfc_stop_hba_timers(phba);
9247
9248 phba->pport->work_port_events = 0;
9249
9250 lpfc_sli_hba_down(phba);
9251
9252 lpfc_sli_brdrestart(phba);
9253
9254 lpfc_sli_disable_intr(phba);
9255
9256 return;
9257}
9258
9259/**
James Smart5af5eee2010-10-22 11:06:38 -04009260 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
9261 * @phba: Pointer to HBA context object.
9262 *
9263 * This function is called in the SLI4 code path to wait for completion
9264 * of device's XRIs exchange busy. It will check the XRI exchange busy
9265 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
9266 * that, it will check the XRI exchange busy on outstanding FCP and ELS
9267 * I/Os every 30 seconds, log error message, and wait forever. Only when
9268 * all XRI exchange busy complete, the driver unload shall proceed with
9269 * invoking the function reset ioctl mailbox command to the CNA and the
9270 * the rest of the driver unload resource release.
9271 **/
9272static void
9273lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
9274{
9275 int wait_time = 0;
9276 int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
9277 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9278
9279 while (!fcp_xri_cmpl || !els_xri_cmpl) {
9280 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
9281 if (!fcp_xri_cmpl)
9282 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9283 "2877 FCP XRI exchange busy "
9284 "wait time: %d seconds.\n",
9285 wait_time/1000);
9286 if (!els_xri_cmpl)
9287 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9288 "2878 ELS XRI exchange busy "
9289 "wait time: %d seconds.\n",
9290 wait_time/1000);
9291 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
9292 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
9293 } else {
9294 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
9295 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
9296 }
9297 fcp_xri_cmpl =
9298 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
9299 els_xri_cmpl =
9300 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9301 }
9302}
9303
9304/**
James Smartda0436e2009-05-22 14:51:39 -04009305 * lpfc_sli4_hba_unset - Unset the fcoe hba
9306 * @phba: Pointer to HBA context object.
9307 *
9308 * This function is called in the SLI4 code path to reset the HBA's FCoE
9309 * function. The caller is not required to hold any lock. This routine
9310 * issues PCI function reset mailbox command to reset the FCoE function.
9311 * At the end of the function, it calls lpfc_hba_down_post function to
9312 * free any pending commands.
9313 **/
9314static void
9315lpfc_sli4_hba_unset(struct lpfc_hba *phba)
9316{
9317 int wait_cnt = 0;
9318 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -04009319 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -04009320
9321 lpfc_stop_hba_timers(phba);
9322 phba->sli4_hba.intr_enable = 0;
9323
9324 /*
9325 * Gracefully wait out the potential current outstanding asynchronous
9326 * mailbox command.
9327 */
9328
9329 /* First, block any pending async mailbox command from posted */
9330 spin_lock_irq(&phba->hbalock);
9331 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
9332 spin_unlock_irq(&phba->hbalock);
9333 /* Now, trying to wait it out if we can */
9334 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9335 msleep(10);
9336 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
9337 break;
9338 }
9339 /* Forcefully release the outstanding mailbox command if timed out */
9340 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9341 spin_lock_irq(&phba->hbalock);
9342 mboxq = phba->sli.mbox_active;
9343 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
9344 __lpfc_mbox_cmpl_put(phba, mboxq);
9345 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9346 phba->sli.mbox_active = NULL;
9347 spin_unlock_irq(&phba->hbalock);
9348 }
9349
James Smart5af5eee2010-10-22 11:06:38 -04009350 /* Abort all iocbs associated with the hba */
9351 lpfc_sli_hba_iocb_abort(phba);
9352
9353 /* Wait for completion of device XRI exchange busy */
9354 lpfc_sli4_xri_exchange_busy_wait(phba);
9355
James Smartda0436e2009-05-22 14:51:39 -04009356 /* Disable PCI subsystem interrupt */
9357 lpfc_sli4_disable_intr(phba);
9358
James Smart912e3ac2011-05-24 11:42:11 -04009359 /* Disable SR-IOV if enabled */
9360 if (phba->cfg_sriov_nr_virtfn)
9361 pci_disable_sriov(pdev);
9362
James Smartda0436e2009-05-22 14:51:39 -04009363 /* Stop kthread signal shall trigger work_done one more time */
9364 kthread_stop(phba->worker_thread);
9365
James Smart3677a3a2010-09-29 11:19:14 -04009366 /* Reset SLI4 HBA FCoE function */
9367 lpfc_pci_function_reset(phba);
James Smart5350d872011-10-10 21:33:49 -04009368 lpfc_sli4_queue_destroy(phba);
James Smart3677a3a2010-09-29 11:19:14 -04009369
James Smartda0436e2009-05-22 14:51:39 -04009370 /* Stop the SLI4 device port */
9371 phba->pport->work_port_events = 0;
9372}
9373
James Smart28baac72010-02-12 14:42:03 -05009374 /**
9375 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
9376 * @phba: Pointer to HBA context object.
9377 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9378 *
9379 * This function is called in the SLI4 code path to read the port's
9380 * sli4 capabilities.
9381 *
9382 * This function may be be called from any context that can block-wait
9383 * for the completion. The expectation is that this routine is called
9384 * typically from probe_one or from the online routine.
9385 **/
9386int
9387lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9388{
9389 int rc;
9390 struct lpfc_mqe *mqe;
9391 struct lpfc_pc_sli4_params *sli4_params;
9392 uint32_t mbox_tmo;
9393
9394 rc = 0;
9395 mqe = &mboxq->u.mqe;
9396
9397 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -05009398 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -05009399 if (!phba->sli4_hba.intr_enable)
9400 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9401 else {
James Smarta183a152011-10-10 21:32:43 -04009402 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -05009403 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
9404 }
9405
9406 if (unlikely(rc))
9407 return 1;
9408
9409 sli4_params = &phba->sli4_hba.pc_sli4_params;
9410 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
9411 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
9412 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
9413 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
9414 &mqe->un.sli4_params);
9415 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
9416 &mqe->un.sli4_params);
9417 sli4_params->proto_types = mqe->un.sli4_params.word3;
9418 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
9419 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
9420 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
9421 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
9422 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
9423 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
9424 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
9425 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
9426 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
9427 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
9428 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
9429 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
9430 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
9431 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
9432 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
9433 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
9434 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
9435 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
9436 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
9437 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -04009438
9439 /* Make sure that sge_supp_len can be handled by the driver */
9440 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
9441 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
9442
James Smart28baac72010-02-12 14:42:03 -05009443 return rc;
9444}
9445
James Smartda0436e2009-05-22 14:51:39 -04009446/**
James Smartfedd3b72011-02-16 12:39:24 -05009447 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
9448 * @phba: Pointer to HBA context object.
9449 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9450 *
9451 * This function is called in the SLI4 code path to read the port's
9452 * sli4 capabilities.
9453 *
9454 * This function may be be called from any context that can block-wait
9455 * for the completion. The expectation is that this routine is called
9456 * typically from probe_one or from the online routine.
9457 **/
9458int
9459lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9460{
9461 int rc;
9462 struct lpfc_mqe *mqe = &mboxq->u.mqe;
9463 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -04009464 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -05009465 int length;
9466 struct lpfc_sli4_parameters *mbx_sli4_parameters;
9467
James Smart6d368e52011-05-24 11:44:12 -04009468 /*
9469 * By default, the driver assumes the SLI4 port requires RPI
9470 * header postings. The SLI4_PARAM response will correct this
9471 * assumption.
9472 */
9473 phba->sli4_hba.rpi_hdrs_in_use = 1;
9474
James Smartfedd3b72011-02-16 12:39:24 -05009475 /* Read the port's SLI4 Config Parameters */
9476 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
9477 sizeof(struct lpfc_sli4_cfg_mhdr));
9478 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9479 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
9480 length, LPFC_SLI4_MBX_EMBED);
9481 if (!phba->sli4_hba.intr_enable)
9482 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -04009483 else {
9484 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
9485 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
9486 }
James Smartfedd3b72011-02-16 12:39:24 -05009487 if (unlikely(rc))
9488 return rc;
9489 sli4_params = &phba->sli4_hba.pc_sli4_params;
9490 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
9491 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
9492 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
9493 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
9494 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
9495 mbx_sli4_parameters);
9496 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
9497 mbx_sli4_parameters);
9498 if (bf_get(cfg_phwq, mbx_sli4_parameters))
9499 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
9500 else
9501 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
9502 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
9503 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
James Smart1ba981f2014-02-20 09:56:45 -05009504 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -05009505 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
9506 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
9507 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
9508 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
James Smart0c651872013-07-15 18:33:23 -04009509 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -05009510 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
9511 mbx_sli4_parameters);
9512 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
9513 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -04009514 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
9515 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart05580562011-05-24 11:40:48 -04009516
9517 /* Make sure that sge_supp_len can be handled by the driver */
9518 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
9519 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
9520
James Smartb5c53952016-03-31 14:12:30 -07009521 /*
9522 * Issue IOs with CDB embedded in WQE to minimized the number
9523 * of DMAs the firmware has to do. Setting this to 1 also forces
9524 * the driver to use 128 bytes WQEs for FCP IOs.
9525 */
9526 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
9527 phba->fcp_embed_io = 1;
9528 else
9529 phba->fcp_embed_io = 0;
James Smartfedd3b72011-02-16 12:39:24 -05009530 return 0;
9531}
9532
9533/**
James Smart3772a992009-05-22 14:50:54 -04009534 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
9535 * @pdev: pointer to PCI device
9536 * @pid: pointer to PCI device identifier
9537 *
9538 * This routine is to be called to attach a device with SLI-3 interface spec
9539 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9540 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
9541 * information of the device and driver to see if the driver state that it can
9542 * support this kind of device. If the match is successful, the driver core
9543 * invokes this routine. If this routine determines it can claim the HBA, it
9544 * does all the initialization that it needs to do to handle the HBA properly.
9545 *
9546 * Return code
9547 * 0 - driver can claim the device
9548 * negative value - driver can not claim the device
9549 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009550static int
James Smart3772a992009-05-22 14:50:54 -04009551lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
9552{
9553 struct lpfc_hba *phba;
9554 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -04009555 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -04009556 int error;
9557 uint32_t cfg_mode, intr_mode;
9558
9559 /* Allocate memory for HBA structure */
9560 phba = lpfc_hba_alloc(pdev);
9561 if (!phba)
9562 return -ENOMEM;
9563
9564 /* Perform generic PCI device enabling operation */
9565 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -04009566 if (error)
James Smart3772a992009-05-22 14:50:54 -04009567 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -04009568
9569 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
9570 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
9571 if (error)
9572 goto out_disable_pci_dev;
9573
9574 /* Set up SLI-3 specific device PCI memory space */
9575 error = lpfc_sli_pci_mem_setup(phba);
9576 if (error) {
9577 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9578 "1402 Failed to set up pci memory space.\n");
9579 goto out_disable_pci_dev;
9580 }
9581
9582 /* Set up phase-1 common device driver resources */
9583 error = lpfc_setup_driver_resource_phase1(phba);
9584 if (error) {
9585 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9586 "1403 Failed to set up driver resource.\n");
9587 goto out_unset_pci_mem_s3;
9588 }
9589
9590 /* Set up SLI-3 specific device driver resources */
9591 error = lpfc_sli_driver_resource_setup(phba);
9592 if (error) {
9593 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9594 "1404 Failed to set up driver resource.\n");
9595 goto out_unset_pci_mem_s3;
9596 }
9597
9598 /* Initialize and populate the iocb list per host */
9599 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
9600 if (error) {
9601 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9602 "1405 Failed to initialize iocb list.\n");
9603 goto out_unset_driver_resource_s3;
9604 }
9605
9606 /* Set up common device driver resources */
9607 error = lpfc_setup_driver_resource_phase2(phba);
9608 if (error) {
9609 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9610 "1406 Failed to set up driver resource.\n");
9611 goto out_free_iocb_list;
9612 }
9613
James Smart079b5c92011-08-21 21:48:49 -04009614 /* Get the default values for Model Name and Description */
9615 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
9616
James Smart3772a992009-05-22 14:50:54 -04009617 /* Create SCSI host to the physical port */
9618 error = lpfc_create_shost(phba);
9619 if (error) {
9620 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9621 "1407 Failed to create scsi host.\n");
9622 goto out_unset_driver_resource;
9623 }
9624
9625 /* Configure sysfs attributes */
9626 vport = phba->pport;
9627 error = lpfc_alloc_sysfs_attr(vport);
9628 if (error) {
9629 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9630 "1476 Failed to allocate sysfs attr\n");
9631 goto out_destroy_shost;
9632 }
9633
James Smart6669f9b2009-10-02 15:16:45 -04009634 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -04009635 /* Now, trying to enable interrupt and bring up the device */
9636 cfg_mode = phba->cfg_use_msi;
9637 while (true) {
9638 /* Put device to a known state before enabling interrupt */
9639 lpfc_stop_port(phba);
9640 /* Configure and enable interrupt */
9641 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
9642 if (intr_mode == LPFC_INTR_ERROR) {
9643 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9644 "0431 Failed to enable interrupt.\n");
9645 error = -ENODEV;
9646 goto out_free_sysfs_attr;
9647 }
9648 /* SLI-3 HBA setup */
9649 if (lpfc_sli_hba_setup(phba)) {
9650 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9651 "1477 Failed to set up hba\n");
9652 error = -ENODEV;
9653 goto out_remove_device;
9654 }
9655
9656 /* Wait 50ms for the interrupts of previous mailbox commands */
9657 msleep(50);
9658 /* Check active interrupts on message signaled interrupts */
9659 if (intr_mode == 0 ||
9660 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
9661 /* Log the current active interrupt mode */
9662 phba->intr_mode = intr_mode;
9663 lpfc_log_intr_mode(phba, intr_mode);
9664 break;
9665 } else {
9666 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9667 "0447 Configure interrupt mode (%d) "
9668 "failed active interrupt test.\n",
9669 intr_mode);
9670 /* Disable the current interrupt mode */
9671 lpfc_sli_disable_intr(phba);
9672 /* Try next level of interrupt mode */
9673 cfg_mode = --intr_mode;
9674 }
9675 }
9676
9677 /* Perform post initialization setup */
9678 lpfc_post_init_setup(phba);
9679
9680 /* Check if there are static vports to be created. */
9681 lpfc_create_static_vport(phba);
9682
9683 return 0;
9684
9685out_remove_device:
9686 lpfc_unset_hba(phba);
9687out_free_sysfs_attr:
9688 lpfc_free_sysfs_attr(vport);
9689out_destroy_shost:
9690 lpfc_destroy_shost(phba);
9691out_unset_driver_resource:
9692 lpfc_unset_driver_resource_phase2(phba);
9693out_free_iocb_list:
9694 lpfc_free_iocb_list(phba);
9695out_unset_driver_resource_s3:
9696 lpfc_sli_driver_resource_unset(phba);
9697out_unset_pci_mem_s3:
9698 lpfc_sli_pci_mem_unset(phba);
9699out_disable_pci_dev:
9700 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -04009701 if (shost)
9702 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -04009703out_free_phba:
9704 lpfc_hba_free(phba);
9705 return error;
9706}
9707
9708/**
9709 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -04009710 * @pdev: pointer to PCI device
9711 *
James Smart3772a992009-05-22 14:50:54 -04009712 * This routine is to be called to disattach a device with SLI-3 interface
9713 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9714 * removed from PCI bus, it performs all the necessary cleanup for the HBA
9715 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -04009716 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009717static void
James Smart3772a992009-05-22 14:50:54 -04009718lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -05009719{
James Smart2e0fef82007-06-17 19:56:36 -05009720 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9721 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -05009722 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -05009723 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -05009724 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05009725 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
9726
James Smart549e55c2007-08-02 11:09:51 -04009727 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04009728 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04009729 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05009730
James Smart858c9f62007-06-17 19:56:39 -05009731 lpfc_free_sysfs_attr(vport);
9732
James Smarteada2722008-12-04 22:39:13 -05009733 /* Release all the vports against this physical port */
9734 vports = lpfc_create_vport_work_array(phba);
9735 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -04009736 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9737 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
9738 continue;
James Smarteada2722008-12-04 22:39:13 -05009739 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -04009740 }
James Smarteada2722008-12-04 22:39:13 -05009741 lpfc_destroy_vport_work_array(phba, vports);
9742
9743 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -05009744 fc_remove_host(shost);
9745 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04009746 lpfc_cleanup(vport);
9747
James Smart2e0fef82007-06-17 19:56:36 -05009748 /*
9749 * Bring down the SLI Layer. This step disable all interrupts,
9750 * clears the rings, discards all mailbox commands, and resets
9751 * the HBA.
9752 */
James Smarta257bf92009-04-06 18:48:10 -04009753
Justin P. Mattock48e34d02010-12-30 15:07:58 -08009754 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -05009755 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -04009756 /* Stop kthread signal shall trigger work_done one more time */
9757 kthread_stop(phba->worker_thread);
9758 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -05009759 lpfc_sli_brdrestart(phba);
9760
James Smart72859902012-01-18 16:25:38 -05009761 kfree(phba->vpi_bmask);
9762 kfree(phba->vpi_ids);
9763
James Smart3772a992009-05-22 14:50:54 -04009764 lpfc_stop_hba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05009765 spin_lock_irq(&phba->hbalock);
9766 list_del_init(&vport->listentry);
9767 spin_unlock_irq(&phba->hbalock);
9768
James Smart858c9f62007-06-17 19:56:39 -05009769 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05009770
James Smart912e3ac2011-05-24 11:42:11 -04009771 /* Disable SR-IOV if enabled */
9772 if (phba->cfg_sriov_nr_virtfn)
9773 pci_disable_sriov(pdev);
9774
James Smart5b75da22008-12-04 22:39:35 -05009775 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009776 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -05009777
James Smart858c9f62007-06-17 19:56:39 -05009778 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05009779
9780 /*
9781 * Call scsi_free before mem_free since scsi bufs are released to their
9782 * corresponding pools here.
9783 */
9784 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -04009785 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -05009786
James Smart34b02dc2008-08-24 21:49:55 -04009787 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
9788 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -05009789
James Smart2e0fef82007-06-17 19:56:36 -05009790 /* Free resources associated with SLI2 interface */
9791 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -04009792 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -05009793
9794 /* unmap adapter SLIM and Control Registers */
9795 iounmap(phba->ctrl_regs_memmap_p);
9796 iounmap(phba->slim_memmap_p);
9797
James Smart3772a992009-05-22 14:50:54 -04009798 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -05009799
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05009800 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05009801 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05009802}
9803
Linas Vepstas8d63f372007-02-14 14:28:36 -06009804/**
James Smart3772a992009-05-22 14:50:54 -04009805 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05009806 * @pdev: pointer to PCI device
9807 * @msg: power management message
9808 *
James Smart3772a992009-05-22 14:50:54 -04009809 * This routine is to be called from the kernel's PCI subsystem to support
9810 * system Power Management (PM) to device with SLI-3 interface spec. When
9811 * PM invokes this method, it quiesces the device by stopping the driver's
9812 * worker thread for the device, turning off device's interrupt and DMA,
9813 * and bring the device offline. Note that as the driver implements the
9814 * minimum PM requirements to a power-aware driver's PM support for the
9815 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
9816 * to the suspend() method call will be treated as SUSPEND and the driver will
9817 * fully reinitialize its device during resume() method call, the driver will
9818 * set device to PCI_D3hot state in PCI config space instead of setting it
9819 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -05009820 *
9821 * Return code
James Smart3772a992009-05-22 14:50:54 -04009822 * 0 - driver suspended the device
9823 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05009824 **/
9825static int
James Smart3772a992009-05-22 14:50:54 -04009826lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -05009827{
9828 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9829 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9830
9831 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9832 "0473 PCI device Power Management suspend.\n");
9833
9834 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -04009835 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -05009836 lpfc_offline(phba);
9837 kthread_stop(phba->worker_thread);
9838
9839 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -04009840 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -05009841
9842 /* Save device state to PCI config space */
9843 pci_save_state(pdev);
9844 pci_set_power_state(pdev, PCI_D3hot);
9845
9846 return 0;
9847}
9848
9849/**
James Smart3772a992009-05-22 14:50:54 -04009850 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05009851 * @pdev: pointer to PCI device
9852 *
James Smart3772a992009-05-22 14:50:54 -04009853 * This routine is to be called from the kernel's PCI subsystem to support
9854 * system Power Management (PM) to device with SLI-3 interface spec. When PM
9855 * invokes this method, it restores the device's PCI config space state and
9856 * fully reinitializes the device and brings it online. Note that as the
9857 * driver implements the minimum PM requirements to a power-aware driver's
9858 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
9859 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
9860 * driver will fully reinitialize its device during resume() method call,
9861 * the device will be set to PCI_D0 directly in PCI config space before
9862 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -05009863 *
9864 * Return code
James Smart3772a992009-05-22 14:50:54 -04009865 * 0 - driver suspended the device
9866 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05009867 **/
9868static int
James Smart3772a992009-05-22 14:50:54 -04009869lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -05009870{
9871 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9872 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -05009873 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05009874 int error;
9875
9876 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9877 "0452 PCI device Power Management resume.\n");
9878
9879 /* Restore device state from PCI config space */
9880 pci_set_power_state(pdev, PCI_D0);
9881 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -04009882
James Smart1dfb5a42010-02-12 14:40:50 -05009883 /*
9884 * As the new kernel behavior of pci_restore_state() API call clears
9885 * device saved_state flag, need to save the restored state again.
9886 */
9887 pci_save_state(pdev);
9888
James Smart3a55b532008-12-04 22:38:54 -05009889 if (pdev->is_busmaster)
9890 pci_set_master(pdev);
9891
9892 /* Startup the kernel thread for this host adapter. */
9893 phba->worker_thread = kthread_run(lpfc_do_work, phba,
9894 "lpfc_worker_%d", phba->brd_no);
9895 if (IS_ERR(phba->worker_thread)) {
9896 error = PTR_ERR(phba->worker_thread);
9897 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9898 "0434 PM resume failed to start worker "
9899 "thread: error=x%x.\n", error);
9900 return error;
9901 }
9902
James Smart5b75da22008-12-04 22:39:35 -05009903 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009904 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05009905 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -05009906 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -05009907 "0430 PM resume Failed to enable interrupt\n");
9908 return -EIO;
9909 } else
9910 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05009911
9912 /* Restart HBA and bring it online */
9913 lpfc_sli_brdrestart(phba);
9914 lpfc_online(phba);
9915
James Smart5b75da22008-12-04 22:39:35 -05009916 /* Log the current active interrupt mode */
9917 lpfc_log_intr_mode(phba, phba->intr_mode);
9918
James Smart3a55b532008-12-04 22:38:54 -05009919 return 0;
9920}
9921
9922/**
James Smart891478a2009-11-18 15:40:23 -05009923 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
9924 * @phba: pointer to lpfc hba data structure.
9925 *
9926 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -04009927 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -05009928 **/
9929static void
9930lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
9931{
9932 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9933 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -04009934
9935 /*
9936 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
9937 * and let the SCSI mid-layer to retry them to recover.
9938 */
James Smartdb55fba2014-04-04 13:52:02 -04009939 lpfc_sli_abort_fcp_rings(phba);
James Smart891478a2009-11-18 15:40:23 -05009940}
9941
9942/**
James Smart0d878412009-10-02 15:16:56 -04009943 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
9944 * @phba: pointer to lpfc hba data structure.
9945 *
9946 * This routine is called to prepare the SLI3 device for PCI slot reset. It
9947 * disables the device interrupt and pci device, and aborts the internal FCP
9948 * pending I/Os.
9949 **/
9950static void
9951lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
9952{
James Smart0d878412009-10-02 15:16:56 -04009953 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -05009954 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -04009955
James Smart75baf692010-06-08 18:31:21 -04009956 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -04009957 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -04009958
James Smarte2af0d22010-03-15 11:25:32 -04009959 /* Block all SCSI devices' I/Os on the host */
9960 lpfc_scsi_dev_block(phba);
9961
James Smartea714f32013-04-17 20:18:47 -04009962 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9963 lpfc_sli_flush_fcp_rings(phba);
9964
James Smarte2af0d22010-03-15 11:25:32 -04009965 /* stop all timers */
9966 lpfc_stop_hba_timers(phba);
9967
James Smart0d878412009-10-02 15:16:56 -04009968 /* Disable interrupt and pci device */
9969 lpfc_sli_disable_intr(phba);
9970 pci_disable_device(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -04009971}
9972
9973/**
9974 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
9975 * @phba: pointer to lpfc hba data structure.
9976 *
9977 * This routine is called to prepare the SLI3 device for PCI slot permanently
9978 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
9979 * pending I/Os.
9980 **/
9981static void
James Smart75baf692010-06-08 18:31:21 -04009982lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -04009983{
9984 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -05009985 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -04009986 /* Block all SCSI devices' I/Os on the host */
9987 lpfc_scsi_dev_block(phba);
9988
9989 /* stop all timers */
9990 lpfc_stop_hba_timers(phba);
9991
James Smart0d878412009-10-02 15:16:56 -04009992 /* Clean up all driver's outstanding SCSI I/Os */
9993 lpfc_sli_flush_fcp_rings(phba);
9994}
9995
9996/**
James Smart3772a992009-05-22 14:50:54 -04009997 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -04009998 * @pdev: pointer to PCI device.
9999 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010000 *
James Smart3772a992009-05-22 14:50:54 -040010001 * This routine is called from the PCI subsystem for I/O error handling to
10002 * device with SLI-3 interface spec. This function is called by the PCI
10003 * subsystem after a PCI bus error affecting this device has been detected.
10004 * When this function is invoked, it will need to stop all the I/Os and
10005 * interrupt(s) to the device. Once that is done, it will return
10006 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
10007 * as desired.
James Smarte59058c2008-08-24 21:49:00 -040010008 *
10009 * Return codes
James Smart0d878412009-10-02 15:16:56 -040010010 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -040010011 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10012 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -040010013 **/
James Smart3772a992009-05-22 14:50:54 -040010014static pci_ers_result_t
10015lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010016{
James Smart51ef4c22007-08-02 11:10:31 -040010017 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10018 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010019
James Smart0d878412009-10-02 15:16:56 -040010020 switch (state) {
10021 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -050010022 /* Non-fatal error, prepare for recovery */
10023 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -040010024 return PCI_ERS_RESULT_CAN_RECOVER;
10025 case pci_channel_io_frozen:
10026 /* Fatal error, prepare for slot reset */
10027 lpfc_sli_prep_dev_for_reset(phba);
10028 return PCI_ERS_RESULT_NEED_RESET;
10029 case pci_channel_io_perm_failure:
10030 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -040010031 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010032 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -040010033 default:
10034 /* Unknown state, prepare and request slot reset */
10035 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10036 "0472 Unknown PCI error state: x%x\n", state);
10037 lpfc_sli_prep_dev_for_reset(phba);
10038 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -040010039 }
Linas Vepstas8d63f372007-02-14 14:28:36 -060010040}
10041
10042/**
James Smart3772a992009-05-22 14:50:54 -040010043 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -040010044 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010045 *
James Smart3772a992009-05-22 14:50:54 -040010046 * This routine is called from the PCI subsystem for error handling to
10047 * device with SLI-3 interface spec. This is called after PCI bus has been
10048 * reset to restart the PCI card from scratch, as if from a cold-boot.
10049 * During the PCI subsystem error recovery, after driver returns
10050 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10051 * recovery and then call this routine before calling the .resume method
10052 * to recover the device. This function will initialize the HBA device,
10053 * enable the interrupt, but it will just put the HBA to offline state
10054 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -040010055 *
10056 * Return codes
James Smart3772a992009-05-22 14:50:54 -040010057 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10058 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -060010059 */
James Smart3772a992009-05-22 14:50:54 -040010060static pci_ers_result_t
10061lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010062{
James Smart51ef4c22007-08-02 11:10:31 -040010063 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10064 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010065 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -050010066 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010067
10068 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +110010069 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -060010070 printk(KERN_ERR "lpfc: Cannot re-enable "
10071 "PCI device after reset.\n");
10072 return PCI_ERS_RESULT_DISCONNECT;
10073 }
10074
James Smart97207482008-12-04 22:39:19 -050010075 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050010076
10077 /*
10078 * As the new kernel behavior of pci_restore_state() API call clears
10079 * device saved_state flag, need to save the restored state again.
10080 */
10081 pci_save_state(pdev);
10082
James Smart97207482008-12-04 22:39:19 -050010083 if (pdev->is_busmaster)
10084 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010085
James Smart92d7f7b2007-06-17 19:56:38 -050010086 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040010087 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -050010088 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010089
James Smart5b75da22008-12-04 22:39:35 -050010090 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040010091 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050010092 if (intr_mode == LPFC_INTR_ERROR) {
10093 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10094 "0427 Cannot re-enable interrupt after "
10095 "slot reset.\n");
10096 return PCI_ERS_RESULT_DISCONNECT;
10097 } else
10098 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010099
James Smart75baf692010-06-08 18:31:21 -040010100 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -040010101 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010102 lpfc_offline(phba);
10103 lpfc_sli_brdrestart(phba);
10104
James Smart5b75da22008-12-04 22:39:35 -050010105 /* Log the current active interrupt mode */
10106 lpfc_log_intr_mode(phba, phba->intr_mode);
10107
Linas Vepstas8d63f372007-02-14 14:28:36 -060010108 return PCI_ERS_RESULT_RECOVERED;
10109}
10110
10111/**
James Smart3772a992009-05-22 14:50:54 -040010112 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -040010113 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -060010114 *
James Smart3772a992009-05-22 14:50:54 -040010115 * This routine is called from the PCI subsystem for error handling to device
10116 * with SLI-3 interface spec. It is called when kernel error recovery tells
10117 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10118 * error recovery. After this call, traffic can start to flow from this device
10119 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010120 */
James Smart3772a992009-05-22 14:50:54 -040010121static void
10122lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010123{
James Smart51ef4c22007-08-02 11:10:31 -040010124 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10125 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010126
James Smarte2af0d22010-03-15 11:25:32 -040010127 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -040010128 lpfc_online(phba);
James Smart0d878412009-10-02 15:16:56 -040010129
10130 /* Clean up Advanced Error Reporting (AER) if needed */
10131 if (phba->hba_flag & HBA_AER_ENABLED)
10132 pci_cleanup_aer_uncorrect_error_status(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010133}
10134
James Smart3772a992009-05-22 14:50:54 -040010135/**
James Smartda0436e2009-05-22 14:51:39 -040010136 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
10137 * @phba: pointer to lpfc hba data structure.
10138 *
10139 * returns the number of ELS/CT IOCBs to reserve
10140 **/
10141int
10142lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
10143{
10144 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
10145
James Smartf1126682009-06-10 17:22:44 -040010146 if (phba->sli_rev == LPFC_SLI_REV4) {
10147 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -040010148 return 10;
James Smartf1126682009-06-10 17:22:44 -040010149 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -040010150 return 25;
James Smartf1126682009-06-10 17:22:44 -040010151 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -040010152 return 50;
James Smartf1126682009-06-10 17:22:44 -040010153 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -040010154 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -040010155 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -040010156 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -040010157 else if (max_xri <= 2048)
10158 return 200;
10159 else
10160 return 250;
James Smartf1126682009-06-10 17:22:44 -040010161 } else
10162 return 0;
James Smartda0436e2009-05-22 14:51:39 -040010163}
10164
10165/**
James Smart52d52442011-05-24 11:42:45 -040010166 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -040010167 * @fw: pointer to firmware image returned from request_firmware.
James Smartce396282012-09-29 11:30:56 -040010168 * @phba: pointer to lpfc hba data structure.
James Smart52d52442011-05-24 11:42:45 -040010169 *
James Smart52d52442011-05-24 11:42:45 -040010170 **/
James Smartce396282012-09-29 11:30:56 -040010171static void
10172lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -040010173{
James Smartce396282012-09-29 11:30:56 -040010174 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -050010175 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -040010176 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -040010177 struct list_head dma_buffer_list;
10178 int i, rc = 0;
10179 struct lpfc_dmabuf *dmabuf, *next;
10180 uint32_t offset = 0, temp_offset = 0;
10181
James Smartc71ab862012-10-31 14:44:33 -040010182 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -040010183 if (!fw) {
10184 rc = -ENXIO;
10185 goto out;
10186 }
10187 image = (struct lpfc_grp_hdr *)fw->data;
10188
James Smart52d52442011-05-24 11:42:45 -040010189 INIT_LIST_HEAD(&dma_buffer_list);
James Smart079b5c92011-08-21 21:48:49 -040010190 if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) ||
10191 (bf_get_be32(lpfc_grp_hdr_file_type, image) !=
10192 LPFC_FILE_TYPE_GROUP) ||
10193 (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) ||
10194 (be32_to_cpu(image->size) != fw->size)) {
James Smart52d52442011-05-24 11:42:45 -040010195 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10196 "3022 Invalid FW image found. "
James Smart079b5c92011-08-21 21:48:49 -040010197 "Magic:%x Type:%x ID:%x\n",
10198 be32_to_cpu(image->magic_number),
10199 bf_get_be32(lpfc_grp_hdr_file_type, image),
10200 bf_get_be32(lpfc_grp_hdr_id, image));
James Smartce396282012-09-29 11:30:56 -040010201 rc = -EINVAL;
10202 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010203 }
10204 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -040010205 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -040010206 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartce396282012-09-29 11:30:56 -040010207 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -040010208 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -040010209 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -040010210 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
10211 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
10212 GFP_KERNEL);
10213 if (!dmabuf) {
10214 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040010215 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010216 }
10217 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
10218 SLI4_PAGE_SIZE,
10219 &dmabuf->phys,
10220 GFP_KERNEL);
10221 if (!dmabuf->virt) {
10222 kfree(dmabuf);
10223 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040010224 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010225 }
10226 list_add_tail(&dmabuf->list, &dma_buffer_list);
10227 }
10228 while (offset < fw->size) {
10229 temp_offset = offset;
10230 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -040010231 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -040010232 memcpy(dmabuf->virt,
10233 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -040010234 fw->size - temp_offset);
10235 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -040010236 break;
10237 }
James Smart52d52442011-05-24 11:42:45 -040010238 memcpy(dmabuf->virt, fw->data + temp_offset,
10239 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -040010240 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -040010241 }
10242 rc = lpfc_wr_object(phba, &dma_buffer_list,
10243 (fw->size - offset), &offset);
James Smartce396282012-09-29 11:30:56 -040010244 if (rc)
10245 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010246 }
10247 rc = offset;
10248 }
James Smartce396282012-09-29 11:30:56 -040010249
10250release_out:
James Smart52d52442011-05-24 11:42:45 -040010251 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
10252 list_del(&dmabuf->list);
10253 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
10254 dmabuf->virt, dmabuf->phys);
10255 kfree(dmabuf);
10256 }
James Smartce396282012-09-29 11:30:56 -040010257 release_firmware(fw);
10258out:
10259 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc71ab862012-10-31 14:44:33 -040010260 "3024 Firmware update done: %d.\n", rc);
James Smartce396282012-09-29 11:30:56 -040010261 return;
James Smart52d52442011-05-24 11:42:45 -040010262}
10263
10264/**
James Smartc71ab862012-10-31 14:44:33 -040010265 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
10266 * @phba: pointer to lpfc hba data structure.
10267 *
10268 * This routine is called to perform Linux generic firmware upgrade on device
10269 * that supports such feature.
10270 **/
10271int
10272lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
10273{
10274 uint8_t file_name[ELX_MODEL_NAME_SIZE];
10275 int ret;
10276 const struct firmware *fw;
10277
10278 /* Only supported on SLI4 interface type 2 for now */
10279 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
10280 LPFC_SLI_INTF_IF_TYPE_2)
10281 return -EPERM;
10282
10283 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
10284
10285 if (fw_upgrade == INT_FW_UPGRADE) {
10286 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
10287 file_name, &phba->pcidev->dev,
10288 GFP_KERNEL, (void *)phba,
10289 lpfc_write_firmware);
10290 } else if (fw_upgrade == RUN_FW_UPGRADE) {
10291 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
10292 if (!ret)
10293 lpfc_write_firmware(fw, (void *)phba);
10294 } else {
10295 ret = -EINVAL;
10296 }
10297
10298 return ret;
10299}
10300
10301/**
James Smartda0436e2009-05-22 14:51:39 -040010302 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
10303 * @pdev: pointer to PCI device
10304 * @pid: pointer to PCI device identifier
10305 *
10306 * This routine is called from the kernel's PCI subsystem to device with
10307 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10308 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10309 * information of the device and driver to see if the driver state that it
10310 * can support this kind of device. If the match is successful, the driver
10311 * core invokes this routine. If this routine determines it can claim the HBA,
10312 * it does all the initialization that it needs to do to handle the HBA
10313 * properly.
10314 *
10315 * Return code
10316 * 0 - driver can claim the device
10317 * negative value - driver can not claim the device
10318 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010319static int
James Smartda0436e2009-05-22 14:51:39 -040010320lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
10321{
10322 struct lpfc_hba *phba;
10323 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040010324 struct Scsi_Host *shost = NULL;
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040010325 int error;
James Smartda0436e2009-05-22 14:51:39 -040010326 uint32_t cfg_mode, intr_mode;
James Smart67d12732012-08-03 12:36:13 -040010327 int adjusted_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -040010328
10329 /* Allocate memory for HBA structure */
10330 phba = lpfc_hba_alloc(pdev);
10331 if (!phba)
10332 return -ENOMEM;
10333
10334 /* Perform generic PCI device enabling operation */
10335 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040010336 if (error)
James Smartda0436e2009-05-22 14:51:39 -040010337 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -040010338
10339 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
10340 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
10341 if (error)
10342 goto out_disable_pci_dev;
10343
10344 /* Set up SLI-4 specific device PCI memory space */
10345 error = lpfc_sli4_pci_mem_setup(phba);
10346 if (error) {
10347 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10348 "1410 Failed to set up pci memory space.\n");
10349 goto out_disable_pci_dev;
10350 }
10351
10352 /* Set up phase-1 common device driver resources */
10353 error = lpfc_setup_driver_resource_phase1(phba);
10354 if (error) {
10355 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10356 "1411 Failed to set up driver resource.\n");
10357 goto out_unset_pci_mem_s4;
10358 }
10359
10360 /* Set up SLI-4 Specific device driver resources */
10361 error = lpfc_sli4_driver_resource_setup(phba);
10362 if (error) {
10363 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10364 "1412 Failed to set up driver resource.\n");
10365 goto out_unset_pci_mem_s4;
10366 }
10367
10368 /* Initialize and populate the iocb list per host */
James Smart2a9bf3d2010-06-07 15:24:45 -040010369
10370 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10371 "2821 initialize iocb list %d.\n",
10372 phba->cfg_iocb_cnt*1024);
10373 error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
10374
James Smartda0436e2009-05-22 14:51:39 -040010375 if (error) {
10376 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10377 "1413 Failed to initialize iocb list.\n");
10378 goto out_unset_driver_resource_s4;
10379 }
10380
James Smart19ca7602010-11-20 23:11:55 -050010381 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -040010382 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -050010383
James Smartda0436e2009-05-22 14:51:39 -040010384 /* Set up common device driver resources */
10385 error = lpfc_setup_driver_resource_phase2(phba);
10386 if (error) {
10387 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10388 "1414 Failed to set up driver resource.\n");
10389 goto out_free_iocb_list;
10390 }
10391
James Smart079b5c92011-08-21 21:48:49 -040010392 /* Get the default values for Model Name and Description */
10393 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
10394
James Smartda0436e2009-05-22 14:51:39 -040010395 /* Create SCSI host to the physical port */
10396 error = lpfc_create_shost(phba);
10397 if (error) {
10398 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10399 "1415 Failed to create scsi host.\n");
10400 goto out_unset_driver_resource;
10401 }
10402
10403 /* Configure sysfs attributes */
10404 vport = phba->pport;
10405 error = lpfc_alloc_sysfs_attr(vport);
10406 if (error) {
10407 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10408 "1416 Failed to allocate sysfs attr\n");
10409 goto out_destroy_shost;
10410 }
10411
James Smart6669f9b2009-10-02 15:16:45 -040010412 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -040010413 /* Now, trying to enable interrupt and bring up the device */
10414 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -040010415
James Smart7b15db32013-01-03 15:43:29 -050010416 /* Put device to a known state before enabling interrupt */
10417 lpfc_stop_port(phba);
10418 /* Configure and enable interrupt */
10419 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
10420 if (intr_mode == LPFC_INTR_ERROR) {
10421 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10422 "0426 Failed to enable interrupt.\n");
10423 error = -ENODEV;
10424 goto out_free_sysfs_attr;
James Smartda0436e2009-05-22 14:51:39 -040010425 }
James Smart7b15db32013-01-03 15:43:29 -050010426 /* Default to single EQ for non-MSI-X */
10427 if (phba->intr_type != MSIX)
10428 adjusted_fcp_io_channel = 1;
10429 else
10430 adjusted_fcp_io_channel = phba->cfg_fcp_io_channel;
10431 phba->cfg_fcp_io_channel = adjusted_fcp_io_channel;
10432 /* Set up SLI-4 HBA */
10433 if (lpfc_sli4_hba_setup(phba)) {
10434 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10435 "1421 Failed to set up hba\n");
10436 error = -ENODEV;
10437 goto out_disable_intr;
10438 }
10439
10440 /* Log the current active interrupt mode */
10441 phba->intr_mode = intr_mode;
10442 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -040010443
10444 /* Perform post initialization setup */
10445 lpfc_post_init_setup(phba);
10446
James Smartc71ab862012-10-31 14:44:33 -040010447 /* check for firmware upgrade or downgrade */
10448 if (phba->cfg_request_firmware_upgrade)
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040010449 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -040010450
James Smart1c6834a2009-07-19 10:01:26 -040010451 /* Check if there are static vports to be created. */
10452 lpfc_create_static_vport(phba);
James Smartda0436e2009-05-22 14:51:39 -040010453 return 0;
10454
10455out_disable_intr:
10456 lpfc_sli4_disable_intr(phba);
10457out_free_sysfs_attr:
10458 lpfc_free_sysfs_attr(vport);
10459out_destroy_shost:
10460 lpfc_destroy_shost(phba);
10461out_unset_driver_resource:
10462 lpfc_unset_driver_resource_phase2(phba);
10463out_free_iocb_list:
10464 lpfc_free_iocb_list(phba);
10465out_unset_driver_resource_s4:
10466 lpfc_sli4_driver_resource_unset(phba);
10467out_unset_pci_mem_s4:
10468 lpfc_sli4_pci_mem_unset(phba);
10469out_disable_pci_dev:
10470 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040010471 if (shost)
10472 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -040010473out_free_phba:
10474 lpfc_hba_free(phba);
10475 return error;
10476}
10477
10478/**
10479 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
10480 * @pdev: pointer to PCI device
10481 *
10482 * This routine is called from the kernel's PCI subsystem to device with
10483 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10484 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10485 * device to be removed from the PCI subsystem properly.
10486 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010487static void
James Smartda0436e2009-05-22 14:51:39 -040010488lpfc_pci_remove_one_s4(struct pci_dev *pdev)
10489{
10490 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10491 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
10492 struct lpfc_vport **vports;
10493 struct lpfc_hba *phba = vport->phba;
10494 int i;
10495
10496 /* Mark the device unloading flag */
10497 spin_lock_irq(&phba->hbalock);
10498 vport->load_flag |= FC_UNLOADING;
10499 spin_unlock_irq(&phba->hbalock);
10500
10501 /* Free the HBA sysfs attributes */
10502 lpfc_free_sysfs_attr(vport);
10503
10504 /* Release all the vports against this physical port */
10505 vports = lpfc_create_vport_work_array(phba);
10506 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040010507 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10508 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
10509 continue;
James Smartda0436e2009-05-22 14:51:39 -040010510 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040010511 }
James Smartda0436e2009-05-22 14:51:39 -040010512 lpfc_destroy_vport_work_array(phba, vports);
10513
10514 /* Remove FC host and then SCSI host with the physical port */
10515 fc_remove_host(shost);
10516 scsi_remove_host(shost);
10517
10518 /* Perform cleanup on the physical port */
10519 lpfc_cleanup(vport);
10520
10521 /*
10522 * Bring down the SLI Layer. This step disables all interrupts,
10523 * clears the rings, discards all mailbox commands, and resets
10524 * the HBA FCoE function.
10525 */
10526 lpfc_debugfs_terminate(vport);
10527 lpfc_sli4_hba_unset(phba);
10528
10529 spin_lock_irq(&phba->hbalock);
10530 list_del_init(&vport->listentry);
10531 spin_unlock_irq(&phba->hbalock);
10532
James Smart3677a3a2010-09-29 11:19:14 -040010533 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -040010534 * buffers are released to their corresponding pools here.
10535 */
10536 lpfc_scsi_free(phba);
James Smart67d12732012-08-03 12:36:13 -040010537
James Smartda0436e2009-05-22 14:51:39 -040010538 lpfc_sli4_driver_resource_unset(phba);
10539
10540 /* Unmap adapter Control and Doorbell registers */
10541 lpfc_sli4_pci_mem_unset(phba);
10542
10543 /* Release PCI resources and disable device's PCI function */
10544 scsi_host_put(shost);
10545 lpfc_disable_pci_dev(phba);
10546
10547 /* Finally, free the driver's device data structure */
10548 lpfc_hba_free(phba);
10549
10550 return;
10551}
10552
10553/**
10554 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
10555 * @pdev: pointer to PCI device
10556 * @msg: power management message
10557 *
10558 * This routine is called from the kernel's PCI subsystem to support system
10559 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
10560 * this method, it quiesces the device by stopping the driver's worker
10561 * thread for the device, turning off device's interrupt and DMA, and bring
10562 * the device offline. Note that as the driver implements the minimum PM
10563 * requirements to a power-aware driver's PM support for suspend/resume -- all
10564 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
10565 * method call will be treated as SUSPEND and the driver will fully
10566 * reinitialize its device during resume() method call, the driver will set
10567 * device to PCI_D3hot state in PCI config space instead of setting it
10568 * according to the @msg provided by the PM.
10569 *
10570 * Return code
10571 * 0 - driver suspended the device
10572 * Error otherwise
10573 **/
10574static int
10575lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
10576{
10577 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10578 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10579
10580 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -040010581 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -040010582
10583 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040010584 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -040010585 lpfc_offline(phba);
10586 kthread_stop(phba->worker_thread);
10587
10588 /* Disable interrupt from device */
10589 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040010590 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040010591
10592 /* Save device state to PCI config space */
10593 pci_save_state(pdev);
10594 pci_set_power_state(pdev, PCI_D3hot);
10595
10596 return 0;
10597}
10598
10599/**
10600 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
10601 * @pdev: pointer to PCI device
10602 *
10603 * This routine is called from the kernel's PCI subsystem to support system
10604 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
10605 * this method, it restores the device's PCI config space state and fully
10606 * reinitializes the device and brings it online. Note that as the driver
10607 * implements the minimum PM requirements to a power-aware driver's PM for
10608 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10609 * to the suspend() method call will be treated as SUSPEND and the driver
10610 * will fully reinitialize its device during resume() method call, the device
10611 * will be set to PCI_D0 directly in PCI config space before restoring the
10612 * state.
10613 *
10614 * Return code
10615 * 0 - driver suspended the device
10616 * Error otherwise
10617 **/
10618static int
10619lpfc_pci_resume_one_s4(struct pci_dev *pdev)
10620{
10621 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10622 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10623 uint32_t intr_mode;
10624 int error;
10625
10626 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10627 "0292 PCI device Power Management resume.\n");
10628
10629 /* Restore device state from PCI config space */
10630 pci_set_power_state(pdev, PCI_D0);
10631 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050010632
10633 /*
10634 * As the new kernel behavior of pci_restore_state() API call clears
10635 * device saved_state flag, need to save the restored state again.
10636 */
10637 pci_save_state(pdev);
10638
James Smartda0436e2009-05-22 14:51:39 -040010639 if (pdev->is_busmaster)
10640 pci_set_master(pdev);
10641
10642 /* Startup the kernel thread for this host adapter. */
10643 phba->worker_thread = kthread_run(lpfc_do_work, phba,
10644 "lpfc_worker_%d", phba->brd_no);
10645 if (IS_ERR(phba->worker_thread)) {
10646 error = PTR_ERR(phba->worker_thread);
10647 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10648 "0293 PM resume failed to start worker "
10649 "thread: error=x%x.\n", error);
10650 return error;
10651 }
10652
10653 /* Configure and enable interrupt */
10654 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
10655 if (intr_mode == LPFC_INTR_ERROR) {
10656 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10657 "0294 PM resume Failed to enable interrupt\n");
10658 return -EIO;
10659 } else
10660 phba->intr_mode = intr_mode;
10661
10662 /* Restart HBA and bring it online */
10663 lpfc_sli_brdrestart(phba);
10664 lpfc_online(phba);
10665
10666 /* Log the current active interrupt mode */
10667 lpfc_log_intr_mode(phba, phba->intr_mode);
10668
10669 return 0;
10670}
10671
10672/**
James Smart75baf692010-06-08 18:31:21 -040010673 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
10674 * @phba: pointer to lpfc hba data structure.
10675 *
10676 * This routine is called to prepare the SLI4 device for PCI slot recover. It
10677 * aborts all the outstanding SCSI I/Os to the pci device.
10678 **/
10679static void
10680lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
10681{
James Smart75baf692010-06-08 18:31:21 -040010682 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10683 "2828 PCI channel I/O abort preparing for recovery\n");
10684 /*
10685 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10686 * and let the SCSI mid-layer to retry them to recover.
10687 */
James Smartdb55fba2014-04-04 13:52:02 -040010688 lpfc_sli_abort_fcp_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040010689}
10690
10691/**
10692 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
10693 * @phba: pointer to lpfc hba data structure.
10694 *
10695 * This routine is called to prepare the SLI4 device for PCI slot reset. It
10696 * disables the device interrupt and pci device, and aborts the internal FCP
10697 * pending I/Os.
10698 **/
10699static void
10700lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
10701{
10702 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10703 "2826 PCI channel disable preparing for reset\n");
10704
10705 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040010706 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010707
10708 /* Block all SCSI devices' I/Os on the host */
10709 lpfc_scsi_dev_block(phba);
10710
James Smartea714f32013-04-17 20:18:47 -040010711 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10712 lpfc_sli_flush_fcp_rings(phba);
10713
James Smart75baf692010-06-08 18:31:21 -040010714 /* stop all timers */
10715 lpfc_stop_hba_timers(phba);
10716
10717 /* Disable interrupt and pci device */
10718 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040010719 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -040010720 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -040010721}
10722
10723/**
10724 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
10725 * @phba: pointer to lpfc hba data structure.
10726 *
10727 * This routine is called to prepare the SLI4 device for PCI slot permanently
10728 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10729 * pending I/Os.
10730 **/
10731static void
10732lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
10733{
10734 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10735 "2827 PCI channel permanent disable for failure\n");
10736
10737 /* Block all SCSI devices' I/Os on the host */
10738 lpfc_scsi_dev_block(phba);
10739
10740 /* stop all timers */
10741 lpfc_stop_hba_timers(phba);
10742
10743 /* Clean up all driver's outstanding SCSI I/Os */
10744 lpfc_sli_flush_fcp_rings(phba);
10745}
10746
10747/**
James Smartda0436e2009-05-22 14:51:39 -040010748 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
10749 * @pdev: pointer to PCI device.
10750 * @state: the current PCI connection state.
10751 *
10752 * This routine is called from the PCI subsystem for error handling to device
10753 * with SLI-4 interface spec. This function is called by the PCI subsystem
10754 * after a PCI bus error affecting this device has been detected. When this
10755 * function is invoked, it will need to stop all the I/Os and interrupt(s)
10756 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
10757 * for the PCI subsystem to perform proper recovery as desired.
10758 *
10759 * Return codes
10760 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10761 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10762 **/
10763static pci_ers_result_t
10764lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
10765{
James Smart75baf692010-06-08 18:31:21 -040010766 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10767 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10768
10769 switch (state) {
10770 case pci_channel_io_normal:
10771 /* Non-fatal error, prepare for recovery */
10772 lpfc_sli4_prep_dev_for_recover(phba);
10773 return PCI_ERS_RESULT_CAN_RECOVER;
10774 case pci_channel_io_frozen:
10775 /* Fatal error, prepare for slot reset */
10776 lpfc_sli4_prep_dev_for_reset(phba);
10777 return PCI_ERS_RESULT_NEED_RESET;
10778 case pci_channel_io_perm_failure:
10779 /* Permanent failure, prepare for device down */
10780 lpfc_sli4_prep_dev_for_perm_failure(phba);
10781 return PCI_ERS_RESULT_DISCONNECT;
10782 default:
10783 /* Unknown state, prepare and request slot reset */
10784 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10785 "2825 Unknown PCI error state: x%x\n", state);
10786 lpfc_sli4_prep_dev_for_reset(phba);
10787 return PCI_ERS_RESULT_NEED_RESET;
10788 }
James Smartda0436e2009-05-22 14:51:39 -040010789}
10790
10791/**
10792 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
10793 * @pdev: pointer to PCI device.
10794 *
10795 * This routine is called from the PCI subsystem for error handling to device
10796 * with SLI-4 interface spec. It is called after PCI bus has been reset to
10797 * restart the PCI card from scratch, as if from a cold-boot. During the
10798 * PCI subsystem error recovery, after the driver returns
10799 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10800 * recovery and then call this routine before calling the .resume method to
10801 * recover the device. This function will initialize the HBA device, enable
10802 * the interrupt, but it will just put the HBA to offline state without
10803 * passing any I/O traffic.
10804 *
10805 * Return codes
10806 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10807 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10808 */
10809static pci_ers_result_t
10810lpfc_io_slot_reset_s4(struct pci_dev *pdev)
10811{
James Smart75baf692010-06-08 18:31:21 -040010812 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10813 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10814 struct lpfc_sli *psli = &phba->sli;
10815 uint32_t intr_mode;
10816
10817 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
10818 if (pci_enable_device_mem(pdev)) {
10819 printk(KERN_ERR "lpfc: Cannot re-enable "
10820 "PCI device after reset.\n");
10821 return PCI_ERS_RESULT_DISCONNECT;
10822 }
10823
10824 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040010825
10826 /*
10827 * As the new kernel behavior of pci_restore_state() API call clears
10828 * device saved_state flag, need to save the restored state again.
10829 */
10830 pci_save_state(pdev);
10831
James Smart75baf692010-06-08 18:31:21 -040010832 if (pdev->is_busmaster)
10833 pci_set_master(pdev);
10834
10835 spin_lock_irq(&phba->hbalock);
10836 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
10837 spin_unlock_irq(&phba->hbalock);
10838
10839 /* Configure and enable interrupt */
10840 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
10841 if (intr_mode == LPFC_INTR_ERROR) {
10842 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10843 "2824 Cannot re-enable interrupt after "
10844 "slot reset.\n");
10845 return PCI_ERS_RESULT_DISCONNECT;
10846 } else
10847 phba->intr_mode = intr_mode;
10848
10849 /* Log the current active interrupt mode */
10850 lpfc_log_intr_mode(phba, phba->intr_mode);
10851
James Smartda0436e2009-05-22 14:51:39 -040010852 return PCI_ERS_RESULT_RECOVERED;
10853}
10854
10855/**
10856 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
10857 * @pdev: pointer to PCI device
10858 *
10859 * This routine is called from the PCI subsystem for error handling to device
10860 * with SLI-4 interface spec. It is called when kernel error recovery tells
10861 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10862 * error recovery. After this call, traffic can start to flow from this device
10863 * again.
10864 **/
10865static void
10866lpfc_io_resume_s4(struct pci_dev *pdev)
10867{
James Smart75baf692010-06-08 18:31:21 -040010868 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10869 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10870
10871 /*
10872 * In case of slot reset, as function reset is performed through
10873 * mailbox command which needs DMA to be enabled, this operation
10874 * has to be moved to the io resume phase. Taking device offline
10875 * will perform the necessary cleanup.
10876 */
10877 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
10878 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040010879 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010880 lpfc_offline(phba);
10881 lpfc_sli_brdrestart(phba);
10882 /* Bring the device back online */
10883 lpfc_online(phba);
10884 }
10885
10886 /* Clean up Advanced Error Reporting (AER) if needed */
10887 if (phba->hba_flag & HBA_AER_ENABLED)
10888 pci_cleanup_aer_uncorrect_error_status(pdev);
James Smartda0436e2009-05-22 14:51:39 -040010889}
10890
10891/**
James Smart3772a992009-05-22 14:50:54 -040010892 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
10893 * @pdev: pointer to PCI device
10894 * @pid: pointer to PCI device identifier
10895 *
10896 * This routine is to be registered to the kernel's PCI subsystem. When an
10897 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
10898 * at PCI device-specific information of the device and driver to see if the
10899 * driver state that it can support this kind of device. If the match is
10900 * successful, the driver core invokes this routine. This routine dispatches
10901 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
10902 * do all the initialization that it needs to do to handle the HBA device
10903 * properly.
10904 *
10905 * Return code
10906 * 0 - driver can claim the device
10907 * negative value - driver can not claim the device
10908 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010909static int
James Smart3772a992009-05-22 14:50:54 -040010910lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
10911{
10912 int rc;
James Smart8fa38512009-07-19 10:01:03 -040010913 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040010914
James Smart28baac72010-02-12 14:42:03 -050010915 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040010916 return -ENODEV;
10917
James Smart8fa38512009-07-19 10:01:03 -040010918 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050010919 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040010920 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040010921 else
James Smart3772a992009-05-22 14:50:54 -040010922 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040010923
James Smart3772a992009-05-22 14:50:54 -040010924 return rc;
10925}
10926
10927/**
10928 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
10929 * @pdev: pointer to PCI device
10930 *
10931 * This routine is to be registered to the kernel's PCI subsystem. When an
10932 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
10933 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
10934 * remove routine, which will perform all the necessary cleanup for the
10935 * device to be removed from the PCI subsystem properly.
10936 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010937static void
James Smart3772a992009-05-22 14:50:54 -040010938lpfc_pci_remove_one(struct pci_dev *pdev)
10939{
10940 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10941 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10942
10943 switch (phba->pci_dev_grp) {
10944 case LPFC_PCI_DEV_LP:
10945 lpfc_pci_remove_one_s3(pdev);
10946 break;
James Smartda0436e2009-05-22 14:51:39 -040010947 case LPFC_PCI_DEV_OC:
10948 lpfc_pci_remove_one_s4(pdev);
10949 break;
James Smart3772a992009-05-22 14:50:54 -040010950 default:
10951 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10952 "1424 Invalid PCI device group: 0x%x\n",
10953 phba->pci_dev_grp);
10954 break;
10955 }
10956 return;
10957}
10958
10959/**
10960 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
10961 * @pdev: pointer to PCI device
10962 * @msg: power management message
10963 *
10964 * This routine is to be registered to the kernel's PCI subsystem to support
10965 * system Power Management (PM). When PM invokes this method, it dispatches
10966 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
10967 * suspend the device.
10968 *
10969 * Return code
10970 * 0 - driver suspended the device
10971 * Error otherwise
10972 **/
10973static int
10974lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
10975{
10976 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10977 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10978 int rc = -ENODEV;
10979
10980 switch (phba->pci_dev_grp) {
10981 case LPFC_PCI_DEV_LP:
10982 rc = lpfc_pci_suspend_one_s3(pdev, msg);
10983 break;
James Smartda0436e2009-05-22 14:51:39 -040010984 case LPFC_PCI_DEV_OC:
10985 rc = lpfc_pci_suspend_one_s4(pdev, msg);
10986 break;
James Smart3772a992009-05-22 14:50:54 -040010987 default:
10988 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10989 "1425 Invalid PCI device group: 0x%x\n",
10990 phba->pci_dev_grp);
10991 break;
10992 }
10993 return rc;
10994}
10995
10996/**
10997 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
10998 * @pdev: pointer to PCI device
10999 *
11000 * This routine is to be registered to the kernel's PCI subsystem to support
11001 * system Power Management (PM). When PM invokes this method, it dispatches
11002 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
11003 * resume the device.
11004 *
11005 * Return code
11006 * 0 - driver suspended the device
11007 * Error otherwise
11008 **/
11009static int
11010lpfc_pci_resume_one(struct pci_dev *pdev)
11011{
11012 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11013 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11014 int rc = -ENODEV;
11015
11016 switch (phba->pci_dev_grp) {
11017 case LPFC_PCI_DEV_LP:
11018 rc = lpfc_pci_resume_one_s3(pdev);
11019 break;
James Smartda0436e2009-05-22 14:51:39 -040011020 case LPFC_PCI_DEV_OC:
11021 rc = lpfc_pci_resume_one_s4(pdev);
11022 break;
James Smart3772a992009-05-22 14:50:54 -040011023 default:
11024 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11025 "1426 Invalid PCI device group: 0x%x\n",
11026 phba->pci_dev_grp);
11027 break;
11028 }
11029 return rc;
11030}
11031
11032/**
11033 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
11034 * @pdev: pointer to PCI device.
11035 * @state: the current PCI connection state.
11036 *
11037 * This routine is registered to the PCI subsystem for error handling. This
11038 * function is called by the PCI subsystem after a PCI bus error affecting
11039 * this device has been detected. When this routine is invoked, it dispatches
11040 * the action to the proper SLI-3 or SLI-4 device error detected handling
11041 * routine, which will perform the proper error detected operation.
11042 *
11043 * Return codes
11044 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11045 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11046 **/
11047static pci_ers_result_t
11048lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
11049{
11050 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11051 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11052 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11053
11054 switch (phba->pci_dev_grp) {
11055 case LPFC_PCI_DEV_LP:
11056 rc = lpfc_io_error_detected_s3(pdev, state);
11057 break;
James Smartda0436e2009-05-22 14:51:39 -040011058 case LPFC_PCI_DEV_OC:
11059 rc = lpfc_io_error_detected_s4(pdev, state);
11060 break;
James Smart3772a992009-05-22 14:50:54 -040011061 default:
11062 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11063 "1427 Invalid PCI device group: 0x%x\n",
11064 phba->pci_dev_grp);
11065 break;
11066 }
11067 return rc;
11068}
11069
11070/**
11071 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
11072 * @pdev: pointer to PCI device.
11073 *
11074 * This routine is registered to the PCI subsystem for error handling. This
11075 * function is called after PCI bus has been reset to restart the PCI card
11076 * from scratch, as if from a cold-boot. When this routine is invoked, it
11077 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
11078 * routine, which will perform the proper device reset.
11079 *
11080 * Return codes
11081 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11082 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11083 **/
11084static pci_ers_result_t
11085lpfc_io_slot_reset(struct pci_dev *pdev)
11086{
11087 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11088 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11089 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11090
11091 switch (phba->pci_dev_grp) {
11092 case LPFC_PCI_DEV_LP:
11093 rc = lpfc_io_slot_reset_s3(pdev);
11094 break;
James Smartda0436e2009-05-22 14:51:39 -040011095 case LPFC_PCI_DEV_OC:
11096 rc = lpfc_io_slot_reset_s4(pdev);
11097 break;
James Smart3772a992009-05-22 14:50:54 -040011098 default:
11099 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11100 "1428 Invalid PCI device group: 0x%x\n",
11101 phba->pci_dev_grp);
11102 break;
11103 }
11104 return rc;
11105}
11106
11107/**
11108 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
11109 * @pdev: pointer to PCI device
11110 *
11111 * This routine is registered to the PCI subsystem for error handling. It
11112 * is called when kernel error recovery tells the lpfc driver that it is
11113 * OK to resume normal PCI operation after PCI bus error recovery. When
11114 * this routine is invoked, it dispatches the action to the proper SLI-3
11115 * or SLI-4 device io_resume routine, which will resume the device operation.
11116 **/
11117static void
11118lpfc_io_resume(struct pci_dev *pdev)
11119{
11120 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11121 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11122
11123 switch (phba->pci_dev_grp) {
11124 case LPFC_PCI_DEV_LP:
11125 lpfc_io_resume_s3(pdev);
11126 break;
James Smartda0436e2009-05-22 14:51:39 -040011127 case LPFC_PCI_DEV_OC:
11128 lpfc_io_resume_s4(pdev);
11129 break;
James Smart3772a992009-05-22 14:50:54 -040011130 default:
11131 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11132 "1429 Invalid PCI device group: 0x%x\n",
11133 phba->pci_dev_grp);
11134 break;
11135 }
11136 return;
11137}
11138
James Smart1ba981f2014-02-20 09:56:45 -050011139/**
11140 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
11141 * @phba: pointer to lpfc hba data structure.
11142 *
11143 * This routine checks to see if OAS is supported for this adapter. If
11144 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
11145 * the enable oas flag is cleared and the pool created for OAS device data
11146 * is destroyed.
11147 *
11148 **/
11149void
11150lpfc_sli4_oas_verify(struct lpfc_hba *phba)
11151{
11152
11153 if (!phba->cfg_EnableXLane)
11154 return;
11155
11156 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
11157 phba->cfg_fof = 1;
11158 } else {
James Smartf38fa0b2014-04-04 13:52:21 -040011159 phba->cfg_fof = 0;
James Smart1ba981f2014-02-20 09:56:45 -050011160 if (phba->device_data_mem_pool)
11161 mempool_destroy(phba->device_data_mem_pool);
11162 phba->device_data_mem_pool = NULL;
11163 }
11164
11165 return;
11166}
11167
11168/**
11169 * lpfc_fof_queue_setup - Set up all the fof queues
11170 * @phba: pointer to lpfc hba data structure.
11171 *
11172 * This routine is invoked to set up all the fof queues for the FC HBA
11173 * operation.
11174 *
11175 * Return codes
11176 * 0 - successful
11177 * -ENOMEM - No available memory
11178 **/
11179int
11180lpfc_fof_queue_setup(struct lpfc_hba *phba)
11181{
11182 struct lpfc_sli *psli = &phba->sli;
11183 int rc;
11184
11185 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
11186 if (rc)
11187 return -ENOMEM;
11188
James Smartf38fa0b2014-04-04 13:52:21 -040011189 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050011190
11191 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
11192 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
11193 if (rc)
11194 goto out_oas_cq;
11195
11196 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
11197 phba->sli4_hba.oas_cq, LPFC_FCP);
11198 if (rc)
11199 goto out_oas_wq;
11200
11201 phba->sli4_hba.oas_cq->pring = &psli->ring[LPFC_FCP_OAS_RING];
11202 phba->sli4_hba.oas_ring = &psli->ring[LPFC_FCP_OAS_RING];
11203 }
11204
11205 return 0;
11206
11207out_oas_wq:
James Smartf38fa0b2014-04-04 13:52:21 -040011208 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
James Smart1ba981f2014-02-20 09:56:45 -050011209out_oas_cq:
11210 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
11211 return rc;
11212
11213}
11214
11215/**
11216 * lpfc_fof_queue_create - Create all the fof queues
11217 * @phba: pointer to lpfc hba data structure.
11218 *
11219 * This routine is invoked to allocate all the fof queues for the FC HBA
11220 * operation. For each SLI4 queue type, the parameters such as queue entry
11221 * count (queue depth) shall be taken from the module parameter. For now,
11222 * we just use some constant number as place holder.
11223 *
11224 * Return codes
11225 * 0 - successful
11226 * -ENOMEM - No availble memory
11227 * -EIO - The mailbox failed to complete successfully.
11228 **/
11229int
11230lpfc_fof_queue_create(struct lpfc_hba *phba)
11231{
11232 struct lpfc_queue *qdesc;
11233
11234 /* Create FOF EQ */
11235 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
11236 phba->sli4_hba.eq_ecount);
11237 if (!qdesc)
11238 goto out_error;
11239
11240 phba->sli4_hba.fof_eq = qdesc;
11241
James Smartf38fa0b2014-04-04 13:52:21 -040011242 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050011243
11244 /* Create OAS CQ */
11245 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
11246 phba->sli4_hba.cq_ecount);
11247 if (!qdesc)
11248 goto out_error;
11249
11250 phba->sli4_hba.oas_cq = qdesc;
11251
11252 /* Create OAS WQ */
11253 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
11254 phba->sli4_hba.wq_ecount);
11255 if (!qdesc)
11256 goto out_error;
11257
11258 phba->sli4_hba.oas_wq = qdesc;
11259
11260 }
11261 return 0;
11262
11263out_error:
11264 lpfc_fof_queue_destroy(phba);
11265 return -ENOMEM;
11266}
11267
11268/**
11269 * lpfc_fof_queue_destroy - Destroy all the fof queues
11270 * @phba: pointer to lpfc hba data structure.
11271 *
11272 * This routine is invoked to release all the SLI4 queues with the FC HBA
11273 * operation.
11274 *
11275 * Return codes
11276 * 0 - successful
11277 **/
11278int
11279lpfc_fof_queue_destroy(struct lpfc_hba *phba)
11280{
11281 /* Release FOF Event queue */
11282 if (phba->sli4_hba.fof_eq != NULL) {
11283 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
11284 phba->sli4_hba.fof_eq = NULL;
11285 }
11286
11287 /* Release OAS Completion queue */
11288 if (phba->sli4_hba.oas_cq != NULL) {
11289 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
11290 phba->sli4_hba.oas_cq = NULL;
11291 }
11292
11293 /* Release OAS Work queue */
11294 if (phba->sli4_hba.oas_wq != NULL) {
11295 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
11296 phba->sli4_hba.oas_wq = NULL;
11297 }
11298 return 0;
11299}
11300
dea31012005-04-17 16:05:31 -050011301static struct pci_device_id lpfc_id_table[] = {
11302 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
11303 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -040011304 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
11305 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011306 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
11307 PCI_ANY_ID, PCI_ANY_ID, },
11308 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
11309 PCI_ANY_ID, PCI_ANY_ID, },
11310 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
11311 PCI_ANY_ID, PCI_ANY_ID, },
11312 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
11313 PCI_ANY_ID, PCI_ANY_ID, },
11314 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
11315 PCI_ANY_ID, PCI_ANY_ID, },
11316 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
11317 PCI_ANY_ID, PCI_ANY_ID, },
11318 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
11319 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011320 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
11321 PCI_ANY_ID, PCI_ANY_ID, },
11322 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
11323 PCI_ANY_ID, PCI_ANY_ID, },
11324 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
11325 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011326 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
11327 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011328 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
11329 PCI_ANY_ID, PCI_ANY_ID, },
11330 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
11331 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011332 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
11333 PCI_ANY_ID, PCI_ANY_ID, },
11334 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
11335 PCI_ANY_ID, PCI_ANY_ID, },
11336 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
11337 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -040011338 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
11339 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011340 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
11341 PCI_ANY_ID, PCI_ANY_ID, },
11342 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
11343 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011344 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
11345 PCI_ANY_ID, PCI_ANY_ID, },
11346 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
11347 PCI_ANY_ID, PCI_ANY_ID, },
11348 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
11349 PCI_ANY_ID, PCI_ANY_ID, },
11350 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
11351 PCI_ANY_ID, PCI_ANY_ID, },
11352 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
11353 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011354 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
11355 PCI_ANY_ID, PCI_ANY_ID, },
11356 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
11357 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -040011358 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
11359 PCI_ANY_ID, PCI_ANY_ID, },
11360 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
11361 PCI_ANY_ID, PCI_ANY_ID, },
11362 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
11363 PCI_ANY_ID, PCI_ANY_ID, },
11364 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
11365 PCI_ANY_ID, PCI_ANY_ID, },
11366 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
11367 PCI_ANY_ID, PCI_ANY_ID, },
11368 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
11369 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -040011370 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
11371 PCI_ANY_ID, PCI_ANY_ID, },
11372 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
11373 PCI_ANY_ID, PCI_ANY_ID, },
11374 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
11375 PCI_ANY_ID, PCI_ANY_ID, },
James Smart3772a992009-05-22 14:50:54 -040011376 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
11377 PCI_ANY_ID, PCI_ANY_ID, },
James Smarta747c9c2009-11-18 15:41:10 -050011378 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT,
11379 PCI_ANY_ID, PCI_ANY_ID, },
11380 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON,
James Smart6669f9b2009-10-02 15:16:45 -040011381 PCI_ANY_ID, PCI_ANY_ID, },
James Smart98fc5dd2010-06-07 15:24:29 -040011382 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS,
11383 PCI_ANY_ID, PCI_ANY_ID, },
James Smart085c6472010-11-20 23:11:37 -050011384 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC,
11385 PCI_ANY_ID, PCI_ANY_ID, },
11386 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE,
11387 PCI_ANY_ID, PCI_ANY_ID, },
James Smartc0c11512011-05-24 11:41:34 -040011388 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF,
11389 PCI_ANY_ID, PCI_ANY_ID, },
11390 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF,
11391 PCI_ANY_ID, PCI_ANY_ID, },
James Smartd38dd522015-08-31 16:48:17 -040011392 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_G6_FC,
11393 PCI_ANY_ID, PCI_ANY_ID, },
James Smartf8cafd32012-08-03 12:42:51 -040011394 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK,
11395 PCI_ANY_ID, PCI_ANY_ID, },
11396 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF,
11397 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011398 { 0 }
11399};
11400
11401MODULE_DEVICE_TABLE(pci, lpfc_id_table);
11402
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070011403static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060011404 .error_detected = lpfc_io_error_detected,
11405 .slot_reset = lpfc_io_slot_reset,
11406 .resume = lpfc_io_resume,
11407};
11408
dea31012005-04-17 16:05:31 -050011409static struct pci_driver lpfc_driver = {
11410 .name = LPFC_DRIVER_NAME,
11411 .id_table = lpfc_id_table,
11412 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011413 .remove = lpfc_pci_remove_one,
James Smart3a55b532008-12-04 22:38:54 -050011414 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040011415 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050011416 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050011417};
11418
James Smart3ef6d242012-01-18 16:23:48 -050011419static const struct file_operations lpfc_mgmt_fop = {
Al Viro858feac2013-04-14 22:39:37 -040011420 .owner = THIS_MODULE,
James Smart3ef6d242012-01-18 16:23:48 -050011421};
11422
11423static struct miscdevice lpfc_mgmt_dev = {
11424 .minor = MISC_DYNAMIC_MINOR,
11425 .name = "lpfcmgmt",
11426 .fops = &lpfc_mgmt_fop,
11427};
11428
James Smarte59058c2008-08-24 21:49:00 -040011429/**
James Smart3621a712009-04-06 18:47:14 -040011430 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040011431 *
11432 * This routine is to be invoked when the lpfc module is loaded into the
11433 * kernel. The special kernel macro module_init() is used to indicate the
11434 * role of this routine to the kernel as lpfc module entry point.
11435 *
11436 * Return codes
11437 * 0 - successful
11438 * -ENOMEM - FC attach transport failed
11439 * all others - failed
11440 */
dea31012005-04-17 16:05:31 -050011441static int __init
11442lpfc_init(void)
11443{
James Smart7bb03bb2013-04-17 20:19:16 -040011444 int cpu;
dea31012005-04-17 16:05:31 -050011445 int error = 0;
11446
11447 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040011448 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050011449
James Smart3ef6d242012-01-18 16:23:48 -050011450 error = misc_register(&lpfc_mgmt_dev);
11451 if (error)
11452 printk(KERN_ERR "Could not register lpfcmgmt device, "
11453 "misc_register returned with status %d", error);
11454
James Smart7ee5d432007-10-27 13:37:17 -040011455 if (lpfc_enable_npiv) {
11456 lpfc_transport_functions.vport_create = lpfc_vport_create;
11457 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
11458 }
dea31012005-04-17 16:05:31 -050011459 lpfc_transport_template =
11460 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040011461 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050011462 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040011463 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -040011464 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -040011465 fc_attach_transport(&lpfc_vport_transport_functions);
11466 if (lpfc_vport_transport_template == NULL) {
11467 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040011468 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -040011469 }
James Smart7ee5d432007-10-27 13:37:17 -040011470 }
James Smart7bb03bb2013-04-17 20:19:16 -040011471
11472 /* Initialize in case vector mapping is needed */
James Smartb246de12013-05-31 17:03:07 -040011473 lpfc_used_cpu = NULL;
11474 lpfc_present_cpu = 0;
11475 for_each_present_cpu(cpu)
11476 lpfc_present_cpu++;
James Smart7bb03bb2013-04-17 20:19:16 -040011477
dea31012005-04-17 16:05:31 -050011478 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050011479 if (error) {
dea31012005-04-17 16:05:31 -050011480 fc_release_transport(lpfc_transport_template);
James Smartd7c255b2008-08-24 21:50:00 -040011481 if (lpfc_enable_npiv)
11482 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050011483 }
dea31012005-04-17 16:05:31 -050011484
11485 return error;
11486}
11487
James Smarte59058c2008-08-24 21:49:00 -040011488/**
James Smart3621a712009-04-06 18:47:14 -040011489 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040011490 *
11491 * This routine is invoked when the lpfc module is removed from the kernel.
11492 * The special kernel macro module_exit() is used to indicate the role of
11493 * this routine to the kernel as lpfc module exit point.
11494 */
dea31012005-04-17 16:05:31 -050011495static void __exit
11496lpfc_exit(void)
11497{
James Smart3ef6d242012-01-18 16:23:48 -050011498 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050011499 pci_unregister_driver(&lpfc_driver);
11500 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040011501 if (lpfc_enable_npiv)
11502 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050011503 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040011504 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
11505 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050011506 (1L << _dump_buf_data_order), _dump_buf_data);
11507 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
11508 }
11509
11510 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040011511 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
11512 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050011513 (1L << _dump_buf_dif_order), _dump_buf_dif);
11514 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
11515 }
James Smartb246de12013-05-31 17:03:07 -040011516 kfree(lpfc_used_cpu);
Johannes Thumshirn79739672015-08-31 16:48:11 -040011517 idr_destroy(&lpfc_hba_index);
dea31012005-04-17 16:05:31 -050011518}
11519
11520module_init(lpfc_init);
11521module_exit(lpfc_exit);
11522MODULE_LICENSE("GPL");
11523MODULE_DESCRIPTION(LPFC_MODULE_DESC);
11524MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
11525MODULE_VERSION("0:" LPFC_DRIVER_VERSION);