blob: e01619c4a992a86a32ab6bedae399db7f99132b5 [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 Smart16a59fb2014-04-04 13:52:41 -04004 * Copyright (C) 2004-2014 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) &&
702 !(phba->lmt & LMT_16Gb))) {
703 /* Reset link speed to auto */
704 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
705 "1302 Invalid speed for this board:%d "
706 "Reset link speed to auto.\n",
707 phba->cfg_link_speed);
708 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
709 }
James Smart1b511972011-12-13 13:23:09 -0500710 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
James Smart84d1b002010-02-12 14:42:33 -0500711 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart1b511972011-12-13 13:23:09 -0500712 if (phba->sli_rev < LPFC_SLI_REV4)
713 lpfc_set_loopback_flag(phba);
James Smart6e7288d2010-06-07 15:23:35 -0400714 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart76a95d72010-11-20 23:11:48 -0500715 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
James Smart84d1b002010-02-12 14:42:33 -0500716 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
717 "0498 Adapter failed to init, mbxCmd x%x "
718 "INIT_LINK, mbxStatus x%x\n",
719 mb->mbxCommand, mb->mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -0500720 if (phba->sli_rev <= LPFC_SLI_REV3) {
721 /* Clear all interrupt enable conditions */
722 writel(0, phba->HCregaddr);
723 readl(phba->HCregaddr); /* flush */
724 /* Clear all pending interrupts */
725 writel(0xffffffff, phba->HAregaddr);
726 readl(phba->HAregaddr); /* flush */
727 }
James Smart84d1b002010-02-12 14:42:33 -0500728 phba->link_state = LPFC_HBA_ERROR;
James Smart6e7288d2010-06-07 15:23:35 -0400729 if (rc != MBX_BUSY || flag == MBX_POLL)
James Smart84d1b002010-02-12 14:42:33 -0500730 mempool_free(pmb, phba->mbox_mem_pool);
731 return -EIO;
732 }
James Smarte40a02c2010-02-26 14:13:54 -0500733 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
James Smart6e7288d2010-06-07 15:23:35 -0400734 if (flag == MBX_POLL)
735 mempool_free(pmb, phba->mbox_mem_pool);
James Smart84d1b002010-02-12 14:42:33 -0500736
737 return 0;
738}
739
740/**
741 * lpfc_hba_down_link - this routine downs the FC link
James Smart6e7288d2010-06-07 15:23:35 -0400742 * @phba: pointer to lpfc hba data structure.
743 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500744 *
745 * This routine will issue the DOWN_LINK mailbox command call.
746 * It is available to other drivers through the lpfc_hba data
747 * structure for use to stop the link.
748 *
749 * Return code
750 * 0 - success
751 * Any other value - error
752 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400753static int
James Smart6e7288d2010-06-07 15:23:35 -0400754lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500755{
756 LPFC_MBOXQ_t *pmb;
757 int rc;
758
759 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
760 if (!pmb) {
761 phba->link_state = LPFC_HBA_ERROR;
762 return -ENOMEM;
763 }
764
765 lpfc_printf_log(phba,
766 KERN_ERR, LOG_INIT,
767 "0491 Adapter Link is disabled.\n");
768 lpfc_down_link(phba, pmb);
769 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart6e7288d2010-06-07 15:23:35 -0400770 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart84d1b002010-02-12 14:42:33 -0500771 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
772 lpfc_printf_log(phba,
773 KERN_ERR, LOG_INIT,
774 "2522 Adapter failed to issue DOWN_LINK"
775 " mbox command rc 0x%x\n", rc);
776
777 mempool_free(pmb, phba->mbox_mem_pool);
778 return -EIO;
779 }
James Smart6e7288d2010-06-07 15:23:35 -0400780 if (flag == MBX_POLL)
781 mempool_free(pmb, phba->mbox_mem_pool);
782
James Smart84d1b002010-02-12 14:42:33 -0500783 return 0;
784}
785
786/**
James Smart3621a712009-04-06 18:47:14 -0400787 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400788 * @phba: pointer to lpfc HBA data structure.
789 *
790 * This routine will do LPFC uninitialization before the HBA is reset when
791 * bringing down the SLI Layer.
792 *
793 * Return codes
794 * 0 - success.
795 * Any other value - error.
796 **/
dea31012005-04-17 16:05:31 -0500797int
James Smart2e0fef82007-06-17 19:56:36 -0500798lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500799{
James Smart1b32f6a2008-02-08 18:49:39 -0500800 struct lpfc_vport **vports;
801 int i;
James Smart3772a992009-05-22 14:50:54 -0400802
803 if (phba->sli_rev <= LPFC_SLI_REV3) {
804 /* Disable interrupts */
805 writel(0, phba->HCregaddr);
806 readl(phba->HCregaddr); /* flush */
807 }
dea31012005-04-17 16:05:31 -0500808
James Smart1b32f6a2008-02-08 18:49:39 -0500809 if (phba->pport->load_flag & FC_UNLOADING)
810 lpfc_cleanup_discovery_resources(phba->pport);
811 else {
812 vports = lpfc_create_vport_work_array(phba);
813 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -0400814 for (i = 0; i <= phba->max_vports &&
815 vports[i] != NULL; i++)
James Smart1b32f6a2008-02-08 18:49:39 -0500816 lpfc_cleanup_discovery_resources(vports[i]);
817 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500818 }
819 return 0;
dea31012005-04-17 16:05:31 -0500820}
821
James Smarte59058c2008-08-24 21:49:00 -0400822/**
James Smart68e814f2014-05-21 08:04:59 -0400823 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
824 * rspiocb which got deferred
825 *
826 * @phba: pointer to lpfc HBA data structure.
827 *
828 * This routine will cleanup completed slow path events after HBA is reset
829 * when bringing down the SLI Layer.
830 *
831 *
832 * Return codes
833 * void.
834 **/
835static void
836lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
837{
838 struct lpfc_iocbq *rspiocbq;
839 struct hbq_dmabuf *dmabuf;
840 struct lpfc_cq_event *cq_event;
841
842 spin_lock_irq(&phba->hbalock);
843 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
844 spin_unlock_irq(&phba->hbalock);
845
846 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
847 /* Get the response iocb from the head of work queue */
848 spin_lock_irq(&phba->hbalock);
849 list_remove_head(&phba->sli4_hba.sp_queue_event,
850 cq_event, struct lpfc_cq_event, list);
851 spin_unlock_irq(&phba->hbalock);
852
853 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
854 case CQE_CODE_COMPL_WQE:
855 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
856 cq_event);
857 lpfc_sli_release_iocbq(phba, rspiocbq);
858 break;
859 case CQE_CODE_RECEIVE:
860 case CQE_CODE_RECEIVE_V1:
861 dmabuf = container_of(cq_event, struct hbq_dmabuf,
862 cq_event);
863 lpfc_in_buf_free(phba, &dmabuf->dbuf);
864 }
865 }
866}
867
868/**
James Smartbcece5f2014-04-04 13:51:34 -0400869 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
870 * @phba: pointer to lpfc HBA data structure.
871 *
872 * This routine will cleanup posted ELS buffers after the HBA is reset
873 * when bringing down the SLI Layer.
874 *
875 *
876 * Return codes
877 * void.
878 **/
879static void
880lpfc_hba_free_post_buf(struct lpfc_hba *phba)
881{
882 struct lpfc_sli *psli = &phba->sli;
883 struct lpfc_sli_ring *pring;
884 struct lpfc_dmabuf *mp, *next_mp;
James Smart07eab622014-04-04 13:51:44 -0400885 LIST_HEAD(buflist);
886 int count;
James Smartbcece5f2014-04-04 13:51:34 -0400887
888 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
889 lpfc_sli_hbqbuf_free_all(phba);
890 else {
891 /* Cleanup preposted buffers on the ELS ring */
James Smartbcece5f2014-04-04 13:51:34 -0400892 pring = &psli->ring[LPFC_ELS_RING];
James Smart07eab622014-04-04 13:51:44 -0400893 spin_lock_irq(&phba->hbalock);
894 list_splice_init(&pring->postbufq, &buflist);
895 spin_unlock_irq(&phba->hbalock);
896
897 count = 0;
898 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
James Smartbcece5f2014-04-04 13:51:34 -0400899 list_del(&mp->list);
James Smart07eab622014-04-04 13:51:44 -0400900 count++;
James Smartbcece5f2014-04-04 13:51:34 -0400901 lpfc_mbuf_free(phba, mp->virt, mp->phys);
902 kfree(mp);
903 }
James Smart07eab622014-04-04 13:51:44 -0400904
905 spin_lock_irq(&phba->hbalock);
906 pring->postbufq_cnt -= count;
James Smartbcece5f2014-04-04 13:51:34 -0400907 spin_unlock_irq(&phba->hbalock);
908 }
909}
910
911/**
912 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
913 * @phba: pointer to lpfc HBA data structure.
914 *
915 * This routine will cleanup the txcmplq after the HBA is reset when bringing
916 * down the SLI Layer.
917 *
918 * Return codes
919 * void
920 **/
921static void
922lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
923{
924 struct lpfc_sli *psli = &phba->sli;
925 struct lpfc_sli_ring *pring;
926 LIST_HEAD(completions);
927 int i;
928
James Smartbcece5f2014-04-04 13:51:34 -0400929 for (i = 0; i < psli->num_rings; i++) {
930 pring = &psli->ring[i];
931 if (phba->sli_rev >= LPFC_SLI_REV4)
932 spin_lock_irq(&pring->ring_lock);
933 else
934 spin_lock_irq(&phba->hbalock);
935 /* At this point in time the HBA is either reset or DOA. Either
936 * way, nothing should be on txcmplq as it will NEVER complete.
937 */
938 list_splice_init(&pring->txcmplq, &completions);
James Smartdb55fba2014-04-04 13:52:02 -0400939 pring->txcmplq_cnt = 0;
James Smartbcece5f2014-04-04 13:51:34 -0400940
941 if (phba->sli_rev >= LPFC_SLI_REV4)
942 spin_unlock_irq(&pring->ring_lock);
943 else
944 spin_unlock_irq(&phba->hbalock);
945
946 /* Cancel all the IOCBs from the completions list */
947 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
948 IOERR_SLI_ABORTED);
949 lpfc_sli_abort_iocb_ring(phba, pring);
950 }
951}
952
953/**
James Smart3772a992009-05-22 14:50:54 -0400954 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smartbcece5f2014-04-04 13:51:34 -0400955 int i;
James Smarte59058c2008-08-24 21:49:00 -0400956 * @phba: pointer to lpfc HBA data structure.
957 *
958 * This routine will do uninitialization after the HBA is reset when bring
959 * down the SLI Layer.
960 *
961 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200962 * 0 - success.
James Smarte59058c2008-08-24 21:49:00 -0400963 * Any other value - error.
964 **/
James Smart3772a992009-05-22 14:50:54 -0400965static int
966lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500967{
James Smartbcece5f2014-04-04 13:51:34 -0400968 lpfc_hba_free_post_buf(phba);
969 lpfc_hba_clean_txcmplq(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500970 return 0;
971}
James Smart5af5eee2010-10-22 11:06:38 -0400972
James Smartda0436e2009-05-22 14:51:39 -0400973/**
974 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
975 * @phba: pointer to lpfc HBA data structure.
976 *
977 * This routine will do uninitialization after the HBA is reset when bring
978 * down the SLI Layer.
979 *
980 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200981 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -0400982 * Any other value - error.
983 **/
984static int
985lpfc_hba_down_post_s4(struct lpfc_hba *phba)
986{
987 struct lpfc_scsi_buf *psb, *psb_next;
988 LIST_HEAD(aborts);
James Smartda0436e2009-05-22 14:51:39 -0400989 unsigned long iflag = 0;
James Smart0f65ff62010-02-26 14:14:23 -0500990 struct lpfc_sglq *sglq_entry = NULL;
James Smartdafe8ce2014-09-03 12:56:40 -0400991 struct lpfc_sli *psli = &phba->sli;
992 struct lpfc_sli_ring *pring;
James Smart0f65ff62010-02-26 14:14:23 -0500993
James Smartbcece5f2014-04-04 13:51:34 -0400994 lpfc_hba_free_post_buf(phba);
995 lpfc_hba_clean_txcmplq(phba);
James Smartdafe8ce2014-09-03 12:56:40 -0400996 pring = &psli->ring[LPFC_ELS_RING];
James Smartbcece5f2014-04-04 13:51:34 -0400997
James Smartda0436e2009-05-22 14:51:39 -0400998 /* At this point in time the HBA is either reset or DOA. Either
999 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
1000 * on the lpfc_sgl_list so that it can either be freed if the
1001 * driver is unloading or reposted if the driver is restarting
1002 * the port.
1003 */
1004 spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */
1005 /* scsl_buf_list */
1006 /* abts_sgl_list_lock required because worker thread uses this
1007 * list.
1008 */
1009 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05001010 list_for_each_entry(sglq_entry,
1011 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1012 sglq_entry->state = SGL_FREED;
1013
James Smartdafe8ce2014-09-03 12:56:40 -04001014 spin_lock(&pring->ring_lock);
James Smartda0436e2009-05-22 14:51:39 -04001015 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
1016 &phba->sli4_hba.lpfc_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04001017 spin_unlock(&pring->ring_lock);
James Smartda0436e2009-05-22 14:51:39 -04001018 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
1019 /* abts_scsi_buf_list_lock required because worker thread uses this
1020 * list.
1021 */
1022 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1023 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
1024 &aborts);
1025 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1026 spin_unlock_irq(&phba->hbalock);
1027
1028 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1029 psb->pCmd = NULL;
1030 psb->status = IOSTAT_SUCCESS;
1031 }
James Smarta40fc5f2013-04-17 20:17:40 -04001032 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1033 list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
1034 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
James Smart68e814f2014-05-21 08:04:59 -04001035
1036 lpfc_sli4_free_sp_events(phba);
James Smartda0436e2009-05-22 14:51:39 -04001037 return 0;
1038}
1039
1040/**
1041 * lpfc_hba_down_post - Wrapper func for hba down post routine
1042 * @phba: pointer to lpfc HBA data structure.
1043 *
1044 * This routine wraps the actual SLI3 or SLI4 routine for performing
1045 * uninitialization after the HBA is reset when bring down the SLI Layer.
1046 *
1047 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001048 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001049 * Any other value - error.
1050 **/
1051int
1052lpfc_hba_down_post(struct lpfc_hba *phba)
1053{
1054 return (*phba->lpfc_hba_down_post)(phba);
1055}
Jamie Wellnitz41415862006-02-28 19:25:27 -05001056
James Smarte59058c2008-08-24 21:49:00 -04001057/**
James Smart3621a712009-04-06 18:47:14 -04001058 * lpfc_hb_timeout - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001059 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1060 *
1061 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1062 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1063 * work-port-events bitmap and the worker thread is notified. This timeout
1064 * event will be used by the worker thread to invoke the actual timeout
1065 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1066 * be performed in the timeout handler and the HBA timeout event bit shall
1067 * be cleared by the worker thread after it has taken the event bitmap out.
1068 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001069static void
James Smart858c9f62007-06-17 19:56:39 -05001070lpfc_hb_timeout(unsigned long ptr)
1071{
1072 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001073 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -05001074 unsigned long iflag;
1075
1076 phba = (struct lpfc_hba *)ptr;
James Smart93996272008-08-24 21:50:30 -04001077
1078 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -05001079 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001080 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1081 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -05001082 phba->pport->work_port_events |= WORKER_HB_TMO;
1083 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1084
James Smart93996272008-08-24 21:50:30 -04001085 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -04001086 if (!tmo_posted)
1087 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -05001088 return;
1089}
1090
James Smarte59058c2008-08-24 21:49:00 -04001091/**
James Smart19ca7602010-11-20 23:11:55 -05001092 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1093 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1094 *
1095 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1096 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1097 * work-port-events bitmap and the worker thread is notified. This timeout
1098 * event will be used by the worker thread to invoke the actual timeout
1099 * handler routine, lpfc_rrq_handler. Any periodical operations will
1100 * be performed in the timeout handler and the RRQ timeout event bit shall
1101 * be cleared by the worker thread after it has taken the event bitmap out.
1102 **/
1103static void
1104lpfc_rrq_timeout(unsigned long ptr)
1105{
1106 struct lpfc_hba *phba;
James Smart19ca7602010-11-20 23:11:55 -05001107 unsigned long iflag;
1108
1109 phba = (struct lpfc_hba *)ptr;
1110 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001111 if (!(phba->pport->load_flag & FC_UNLOADING))
1112 phba->hba_flag |= HBA_RRQ_ACTIVE;
1113 else
1114 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
James Smart19ca7602010-11-20 23:11:55 -05001115 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001116
1117 if (!(phba->pport->load_flag & FC_UNLOADING))
1118 lpfc_worker_wake_up(phba);
James Smart19ca7602010-11-20 23:11:55 -05001119}
1120
1121/**
James Smart3621a712009-04-06 18:47:14 -04001122 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -04001123 * @phba: pointer to lpfc hba data structure.
1124 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1125 *
1126 * This is the callback function to the lpfc heart-beat mailbox command.
1127 * If configured, the lpfc driver issues the heart-beat mailbox command to
1128 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1129 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1130 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1131 * heart-beat outstanding state. Once the mailbox command comes back and
1132 * no error conditions detected, the heart-beat mailbox command timer is
1133 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1134 * state is cleared for the next heart-beat. If the timer expired with the
1135 * heart-beat outstanding state set, the driver will put the HBA offline.
1136 **/
James Smart858c9f62007-06-17 19:56:39 -05001137static void
1138lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1139{
1140 unsigned long drvr_flag;
1141
1142 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1143 phba->hb_outstanding = 0;
1144 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1145
James Smart93996272008-08-24 21:50:30 -04001146 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -05001147 mempool_free(pmboxq, phba->mbox_mem_pool);
1148 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1149 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -04001150 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -05001151 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001152 jiffies +
1153 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001154 return;
1155}
1156
James Smarte59058c2008-08-24 21:49:00 -04001157/**
James Smart3621a712009-04-06 18:47:14 -04001158 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001159 * @phba: pointer to lpfc hba data structure.
1160 *
1161 * This is the actual HBA-timer timeout handler to be invoked by the worker
1162 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1163 * handler performs any periodic operations needed for the device. If such
1164 * periodic event has already been attended to either in the interrupt handler
1165 * or by processing slow-ring or fast-ring events within the HBA-timer
1166 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1167 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1168 * is configured and there is no heart-beat mailbox command outstanding, a
1169 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1170 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1171 * to offline.
1172 **/
James Smart858c9f62007-06-17 19:56:39 -05001173void
1174lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1175{
James Smart45ed1192009-10-02 15:17:02 -04001176 struct lpfc_vport **vports;
James Smart858c9f62007-06-17 19:56:39 -05001177 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -05001178 struct lpfc_dmabuf *buf_ptr;
James Smart45ed1192009-10-02 15:17:02 -04001179 int retval, i;
James Smart858c9f62007-06-17 19:56:39 -05001180 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -05001181 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -05001182
James Smart45ed1192009-10-02 15:17:02 -04001183 vports = lpfc_create_vport_work_array(phba);
1184 if (vports != NULL)
1185 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
1186 lpfc_rcv_seq_check_edtov(vports[i]);
1187 lpfc_destroy_vport_work_array(phba, vports);
1188
James Smart858c9f62007-06-17 19:56:39 -05001189 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -04001190 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -05001191 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1192 return;
1193
1194 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -05001195
James Smart256ec0d2013-04-17 20:14:58 -04001196 if (time_after(phba->last_completion_time +
1197 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1198 jiffies)) {
James Smart858c9f62007-06-17 19:56:39 -05001199 spin_unlock_irq(&phba->pport->work_port_lock);
1200 if (!phba->hb_outstanding)
1201 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001202 jiffies +
1203 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001204 else
1205 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001206 jiffies +
1207 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001208 return;
1209 }
1210 spin_unlock_irq(&phba->pport->work_port_lock);
1211
James Smart0ff10d42008-01-11 01:52:36 -05001212 if (phba->elsbuf_cnt &&
1213 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1214 spin_lock_irq(&phba->hbalock);
1215 list_splice_init(&phba->elsbuf, &completions);
1216 phba->elsbuf_cnt = 0;
1217 phba->elsbuf_prev_cnt = 0;
1218 spin_unlock_irq(&phba->hbalock);
1219
1220 while (!list_empty(&completions)) {
1221 list_remove_head(&completions, buf_ptr,
1222 struct lpfc_dmabuf, list);
1223 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1224 kfree(buf_ptr);
1225 }
1226 }
1227 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1228
James Smart858c9f62007-06-17 19:56:39 -05001229 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -05001230 if (phba->cfg_enable_hba_heartbeat) {
1231 if (!phba->hb_outstanding) {
James Smartbc739052010-08-04 16:11:18 -04001232 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1233 (list_empty(&psli->mboxq))) {
1234 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1235 GFP_KERNEL);
1236 if (!pmboxq) {
1237 mod_timer(&phba->hb_tmofunc,
1238 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001239 msecs_to_jiffies(1000 *
1240 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001241 return;
1242 }
James Smart13815c82008-01-11 01:52:48 -05001243
James Smartbc739052010-08-04 16:11:18 -04001244 lpfc_heart_beat(phba, pmboxq);
1245 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1246 pmboxq->vport = phba->pport;
1247 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1248 MBX_NOWAIT);
James Smart13815c82008-01-11 01:52:48 -05001249
James Smartbc739052010-08-04 16:11:18 -04001250 if (retval != MBX_BUSY &&
1251 retval != MBX_SUCCESS) {
1252 mempool_free(pmboxq,
1253 phba->mbox_mem_pool);
1254 mod_timer(&phba->hb_tmofunc,
1255 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001256 msecs_to_jiffies(1000 *
1257 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001258 return;
1259 }
1260 phba->skipped_hb = 0;
1261 phba->hb_outstanding = 1;
1262 } else if (time_before_eq(phba->last_completion_time,
1263 phba->skipped_hb)) {
1264 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1265 "2857 Last completion time not "
1266 " updated in %d ms\n",
1267 jiffies_to_msecs(jiffies
1268 - phba->last_completion_time));
1269 } else
1270 phba->skipped_hb = jiffies;
1271
James Smart858c9f62007-06-17 19:56:39 -05001272 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001273 jiffies +
1274 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001275 return;
James Smart13815c82008-01-11 01:52:48 -05001276 } else {
1277 /*
1278 * If heart beat timeout called with hb_outstanding set
James Smartdcf2a4e2010-09-29 11:18:53 -04001279 * we need to give the hb mailbox cmd a chance to
1280 * complete or TMO.
James Smart13815c82008-01-11 01:52:48 -05001281 */
James Smartdcf2a4e2010-09-29 11:18:53 -04001282 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1283 "0459 Adapter heartbeat still out"
1284 "standing:last compl time was %d ms.\n",
1285 jiffies_to_msecs(jiffies
1286 - phba->last_completion_time));
1287 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001288 jiffies +
1289 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001290 }
James Smart858c9f62007-06-17 19:56:39 -05001291 }
1292}
1293
James Smarte59058c2008-08-24 21:49:00 -04001294/**
James Smart3621a712009-04-06 18:47:14 -04001295 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -04001296 * @phba: pointer to lpfc hba data structure.
1297 *
1298 * This routine is called to bring the HBA offline when HBA hardware error
1299 * other than Port Error 6 has been detected.
1300 **/
James Smart09372822008-01-11 01:52:54 -05001301static void
1302lpfc_offline_eratt(struct lpfc_hba *phba)
1303{
1304 struct lpfc_sli *psli = &phba->sli;
1305
1306 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001307 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -05001308 spin_unlock_irq(&phba->hbalock);
James Smart618a5232012-06-12 13:54:36 -04001309 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart09372822008-01-11 01:52:54 -05001310
1311 lpfc_offline(phba);
1312 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001313 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001314 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001315 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001316 lpfc_hba_down_post(phba);
1317 lpfc_sli_brdready(phba, HS_MBRDY);
1318 lpfc_unblock_mgmt_io(phba);
1319 phba->link_state = LPFC_HBA_ERROR;
1320 return;
1321}
1322
James Smarte59058c2008-08-24 21:49:00 -04001323/**
James Smartda0436e2009-05-22 14:51:39 -04001324 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1325 * @phba: pointer to lpfc hba data structure.
1326 *
1327 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1328 * other than Port Error 6 has been detected.
1329 **/
James Smarta88dbb62013-04-17 20:18:39 -04001330void
James Smartda0436e2009-05-22 14:51:39 -04001331lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1332{
James Smart946727d2015-04-07 15:07:09 -04001333 spin_lock_irq(&phba->hbalock);
1334 phba->link_state = LPFC_HBA_ERROR;
1335 spin_unlock_irq(&phba->hbalock);
1336
James Smart618a5232012-06-12 13:54:36 -04001337 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smartda0436e2009-05-22 14:51:39 -04001338 lpfc_offline(phba);
James Smartda0436e2009-05-22 14:51:39 -04001339 lpfc_hba_down_post(phba);
James Smartda0436e2009-05-22 14:51:39 -04001340 lpfc_unblock_mgmt_io(phba);
James Smartda0436e2009-05-22 14:51:39 -04001341}
1342
1343/**
James Smarta257bf92009-04-06 18:48:10 -04001344 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1345 * @phba: pointer to lpfc hba data structure.
1346 *
1347 * This routine is invoked to handle the deferred HBA hardware error
1348 * conditions. This type of error is indicated by HBA by setting ER1
1349 * and another ER bit in the host status register. The driver will
1350 * wait until the ER1 bit clears before handling the error condition.
1351 **/
1352static void
1353lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1354{
1355 uint32_t old_host_status = phba->work_hs;
James Smarta257bf92009-04-06 18:48:10 -04001356 struct lpfc_sli *psli = &phba->sli;
1357
James Smartf4b4c682009-05-22 14:53:12 -04001358 /* If the pci channel is offline, ignore possible errors,
1359 * since we cannot communicate with the pci card anyway.
1360 */
1361 if (pci_channel_offline(phba->pcidev)) {
1362 spin_lock_irq(&phba->hbalock);
1363 phba->hba_flag &= ~DEFER_ERATT;
1364 spin_unlock_irq(&phba->hbalock);
1365 return;
1366 }
1367
James Smarta257bf92009-04-06 18:48:10 -04001368 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1369 "0479 Deferred Adapter Hardware Error "
1370 "Data: x%x x%x x%x\n",
1371 phba->work_hs,
1372 phba->work_status[0], phba->work_status[1]);
1373
1374 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001375 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001376 spin_unlock_irq(&phba->hbalock);
1377
1378
1379 /*
1380 * Firmware stops when it triggred erratt. That could cause the I/Os
1381 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1382 * SCSI layer retry it after re-establishing link.
1383 */
James Smartdb55fba2014-04-04 13:52:02 -04001384 lpfc_sli_abort_fcp_rings(phba);
James Smarta257bf92009-04-06 18:48:10 -04001385
1386 /*
1387 * There was a firmware error. Take the hba offline and then
1388 * attempt to restart it.
1389 */
James Smart618a5232012-06-12 13:54:36 -04001390 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smarta257bf92009-04-06 18:48:10 -04001391 lpfc_offline(phba);
1392
1393 /* Wait for the ER1 bit to clear.*/
1394 while (phba->work_hs & HS_FFER1) {
1395 msleep(100);
James Smart9940b972011-03-11 16:06:12 -05001396 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1397 phba->work_hs = UNPLUG_ERR ;
1398 break;
1399 }
James Smarta257bf92009-04-06 18:48:10 -04001400 /* If driver is unloading let the worker thread continue */
1401 if (phba->pport->load_flag & FC_UNLOADING) {
1402 phba->work_hs = 0;
1403 break;
1404 }
1405 }
1406
1407 /*
1408 * This is to ptrotect against a race condition in which
1409 * first write to the host attention register clear the
1410 * host status register.
1411 */
1412 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1413 phba->work_hs = old_host_status & ~HS_FFER1;
1414
James Smart3772a992009-05-22 14:50:54 -04001415 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001416 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001417 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001418 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1419 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1420}
1421
James Smart3772a992009-05-22 14:50:54 -04001422static void
1423lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1424{
1425 struct lpfc_board_event_header board_event;
1426 struct Scsi_Host *shost;
1427
1428 board_event.event_type = FC_REG_BOARD_EVENT;
1429 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1430 shost = lpfc_shost_from_vport(phba->pport);
1431 fc_host_post_vendor_event(shost, fc_get_event_number(),
1432 sizeof(board_event),
1433 (char *) &board_event,
1434 LPFC_NL_VENDOR_ID);
1435}
1436
James Smarta257bf92009-04-06 18:48:10 -04001437/**
James Smart3772a992009-05-22 14:50:54 -04001438 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001439 * @phba: pointer to lpfc hba data structure.
1440 *
1441 * This routine is invoked to handle the following HBA hardware error
1442 * conditions:
1443 * 1 - HBA error attention interrupt
1444 * 2 - DMA ring index out of range
1445 * 3 - Mailbox command came back as unknown
1446 **/
James Smart3772a992009-05-22 14:50:54 -04001447static void
1448lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001449{
James Smart2e0fef82007-06-17 19:56:36 -05001450 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001451 struct lpfc_sli *psli = &phba->sli;
James Smartd2873e42006-08-18 17:46:43 -04001452 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001453 unsigned long temperature;
1454 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001455 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001456
Linas Vepstas8d63f372007-02-14 14:28:36 -06001457 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001458 * since we cannot communicate with the pci card anyway.
1459 */
1460 if (pci_channel_offline(phba->pcidev)) {
1461 spin_lock_irq(&phba->hbalock);
1462 phba->hba_flag &= ~DEFER_ERATT;
1463 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001464 return;
James Smart3772a992009-05-22 14:50:54 -04001465 }
1466
James Smart13815c82008-01-11 01:52:48 -05001467 /* If resets are disabled then leave the HBA alone and return */
1468 if (!phba->cfg_enable_hba_reset)
1469 return;
dea31012005-04-17 16:05:31 -05001470
James Smartea2151b2008-09-07 11:52:10 -04001471 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001472 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001473
James Smarta257bf92009-04-06 18:48:10 -04001474 if (phba->hba_flag & DEFER_ERATT)
1475 lpfc_handle_deferred_eratt(phba);
1476
James Smartdcf2a4e2010-09-29 11:18:53 -04001477 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1478 if (phba->work_hs & HS_FFER6)
1479 /* Re-establishing Link */
1480 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1481 "1301 Re-establishing Link "
1482 "Data: x%x x%x x%x\n",
1483 phba->work_hs, phba->work_status[0],
1484 phba->work_status[1]);
1485 if (phba->work_hs & HS_FFER8)
1486 /* Device Zeroization */
1487 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1488 "2861 Host Authentication device "
1489 "zeroization Data:x%x x%x x%x\n",
1490 phba->work_hs, phba->work_status[0],
1491 phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001492
James Smart92d7f7b2007-06-17 19:56:38 -05001493 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001494 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001495 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001496
1497 /*
1498 * Firmware stops when it triggled erratt with HS_FFER6.
1499 * That could cause the I/Os dropped by the firmware.
1500 * Error iocb (I/O) on txcmplq and let the SCSI layer
1501 * retry it after re-establishing link.
1502 */
James Smartdb55fba2014-04-04 13:52:02 -04001503 lpfc_sli_abort_fcp_rings(phba);
dea31012005-04-17 16:05:31 -05001504
dea31012005-04-17 16:05:31 -05001505 /*
1506 * There was a firmware error. Take the hba offline and then
1507 * attempt to restart it.
1508 */
James Smart618a5232012-06-12 13:54:36 -04001509 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
dea31012005-04-17 16:05:31 -05001510 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001511 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001512 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001513 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001514 return;
1515 }
James Smart46fa3112007-04-25 09:51:45 -04001516 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001517 } else if (phba->work_hs & HS_CRIT_TEMP) {
1518 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1519 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1520 temp_event_data.event_code = LPFC_CRIT_TEMP;
1521 temp_event_data.data = (uint32_t)temperature;
1522
1523 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001524 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001525 "(%ld), taking this port offline "
1526 "Data: x%x x%x x%x\n",
1527 temperature, phba->work_hs,
1528 phba->work_status[0], phba->work_status[1]);
1529
1530 shost = lpfc_shost_from_vport(phba->pport);
1531 fc_host_post_vendor_event(shost, fc_get_event_number(),
1532 sizeof(temp_event_data),
1533 (char *) &temp_event_data,
1534 SCSI_NL_VID_TYPE_PCI
1535 | PCI_VENDOR_ID_EMULEX);
1536
James Smart7af67052007-10-27 13:38:11 -04001537 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001538 phba->over_temp_state = HBA_OVER_TEMP;
1539 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001540 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001541
dea31012005-04-17 16:05:31 -05001542 } else {
1543 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001544 * failure is a value other than FFER6. Do not call the offline
1545 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001546 */
1547 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001548 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001549 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001550 phba->work_hs,
dea31012005-04-17 16:05:31 -05001551 phba->work_status[0], phba->work_status[1]);
1552
James Smartd2873e42006-08-18 17:46:43 -04001553 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001554 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001555 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001556 sizeof(event_data), (char *) &event_data,
1557 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1558
James Smart09372822008-01-11 01:52:54 -05001559 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001560 }
James Smart93996272008-08-24 21:50:30 -04001561 return;
dea31012005-04-17 16:05:31 -05001562}
1563
James Smarte59058c2008-08-24 21:49:00 -04001564/**
James Smart618a5232012-06-12 13:54:36 -04001565 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1566 * @phba: pointer to lpfc hba data structure.
1567 * @mbx_action: flag for mailbox shutdown action.
1568 *
1569 * This routine is invoked to perform an SLI4 port PCI function reset in
1570 * response to port status register polling attention. It waits for port
1571 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1572 * During this process, interrupt vectors are freed and later requested
1573 * for handling possible port resource change.
1574 **/
1575static int
James Smarte10b2022014-02-20 09:57:43 -05001576lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1577 bool en_rn_msg)
James Smart618a5232012-06-12 13:54:36 -04001578{
1579 int rc;
1580 uint32_t intr_mode;
1581
1582 /*
1583 * On error status condition, driver need to wait for port
1584 * ready before performing reset.
1585 */
1586 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1587 if (!rc) {
1588 /* need reset: attempt for port recovery */
James Smarte10b2022014-02-20 09:57:43 -05001589 if (en_rn_msg)
1590 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1591 "2887 Reset Needed: Attempting Port "
1592 "Recovery...\n");
James Smart618a5232012-06-12 13:54:36 -04001593 lpfc_offline_prep(phba, mbx_action);
1594 lpfc_offline(phba);
1595 /* release interrupt for possible resource change */
1596 lpfc_sli4_disable_intr(phba);
1597 lpfc_sli_brdrestart(phba);
1598 /* request and enable interrupt */
1599 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1600 if (intr_mode == LPFC_INTR_ERROR) {
1601 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1602 "3175 Failed to enable interrupt\n");
1603 return -EIO;
1604 } else {
1605 phba->intr_mode = intr_mode;
1606 }
1607 rc = lpfc_online(phba);
1608 if (rc == 0)
1609 lpfc_unblock_mgmt_io(phba);
1610 }
1611 return rc;
1612}
1613
1614/**
James Smartda0436e2009-05-22 14:51:39 -04001615 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1616 * @phba: pointer to lpfc hba data structure.
1617 *
1618 * This routine is invoked to handle the SLI4 HBA hardware error attention
1619 * conditions.
1620 **/
1621static void
1622lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1623{
1624 struct lpfc_vport *vport = phba->pport;
1625 uint32_t event_data;
1626 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001627 uint32_t if_type;
James Smart2e90f4b2011-12-13 13:22:37 -05001628 struct lpfc_register portstat_reg = {0};
1629 uint32_t reg_err1, reg_err2;
1630 uint32_t uerrlo_reg, uemasklo_reg;
1631 uint32_t pci_rd_rc1, pci_rd_rc2;
James Smarte10b2022014-02-20 09:57:43 -05001632 bool en_rn_msg = true;
James Smart946727d2015-04-07 15:07:09 -04001633 struct temp_event temp_event_data;
James Smart73d91e52011-10-10 21:32:10 -04001634 int rc;
James Smartda0436e2009-05-22 14:51:39 -04001635
1636 /* If the pci channel is offline, ignore possible errors, since
1637 * we cannot communicate with the pci card anyway.
1638 */
1639 if (pci_channel_offline(phba->pcidev))
1640 return;
James Smartda0436e2009-05-22 14:51:39 -04001641
James Smart2fcee4b2010-12-15 17:57:46 -05001642 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1643 switch (if_type) {
1644 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart2e90f4b2011-12-13 13:22:37 -05001645 pci_rd_rc1 = lpfc_readl(
1646 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1647 &uerrlo_reg);
1648 pci_rd_rc2 = lpfc_readl(
1649 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1650 &uemasklo_reg);
1651 /* consider PCI bus read error as pci_channel_offline */
1652 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1653 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001654 lpfc_sli4_offline_eratt(phba);
1655 break;
James Smart946727d2015-04-07 15:07:09 -04001656
James Smart2fcee4b2010-12-15 17:57:46 -05001657 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2e90f4b2011-12-13 13:22:37 -05001658 pci_rd_rc1 = lpfc_readl(
1659 phba->sli4_hba.u.if_type2.STATUSregaddr,
1660 &portstat_reg.word0);
1661 /* consider PCI bus read error as pci_channel_offline */
James Smart6b5151f2012-01-18 16:24:06 -05001662 if (pci_rd_rc1 == -EIO) {
1663 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1664 "3151 PCI bus read access failure: x%x\n",
1665 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
James Smart2e90f4b2011-12-13 13:22:37 -05001666 return;
James Smart6b5151f2012-01-18 16:24:06 -05001667 }
James Smart2e90f4b2011-12-13 13:22:37 -05001668 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1669 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
James Smart2fcee4b2010-12-15 17:57:46 -05001670 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
James Smart2fcee4b2010-12-15 17:57:46 -05001671 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1672 "2889 Port Overtemperature event, "
James Smart946727d2015-04-07 15:07:09 -04001673 "taking port offline Data: x%x x%x\n",
1674 reg_err1, reg_err2);
1675
1676 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1677 temp_event_data.event_code = LPFC_CRIT_TEMP;
1678 temp_event_data.data = 0xFFFFFFFF;
1679
1680 shost = lpfc_shost_from_vport(phba->pport);
1681 fc_host_post_vendor_event(shost, fc_get_event_number(),
1682 sizeof(temp_event_data),
1683 (char *)&temp_event_data,
1684 SCSI_NL_VID_TYPE_PCI
1685 | PCI_VENDOR_ID_EMULEX);
1686
James Smart2fcee4b2010-12-15 17:57:46 -05001687 spin_lock_irq(&phba->hbalock);
1688 phba->over_temp_state = HBA_OVER_TEMP;
1689 spin_unlock_irq(&phba->hbalock);
1690 lpfc_sli4_offline_eratt(phba);
James Smart946727d2015-04-07 15:07:09 -04001691 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001692 }
James Smart2e90f4b2011-12-13 13:22:37 -05001693 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smarte10b2022014-02-20 09:57:43 -05001694 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
James Smart2e90f4b2011-12-13 13:22:37 -05001695 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte10b2022014-02-20 09:57:43 -05001696 "3143 Port Down: Firmware Update "
1697 "Detected\n");
1698 en_rn_msg = false;
1699 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smart2e90f4b2011-12-13 13:22:37 -05001700 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1701 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1702 "3144 Port Down: Debug Dump\n");
1703 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1704 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1705 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1706 "3145 Port Down: Provisioning\n");
James Smart618a5232012-06-12 13:54:36 -04001707
James Smart946727d2015-04-07 15:07:09 -04001708 /* If resets are disabled then leave the HBA alone and return */
1709 if (!phba->cfg_enable_hba_reset)
1710 return;
1711
James Smart618a5232012-06-12 13:54:36 -04001712 /* Check port status register for function reset */
James Smarte10b2022014-02-20 09:57:43 -05001713 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1714 en_rn_msg);
James Smart618a5232012-06-12 13:54:36 -04001715 if (rc == 0) {
1716 /* don't report event on forced debug dump */
1717 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1718 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1719 return;
1720 else
1721 break;
James Smart2fcee4b2010-12-15 17:57:46 -05001722 }
James Smart618a5232012-06-12 13:54:36 -04001723 /* fall through for not able to recover */
James Smart6b5151f2012-01-18 16:24:06 -05001724 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1725 "3152 Unrecoverable error, bring the port "
1726 "offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05001727 lpfc_sli4_offline_eratt(phba);
1728 break;
1729 case LPFC_SLI_INTF_IF_TYPE_1:
1730 default:
1731 break;
1732 }
James Smart2e90f4b2011-12-13 13:22:37 -05001733 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1734 "3123 Report dump event to upper layer\n");
1735 /* Send an internal error event to mgmt application */
1736 lpfc_board_errevt_to_mgmt(phba);
1737
1738 event_data = FC_REG_DUMP_EVENT;
1739 shost = lpfc_shost_from_vport(vport);
1740 fc_host_post_vendor_event(shost, fc_get_event_number(),
1741 sizeof(event_data), (char *) &event_data,
1742 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
James Smartda0436e2009-05-22 14:51:39 -04001743}
1744
1745/**
1746 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1747 * @phba: pointer to lpfc HBA data structure.
1748 *
1749 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1750 * routine from the API jump table function pointer from the lpfc_hba struct.
1751 *
1752 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001753 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001754 * Any other value - error.
1755 **/
1756void
1757lpfc_handle_eratt(struct lpfc_hba *phba)
1758{
1759 (*phba->lpfc_handle_eratt)(phba);
1760}
1761
1762/**
James Smart3621a712009-04-06 18:47:14 -04001763 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04001764 * @phba: pointer to lpfc hba data structure.
1765 *
1766 * This routine is invoked from the worker thread to handle a HBA host
1767 * attention link event.
1768 **/
dea31012005-04-17 16:05:31 -05001769void
James Smart2e0fef82007-06-17 19:56:36 -05001770lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001771{
James Smart2e0fef82007-06-17 19:56:36 -05001772 struct lpfc_vport *vport = phba->pport;
1773 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001774 LPFC_MBOXQ_t *pmb;
1775 volatile uint32_t control;
1776 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05001777 int rc = 0;
dea31012005-04-17 16:05:31 -05001778
1779 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001780 if (!pmb) {
1781 rc = 1;
dea31012005-04-17 16:05:31 -05001782 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05001783 }
dea31012005-04-17 16:05:31 -05001784
1785 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001786 if (!mp) {
1787 rc = 2;
dea31012005-04-17 16:05:31 -05001788 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05001789 }
dea31012005-04-17 16:05:31 -05001790
1791 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05001792 if (!mp->virt) {
1793 rc = 3;
dea31012005-04-17 16:05:31 -05001794 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05001795 }
dea31012005-04-17 16:05:31 -05001796
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001797 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04001798 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05001799
1800 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05001801 lpfc_read_topology(phba, pmb, mp);
1802 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05001803 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04001804 /* Block ELS IOCBs until we have processed this mbox command */
1805 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04001806 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05001807 if (rc == MBX_NOT_FINISHED) {
1808 rc = 4;
James Smart14691152006-12-02 13:34:28 -05001809 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05001810 }
dea31012005-04-17 16:05:31 -05001811
1812 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05001813 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001814 writel(HA_LATT, phba->HAregaddr);
1815 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001816 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001817
1818 return;
1819
James Smart14691152006-12-02 13:34:28 -05001820lpfc_handle_latt_free_mbuf:
James Smart0d2b6b82008-06-14 22:52:47 -04001821 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05001822 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05001823lpfc_handle_latt_free_mp:
1824 kfree(mp);
1825lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04001826 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001827lpfc_handle_latt_err_exit:
1828 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001829 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001830 psli->sli_flag |= LPFC_PROCESS_LA;
1831 control = readl(phba->HCregaddr);
1832 control |= HC_LAINT_ENA;
1833 writel(control, phba->HCregaddr);
1834 readl(phba->HCregaddr); /* flush */
1835
1836 /* Clear Link Attention in HA REG */
1837 writel(HA_LATT, phba->HAregaddr);
1838 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001839 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001840 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001841 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001842
James Smart09372822008-01-11 01:52:54 -05001843 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1844 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05001845
1846 return;
1847}
1848
James Smarte59058c2008-08-24 21:49:00 -04001849/**
James Smart3621a712009-04-06 18:47:14 -04001850 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04001851 * @phba: pointer to lpfc hba data structure.
1852 * @vpd: pointer to the vital product data.
1853 * @len: length of the vital product data in bytes.
1854 *
1855 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1856 * an array of characters. In this routine, the ModelName, ProgramType, and
1857 * ModelDesc, etc. fields of the phba data structure will be populated.
1858 *
1859 * Return codes
1860 * 0 - pointer to the VPD passed in is NULL
1861 * 1 - success
1862 **/
James Smart3772a992009-05-22 14:50:54 -04001863int
James Smart2e0fef82007-06-17 19:56:36 -05001864lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05001865{
1866 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05001867 int Length;
dea31012005-04-17 16:05:31 -05001868 int i, j;
1869 int finished = 0;
1870 int index = 0;
1871
1872 if (!vpd)
1873 return 0;
1874
1875 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05001876 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001877 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001878 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
1879 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001880 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05001881 switch (vpd[index]) {
1882 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001883 case 0x91:
dea31012005-04-17 16:05:31 -05001884 index += 1;
1885 lenlo = vpd[index];
1886 index += 1;
1887 lenhi = vpd[index];
1888 index += 1;
1889 i = ((((unsigned short)lenhi) << 8) + lenlo);
1890 index += i;
1891 break;
1892 case 0x90:
1893 index += 1;
1894 lenlo = vpd[index];
1895 index += 1;
1896 lenhi = vpd[index];
1897 index += 1;
1898 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001899 if (Length > len - index)
1900 Length = len - index;
dea31012005-04-17 16:05:31 -05001901 while (Length > 0) {
1902 /* Look for Serial Number */
1903 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
1904 index += 2;
1905 i = vpd[index];
1906 index += 1;
1907 j = 0;
1908 Length -= (3+i);
1909 while(i--) {
1910 phba->SerialNumber[j++] = vpd[index++];
1911 if (j == 31)
1912 break;
1913 }
1914 phba->SerialNumber[j] = 0;
1915 continue;
1916 }
1917 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
1918 phba->vpd_flag |= VPD_MODEL_DESC;
1919 index += 2;
1920 i = vpd[index];
1921 index += 1;
1922 j = 0;
1923 Length -= (3+i);
1924 while(i--) {
1925 phba->ModelDesc[j++] = vpd[index++];
1926 if (j == 255)
1927 break;
1928 }
1929 phba->ModelDesc[j] = 0;
1930 continue;
1931 }
1932 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
1933 phba->vpd_flag |= VPD_MODEL_NAME;
1934 index += 2;
1935 i = vpd[index];
1936 index += 1;
1937 j = 0;
1938 Length -= (3+i);
1939 while(i--) {
1940 phba->ModelName[j++] = vpd[index++];
1941 if (j == 79)
1942 break;
1943 }
1944 phba->ModelName[j] = 0;
1945 continue;
1946 }
1947 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
1948 phba->vpd_flag |= VPD_PROGRAM_TYPE;
1949 index += 2;
1950 i = vpd[index];
1951 index += 1;
1952 j = 0;
1953 Length -= (3+i);
1954 while(i--) {
1955 phba->ProgramType[j++] = vpd[index++];
1956 if (j == 255)
1957 break;
1958 }
1959 phba->ProgramType[j] = 0;
1960 continue;
1961 }
1962 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1963 phba->vpd_flag |= VPD_PORT;
1964 index += 2;
1965 i = vpd[index];
1966 index += 1;
1967 j = 0;
1968 Length -= (3+i);
1969 while(i--) {
James Smartcd1c8302011-10-10 21:33:25 -04001970 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1971 (phba->sli4_hba.pport_name_sta ==
1972 LPFC_SLI4_PPNAME_GET)) {
1973 j++;
1974 index++;
1975 } else
1976 phba->Port[j++] = vpd[index++];
1977 if (j == 19)
1978 break;
dea31012005-04-17 16:05:31 -05001979 }
James Smartcd1c8302011-10-10 21:33:25 -04001980 if ((phba->sli_rev != LPFC_SLI_REV4) ||
1981 (phba->sli4_hba.pport_name_sta ==
1982 LPFC_SLI4_PPNAME_NON))
1983 phba->Port[j] = 0;
dea31012005-04-17 16:05:31 -05001984 continue;
1985 }
1986 else {
1987 index += 2;
1988 i = vpd[index];
1989 index += 1;
1990 index += i;
1991 Length -= (3 + i);
1992 }
1993 }
1994 finished = 0;
1995 break;
1996 case 0x78:
1997 finished = 1;
1998 break;
1999 default:
2000 index ++;
2001 break;
2002 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002003 }
dea31012005-04-17 16:05:31 -05002004
2005 return(1);
2006}
2007
James Smarte59058c2008-08-24 21:49:00 -04002008/**
James Smart3621a712009-04-06 18:47:14 -04002009 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04002010 * @phba: pointer to lpfc hba data structure.
2011 * @mdp: pointer to the data structure to hold the derived model name.
2012 * @descp: pointer to the data structure to hold the derived description.
2013 *
2014 * This routine retrieves HBA's description based on its registered PCI device
2015 * ID. The @descp passed into this function points to an array of 256 chars. It
2016 * shall be returned with the model name, maximum speed, and the host bus type.
2017 * The @mdp passed into this function points to an array of 80 chars. When the
2018 * function returns, the @mdp will be filled with the model name.
2019 **/
dea31012005-04-17 16:05:31 -05002020static void
James Smart2e0fef82007-06-17 19:56:36 -05002021lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05002022{
2023 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05002024 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002025 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04002026 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04002027 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002028 struct {
James Smarta747c9c2009-11-18 15:41:10 -05002029 char *name;
2030 char *bus;
2031 char *function;
2032 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002033
2034 if (mdp && mdp[0] != '\0'
2035 && descp && descp[0] != '\0')
2036 return;
2037
James Smartc0c11512011-05-24 11:41:34 -04002038 if (phba->lmt & LMT_16Gb)
2039 max_speed = 16;
2040 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002041 max_speed = 10;
2042 else if (phba->lmt & LMT_8Gb)
2043 max_speed = 8;
2044 else if (phba->lmt & LMT_4Gb)
2045 max_speed = 4;
2046 else if (phba->lmt & LMT_2Gb)
2047 max_speed = 2;
James Smart4169d862012-09-29 11:32:09 -04002048 else if (phba->lmt & LMT_1Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002049 max_speed = 1;
James Smart4169d862012-09-29 11:32:09 -04002050 else
2051 max_speed = 0;
dea31012005-04-17 16:05:31 -05002052
2053 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05002054
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002055 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002056 case PCI_DEVICE_ID_FIREFLY:
James Smart12222f42014-05-21 08:05:19 -04002057 m = (typeof(m)){"LP6000", "PCI",
2058 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002059 break;
dea31012005-04-17 16:05:31 -05002060 case PCI_DEVICE_ID_SUPERFLY:
2061 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart12222f42014-05-21 08:05:19 -04002062 m = (typeof(m)){"LP7000", "PCI", ""};
dea31012005-04-17 16:05:31 -05002063 else
James Smart12222f42014-05-21 08:05:19 -04002064 m = (typeof(m)){"LP7000E", "PCI", ""};
2065 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002066 break;
2067 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002068 m = (typeof(m)){"LP8000", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002069 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002070 break;
2071 case PCI_DEVICE_ID_CENTAUR:
2072 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart12222f42014-05-21 08:05:19 -04002073 m = (typeof(m)){"LP9002", "PCI", ""};
dea31012005-04-17 16:05:31 -05002074 else
James Smart12222f42014-05-21 08:05:19 -04002075 m = (typeof(m)){"LP9000", "PCI", ""};
2076 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002077 break;
2078 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002079 m = (typeof(m)){"LP952", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002080 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002081 break;
2082 case PCI_DEVICE_ID_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05002083 m = (typeof(m)){"LP9802", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002084 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002085 break;
2086 case PCI_DEVICE_ID_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05002087 m = (typeof(m)){"LP10000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002088 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002089 break;
2090 case PCI_DEVICE_ID_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05002091 m = (typeof(m)){"LPX1000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002092 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002093 break;
2094 case PCI_DEVICE_ID_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002095 m = (typeof(m)){"LP982", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002096 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002097 break;
2098 case PCI_DEVICE_ID_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002099 m = (typeof(m)){"LP1050", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002100 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002101 break;
2102 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05002103 m = (typeof(m)){"LP11000", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002104 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002105 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002106 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002107 m = (typeof(m)){"LP11000-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002108 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002109 break;
2110 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002111 m = (typeof(m)){"LP11002-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002112 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002113 break;
2114 case PCI_DEVICE_ID_NEPTUNE:
James Smart12222f42014-05-21 08:05:19 -04002115 m = (typeof(m)){"LPe1000", "PCIe",
2116 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002117 break;
2118 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart12222f42014-05-21 08:05:19 -04002119 m = (typeof(m)){"LPe1000-SP", "PCIe",
2120 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002121 break;
2122 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart12222f42014-05-21 08:05:19 -04002123 m = (typeof(m)){"LPe1002-SP", "PCIe",
2124 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002125 break;
dea31012005-04-17 16:05:31 -05002126 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05002127 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002128 break;
2129 case PCI_DEVICE_ID_BSMB:
James Smart12222f42014-05-21 08:05:19 -04002130 m = (typeof(m)){"LP111", "PCI-X2",
2131 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002132 break;
2133 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05002134 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002135 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002136 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002137 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002138 break;
2139 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002140 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04002141 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002142 break;
dea31012005-04-17 16:05:31 -05002143 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05002144 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002145 break;
2146 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05002147 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002148 break;
2149 case PCI_DEVICE_ID_LP101:
James Smart12222f42014-05-21 08:05:19 -04002150 m = (typeof(m)){"LP101", "PCI-X",
2151 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002152 break;
2153 case PCI_DEVICE_ID_LP10000S:
James Smart12222f42014-05-21 08:05:19 -04002154 m = (typeof(m)){"LP10000-S", "PCI",
2155 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002156 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002157 case PCI_DEVICE_ID_LP11000S:
James Smart12222f42014-05-21 08:05:19 -04002158 m = (typeof(m)){"LP11000-S", "PCI-X2",
2159 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05002160 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002161 case PCI_DEVICE_ID_LPE11000S:
James Smart12222f42014-05-21 08:05:19 -04002162 m = (typeof(m)){"LPe11000-S", "PCIe",
2163 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002164 break;
James Smartb87eab32007-04-25 09:53:28 -04002165 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05002166 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002167 break;
2168 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05002169 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002170 break;
2171 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05002172 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002173 break;
2174 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002175 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002176 break;
2177 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002178 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002179 break;
2180 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05002181 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002182 break;
James Smart84774a42008-08-24 21:50:06 -04002183 case PCI_DEVICE_ID_HORNET:
James Smart12222f42014-05-21 08:05:19 -04002184 m = (typeof(m)){"LP21000", "PCIe",
2185 "Obsolete, Unsupported FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002186 GE = 1;
2187 break;
2188 case PCI_DEVICE_ID_PROTEUS_VF:
James Smarta747c9c2009-11-18 15:41:10 -05002189 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002190 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002191 break;
2192 case PCI_DEVICE_ID_PROTEUS_PF:
James Smarta747c9c2009-11-18 15:41:10 -05002193 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002194 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002195 break;
2196 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05002197 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002198 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002199 break;
James Smartda0436e2009-05-22 14:51:39 -04002200 case PCI_DEVICE_ID_TIGERSHARK:
2201 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002202 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04002203 break;
James Smarta747c9c2009-11-18 15:41:10 -05002204 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04002205 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002206 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2207 break;
2208 case PCI_DEVICE_ID_FALCON:
2209 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2210 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04002211 break;
James Smart98fc5dd2010-06-07 15:24:29 -04002212 case PCI_DEVICE_ID_BALIUS:
2213 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
James Smart12222f42014-05-21 08:05:19 -04002214 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart98fc5dd2010-06-07 15:24:29 -04002215 break;
James Smart085c6472010-11-20 23:11:37 -05002216 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04002217 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05002218 break;
James Smart12222f42014-05-21 08:05:19 -04002219 case PCI_DEVICE_ID_LANCER_FC_VF:
2220 m = (typeof(m)){"LPe16000", "PCIe",
2221 "Obsolete, Unsupported Fibre Channel Adapter"};
2222 break;
James Smart085c6472010-11-20 23:11:37 -05002223 case PCI_DEVICE_ID_LANCER_FCOE:
2224 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04002225 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05002226 break;
James Smart12222f42014-05-21 08:05:19 -04002227 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2228 oneConnect = 1;
2229 m = (typeof(m)){"OCe15100", "PCIe",
2230 "Obsolete, Unsupported FCoE"};
2231 break;
James Smartf8cafd32012-08-03 12:42:51 -04002232 case PCI_DEVICE_ID_SKYHAWK:
2233 case PCI_DEVICE_ID_SKYHAWK_VF:
2234 oneConnect = 1;
2235 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2236 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002237 default:
James Smarta747c9c2009-11-18 15:41:10 -05002238 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002239 break;
dea31012005-04-17 16:05:31 -05002240 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002241
2242 if (mdp && mdp[0] == '\0')
2243 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04002244 /*
2245 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04002246 * and we put the port number on the end
2247 */
2248 if (descp && descp[0] == '\0') {
2249 if (oneConnect)
2250 snprintf(descp, 255,
James Smart4169d862012-09-29 11:32:09 -04002251 "Emulex OneConnect %s, %s Initiator %s",
James Smarta747c9c2009-11-18 15:41:10 -05002252 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04002253 phba->Port);
James Smart4169d862012-09-29 11:32:09 -04002254 else if (max_speed == 0)
2255 snprintf(descp, 255,
2256 "Emulex %s %s %s ",
2257 m.name, m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002258 else
2259 snprintf(descp, 255,
2260 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05002261 m.name, max_speed, (GE) ? "GE" : "Gb",
2262 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002263 }
dea31012005-04-17 16:05:31 -05002264}
2265
James Smarte59058c2008-08-24 21:49:00 -04002266/**
James Smart3621a712009-04-06 18:47:14 -04002267 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04002268 * @phba: pointer to lpfc hba data structure.
2269 * @pring: pointer to a IOCB ring.
2270 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2271 *
2272 * This routine posts a given number of IOCBs with the associated DMA buffer
2273 * descriptors specified by the cnt argument to the given IOCB ring.
2274 *
2275 * Return codes
2276 * The number of IOCBs NOT able to be posted to the IOCB ring.
2277 **/
dea31012005-04-17 16:05:31 -05002278int
James Smart495a7142008-06-14 22:52:59 -04002279lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002280{
2281 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002282 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002283 struct lpfc_dmabuf *mp1, *mp2;
2284
2285 cnt += pring->missbufcnt;
2286
2287 /* While there are buffers to post */
2288 while (cnt > 0) {
2289 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002290 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002291 if (iocb == NULL) {
2292 pring->missbufcnt = cnt;
2293 return cnt;
2294 }
dea31012005-04-17 16:05:31 -05002295 icmd = &iocb->iocb;
2296
2297 /* 2 buffers can be posted per command */
2298 /* Allocate buffer to post */
2299 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2300 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002301 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2302 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002303 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002304 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002305 pring->missbufcnt = cnt;
2306 return cnt;
2307 }
2308
2309 INIT_LIST_HEAD(&mp1->list);
2310 /* Allocate buffer to post */
2311 if (cnt > 1) {
2312 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2313 if (mp2)
2314 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2315 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002316 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002317 kfree(mp2);
dea31012005-04-17 16:05:31 -05002318 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2319 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002320 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002321 pring->missbufcnt = cnt;
2322 return cnt;
2323 }
2324
2325 INIT_LIST_HEAD(&mp2->list);
2326 } else {
2327 mp2 = NULL;
2328 }
2329
2330 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2331 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2332 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2333 icmd->ulpBdeCount = 1;
2334 cnt--;
2335 if (mp2) {
2336 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2337 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2338 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2339 cnt--;
2340 icmd->ulpBdeCount = 2;
2341 }
2342
2343 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2344 icmd->ulpLe = 1;
2345
James Smart3772a992009-05-22 14:50:54 -04002346 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2347 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002348 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2349 kfree(mp1);
2350 cnt++;
2351 if (mp2) {
2352 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2353 kfree(mp2);
2354 cnt++;
2355 }
James Bottomley604a3e32005-10-29 10:28:33 -05002356 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002357 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002358 return cnt;
2359 }
dea31012005-04-17 16:05:31 -05002360 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002361 if (mp2)
dea31012005-04-17 16:05:31 -05002362 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002363 }
2364 pring->missbufcnt = 0;
2365 return 0;
2366}
2367
James Smarte59058c2008-08-24 21:49:00 -04002368/**
James Smart3621a712009-04-06 18:47:14 -04002369 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002370 * @phba: pointer to lpfc hba data structure.
2371 *
2372 * This routine posts initial receive IOCB buffers to the ELS ring. The
2373 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2374 * set to 64 IOCBs.
2375 *
2376 * Return codes
2377 * 0 - success (currently always success)
2378 **/
dea31012005-04-17 16:05:31 -05002379static int
James Smart2e0fef82007-06-17 19:56:36 -05002380lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002381{
2382 struct lpfc_sli *psli = &phba->sli;
2383
2384 /* Ring 0, ELS / CT buffers */
James Smart495a7142008-06-14 22:52:59 -04002385 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002386 /* Ring 2 - FCP no buffers needed */
2387
2388 return 0;
2389}
2390
2391#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2392
James Smarte59058c2008-08-24 21:49:00 -04002393/**
James Smart3621a712009-04-06 18:47:14 -04002394 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002395 * @HashResultPointer: pointer to an array as hash table.
2396 *
2397 * This routine sets up the initial values to the array of hash table entries
2398 * for the LC HBAs.
2399 **/
dea31012005-04-17 16:05:31 -05002400static void
2401lpfc_sha_init(uint32_t * HashResultPointer)
2402{
2403 HashResultPointer[0] = 0x67452301;
2404 HashResultPointer[1] = 0xEFCDAB89;
2405 HashResultPointer[2] = 0x98BADCFE;
2406 HashResultPointer[3] = 0x10325476;
2407 HashResultPointer[4] = 0xC3D2E1F0;
2408}
2409
James Smarte59058c2008-08-24 21:49:00 -04002410/**
James Smart3621a712009-04-06 18:47:14 -04002411 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002412 * @HashResultPointer: pointer to an initial/result hash table.
2413 * @HashWorkingPointer: pointer to an working hash table.
2414 *
2415 * This routine iterates an initial hash table pointed by @HashResultPointer
2416 * with the values from the working hash table pointeed by @HashWorkingPointer.
2417 * The results are putting back to the initial hash table, returned through
2418 * the @HashResultPointer as the result hash table.
2419 **/
dea31012005-04-17 16:05:31 -05002420static void
2421lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2422{
2423 int t;
2424 uint32_t TEMP;
2425 uint32_t A, B, C, D, E;
2426 t = 16;
2427 do {
2428 HashWorkingPointer[t] =
2429 S(1,
2430 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2431 8] ^
2432 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2433 } while (++t <= 79);
2434 t = 0;
2435 A = HashResultPointer[0];
2436 B = HashResultPointer[1];
2437 C = HashResultPointer[2];
2438 D = HashResultPointer[3];
2439 E = HashResultPointer[4];
2440
2441 do {
2442 if (t < 20) {
2443 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2444 } else if (t < 40) {
2445 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2446 } else if (t < 60) {
2447 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2448 } else {
2449 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2450 }
2451 TEMP += S(5, A) + E + HashWorkingPointer[t];
2452 E = D;
2453 D = C;
2454 C = S(30, B);
2455 B = A;
2456 A = TEMP;
2457 } while (++t <= 79);
2458
2459 HashResultPointer[0] += A;
2460 HashResultPointer[1] += B;
2461 HashResultPointer[2] += C;
2462 HashResultPointer[3] += D;
2463 HashResultPointer[4] += E;
2464
2465}
2466
James Smarte59058c2008-08-24 21:49:00 -04002467/**
James Smart3621a712009-04-06 18:47:14 -04002468 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002469 * @RandomChallenge: pointer to the entry of host challenge random number array.
2470 * @HashWorking: pointer to the entry of the working hash array.
2471 *
2472 * This routine calculates the working hash array referred by @HashWorking
2473 * from the challenge random numbers associated with the host, referred by
2474 * @RandomChallenge. The result is put into the entry of the working hash
2475 * array and returned by reference through @HashWorking.
2476 **/
dea31012005-04-17 16:05:31 -05002477static void
2478lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2479{
2480 *HashWorking = (*RandomChallenge ^ *HashWorking);
2481}
2482
James Smarte59058c2008-08-24 21:49:00 -04002483/**
James Smart3621a712009-04-06 18:47:14 -04002484 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002485 * @phba: pointer to lpfc hba data structure.
2486 * @hbainit: pointer to an array of unsigned 32-bit integers.
2487 *
2488 * This routine performs the special handling for LC HBA initialization.
2489 **/
dea31012005-04-17 16:05:31 -05002490void
2491lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2492{
2493 int t;
2494 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002495 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002496
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002497 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002498 if (!HashWorking)
2499 return;
2500
dea31012005-04-17 16:05:31 -05002501 HashWorking[0] = HashWorking[78] = *pwwnn++;
2502 HashWorking[1] = HashWorking[79] = *pwwnn;
2503
2504 for (t = 0; t < 7; t++)
2505 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2506
2507 lpfc_sha_init(hbainit);
2508 lpfc_sha_iterate(hbainit, HashWorking);
2509 kfree(HashWorking);
2510}
2511
James Smarte59058c2008-08-24 21:49:00 -04002512/**
James Smart3621a712009-04-06 18:47:14 -04002513 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002514 * @vport: pointer to a virtual N_Port data structure.
2515 *
2516 * This routine performs the necessary cleanups before deleting the @vport.
2517 * It invokes the discovery state machine to perform necessary state
2518 * transitions and to release the ndlps associated with the @vport. Note,
2519 * the physical port is treated as @vport 0.
2520 **/
James Smart87af33f2007-10-27 13:37:43 -04002521void
James Smart2e0fef82007-06-17 19:56:36 -05002522lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002523{
James Smart87af33f2007-10-27 13:37:43 -04002524 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002525 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002526 int i = 0;
dea31012005-04-17 16:05:31 -05002527
James Smart87af33f2007-10-27 13:37:43 -04002528 if (phba->link_state > LPFC_LINK_DOWN)
2529 lpfc_port_link_failure(vport);
2530
2531 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002532 if (!NLP_CHK_NODE_ACT(ndlp)) {
2533 ndlp = lpfc_enable_node(vport, ndlp,
2534 NLP_STE_UNUSED_NODE);
2535 if (!ndlp)
2536 continue;
2537 spin_lock_irq(&phba->ndlp_lock);
2538 NLP_SET_FREE_REQ(ndlp);
2539 spin_unlock_irq(&phba->ndlp_lock);
2540 /* Trigger the release of the ndlp memory */
2541 lpfc_nlp_put(ndlp);
2542 continue;
2543 }
2544 spin_lock_irq(&phba->ndlp_lock);
2545 if (NLP_CHK_FREE_REQ(ndlp)) {
2546 /* The ndlp should not be in memory free mode already */
2547 spin_unlock_irq(&phba->ndlp_lock);
2548 continue;
2549 } else
2550 /* Indicate request for freeing ndlp memory */
2551 NLP_SET_FREE_REQ(ndlp);
2552 spin_unlock_irq(&phba->ndlp_lock);
2553
James Smart58da1ff2008-04-07 10:15:56 -04002554 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2555 ndlp->nlp_DID == Fabric_DID) {
2556 /* Just free up ndlp with Fabric_DID for vports */
2557 lpfc_nlp_put(ndlp);
2558 continue;
2559 }
2560
James Smarteff4a012012-01-18 16:25:25 -05002561 /* take care of nodes in unused state before the state
2562 * machine taking action.
2563 */
2564 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2565 lpfc_nlp_put(ndlp);
2566 continue;
2567 }
2568
James Smart87af33f2007-10-27 13:37:43 -04002569 if (ndlp->nlp_type & NLP_FABRIC)
2570 lpfc_disc_state_machine(vport, ndlp, NULL,
2571 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002572
James Smart87af33f2007-10-27 13:37:43 -04002573 lpfc_disc_state_machine(vport, ndlp, NULL,
2574 NLP_EVT_DEVICE_RM);
2575 }
2576
James Smarta8adb832007-10-27 13:37:53 -04002577 /* At this point, ALL ndlp's should be gone
2578 * because of the previous NLP_EVT_DEVICE_RM.
2579 * Lets wait for this to happen, if needed.
2580 */
James Smart87af33f2007-10-27 13:37:43 -04002581 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002582 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04002583 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04002584 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002585 list_for_each_entry_safe(ndlp, next_ndlp,
2586 &vport->fc_nodes, nlp_listp) {
2587 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2588 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04002589 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05002590 "usgmap:x%x refcnt:%d\n",
2591 ndlp->nlp_DID, (void *)ndlp,
2592 ndlp->nlp_usg_map,
2593 atomic_read(
2594 &ndlp->kref.refcount));
2595 }
James Smarta8adb832007-10-27 13:37:53 -04002596 break;
James Smart87af33f2007-10-27 13:37:43 -04002597 }
James Smarta8adb832007-10-27 13:37:53 -04002598
2599 /* Wait for any activity on ndlps to settle */
2600 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002601 }
James Smart1151e3e2011-02-16 12:39:35 -05002602 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002603}
2604
James Smarte59058c2008-08-24 21:49:00 -04002605/**
James Smart3621a712009-04-06 18:47:14 -04002606 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002607 * @vport: pointer to a virtual N_Port data structure.
2608 *
2609 * This routine stops all the timers associated with a @vport. This function
2610 * is invoked before disabling or deleting a @vport. Note that the physical
2611 * port is treated as @vport 0.
2612 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002613void
2614lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002615{
James Smart92d7f7b2007-06-17 19:56:38 -05002616 del_timer_sync(&vport->els_tmofunc);
2617 del_timer_sync(&vport->fc_fdmitmo);
James Smart92494142011-02-16 12:39:44 -05002618 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002619 lpfc_can_disctmo(vport);
2620 return;
dea31012005-04-17 16:05:31 -05002621}
2622
James Smarte59058c2008-08-24 21:49:00 -04002623/**
James Smartecfd03c2010-02-12 14:41:27 -05002624 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2625 * @phba: pointer to lpfc hba data structure.
2626 *
2627 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2628 * caller of this routine should already hold the host lock.
2629 **/
2630void
2631__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2632{
James Smart5ac6b302010-10-22 11:05:36 -04002633 /* Clear pending FCF rediscovery wait flag */
2634 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2635
James Smartecfd03c2010-02-12 14:41:27 -05002636 /* Now, try to stop the timer */
2637 del_timer(&phba->fcf.redisc_wait);
2638}
2639
2640/**
2641 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2642 * @phba: pointer to lpfc hba data structure.
2643 *
2644 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2645 * checks whether the FCF rediscovery wait timer is pending with the host
2646 * lock held before proceeding with disabling the timer and clearing the
2647 * wait timer pendig flag.
2648 **/
2649void
2650lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2651{
2652 spin_lock_irq(&phba->hbalock);
2653 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2654 /* FCF rediscovery timer already fired or stopped */
2655 spin_unlock_irq(&phba->hbalock);
2656 return;
2657 }
2658 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002659 /* Clear failover in progress flags */
2660 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002661 spin_unlock_irq(&phba->hbalock);
2662}
2663
2664/**
James Smart3772a992009-05-22 14:50:54 -04002665 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002666 * @phba: pointer to lpfc hba data structure.
2667 *
2668 * This routine stops all the timers associated with a HBA. This function is
2669 * invoked before either putting a HBA offline or unloading the driver.
2670 **/
James Smart3772a992009-05-22 14:50:54 -04002671void
2672lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002673{
James Smart51ef4c22007-08-02 11:10:31 -04002674 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05002675 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002676 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002677 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002678 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002679 if (phba->sli_rev == LPFC_SLI_REV4) {
2680 del_timer_sync(&phba->rrq_tmr);
2681 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2682 }
James Smart3772a992009-05-22 14:50:54 -04002683 phba->hb_outstanding = 0;
2684
2685 switch (phba->pci_dev_grp) {
2686 case LPFC_PCI_DEV_LP:
2687 /* Stop any LightPulse device specific driver timers */
2688 del_timer_sync(&phba->fcp_poll_timer);
2689 break;
2690 case LPFC_PCI_DEV_OC:
2691 /* Stop any OneConnect device sepcific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002692 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002693 break;
2694 default:
2695 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2696 "0297 Invalid device group (x%x)\n",
2697 phba->pci_dev_grp);
2698 break;
2699 }
James Smart2e0fef82007-06-17 19:56:36 -05002700 return;
dea31012005-04-17 16:05:31 -05002701}
2702
James Smarte59058c2008-08-24 21:49:00 -04002703/**
James Smart3621a712009-04-06 18:47:14 -04002704 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002705 * @phba: pointer to lpfc hba data structure.
2706 *
2707 * This routine marks a HBA's management interface as blocked. Once the HBA's
2708 * management interface is marked as blocked, all the user space access to
2709 * the HBA, whether they are from sysfs interface or libdfc interface will
2710 * all be blocked. The HBA is set to block the management interface when the
2711 * driver prepares the HBA interface for online or offline.
2712 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01002713static void
James Smart618a5232012-06-12 13:54:36 -04002714lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
Adrian Bunka6ababd2007-11-05 18:07:33 +01002715{
2716 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04002717 uint8_t actcmd = MBX_HEARTBEAT;
2718 unsigned long timeout;
2719
Adrian Bunka6ababd2007-11-05 18:07:33 +01002720 spin_lock_irqsave(&phba->hbalock, iflag);
2721 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart618a5232012-06-12 13:54:36 -04002722 spin_unlock_irqrestore(&phba->hbalock, iflag);
2723 if (mbx_action == LPFC_MBX_NO_WAIT)
2724 return;
2725 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2726 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002727 if (phba->sli.mbox_active) {
James Smart6e7288d2010-06-07 15:23:35 -04002728 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
James Smarta183a152011-10-10 21:32:43 -04002729 /* Determine how long we might wait for the active mailbox
2730 * command to be gracefully completed by firmware.
2731 */
2732 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
2733 phba->sli.mbox_active) * 1000) + jiffies;
2734 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002735 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002736
James Smart6e7288d2010-06-07 15:23:35 -04002737 /* Wait for the outstnading mailbox command to complete */
2738 while (phba->sli.mbox_active) {
2739 /* Check active mailbox complete status every 2ms */
2740 msleep(2);
2741 if (time_after(jiffies, timeout)) {
2742 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2743 "2813 Mgmt IO is Blocked %x "
2744 "- mbox cmd %x still active\n",
2745 phba->sli.sli_flag, actcmd);
2746 break;
2747 }
2748 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002749}
2750
James Smarte59058c2008-08-24 21:49:00 -04002751/**
James Smart6b5151f2012-01-18 16:24:06 -05002752 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
2753 * @phba: pointer to lpfc hba data structure.
2754 *
2755 * Allocate RPIs for all active remote nodes. This is needed whenever
2756 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
2757 * is to fixup the temporary rpi assignments.
2758 **/
2759void
2760lpfc_sli4_node_prep(struct lpfc_hba *phba)
2761{
2762 struct lpfc_nodelist *ndlp, *next_ndlp;
2763 struct lpfc_vport **vports;
2764 int i;
2765
2766 if (phba->sli_rev != LPFC_SLI_REV4)
2767 return;
2768
2769 vports = lpfc_create_vport_work_array(phba);
2770 if (vports != NULL) {
2771 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2772 if (vports[i]->load_flag & FC_UNLOADING)
2773 continue;
2774
2775 list_for_each_entry_safe(ndlp, next_ndlp,
2776 &vports[i]->fc_nodes,
2777 nlp_listp) {
2778 if (NLP_CHK_NODE_ACT(ndlp))
2779 ndlp->nlp_rpi =
2780 lpfc_sli4_alloc_rpi(phba);
2781 }
2782 }
2783 }
2784 lpfc_destroy_vport_work_array(phba, vports);
2785}
2786
2787/**
James Smart3621a712009-04-06 18:47:14 -04002788 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04002789 * @phba: pointer to lpfc hba data structure.
2790 *
2791 * This routine initializes the HBA and brings a HBA online. During this
2792 * process, the management interface is blocked to prevent user space access
2793 * to the HBA interfering with the driver initialization.
2794 *
2795 * Return codes
2796 * 0 - successful
2797 * 1 - failed
2798 **/
dea31012005-04-17 16:05:31 -05002799int
James Smart2e0fef82007-06-17 19:56:36 -05002800lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002801{
Julia Lawall372bd282008-12-16 16:15:08 +01002802 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04002803 struct lpfc_vport **vports;
2804 int i;
James Smart16a3a202013-04-17 20:14:38 -04002805 bool vpis_cleared = false;
James Smart2e0fef82007-06-17 19:56:36 -05002806
dea31012005-04-17 16:05:31 -05002807 if (!phba)
2808 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01002809 vport = phba->pport;
dea31012005-04-17 16:05:31 -05002810
James Smart2e0fef82007-06-17 19:56:36 -05002811 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05002812 return 0;
2813
James Smarted957682007-06-17 19:56:37 -05002814 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002815 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05002816
James Smart618a5232012-06-12 13:54:36 -04002817 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05002818
James Smart46fa3112007-04-25 09:51:45 -04002819 if (!lpfc_sli_queue_setup(phba)) {
2820 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002821 return 1;
James Smart46fa3112007-04-25 09:51:45 -04002822 }
2823
James Smartda0436e2009-05-22 14:51:39 -04002824 if (phba->sli_rev == LPFC_SLI_REV4) {
2825 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
2826 lpfc_unblock_mgmt_io(phba);
2827 return 1;
2828 }
James Smart16a3a202013-04-17 20:14:38 -04002829 spin_lock_irq(&phba->hbalock);
2830 if (!phba->sli4_hba.max_cfg_param.vpi_used)
2831 vpis_cleared = true;
2832 spin_unlock_irq(&phba->hbalock);
James Smartda0436e2009-05-22 14:51:39 -04002833 } else {
2834 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
2835 lpfc_unblock_mgmt_io(phba);
2836 return 1;
2837 }
James Smart46fa3112007-04-25 09:51:45 -04002838 }
dea31012005-04-17 16:05:31 -05002839
James Smart549e55c2007-08-02 11:09:51 -04002840 vports = lpfc_create_vport_work_array(phba);
2841 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002842 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002843 struct Scsi_Host *shost;
2844 shost = lpfc_shost_from_vport(vports[i]);
2845 spin_lock_irq(shost->host_lock);
2846 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
2847 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2848 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart16a3a202013-04-17 20:14:38 -04002849 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart1c6834a2009-07-19 10:01:26 -04002850 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart16a3a202013-04-17 20:14:38 -04002851 if ((vpis_cleared) &&
2852 (vports[i]->port_type !=
2853 LPFC_PHYSICAL_PORT))
2854 vports[i]->vpi = 0;
2855 }
James Smart549e55c2007-08-02 11:09:51 -04002856 spin_unlock_irq(shost->host_lock);
2857 }
James Smart09372822008-01-11 01:52:54 -05002858 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002859
James Smart46fa3112007-04-25 09:51:45 -04002860 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002861 return 0;
2862}
2863
James Smarte59058c2008-08-24 21:49:00 -04002864/**
James Smart3621a712009-04-06 18:47:14 -04002865 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04002866 * @phba: pointer to lpfc hba data structure.
2867 *
2868 * This routine marks a HBA's management interface as not blocked. Once the
2869 * HBA's management interface is marked as not blocked, all the user space
2870 * access to the HBA, whether they are from sysfs interface or libdfc
2871 * interface will be allowed. The HBA is set to block the management interface
2872 * when the driver prepares the HBA interface for online or offline and then
2873 * set to unblock the management interface afterwards.
2874 **/
James Smart46fa3112007-04-25 09:51:45 -04002875void
James Smart46fa3112007-04-25 09:51:45 -04002876lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
2877{
2878 unsigned long iflag;
2879
James Smart2e0fef82007-06-17 19:56:36 -05002880 spin_lock_irqsave(&phba->hbalock, iflag);
2881 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
2882 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04002883}
2884
James Smarte59058c2008-08-24 21:49:00 -04002885/**
James Smart3621a712009-04-06 18:47:14 -04002886 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04002887 * @phba: pointer to lpfc hba data structure.
2888 *
2889 * This routine is invoked to prepare a HBA to be brought offline. It performs
2890 * unregistration login to all the nodes on all vports and flushes the mailbox
2891 * queue to make it ready to be brought offline.
2892 **/
James Smart46fa3112007-04-25 09:51:45 -04002893void
James Smart618a5232012-06-12 13:54:36 -04002894lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04002895{
James Smart2e0fef82007-06-17 19:56:36 -05002896 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04002897 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04002898 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05002899 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04002900 int i;
dea31012005-04-17 16:05:31 -05002901
James Smart2e0fef82007-06-17 19:56:36 -05002902 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002903 return;
dea31012005-04-17 16:05:31 -05002904
James Smart618a5232012-06-12 13:54:36 -04002905 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05002906
2907 lpfc_linkdown(phba);
2908
James Smart87af33f2007-10-27 13:37:43 -04002909 /* Issue an unreg_login to all nodes on all vports */
2910 vports = lpfc_create_vport_work_array(phba);
2911 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04002912 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04002913 if (vports[i]->load_flag & FC_UNLOADING)
2914 continue;
James Smart72100cc2010-02-12 14:43:01 -05002915 shost = lpfc_shost_from_vport(vports[i]);
2916 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05002917 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002918 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2919 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05002920 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05002921
James Smart87af33f2007-10-27 13:37:43 -04002922 shost = lpfc_shost_from_vport(vports[i]);
2923 list_for_each_entry_safe(ndlp, next_ndlp,
2924 &vports[i]->fc_nodes,
2925 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002926 if (!NLP_CHK_NODE_ACT(ndlp))
2927 continue;
James Smart87af33f2007-10-27 13:37:43 -04002928 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2929 continue;
2930 if (ndlp->nlp_type & NLP_FABRIC) {
2931 lpfc_disc_state_machine(vports[i], ndlp,
2932 NULL, NLP_EVT_DEVICE_RECOVERY);
2933 lpfc_disc_state_machine(vports[i], ndlp,
2934 NULL, NLP_EVT_DEVICE_RM);
2935 }
2936 spin_lock_irq(shost->host_lock);
2937 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart401ee0c2012-03-01 22:35:34 -05002938 spin_unlock_irq(shost->host_lock);
James Smart6b5151f2012-01-18 16:24:06 -05002939 /*
2940 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05002941 * RPI. Get a new RPI when the adapter port
2942 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05002943 */
2944 if (phba->sli_rev == LPFC_SLI_REV4)
2945 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04002946 lpfc_unreg_rpi(vports[i], ndlp);
2947 }
2948 }
2949 }
James Smart09372822008-01-11 01:52:54 -05002950 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002951
James Smart618a5232012-06-12 13:54:36 -04002952 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
James Smart46fa3112007-04-25 09:51:45 -04002953}
2954
James Smarte59058c2008-08-24 21:49:00 -04002955/**
James Smart3621a712009-04-06 18:47:14 -04002956 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04002957 * @phba: pointer to lpfc hba data structure.
2958 *
2959 * This routine actually brings a HBA offline. It stops all the timers
2960 * associated with the HBA, brings down the SLI layer, and eventually
2961 * marks the HBA as in offline state for the upper layer protocol.
2962 **/
James Smart46fa3112007-04-25 09:51:45 -04002963void
James Smart2e0fef82007-06-17 19:56:36 -05002964lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04002965{
James Smart549e55c2007-08-02 11:09:51 -04002966 struct Scsi_Host *shost;
2967 struct lpfc_vport **vports;
2968 int i;
James Smart46fa3112007-04-25 09:51:45 -04002969
James Smart549e55c2007-08-02 11:09:51 -04002970 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002971 return;
James Smart688a8862006-07-06 15:49:56 -04002972
James Smartda0436e2009-05-22 14:51:39 -04002973 /* stop port and all timers associated with this hba */
2974 lpfc_stop_port(phba);
James Smart51ef4c22007-08-02 11:10:31 -04002975 vports = lpfc_create_vport_work_array(phba);
2976 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002977 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04002978 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05002979 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05002980 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002981 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05002982 /* Bring down the SLI Layer and cleanup. The HBA is offline
2983 now. */
2984 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002985 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04002986 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05002987 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04002988 vports = lpfc_create_vport_work_array(phba);
2989 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002990 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002991 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04002992 spin_lock_irq(shost->host_lock);
2993 vports[i]->work_port_events = 0;
2994 vports[i]->fc_flag |= FC_OFFLINE_MODE;
2995 spin_unlock_irq(shost->host_lock);
2996 }
James Smart09372822008-01-11 01:52:54 -05002997 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002998}
2999
James Smarte59058c2008-08-24 21:49:00 -04003000/**
James Smart3621a712009-04-06 18:47:14 -04003001 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04003002 * @phba: pointer to lpfc hba data structure.
3003 *
3004 * This routine is to free all the SCSI buffers and IOCBs from the driver
3005 * list back to kernel. It is called from lpfc_pci_remove_one to free
3006 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04003007 **/
James Smart8a9d2e82012-05-09 21:16:12 -04003008static void
James Smart2e0fef82007-06-17 19:56:36 -05003009lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003010{
3011 struct lpfc_scsi_buf *sb, *sb_next;
3012 struct lpfc_iocbq *io, *io_next;
3013
James Smart2e0fef82007-06-17 19:56:36 -05003014 spin_lock_irq(&phba->hbalock);
James Smarta40fc5f2013-04-17 20:17:40 -04003015
dea31012005-04-17 16:05:31 -05003016 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smarta40fc5f2013-04-17 20:17:40 -04003017
3018 spin_lock(&phba->scsi_buf_list_put_lock);
3019 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3020 list) {
dea31012005-04-17 16:05:31 -05003021 list_del(&sb->list);
3022 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05003023 sb->dma_handle);
dea31012005-04-17 16:05:31 -05003024 kfree(sb);
3025 phba->total_scsi_bufs--;
3026 }
James Smarta40fc5f2013-04-17 20:17:40 -04003027 spin_unlock(&phba->scsi_buf_list_put_lock);
3028
3029 spin_lock(&phba->scsi_buf_list_get_lock);
3030 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3031 list) {
3032 list_del(&sb->list);
3033 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
3034 sb->dma_handle);
3035 kfree(sb);
3036 phba->total_scsi_bufs--;
3037 }
3038 spin_unlock(&phba->scsi_buf_list_get_lock);
dea31012005-04-17 16:05:31 -05003039
3040 /* Release all the lpfc_iocbq entries maintained by this host. */
3041 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
3042 list_del(&io->list);
3043 kfree(io);
3044 phba->total_iocbq_bufs--;
3045 }
James Smart6d368e52011-05-24 11:44:12 -04003046
James Smart2e0fef82007-06-17 19:56:36 -05003047 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003048}
3049
3050/**
3051 * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping
3052 * @phba: pointer to lpfc hba data structure.
3053 *
3054 * This routine first calculates the sizes of the current els and allocated
3055 * scsi sgl lists, and then goes through all sgls to updates the physical
3056 * XRIs assigned due to port function reset. During port initialization, the
3057 * current els and allocated scsi sgl lists are 0s.
3058 *
3059 * Return codes
3060 * 0 - successful (for now, it always returns 0)
3061 **/
3062int
3063lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba)
3064{
3065 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3066 struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL;
3067 uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt;
3068 LIST_HEAD(els_sgl_list);
3069 LIST_HEAD(scsi_sgl_list);
3070 int rc;
James Smartdafe8ce2014-09-03 12:56:40 -04003071 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart8a9d2e82012-05-09 21:16:12 -04003072
3073 /*
3074 * update on pci function's els xri-sgl list
3075 */
3076 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3077 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3078 /* els xri-sgl expanded */
3079 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3080 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3081 "3157 ELS xri-sgl count increased from "
3082 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3083 els_xri_cnt);
3084 /* allocate the additional els sgls */
3085 for (i = 0; i < xri_cnt; i++) {
3086 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3087 GFP_KERNEL);
3088 if (sglq_entry == NULL) {
3089 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3090 "2562 Failure to allocate an "
3091 "ELS sgl entry:%d\n", i);
3092 rc = -ENOMEM;
3093 goto out_free_mem;
3094 }
3095 sglq_entry->buff_type = GEN_BUFF_TYPE;
3096 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3097 &sglq_entry->phys);
3098 if (sglq_entry->virt == NULL) {
3099 kfree(sglq_entry);
3100 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3101 "2563 Failure to allocate an "
3102 "ELS mbuf:%d\n", i);
3103 rc = -ENOMEM;
3104 goto out_free_mem;
3105 }
3106 sglq_entry->sgl = sglq_entry->virt;
3107 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3108 sglq_entry->state = SGL_FREED;
3109 list_add_tail(&sglq_entry->list, &els_sgl_list);
3110 }
James Smart38c20672013-03-01 16:37:44 -05003111 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04003112 spin_lock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003113 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04003114 spin_unlock(&pring->ring_lock);
James Smart38c20672013-03-01 16:37:44 -05003115 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003116 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3117 /* els xri-sgl shrinked */
3118 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3119 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3120 "3158 ELS xri-sgl count decreased from "
3121 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3122 els_xri_cnt);
3123 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04003124 spin_lock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003125 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04003126 spin_unlock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003127 spin_unlock_irq(&phba->hbalock);
3128 /* release extra els sgls from list */
3129 for (i = 0; i < xri_cnt; i++) {
3130 list_remove_head(&els_sgl_list,
3131 sglq_entry, struct lpfc_sglq, list);
3132 if (sglq_entry) {
3133 lpfc_mbuf_free(phba, sglq_entry->virt,
3134 sglq_entry->phys);
3135 kfree(sglq_entry);
3136 }
3137 }
3138 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04003139 spin_lock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003140 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04003141 spin_unlock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003142 spin_unlock_irq(&phba->hbalock);
3143 } else
3144 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3145 "3163 ELS xri-sgl count unchanged: %d\n",
3146 els_xri_cnt);
3147 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3148
3149 /* update xris to els sgls on the list */
3150 sglq_entry = NULL;
3151 sglq_entry_next = NULL;
3152 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3153 &phba->sli4_hba.lpfc_sgl_list, list) {
3154 lxri = lpfc_sli4_next_xritag(phba);
3155 if (lxri == NO_XRI) {
3156 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3157 "2400 Failed to allocate xri for "
3158 "ELS sgl\n");
3159 rc = -ENOMEM;
3160 goto out_free_mem;
3161 }
3162 sglq_entry->sli4_lxritag = lxri;
3163 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3164 }
3165
3166 /*
3167 * update on pci function's allocated scsi xri-sgl list
3168 */
3169 phba->total_scsi_bufs = 0;
3170
3171 /* maximum number of xris available for scsi buffers */
3172 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3173 els_xri_cnt;
3174
3175 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3176 "2401 Current allocated SCSI xri-sgl count:%d, "
3177 "maximum SCSI xri count:%d\n",
3178 phba->sli4_hba.scsi_xri_cnt,
3179 phba->sli4_hba.scsi_xri_max);
3180
James Smarta40fc5f2013-04-17 20:17:40 -04003181 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003182 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003183 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3184 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
James Smart164cecd2013-09-06 12:22:38 -04003185 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003186 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003187
3188 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3189 /* max scsi xri shrinked below the allocated scsi buffers */
3190 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3191 phba->sli4_hba.scsi_xri_max;
3192 /* release the extra allocated scsi buffers */
3193 for (i = 0; i < scsi_xri_cnt; i++) {
3194 list_remove_head(&scsi_sgl_list, psb,
3195 struct lpfc_scsi_buf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04003196 if (psb) {
3197 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
3198 psb->data, psb->dma_handle);
3199 kfree(psb);
3200 }
James Smart8a9d2e82012-05-09 21:16:12 -04003201 }
James Smarta40fc5f2013-04-17 20:17:40 -04003202 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003203 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
James Smarta40fc5f2013-04-17 20:17:40 -04003204 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003205 }
3206
3207 /* update xris associated to remaining allocated scsi buffers */
3208 psb = NULL;
3209 psb_next = NULL;
3210 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3211 lxri = lpfc_sli4_next_xritag(phba);
3212 if (lxri == NO_XRI) {
3213 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3214 "2560 Failed to allocate xri for "
3215 "scsi buffer\n");
3216 rc = -ENOMEM;
3217 goto out_free_mem;
3218 }
3219 psb->cur_iocbq.sli4_lxritag = lxri;
3220 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3221 }
James Smarta40fc5f2013-04-17 20:17:40 -04003222 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003223 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003224 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3225 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
James Smart164cecd2013-09-06 12:22:38 -04003226 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003227 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003228
dea31012005-04-17 16:05:31 -05003229 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003230
3231out_free_mem:
3232 lpfc_free_els_sgl_list(phba);
3233 lpfc_scsi_free(phba);
3234 return rc;
dea31012005-04-17 16:05:31 -05003235}
3236
James Smarte59058c2008-08-24 21:49:00 -04003237/**
James Smart3621a712009-04-06 18:47:14 -04003238 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04003239 * @phba: pointer to lpfc hba data structure.
3240 * @instance: a unique integer ID to this FC port.
3241 * @dev: pointer to the device data structure.
3242 *
3243 * This routine creates a FC port for the upper layer protocol. The FC port
3244 * can be created on top of either a physical port or a virtual port provided
3245 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3246 * and associates the FC port created before adding the shost into the SCSI
3247 * layer.
3248 *
3249 * Return codes
3250 * @vport - pointer to the virtual N_Port data structure.
3251 * NULL - port create failed.
3252 **/
James Smart2e0fef82007-06-17 19:56:36 -05003253struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04003254lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04003255{
James Smart2e0fef82007-06-17 19:56:36 -05003256 struct lpfc_vport *vport;
3257 struct Scsi_Host *shost;
3258 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04003259
James Smartea4142f2015-04-07 15:07:13 -04003260 if (dev != &phba->pcidev->dev) {
James Smart3de2a652007-08-02 11:09:59 -04003261 shost = scsi_host_alloc(&lpfc_vport_template,
3262 sizeof(struct lpfc_vport));
James Smartea4142f2015-04-07 15:07:13 -04003263 } else {
3264 if (phba->sli_rev == LPFC_SLI_REV4)
3265 shost = scsi_host_alloc(&lpfc_template,
James Smart3de2a652007-08-02 11:09:59 -04003266 sizeof(struct lpfc_vport));
James Smartea4142f2015-04-07 15:07:13 -04003267 else
3268 shost = scsi_host_alloc(&lpfc_template_s3,
3269 sizeof(struct lpfc_vport));
3270 }
James Smart2e0fef82007-06-17 19:56:36 -05003271 if (!shost)
3272 goto out;
James Smart47a86172007-04-25 09:53:22 -04003273
James Smart2e0fef82007-06-17 19:56:36 -05003274 vport = (struct lpfc_vport *) shost->hostdata;
3275 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05003276 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05003277 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05003278 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04003279
James Smart3de2a652007-08-02 11:09:59 -04003280 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05003281 shost->unique_id = instance;
3282 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04003283 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05003284 shost->this_id = -1;
3285 shost->max_cmd_len = 16;
James Smartda0436e2009-05-22 14:51:39 -04003286 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05003287 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04003288 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smartda0436e2009-05-22 14:51:39 -04003289 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
3290 }
James Smart81301a92008-12-04 22:39:46 -05003291
James Smart47a86172007-04-25 09:53:22 -04003292 /*
James Smart2e0fef82007-06-17 19:56:36 -05003293 * Set initial can_queue value since 0 is no longer supported and
3294 * scsi_add_host will fail. This will be adjusted later based on the
3295 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04003296 */
James Smart2e0fef82007-06-17 19:56:36 -05003297 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04003298 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05003299 shost->transportt = lpfc_vport_transport_template;
3300 vport->port_type = LPFC_NPIV_PORT;
3301 } else {
3302 shost->transportt = lpfc_transport_template;
3303 vport->port_type = LPFC_PHYSICAL_PORT;
3304 }
James Smart47a86172007-04-25 09:53:22 -04003305
James Smart2e0fef82007-06-17 19:56:36 -05003306 /* Initialize all internally managed lists. */
3307 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04003308 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05003309 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04003310
James Smart2e0fef82007-06-17 19:56:36 -05003311 init_timer(&vport->fc_disctmo);
3312 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003313 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04003314
James Smart2e0fef82007-06-17 19:56:36 -05003315 init_timer(&vport->fc_fdmitmo);
3316 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
James Smart92d7f7b2007-06-17 19:56:38 -05003317 vport->fc_fdmitmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04003318
James Smart2e0fef82007-06-17 19:56:36 -05003319 init_timer(&vport->els_tmofunc);
3320 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003321 vport->els_tmofunc.data = (unsigned long)vport;
James Smart92494142011-02-16 12:39:44 -05003322
3323 init_timer(&vport->delayed_disc_tmo);
3324 vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
3325 vport->delayed_disc_tmo.data = (unsigned long)vport;
3326
James Bottomleyd139b9b2009-11-05 13:33:12 -06003327 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05003328 if (error)
3329 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04003330
James Smart549e55c2007-08-02 11:09:51 -04003331 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003332 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04003333 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003334 return vport;
James Smart47a86172007-04-25 09:53:22 -04003335
James Smart2e0fef82007-06-17 19:56:36 -05003336out_put_shost:
3337 scsi_host_put(shost);
3338out:
3339 return NULL;
James Smart47a86172007-04-25 09:53:22 -04003340}
3341
James Smarte59058c2008-08-24 21:49:00 -04003342/**
James Smart3621a712009-04-06 18:47:14 -04003343 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04003344 * @vport: pointer to an lpfc virtual N_Port data structure.
3345 *
3346 * This routine destroys a FC port from the upper layer protocol. All the
3347 * resources associated with the port are released.
3348 **/
James Smart2e0fef82007-06-17 19:56:36 -05003349void
3350destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04003351{
James Smart92d7f7b2007-06-17 19:56:38 -05003352 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3353 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003354
James Smart858c9f62007-06-17 19:56:39 -05003355 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05003356 fc_remove_host(shost);
3357 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04003358
James Smart92d7f7b2007-06-17 19:56:38 -05003359 spin_lock_irq(&phba->hbalock);
3360 list_del_init(&vport->listentry);
3361 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04003362
James Smart92d7f7b2007-06-17 19:56:38 -05003363 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04003364 return;
James Smart47a86172007-04-25 09:53:22 -04003365}
3366
James Smarte59058c2008-08-24 21:49:00 -04003367/**
James Smart3621a712009-04-06 18:47:14 -04003368 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04003369 *
3370 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3371 * uses the kernel idr facility to perform the task.
3372 *
3373 * Return codes:
3374 * instance - a unique integer ID allocated as the new instance.
3375 * -1 - lpfc get instance failed.
3376 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003377int
3378lpfc_get_instance(void)
3379{
Tejun Heoab516032013-02-27 17:04:44 -08003380 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003381
Tejun Heoab516032013-02-27 17:04:44 -08003382 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
3383 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003384}
3385
James Smarte59058c2008-08-24 21:49:00 -04003386/**
James Smart3621a712009-04-06 18:47:14 -04003387 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04003388 * @shost: pointer to SCSI host data structure.
3389 * @time: elapsed time of the scan in jiffies.
3390 *
3391 * This routine is called by the SCSI layer with a SCSI host to determine
3392 * whether the scan host is finished.
3393 *
3394 * Note: there is no scan_start function as adapter initialization will have
3395 * asynchronously kicked off the link initialization.
3396 *
3397 * Return codes
3398 * 0 - SCSI host scan is not over yet.
3399 * 1 - SCSI host scan is over.
3400 **/
James Smart47a86172007-04-25 09:53:22 -04003401int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
3402{
James Smart2e0fef82007-06-17 19:56:36 -05003403 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3404 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05003405 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04003406
James Smart858c9f62007-06-17 19:56:39 -05003407 spin_lock_irq(shost->host_lock);
3408
James Smart51ef4c22007-08-02 11:10:31 -04003409 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05003410 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003411 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05003412 }
James Smart256ec0d2013-04-17 20:14:58 -04003413 if (time >= msecs_to_jiffies(30 * 1000)) {
James Smart2e0fef82007-06-17 19:56:36 -05003414 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003415 "0461 Scanning longer than 30 "
3416 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003417 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003418 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003419 }
James Smart256ec0d2013-04-17 20:14:58 -04003420 if (time >= msecs_to_jiffies(15 * 1000) &&
3421 phba->link_state <= LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05003422 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003423 "0465 Link down longer than 15 "
3424 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003425 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05003426 goto finished;
James Smart47a86172007-04-25 09:53:22 -04003427 }
3428
James Smart2e0fef82007-06-17 19:56:36 -05003429 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05003430 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003431 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05003432 goto finished;
James Smart256ec0d2013-04-17 20:14:58 -04003433 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
James Smart858c9f62007-06-17 19:56:39 -05003434 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003435 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05003436 goto finished;
3437
3438 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003439
3440finished:
James Smart858c9f62007-06-17 19:56:39 -05003441 spin_unlock_irq(shost->host_lock);
3442 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003443}
3444
James Smarte59058c2008-08-24 21:49:00 -04003445/**
James Smart3621a712009-04-06 18:47:14 -04003446 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04003447 * @shost: pointer to SCSI host data structure.
3448 *
3449 * This routine initializes a given SCSI host attributes on a FC port. The
3450 * SCSI host can be either on top of a physical port or a virtual port.
3451 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003452void lpfc_host_attrib_init(struct Scsi_Host *shost)
3453{
3454 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3455 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003456 /*
James Smart2e0fef82007-06-17 19:56:36 -05003457 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04003458 */
3459
James Smart2e0fef82007-06-17 19:56:36 -05003460 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
3461 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04003462 fc_host_supported_classes(shost) = FC_COS_CLASS3;
3463
3464 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003465 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003466 fc_host_supported_fc4s(shost)[2] = 1;
3467 fc_host_supported_fc4s(shost)[7] = 1;
3468
James Smart92d7f7b2007-06-17 19:56:38 -05003469 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
3470 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04003471
3472 fc_host_supported_speeds(shost) = 0;
James Smart88a2cfb2011-07-22 18:36:33 -04003473 if (phba->lmt & LMT_16Gb)
3474 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
James Smart47a86172007-04-25 09:53:22 -04003475 if (phba->lmt & LMT_10Gb)
3476 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04003477 if (phba->lmt & LMT_8Gb)
3478 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04003479 if (phba->lmt & LMT_4Gb)
3480 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
3481 if (phba->lmt & LMT_2Gb)
3482 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
3483 if (phba->lmt & LMT_1Gb)
3484 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
3485
3486 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05003487 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
3488 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04003489
Mike Christie0af5d702010-09-15 16:52:31 -05003490 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
3491
James Smart47a86172007-04-25 09:53:22 -04003492 /* This value is also unchanging */
3493 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003494 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003495 fc_host_active_fc4s(shost)[2] = 1;
3496 fc_host_active_fc4s(shost)[7] = 1;
3497
James Smart92d7f7b2007-06-17 19:56:38 -05003498 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04003499 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04003500 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04003501 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04003502}
dea31012005-04-17 16:05:31 -05003503
James Smarte59058c2008-08-24 21:49:00 -04003504/**
James Smartda0436e2009-05-22 14:51:39 -04003505 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04003506 * @phba: pointer to lpfc hba data structure.
3507 *
James Smartda0436e2009-05-22 14:51:39 -04003508 * This routine is invoked to stop an SLI3 device port, it stops the device
3509 * from generating interrupts and stops the device driver's timers for the
3510 * device.
James Smarte59058c2008-08-24 21:49:00 -04003511 **/
James Smartdb2378e2008-02-08 18:49:51 -05003512static void
James Smartda0436e2009-05-22 14:51:39 -04003513lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05003514{
James Smartda0436e2009-05-22 14:51:39 -04003515 /* Clear all interrupt enable conditions */
3516 writel(0, phba->HCregaddr);
3517 readl(phba->HCregaddr); /* flush */
3518 /* Clear all pending interrupts */
3519 writel(0xffffffff, phba->HAregaddr);
3520 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04003521
James Smartda0436e2009-05-22 14:51:39 -04003522 /* Reset some HBA SLI setup states */
3523 lpfc_stop_hba_timers(phba);
3524 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05003525}
3526
James Smarte59058c2008-08-24 21:49:00 -04003527/**
James Smartda0436e2009-05-22 14:51:39 -04003528 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05003529 * @phba: pointer to lpfc hba data structure.
3530 *
James Smartda0436e2009-05-22 14:51:39 -04003531 * This routine is invoked to stop an SLI4 device port, it stops the device
3532 * from generating interrupts and stops the device driver's timers for the
3533 * device.
3534 **/
3535static void
3536lpfc_stop_port_s4(struct lpfc_hba *phba)
3537{
3538 /* Reset some HBA SLI4 setup states */
3539 lpfc_stop_hba_timers(phba);
3540 phba->pport->work_port_events = 0;
3541 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04003542}
3543
3544/**
3545 * lpfc_stop_port - Wrapper function for stopping hba port
3546 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05003547 *
James Smartda0436e2009-05-22 14:51:39 -04003548 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3549 * the API jump table function pointer from the lpfc_hba struct.
3550 **/
3551void
3552lpfc_stop_port(struct lpfc_hba *phba)
3553{
3554 phba->lpfc_stop_port(phba);
3555}
3556
3557/**
James Smartecfd03c2010-02-12 14:41:27 -05003558 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3559 * @phba: Pointer to hba for which this call is being executed.
3560 *
3561 * This routine starts the timer waiting for the FCF rediscovery to complete.
3562 **/
3563void
3564lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
3565{
3566 unsigned long fcf_redisc_wait_tmo =
3567 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
3568 /* Start fcf rediscovery wait period timer */
3569 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
3570 spin_lock_irq(&phba->hbalock);
3571 /* Allow action to new fcf asynchronous event */
3572 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
3573 /* Mark the FCF rediscovery pending state */
3574 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
3575 spin_unlock_irq(&phba->hbalock);
3576}
3577
3578/**
3579 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
3580 * @ptr: Map to lpfc_hba data structure pointer.
3581 *
3582 * This routine is invoked when waiting for FCF table rediscover has been
3583 * timed out. If new FCF record(s) has (have) been discovered during the
3584 * wait period, a new FCF event shall be added to the FCOE async event
3585 * list, and then worker thread shall be waked up for processing from the
3586 * worker thread context.
3587 **/
Rashika Kheriae399b222014-09-03 12:55:28 -04003588static void
James Smartecfd03c2010-02-12 14:41:27 -05003589lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
3590{
3591 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
3592
3593 /* Don't send FCF rediscovery event if timer cancelled */
3594 spin_lock_irq(&phba->hbalock);
3595 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
3596 spin_unlock_irq(&phba->hbalock);
3597 return;
3598 }
3599 /* Clear FCF rediscovery timer pending flag */
3600 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
3601 /* FCF rediscovery event to worker thread */
3602 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
3603 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003604 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04003605 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05003606 /* wake up worker thread */
3607 lpfc_worker_wake_up(phba);
3608}
3609
3610/**
James Smartda0436e2009-05-22 14:51:39 -04003611 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
3612 * @phba: pointer to lpfc hba data structure.
3613 * @acqe_link: pointer to the async link completion queue entry.
3614 *
3615 * This routine is to parse the SLI4 link-attention link fault code and
3616 * translate it into the base driver's read link attention mailbox command
3617 * status.
3618 *
3619 * Return: Link-attention status in terms of base driver's coding.
3620 **/
3621static uint16_t
3622lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
3623 struct lpfc_acqe_link *acqe_link)
3624{
3625 uint16_t latt_fault;
3626
3627 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
3628 case LPFC_ASYNC_LINK_FAULT_NONE:
3629 case LPFC_ASYNC_LINK_FAULT_LOCAL:
3630 case LPFC_ASYNC_LINK_FAULT_REMOTE:
3631 latt_fault = 0;
3632 break;
3633 default:
3634 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3635 "0398 Invalid link fault code: x%x\n",
3636 bf_get(lpfc_acqe_link_fault, acqe_link));
3637 latt_fault = MBXERR_ERROR;
3638 break;
3639 }
3640 return latt_fault;
3641}
3642
3643/**
3644 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
3645 * @phba: pointer to lpfc hba data structure.
3646 * @acqe_link: pointer to the async link completion queue entry.
3647 *
3648 * This routine is to parse the SLI4 link attention type and translate it
3649 * into the base driver's link attention type coding.
3650 *
3651 * Return: Link attention type in terms of base driver's coding.
3652 **/
3653static uint8_t
3654lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
3655 struct lpfc_acqe_link *acqe_link)
3656{
3657 uint8_t att_type;
3658
3659 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
3660 case LPFC_ASYNC_LINK_STATUS_DOWN:
3661 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05003662 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04003663 break;
3664 case LPFC_ASYNC_LINK_STATUS_UP:
3665 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05003666 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003667 break;
3668 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05003669 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04003670 break;
3671 default:
3672 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3673 "0399 Invalid link attention type: x%x\n",
3674 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003675 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003676 break;
3677 }
3678 return att_type;
3679}
3680
3681/**
3682 * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
3683 * @phba: pointer to lpfc hba data structure.
3684 * @acqe_link: pointer to the async link completion queue entry.
3685 *
3686 * This routine is to parse the SLI4 link-attention link speed and translate
3687 * it into the base driver's link-attention link speed coding.
3688 *
3689 * Return: Link-attention link speed in terms of base driver's coding.
3690 **/
3691static uint8_t
3692lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba,
3693 struct lpfc_acqe_link *acqe_link)
3694{
3695 uint8_t link_speed;
3696
3697 switch (bf_get(lpfc_acqe_link_speed, acqe_link)) {
3698 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smartda0436e2009-05-22 14:51:39 -04003699 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smartda0436e2009-05-22 14:51:39 -04003700 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart76a95d72010-11-20 23:11:48 -05003701 link_speed = LPFC_LINK_SPEED_UNKNOWN;
James Smartda0436e2009-05-22 14:51:39 -04003702 break;
3703 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart76a95d72010-11-20 23:11:48 -05003704 link_speed = LPFC_LINK_SPEED_1GHZ;
James Smartda0436e2009-05-22 14:51:39 -04003705 break;
3706 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart76a95d72010-11-20 23:11:48 -05003707 link_speed = LPFC_LINK_SPEED_10GHZ;
James Smartda0436e2009-05-22 14:51:39 -04003708 break;
3709 default:
3710 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3711 "0483 Invalid link-attention link speed: x%x\n",
3712 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003713 link_speed = LPFC_LINK_SPEED_UNKNOWN;
James Smartda0436e2009-05-22 14:51:39 -04003714 break;
3715 }
3716 return link_speed;
3717}
3718
3719/**
James Smart8b68cd52012-09-29 11:32:37 -04003720 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
3721 * @phba: pointer to lpfc hba data structure.
3722 *
3723 * This routine is to get an SLI3 FC port's link speed in Mbps.
3724 *
3725 * Return: link speed in terms of Mbps.
3726 **/
3727uint32_t
3728lpfc_sli_port_speed_get(struct lpfc_hba *phba)
3729{
3730 uint32_t link_speed;
3731
3732 if (!lpfc_is_link_up(phba))
3733 return 0;
3734
3735 switch (phba->fc_linkspeed) {
3736 case LPFC_LINK_SPEED_1GHZ:
3737 link_speed = 1000;
3738 break;
3739 case LPFC_LINK_SPEED_2GHZ:
3740 link_speed = 2000;
3741 break;
3742 case LPFC_LINK_SPEED_4GHZ:
3743 link_speed = 4000;
3744 break;
3745 case LPFC_LINK_SPEED_8GHZ:
3746 link_speed = 8000;
3747 break;
3748 case LPFC_LINK_SPEED_10GHZ:
3749 link_speed = 10000;
3750 break;
3751 case LPFC_LINK_SPEED_16GHZ:
3752 link_speed = 16000;
3753 break;
3754 default:
3755 link_speed = 0;
3756 }
3757 return link_speed;
3758}
3759
3760/**
3761 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
3762 * @phba: pointer to lpfc hba data structure.
3763 * @evt_code: asynchronous event code.
3764 * @speed_code: asynchronous event link speed code.
3765 *
3766 * This routine is to parse the giving SLI4 async event link speed code into
3767 * value of Mbps for the link speed.
3768 *
3769 * Return: link speed in terms of Mbps.
3770 **/
3771static uint32_t
3772lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
3773 uint8_t speed_code)
3774{
3775 uint32_t port_speed;
3776
3777 switch (evt_code) {
3778 case LPFC_TRAILER_CODE_LINK:
3779 switch (speed_code) {
3780 case LPFC_EVT_CODE_LINK_NO_LINK:
3781 port_speed = 0;
3782 break;
3783 case LPFC_EVT_CODE_LINK_10_MBIT:
3784 port_speed = 10;
3785 break;
3786 case LPFC_EVT_CODE_LINK_100_MBIT:
3787 port_speed = 100;
3788 break;
3789 case LPFC_EVT_CODE_LINK_1_GBIT:
3790 port_speed = 1000;
3791 break;
3792 case LPFC_EVT_CODE_LINK_10_GBIT:
3793 port_speed = 10000;
3794 break;
3795 default:
3796 port_speed = 0;
3797 }
3798 break;
3799 case LPFC_TRAILER_CODE_FC:
3800 switch (speed_code) {
3801 case LPFC_EVT_CODE_FC_NO_LINK:
3802 port_speed = 0;
3803 break;
3804 case LPFC_EVT_CODE_FC_1_GBAUD:
3805 port_speed = 1000;
3806 break;
3807 case LPFC_EVT_CODE_FC_2_GBAUD:
3808 port_speed = 2000;
3809 break;
3810 case LPFC_EVT_CODE_FC_4_GBAUD:
3811 port_speed = 4000;
3812 break;
3813 case LPFC_EVT_CODE_FC_8_GBAUD:
3814 port_speed = 8000;
3815 break;
3816 case LPFC_EVT_CODE_FC_10_GBAUD:
3817 port_speed = 10000;
3818 break;
3819 case LPFC_EVT_CODE_FC_16_GBAUD:
3820 port_speed = 16000;
3821 break;
3822 default:
3823 port_speed = 0;
3824 }
3825 break;
3826 default:
3827 port_speed = 0;
3828 }
3829 return port_speed;
3830}
3831
3832/**
James Smart70f3c072010-12-15 17:57:33 -05003833 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04003834 * @phba: pointer to lpfc hba data structure.
3835 * @acqe_link: pointer to the async link completion queue entry.
3836 *
James Smart70f3c072010-12-15 17:57:33 -05003837 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04003838 **/
3839static void
3840lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
3841 struct lpfc_acqe_link *acqe_link)
3842{
3843 struct lpfc_dmabuf *mp;
3844 LPFC_MBOXQ_t *pmb;
3845 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05003846 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04003847 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05003848 int rc;
James Smartda0436e2009-05-22 14:51:39 -04003849
3850 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05003851 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04003852 return;
James Smart32b97932009-07-19 10:01:21 -04003853 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04003854 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3855 if (!pmb) {
3856 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3857 "0395 The mboxq allocation failed\n");
3858 return;
3859 }
3860 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3861 if (!mp) {
3862 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3863 "0396 The lpfc_dmabuf allocation failed\n");
3864 goto out_free_pmb;
3865 }
3866 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
3867 if (!mp->virt) {
3868 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3869 "0397 The mbuf allocation failed\n");
3870 goto out_free_dmabuf;
3871 }
3872
3873 /* Cleanup any outstanding ELS commands */
3874 lpfc_els_flush_all_cmd(phba);
3875
3876 /* Block ELS IOCBs until we have done process link event */
3877 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
3878
3879 /* Update link event statistics */
3880 phba->sli.slistat.link_event++;
3881
James Smart76a95d72010-11-20 23:11:48 -05003882 /* Create lpfc_handle_latt mailbox command from link ACQE */
3883 lpfc_read_topology(phba, pmb, mp);
3884 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04003885 pmb->vport = phba->pport;
3886
James Smartda0436e2009-05-22 14:51:39 -04003887 /* Keep the link status for extra SLI4 state machine reference */
3888 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04003889 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
3890 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04003891 phba->sli4_hba.link_state.duplex =
3892 bf_get(lpfc_acqe_link_duplex, acqe_link);
3893 phba->sli4_hba.link_state.status =
3894 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05003895 phba->sli4_hba.link_state.type =
3896 bf_get(lpfc_acqe_link_type, acqe_link);
3897 phba->sli4_hba.link_state.number =
3898 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04003899 phba->sli4_hba.link_state.fault =
3900 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05003901 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04003902 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
3903
James Smart70f3c072010-12-15 17:57:33 -05003904 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04003905 "2900 Async FC/FCoE Link event - Speed:%dGBit "
3906 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
3907 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05003908 phba->sli4_hba.link_state.speed,
3909 phba->sli4_hba.link_state.topology,
3910 phba->sli4_hba.link_state.status,
3911 phba->sli4_hba.link_state.type,
3912 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04003913 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05003914 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05003915 /*
3916 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
3917 * topology info. Note: Optional for non FC-AL ports.
3918 */
3919 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3920 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3921 if (rc == MBX_NOT_FINISHED)
3922 goto out_free_dmabuf;
3923 return;
3924 }
3925 /*
3926 * For FCoE Mode: fill in all the topology information we need and call
3927 * the READ_TOPOLOGY completion routine to continue without actually
3928 * sending the READ_TOPOLOGY mailbox command to the port.
3929 */
3930 /* Parse and translate status field */
3931 mb = &pmb->u.mb;
3932 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
3933
3934 /* Parse and translate link attention fields */
3935 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3936 la->eventTag = acqe_link->event_tag;
3937 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
3938 bf_set(lpfc_mbx_read_top_link_spd, la,
3939 lpfc_sli4_parse_latt_link_speed(phba, acqe_link));
3940
3941 /* Fake the the following irrelvant fields */
3942 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
3943 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
3944 bf_set(lpfc_mbx_read_top_il, la, 0);
3945 bf_set(lpfc_mbx_read_top_pb, la, 0);
3946 bf_set(lpfc_mbx_read_top_fa, la, 0);
3947 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04003948
3949 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05003950 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04003951
3952 return;
3953
3954out_free_dmabuf:
3955 kfree(mp);
3956out_free_pmb:
3957 mempool_free(pmb, phba->mbox_mem_pool);
3958}
3959
3960/**
James Smart70f3c072010-12-15 17:57:33 -05003961 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
3962 * @phba: pointer to lpfc hba data structure.
3963 * @acqe_fc: pointer to the async fc completion queue entry.
3964 *
3965 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
3966 * that the event was received and then issue a read_topology mailbox command so
3967 * that the rest of the driver will treat it the same as SLI3.
3968 **/
3969static void
3970lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
3971{
3972 struct lpfc_dmabuf *mp;
3973 LPFC_MBOXQ_t *pmb;
3974 int rc;
3975
3976 if (bf_get(lpfc_trailer_type, acqe_fc) !=
3977 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
3978 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3979 "2895 Non FC link Event detected.(%d)\n",
3980 bf_get(lpfc_trailer_type, acqe_fc));
3981 return;
3982 }
3983 /* Keep the link status for extra SLI4 state machine reference */
3984 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04003985 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
3986 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05003987 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
3988 phba->sli4_hba.link_state.topology =
3989 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
3990 phba->sli4_hba.link_state.status =
3991 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
3992 phba->sli4_hba.link_state.type =
3993 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
3994 phba->sli4_hba.link_state.number =
3995 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
3996 phba->sli4_hba.link_state.fault =
3997 bf_get(lpfc_acqe_link_fault, acqe_fc);
3998 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04003999 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart70f3c072010-12-15 17:57:33 -05004000 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4001 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4002 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4003 "%dMbps Fault:%d\n",
4004 phba->sli4_hba.link_state.speed,
4005 phba->sli4_hba.link_state.topology,
4006 phba->sli4_hba.link_state.status,
4007 phba->sli4_hba.link_state.type,
4008 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004009 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004010 phba->sli4_hba.link_state.fault);
4011 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4012 if (!pmb) {
4013 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4014 "2897 The mboxq allocation failed\n");
4015 return;
4016 }
4017 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4018 if (!mp) {
4019 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4020 "2898 The lpfc_dmabuf allocation failed\n");
4021 goto out_free_pmb;
4022 }
4023 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4024 if (!mp->virt) {
4025 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4026 "2899 The mbuf allocation failed\n");
4027 goto out_free_dmabuf;
4028 }
4029
4030 /* Cleanup any outstanding ELS commands */
4031 lpfc_els_flush_all_cmd(phba);
4032
4033 /* Block ELS IOCBs until we have done process link event */
4034 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
4035
4036 /* Update link event statistics */
4037 phba->sli.slistat.link_event++;
4038
4039 /* Create lpfc_handle_latt mailbox command from link ACQE */
4040 lpfc_read_topology(phba, pmb, mp);
4041 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4042 pmb->vport = phba->pport;
4043
4044 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4045 if (rc == MBX_NOT_FINISHED)
4046 goto out_free_dmabuf;
4047 return;
4048
4049out_free_dmabuf:
4050 kfree(mp);
4051out_free_pmb:
4052 mempool_free(pmb, phba->mbox_mem_pool);
4053}
4054
4055/**
4056 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4057 * @phba: pointer to lpfc hba data structure.
4058 * @acqe_fc: pointer to the async SLI completion queue entry.
4059 *
4060 * This routine is to handle the SLI4 asynchronous SLI events.
4061 **/
4062static void
4063lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
4064{
James Smart4b8bae02012-06-12 13:55:07 -04004065 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04004066 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04004067 uint8_t status;
James Smart946727d2015-04-07 15:07:09 -04004068 uint8_t evt_type;
4069 struct temp_event temp_event_data;
James Smart4b8bae02012-06-12 13:55:07 -04004070 struct lpfc_acqe_misconfigured_event *misconfigured;
James Smart946727d2015-04-07 15:07:09 -04004071 struct Scsi_Host *shost;
James Smart4b8bae02012-06-12 13:55:07 -04004072
James Smart946727d2015-04-07 15:07:09 -04004073 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
4074
4075 /* Special case Lancer */
4076 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
4077 LPFC_SLI_INTF_IF_TYPE_2) {
James Smart4b8bae02012-06-12 13:55:07 -04004078 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4079 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4080 "x%08x SLI Event Type:%d\n",
4081 acqe_sli->event_data1, acqe_sli->event_data2,
James Smart946727d2015-04-07 15:07:09 -04004082 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004083 return;
4084 }
4085
4086 port_name = phba->Port[0];
4087 if (port_name == 0x00)
4088 port_name = '?'; /* get port name is empty */
4089
James Smart946727d2015-04-07 15:07:09 -04004090 switch (evt_type) {
4091 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
4092 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4093 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
4094 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4095
4096 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4097 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4098 acqe_sli->event_data1, port_name);
4099
4100 shost = lpfc_shost_from_vport(phba->pport);
4101 fc_host_post_vendor_event(shost, fc_get_event_number(),
4102 sizeof(temp_event_data),
4103 (char *)&temp_event_data,
4104 SCSI_NL_VID_TYPE_PCI
4105 | PCI_VENDOR_ID_EMULEX);
4106 break;
4107 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
4108 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4109 temp_event_data.event_code = LPFC_NORMAL_TEMP;
4110 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4111
4112 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4113 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4114 acqe_sli->event_data1, port_name);
4115
4116 shost = lpfc_shost_from_vport(phba->pport);
4117 fc_host_post_vendor_event(shost, fc_get_event_number(),
4118 sizeof(temp_event_data),
4119 (char *)&temp_event_data,
4120 SCSI_NL_VID_TYPE_PCI
4121 | PCI_VENDOR_ID_EMULEX);
4122 break;
4123 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
4124 misconfigured = (struct lpfc_acqe_misconfigured_event *)
James Smart4b8bae02012-06-12 13:55:07 -04004125 &acqe_sli->event_data1;
4126
James Smart946727d2015-04-07 15:07:09 -04004127 /* fetch the status for this port */
4128 switch (phba->sli4_hba.lnk_info.lnk_no) {
4129 case LPFC_LINK_NUMBER_0:
4130 status = bf_get(lpfc_sli_misconfigured_port0,
James Smart4b8bae02012-06-12 13:55:07 -04004131 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004132 break;
4133 case LPFC_LINK_NUMBER_1:
4134 status = bf_get(lpfc_sli_misconfigured_port1,
James Smart4b8bae02012-06-12 13:55:07 -04004135 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004136 break;
4137 case LPFC_LINK_NUMBER_2:
4138 status = bf_get(lpfc_sli_misconfigured_port2,
James Smart4b8bae02012-06-12 13:55:07 -04004139 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004140 break;
4141 case LPFC_LINK_NUMBER_3:
4142 status = bf_get(lpfc_sli_misconfigured_port3,
James Smart4b8bae02012-06-12 13:55:07 -04004143 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004144 break;
4145 default:
4146 status = ~LPFC_SLI_EVENT_STATUS_VALID;
4147 break;
4148 }
James Smart4b8bae02012-06-12 13:55:07 -04004149
James Smart946727d2015-04-07 15:07:09 -04004150 switch (status) {
4151 case LPFC_SLI_EVENT_STATUS_VALID:
4152 return; /* no message if the sfp is okay */
4153 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
4154 sprintf(message, "Optics faulted/incorrectly "
4155 "installed/not installed - Reseat optics, "
4156 "if issue not resolved, replace.");
4157 break;
4158 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
4159 sprintf(message,
4160 "Optics of two types installed - Remove one "
4161 "optic or install matching pair of optics.");
4162 break;
4163 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
4164 sprintf(message, "Incompatible optics - Replace with "
James Smart292098b2012-09-29 11:31:41 -04004165 "compatible optics for card to function.");
James Smart946727d2015-04-07 15:07:09 -04004166 break;
4167 default:
4168 /* firmware is reporting a status we don't know about */
4169 sprintf(message, "Unknown event status x%02x", status);
4170 break;
4171 }
4172
4173 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4174 "3176 Misconfigured Physical Port - "
4175 "Port Name %c %s\n", port_name, message);
4176 break;
4177 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
4178 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4179 "3192 Remote DPort Test Initiated - "
4180 "Event Data1:x%08x Event Data2: x%08x\n",
4181 acqe_sli->event_data1, acqe_sli->event_data2);
James Smart4b8bae02012-06-12 13:55:07 -04004182 break;
4183 default:
James Smart946727d2015-04-07 15:07:09 -04004184 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4185 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
4186 "x%08x SLI Event Type:%d\n",
4187 acqe_sli->event_data1, acqe_sli->event_data2,
4188 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004189 break;
4190 }
James Smart70f3c072010-12-15 17:57:33 -05004191}
4192
4193/**
James Smartfc2b9892010-02-26 14:15:29 -05004194 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
4195 * @vport: pointer to vport data structure.
4196 *
4197 * This routine is to perform Clear Virtual Link (CVL) on a vport in
4198 * response to a CVL event.
4199 *
4200 * Return the pointer to the ndlp with the vport if successful, otherwise
4201 * return NULL.
4202 **/
4203static struct lpfc_nodelist *
4204lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
4205{
4206 struct lpfc_nodelist *ndlp;
4207 struct Scsi_Host *shost;
4208 struct lpfc_hba *phba;
4209
4210 if (!vport)
4211 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05004212 phba = vport->phba;
4213 if (!phba)
4214 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04004215 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4216 if (!ndlp) {
4217 /* Cannot find existing Fabric ndlp, so allocate a new one */
4218 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4219 if (!ndlp)
4220 return 0;
4221 lpfc_nlp_init(vport, ndlp, Fabric_DID);
4222 /* Set the node type */
4223 ndlp->nlp_type |= NLP_FABRIC;
4224 /* Put ndlp onto node list */
4225 lpfc_enqueue_node(vport, ndlp);
4226 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4227 /* re-setup ndlp without removing from node list */
4228 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4229 if (!ndlp)
4230 return 0;
4231 }
James Smart63e801c2010-11-20 23:14:19 -05004232 if ((phba->pport->port_state < LPFC_FLOGI) &&
4233 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004234 return NULL;
4235 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05004236 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
4237 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004238 return NULL;
4239 shost = lpfc_shost_from_vport(vport);
4240 if (!shost)
4241 return NULL;
4242 lpfc_linkdown_port(vport);
4243 lpfc_cleanup_pending_mbox(vport);
4244 spin_lock_irq(shost->host_lock);
4245 vport->fc_flag |= FC_VPORT_CVL_RCVD;
4246 spin_unlock_irq(shost->host_lock);
4247
4248 return ndlp;
4249}
4250
4251/**
4252 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4253 * @vport: pointer to lpfc hba data structure.
4254 *
4255 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4256 * response to a FCF dead event.
4257 **/
4258static void
4259lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
4260{
4261 struct lpfc_vport **vports;
4262 int i;
4263
4264 vports = lpfc_create_vport_work_array(phba);
4265 if (vports)
4266 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4267 lpfc_sli4_perform_vport_cvl(vports[i]);
4268 lpfc_destroy_vport_work_array(phba, vports);
4269}
4270
4271/**
James Smart76a95d72010-11-20 23:11:48 -05004272 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04004273 * @phba: pointer to lpfc hba data structure.
4274 * @acqe_link: pointer to the async fcoe completion queue entry.
4275 *
4276 * This routine is to handle the SLI4 asynchronous fcoe event.
4277 **/
4278static void
James Smart76a95d72010-11-20 23:11:48 -05004279lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05004280 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04004281{
James Smart70f3c072010-12-15 17:57:33 -05004282 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004283 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04004284 struct lpfc_vport *vport;
4285 struct lpfc_nodelist *ndlp;
4286 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05004287 int active_vlink_present;
4288 struct lpfc_vport **vports;
4289 int i;
James Smartda0436e2009-05-22 14:51:39 -04004290
James Smart70f3c072010-12-15 17:57:33 -05004291 phba->fc_eventTag = acqe_fip->event_tag;
4292 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004293 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05004294 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
4295 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
4296 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04004297 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4298 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004299 "2546 New FCF event, evt_tag:x%x, "
4300 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004301 acqe_fip->event_tag,
4302 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04004303 else
4304 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
4305 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004306 "2788 FCF param modified event, "
4307 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004308 acqe_fip->event_tag,
4309 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04004310 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004311 /*
4312 * During period of FCF discovery, read the FCF
4313 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04004314 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05004315 */
4316 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4317 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004318 "2779 Read FCF (x%x) for updating "
4319 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05004320 acqe_fip->index);
4321 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004322 }
James Smart38b92ef2010-08-04 16:11:39 -04004323
4324 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04004325 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04004326 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04004327 spin_unlock_irq(&phba->hbalock);
4328 break;
4329 }
4330 /* If fast FCF failover rescan event is pending, do nothing */
4331 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
4332 spin_unlock_irq(&phba->hbalock);
4333 break;
4334 }
4335
James Smartc2b97122013-05-31 17:05:36 -04004336 /* If the FCF has been in discovered state, do nothing. */
4337 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
James Smart3804dc82010-07-14 15:31:37 -04004338 spin_unlock_irq(&phba->hbalock);
4339 break;
4340 }
4341 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04004342
James Smart0c9ab6f2010-02-26 14:15:57 -05004343 /* Otherwise, scan the entire FCF table and re-discover SAN */
4344 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004345 "2770 Start FCF table scan per async FCF "
4346 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004347 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004348 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
4349 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04004350 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004351 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4352 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04004353 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04004354 break;
4355
James Smart70f3c072010-12-15 17:57:33 -05004356 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04004357 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04004358 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004359 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
4360 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004361 break;
4362
James Smart70f3c072010-12-15 17:57:33 -05004363 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05004364 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004365 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004366 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05004367 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04004368 /*
4369 * If we are in the middle of FCF failover process, clear
4370 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04004371 */
James Smartfc2b9892010-02-26 14:15:29 -05004372 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004373 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05004374 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004375 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05004376 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004377 break;
4378 }
James Smart38b92ef2010-08-04 16:11:39 -04004379 spin_unlock_irq(&phba->hbalock);
4380
4381 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05004382 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04004383 break;
4384
4385 /*
4386 * Otherwise, request the port to rediscover the entire FCF
4387 * table for a fast recovery from case that the current FCF
4388 * is no longer valid as we are not in the middle of FCF
4389 * failover process already.
4390 */
James Smartc2b97122013-05-31 17:05:36 -04004391 spin_lock_irq(&phba->hbalock);
4392 /* Mark the fast failover process in progress */
4393 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
4394 spin_unlock_irq(&phba->hbalock);
4395
4396 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
4397 "2771 Start FCF fast failover process due to "
4398 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
4399 "\n", acqe_fip->event_tag, acqe_fip->index);
4400 rc = lpfc_sli4_redisc_fcf_table(phba);
4401 if (rc) {
4402 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4403 LOG_DISCOVERY,
4404 "2772 Issue FCF rediscover mabilbox "
4405 "command failed, fail through to FCF "
4406 "dead event\n");
4407 spin_lock_irq(&phba->hbalock);
4408 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
4409 spin_unlock_irq(&phba->hbalock);
4410 /*
4411 * Last resort will fail over by treating this
4412 * as a link down to FCF registration.
4413 */
4414 lpfc_sli4_fcf_dead_failthrough(phba);
4415 } else {
4416 /* Reset FCF roundrobin bmask for new discovery */
4417 lpfc_sli4_clear_fcf_rr_bmask(phba);
4418 /*
4419 * Handling fast FCF failover to a DEAD FCF event is
4420 * considered equalivant to receiving CVL to all vports.
4421 */
4422 lpfc_sli4_perform_all_vport_cvl(phba);
4423 }
James Smartda0436e2009-05-22 14:51:39 -04004424 break;
James Smart70f3c072010-12-15 17:57:33 -05004425 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05004426 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004427 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04004428 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05004429 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04004430
James Smart6669f9b2009-10-02 15:16:45 -04004431 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04004432 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004433 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004434 if (!ndlp)
4435 break;
James Smart695a8142010-01-26 23:08:03 -05004436 active_vlink_present = 0;
4437
4438 vports = lpfc_create_vport_work_array(phba);
4439 if (vports) {
4440 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
4441 i++) {
4442 if ((!(vports[i]->fc_flag &
4443 FC_VPORT_CVL_RCVD)) &&
4444 (vports[i]->port_state > LPFC_FDISC)) {
4445 active_vlink_present = 1;
4446 break;
4447 }
4448 }
4449 lpfc_destroy_vport_work_array(phba, vports);
4450 }
4451
4452 if (active_vlink_present) {
4453 /*
4454 * If there are other active VLinks present,
4455 * re-instantiate the Vlink using FDISC.
4456 */
James Smart256ec0d2013-04-17 20:14:58 -04004457 mod_timer(&ndlp->nlp_delayfunc,
4458 jiffies + msecs_to_jiffies(1000));
James Smartfc2b9892010-02-26 14:15:29 -05004459 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004460 spin_lock_irq(shost->host_lock);
4461 ndlp->nlp_flag |= NLP_DELAY_TMO;
4462 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05004463 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
4464 vport->port_state = LPFC_FDISC;
4465 } else {
James Smartecfd03c2010-02-12 14:41:27 -05004466 /*
4467 * Otherwise, we request port to rediscover
4468 * the entire FCF table for a fast recovery
4469 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05004470 * is no longer valid if we are not already
4471 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05004472 */
James Smartfc2b9892010-02-26 14:15:29 -05004473 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004474 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05004475 spin_unlock_irq(&phba->hbalock);
4476 break;
4477 }
4478 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05004479 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004480 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004481 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4482 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004483 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05004484 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05004485 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05004486 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004487 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4488 LOG_DISCOVERY,
4489 "2774 Issue FCF rediscover "
4490 "mabilbox command failed, "
4491 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05004492 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004493 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004494 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05004495 /*
4496 * Last resort will be re-try on the
4497 * the current registered FCF entry.
4498 */
4499 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04004500 } else
4501 /*
4502 * Reset FCF roundrobin bmask for new
4503 * discovery.
4504 */
James Smart7d791df2011-07-22 18:37:52 -04004505 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04004506 }
4507 break;
James Smartda0436e2009-05-22 14:51:39 -04004508 default:
4509 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4510 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05004511 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004512 break;
4513 }
4514}
4515
4516/**
4517 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
4518 * @phba: pointer to lpfc hba data structure.
4519 * @acqe_link: pointer to the async dcbx completion queue entry.
4520 *
4521 * This routine is to handle the SLI4 asynchronous dcbx event.
4522 **/
4523static void
4524lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
4525 struct lpfc_acqe_dcbx *acqe_dcbx)
4526{
James Smart4d9ab992009-10-02 15:16:39 -04004527 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004528 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4529 "0290 The SLI4 DCBX asynchronous event is not "
4530 "handled yet\n");
4531}
4532
4533/**
James Smartb19a0612010-04-06 14:48:51 -04004534 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
4535 * @phba: pointer to lpfc hba data structure.
4536 * @acqe_link: pointer to the async grp5 completion queue entry.
4537 *
4538 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
4539 * is an asynchronous notified of a logical link speed change. The Port
4540 * reports the logical link speed in units of 10Mbps.
4541 **/
4542static void
4543lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
4544 struct lpfc_acqe_grp5 *acqe_grp5)
4545{
4546 uint16_t prev_ll_spd;
4547
4548 phba->fc_eventTag = acqe_grp5->event_tag;
4549 phba->fcoe_eventtag = acqe_grp5->event_tag;
4550 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
4551 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004552 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04004553 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4554 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04004555 "from %dMbps to %dMbps\n", prev_ll_spd,
4556 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04004557}
4558
4559/**
James Smartda0436e2009-05-22 14:51:39 -04004560 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
4561 * @phba: pointer to lpfc hba data structure.
4562 *
4563 * This routine is invoked by the worker thread to process all the pending
4564 * SLI4 asynchronous events.
4565 **/
4566void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
4567{
4568 struct lpfc_cq_event *cq_event;
4569
4570 /* First, declare the async event has been handled */
4571 spin_lock_irq(&phba->hbalock);
4572 phba->hba_flag &= ~ASYNC_EVENT;
4573 spin_unlock_irq(&phba->hbalock);
4574 /* Now, handle all the async events */
4575 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
4576 /* Get the first event from the head of the event queue */
4577 spin_lock_irq(&phba->hbalock);
4578 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
4579 cq_event, struct lpfc_cq_event, list);
4580 spin_unlock_irq(&phba->hbalock);
4581 /* Process the asynchronous event */
4582 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
4583 case LPFC_TRAILER_CODE_LINK:
4584 lpfc_sli4_async_link_evt(phba,
4585 &cq_event->cqe.acqe_link);
4586 break;
4587 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05004588 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004589 break;
4590 case LPFC_TRAILER_CODE_DCBX:
4591 lpfc_sli4_async_dcbx_evt(phba,
4592 &cq_event->cqe.acqe_dcbx);
4593 break;
James Smartb19a0612010-04-06 14:48:51 -04004594 case LPFC_TRAILER_CODE_GRP5:
4595 lpfc_sli4_async_grp5_evt(phba,
4596 &cq_event->cqe.acqe_grp5);
4597 break;
James Smart70f3c072010-12-15 17:57:33 -05004598 case LPFC_TRAILER_CODE_FC:
4599 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
4600 break;
4601 case LPFC_TRAILER_CODE_SLI:
4602 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
4603 break;
James Smartda0436e2009-05-22 14:51:39 -04004604 default:
4605 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4606 "1804 Invalid asynchrous event code: "
4607 "x%x\n", bf_get(lpfc_trailer_code,
4608 &cq_event->cqe.mcqe_cmpl));
4609 break;
4610 }
4611 /* Free the completion event processed to the free pool */
4612 lpfc_sli4_cq_event_release(phba, cq_event);
4613 }
4614}
4615
4616/**
James Smartecfd03c2010-02-12 14:41:27 -05004617 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
4618 * @phba: pointer to lpfc hba data structure.
4619 *
4620 * This routine is invoked by the worker thread to process FCF table
4621 * rediscovery pending completion event.
4622 **/
4623void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
4624{
4625 int rc;
4626
4627 spin_lock_irq(&phba->hbalock);
4628 /* Clear FCF rediscovery timeout event */
4629 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
4630 /* Clear driver fast failover FCF record flag */
4631 phba->fcf.failover_rec.flag = 0;
4632 /* Set state for FCF fast failover */
4633 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
4634 spin_unlock_irq(&phba->hbalock);
4635
4636 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05004637 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004638 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05004639 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05004640 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004641 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4642 "2747 Issue FCF scan read FCF mailbox "
4643 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05004644}
4645
4646/**
James Smartda0436e2009-05-22 14:51:39 -04004647 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
4648 * @phba: pointer to lpfc hba data structure.
4649 * @dev_grp: The HBA PCI-Device group number.
4650 *
4651 * This routine is invoked to set up the per HBA PCI-Device group function
4652 * API jump table entries.
4653 *
4654 * Return: 0 if success, otherwise -ENODEV
4655 **/
4656int
4657lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05004658{
4659 int rc;
4660
James Smartda0436e2009-05-22 14:51:39 -04004661 /* Set up lpfc PCI-device group */
4662 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05004663
James Smartda0436e2009-05-22 14:51:39 -04004664 /* The LPFC_PCI_DEV_OC uses SLI4 */
4665 if (dev_grp == LPFC_PCI_DEV_OC)
4666 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05004667
James Smartda0436e2009-05-22 14:51:39 -04004668 /* Set up device INIT API function jump table */
4669 rc = lpfc_init_api_table_setup(phba, dev_grp);
4670 if (rc)
4671 return -ENODEV;
4672 /* Set up SCSI API function jump table */
4673 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
4674 if (rc)
4675 return -ENODEV;
4676 /* Set up SLI API function jump table */
4677 rc = lpfc_sli_api_table_setup(phba, dev_grp);
4678 if (rc)
4679 return -ENODEV;
4680 /* Set up MBOX API function jump table */
4681 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
4682 if (rc)
4683 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05004684
James Smartda0436e2009-05-22 14:51:39 -04004685 return 0;
James Smart5b75da22008-12-04 22:39:35 -05004686}
4687
4688/**
James Smart3621a712009-04-06 18:47:14 -04004689 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05004690 * @phba: pointer to lpfc hba data structure.
4691 * @intr_mode: active interrupt mode adopted.
4692 *
4693 * This routine it invoked to log the currently used active interrupt mode
4694 * to the device.
James Smart3772a992009-05-22 14:50:54 -04004695 **/
4696static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05004697{
4698 switch (intr_mode) {
4699 case 0:
4700 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4701 "0470 Enable INTx interrupt mode.\n");
4702 break;
4703 case 1:
4704 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4705 "0481 Enabled MSI interrupt mode.\n");
4706 break;
4707 case 2:
4708 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4709 "0480 Enabled MSI-X interrupt mode.\n");
4710 break;
4711 default:
4712 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4713 "0482 Illegal interrupt mode.\n");
4714 break;
4715 }
4716 return;
4717}
4718
James Smart5b75da22008-12-04 22:39:35 -05004719/**
James Smart3772a992009-05-22 14:50:54 -04004720 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05004721 * @phba: pointer to lpfc hba data structure.
4722 *
James Smart3772a992009-05-22 14:50:54 -04004723 * This routine is invoked to enable the PCI device that is common to all
4724 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05004725 *
4726 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004727 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004728 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05004729 **/
James Smart3772a992009-05-22 14:50:54 -04004730static int
4731lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05004732{
James Smart3772a992009-05-22 14:50:54 -04004733 struct pci_dev *pdev;
James Smart079b5c92011-08-21 21:48:49 -04004734 int bars = 0;
James Smart5b75da22008-12-04 22:39:35 -05004735
James Smart3772a992009-05-22 14:50:54 -04004736 /* Obtain PCI device reference */
4737 if (!phba->pcidev)
4738 goto out_error;
4739 else
4740 pdev = phba->pcidev;
4741 /* Select PCI BARs */
4742 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4743 /* Enable PCI device */
4744 if (pci_enable_device_mem(pdev))
4745 goto out_error;
4746 /* Request PCI resource for the device */
4747 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
4748 goto out_disable_device;
4749 /* Set up device as PCI master and save state for EEH */
4750 pci_set_master(pdev);
4751 pci_try_set_mwi(pdev);
4752 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05004753
James Smart05580562011-05-24 11:40:48 -04004754 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
Jon Mason453193e2013-09-11 15:38:13 -07004755 if (pci_is_pcie(pdev))
James Smart05580562011-05-24 11:40:48 -04004756 pdev->needs_freset = 1;
4757
James Smart3772a992009-05-22 14:50:54 -04004758 return 0;
James Smart5b75da22008-12-04 22:39:35 -05004759
James Smart3772a992009-05-22 14:50:54 -04004760out_disable_device:
4761 pci_disable_device(pdev);
4762out_error:
James Smart079b5c92011-08-21 21:48:49 -04004763 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4764 "1401 Failed to enable pci device, bars:x%x\n", bars);
James Smart3772a992009-05-22 14:50:54 -04004765 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05004766}
4767
4768/**
James Smart3772a992009-05-22 14:50:54 -04004769 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05004770 * @phba: pointer to lpfc hba data structure.
4771 *
James Smart3772a992009-05-22 14:50:54 -04004772 * This routine is invoked to disable the PCI device that is common to all
4773 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05004774 **/
4775static void
James Smart3772a992009-05-22 14:50:54 -04004776lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05004777{
James Smart3772a992009-05-22 14:50:54 -04004778 struct pci_dev *pdev;
4779 int bars;
James Smart5b75da22008-12-04 22:39:35 -05004780
James Smart3772a992009-05-22 14:50:54 -04004781 /* Obtain PCI device reference */
4782 if (!phba->pcidev)
4783 return;
4784 else
4785 pdev = phba->pcidev;
4786 /* Select PCI BARs */
4787 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4788 /* Release PCI resource and disable PCI device */
4789 pci_release_selected_regions(pdev, bars);
4790 pci_disable_device(pdev);
James Smart5b75da22008-12-04 22:39:35 -05004791
4792 return;
4793}
4794
4795/**
James Smart3772a992009-05-22 14:50:54 -04004796 * lpfc_reset_hba - Reset a hba
4797 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04004798 *
James Smart3772a992009-05-22 14:50:54 -04004799 * This routine is invoked to reset a hba device. It brings the HBA
4800 * offline, performs a board restart, and then brings the board back
4801 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
4802 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04004803 **/
James Smart3772a992009-05-22 14:50:54 -04004804void
4805lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05004806{
James Smart3772a992009-05-22 14:50:54 -04004807 /* If resets are disabled then set error state and return. */
4808 if (!phba->cfg_enable_hba_reset) {
4809 phba->link_state = LPFC_HBA_ERROR;
4810 return;
4811 }
James Smartee620212014-04-04 13:51:53 -04004812 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
4813 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
4814 else
4815 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart3772a992009-05-22 14:50:54 -04004816 lpfc_offline(phba);
4817 lpfc_sli_brdrestart(phba);
4818 lpfc_online(phba);
4819 lpfc_unblock_mgmt_io(phba);
4820}
dea31012005-04-17 16:05:31 -05004821
James Smart3772a992009-05-22 14:50:54 -04004822/**
James Smart0a96e972011-07-22 18:37:28 -04004823 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
4824 * @phba: pointer to lpfc hba data structure.
4825 *
4826 * This function enables the PCI SR-IOV virtual functions to a physical
4827 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4828 * enable the number of virtual functions to the physical function. As
4829 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4830 * API call does not considered as an error condition for most of the device.
4831 **/
4832uint16_t
4833lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
4834{
4835 struct pci_dev *pdev = phba->pcidev;
4836 uint16_t nr_virtfn;
4837 int pos;
4838
James Smart0a96e972011-07-22 18:37:28 -04004839 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4840 if (pos == 0)
4841 return 0;
4842
4843 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
4844 return nr_virtfn;
4845}
4846
4847/**
James Smart912e3ac2011-05-24 11:42:11 -04004848 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
4849 * @phba: pointer to lpfc hba data structure.
4850 * @nr_vfn: number of virtual functions to be enabled.
4851 *
4852 * This function enables the PCI SR-IOV virtual functions to a physical
4853 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4854 * enable the number of virtual functions to the physical function. As
4855 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4856 * API call does not considered as an error condition for most of the device.
4857 **/
4858int
4859lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
4860{
4861 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04004862 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04004863 int rc;
4864
James Smart0a96e972011-07-22 18:37:28 -04004865 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
4866 if (nr_vfn > max_nr_vfn) {
4867 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4868 "3057 Requested vfs (%d) greater than "
4869 "supported vfs (%d)", nr_vfn, max_nr_vfn);
4870 return -EINVAL;
4871 }
4872
James Smart912e3ac2011-05-24 11:42:11 -04004873 rc = pci_enable_sriov(pdev, nr_vfn);
4874 if (rc) {
4875 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4876 "2806 Failed to enable sriov on this device "
4877 "with vfn number nr_vf:%d, rc:%d\n",
4878 nr_vfn, rc);
4879 } else
4880 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4881 "2807 Successful enable sriov on this device "
4882 "with vfn number nr_vf:%d\n", nr_vfn);
4883 return rc;
4884}
4885
4886/**
James Smart3772a992009-05-22 14:50:54 -04004887 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
4888 * @phba: pointer to lpfc hba data structure.
4889 *
4890 * This routine is invoked to set up the driver internal resources specific to
4891 * support the SLI-3 HBA device it attached to.
4892 *
4893 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004894 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004895 * other values - error
4896 **/
4897static int
4898lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
4899{
4900 struct lpfc_sli *psli;
James Smart912e3ac2011-05-24 11:42:11 -04004901 int rc;
dea31012005-04-17 16:05:31 -05004902
James Smart3772a992009-05-22 14:50:54 -04004903 /*
4904 * Initialize timers used by driver
4905 */
dea31012005-04-17 16:05:31 -05004906
James Smart3772a992009-05-22 14:50:54 -04004907 /* Heartbeat timer */
4908 init_timer(&phba->hb_tmofunc);
4909 phba->hb_tmofunc.function = lpfc_hb_timeout;
4910 phba->hb_tmofunc.data = (unsigned long)phba;
4911
4912 psli = &phba->sli;
4913 /* MBOX heartbeat timer */
4914 init_timer(&psli->mbox_tmo);
4915 psli->mbox_tmo.function = lpfc_mbox_timeout;
4916 psli->mbox_tmo.data = (unsigned long) phba;
4917 /* FCP polling mode timer */
4918 init_timer(&phba->fcp_poll_timer);
4919 phba->fcp_poll_timer.function = lpfc_poll_timeout;
4920 phba->fcp_poll_timer.data = (unsigned long) phba;
4921 /* Fabric block timer */
4922 init_timer(&phba->fabric_block_timer);
4923 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
4924 phba->fabric_block_timer.data = (unsigned long) phba;
4925 /* EA polling mode timer */
4926 init_timer(&phba->eratt_poll);
4927 phba->eratt_poll.function = lpfc_poll_eratt;
4928 phba->eratt_poll.data = (unsigned long) phba;
4929
4930 /* Host attention work mask setup */
4931 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
4932 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
4933
4934 /* Get all the module params for configuring this host */
4935 lpfc_get_cfgparam(phba);
James Smart49198b32010-04-06 15:04:33 -04004936 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
4937 phba->menlo_flag |= HBA_MENLO_SUPPORT;
4938 /* check for menlo minimum sg count */
4939 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
4940 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
4941 }
4942
James Smart2a76a282012-08-03 12:35:54 -04004943 if (!phba->sli.ring)
4944 phba->sli.ring = (struct lpfc_sli_ring *)
4945 kzalloc(LPFC_SLI3_MAX_RING *
4946 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
4947 if (!phba->sli.ring)
4948 return -ENOMEM;
4949
James Smart3772a992009-05-22 14:50:54 -04004950 /*
James Smart96f70772013-04-17 20:16:15 -04004951 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smart3772a992009-05-22 14:50:54 -04004952 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart3772a992009-05-22 14:50:54 -04004953 */
James Smart3772a992009-05-22 14:50:54 -04004954
James Smart96f70772013-04-17 20:16:15 -04004955 /* Initialize the host templates the configured values. */
James Smart3772a992009-05-22 14:50:54 -04004956 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4957 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4958
James Smart96f70772013-04-17 20:16:15 -04004959 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
4960 if (phba->cfg_enable_bg) {
4961 /*
4962 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
4963 * the FCP rsp, and a BDE for each. Sice we have no control
4964 * over how many protection data segments the SCSI Layer
4965 * will hand us (ie: there could be one for every block
4966 * in the IO), we just allocate enough BDEs to accomidate
4967 * our max amount and we need to limit lpfc_sg_seg_cnt to
4968 * minimize the risk of running out.
4969 */
4970 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
4971 sizeof(struct fcp_rsp) +
4972 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
4973
4974 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
4975 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
4976
4977 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
4978 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
4979 } else {
4980 /*
4981 * The scsi_buf for a regular I/O will hold the FCP cmnd,
4982 * the FCP rsp, a BDE for each, and a BDE for up to
4983 * cfg_sg_seg_cnt data segments.
4984 */
4985 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
4986 sizeof(struct fcp_rsp) +
4987 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
4988
4989 /* Total BDEs in BPL for scsi_sg_list */
4990 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
4991 }
4992
4993 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
4994 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
4995 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
4996 phba->cfg_total_seg_cnt);
4997
James Smart3772a992009-05-22 14:50:54 -04004998 phba->max_vpi = LPFC_MAX_VPI;
4999 /* This will be set to correct value after config_port mbox */
5000 phba->max_vports = 0;
5001
5002 /*
5003 * Initialize the SLI Layer to run with lpfc HBAs.
5004 */
5005 lpfc_sli_setup(phba);
5006 lpfc_sli_queue_setup(phba);
5007
5008 /* Allocate device driver memory */
5009 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
5010 return -ENOMEM;
5011
James Smart912e3ac2011-05-24 11:42:11 -04005012 /*
5013 * Enable sr-iov virtual functions if supported and configured
5014 * through the module parameter.
5015 */
5016 if (phba->cfg_sriov_nr_virtfn > 0) {
5017 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5018 phba->cfg_sriov_nr_virtfn);
5019 if (rc) {
5020 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5021 "2808 Requested number of SR-IOV "
5022 "virtual functions (%d) is not "
5023 "supported\n",
5024 phba->cfg_sriov_nr_virtfn);
5025 phba->cfg_sriov_nr_virtfn = 0;
5026 }
5027 }
5028
James Smart3772a992009-05-22 14:50:54 -04005029 return 0;
5030}
5031
5032/**
5033 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
5034 * @phba: pointer to lpfc hba data structure.
5035 *
5036 * This routine is invoked to unset the driver internal resources set up
5037 * specific for supporting the SLI-3 HBA device it attached to.
5038 **/
5039static void
5040lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
5041{
5042 /* Free device driver memory allocated */
5043 lpfc_mem_free_all(phba);
5044
5045 return;
5046}
5047
5048/**
James Smartda0436e2009-05-22 14:51:39 -04005049 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
5050 * @phba: pointer to lpfc hba data structure.
5051 *
5052 * This routine is invoked to set up the driver internal resources specific to
5053 * support the SLI-4 HBA device it attached to.
5054 *
5055 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005056 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04005057 * other values - error
5058 **/
5059static int
5060lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5061{
James Smart7bb03bb2013-04-17 20:19:16 -04005062 struct lpfc_vector_map_info *cpup;
James Smartda0436e2009-05-22 14:51:39 -04005063 struct lpfc_sli *psli;
James Smart28baac72010-02-12 14:42:03 -05005064 LPFC_MBOXQ_t *mboxq;
James Smart96f70772013-04-17 20:16:15 -04005065 int rc, i, hbq_count, max_buf_size;
James Smart28baac72010-02-12 14:42:03 -05005066 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
5067 struct lpfc_mqe *mqe;
James Smart09294d42013-04-17 20:16:05 -04005068 int longs;
James Smart1ba981f2014-02-20 09:56:45 -05005069 int fof_vectors = 0;
James Smartda0436e2009-05-22 14:51:39 -04005070
James Smart716d3bc2013-09-06 12:18:28 -04005071 /* Get all the module params for configuring this host */
5072 lpfc_get_cfgparam(phba);
5073
James Smartda0436e2009-05-22 14:51:39 -04005074 /* Before proceed, wait for POST done and device ready */
5075 rc = lpfc_sli4_post_status_check(phba);
5076 if (rc)
5077 return -ENODEV;
5078
5079 /*
5080 * Initialize timers used by driver
5081 */
5082
5083 /* Heartbeat timer */
5084 init_timer(&phba->hb_tmofunc);
5085 phba->hb_tmofunc.function = lpfc_hb_timeout;
5086 phba->hb_tmofunc.data = (unsigned long)phba;
James Smart19ca7602010-11-20 23:11:55 -05005087 init_timer(&phba->rrq_tmr);
5088 phba->rrq_tmr.function = lpfc_rrq_timeout;
5089 phba->rrq_tmr.data = (unsigned long)phba;
James Smartda0436e2009-05-22 14:51:39 -04005090
5091 psli = &phba->sli;
5092 /* MBOX heartbeat timer */
5093 init_timer(&psli->mbox_tmo);
5094 psli->mbox_tmo.function = lpfc_mbox_timeout;
5095 psli->mbox_tmo.data = (unsigned long) phba;
5096 /* Fabric block timer */
5097 init_timer(&phba->fabric_block_timer);
5098 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
5099 phba->fabric_block_timer.data = (unsigned long) phba;
5100 /* EA polling mode timer */
5101 init_timer(&phba->eratt_poll);
5102 phba->eratt_poll.function = lpfc_poll_eratt;
5103 phba->eratt_poll.data = (unsigned long) phba;
James Smartecfd03c2010-02-12 14:41:27 -05005104 /* FCF rediscover timer */
5105 init_timer(&phba->fcf.redisc_wait);
5106 phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
5107 phba->fcf.redisc_wait.data = (unsigned long)phba;
5108
James Smartda0436e2009-05-22 14:51:39 -04005109 /*
James Smart7ad20aa2011-05-24 11:44:28 -04005110 * Control structure for handling external multi-buffer mailbox
5111 * command pass-through.
5112 */
5113 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
5114 sizeof(struct lpfc_mbox_ext_buf_ctx));
5115 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
5116
James Smartda0436e2009-05-22 14:51:39 -04005117 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04005118
James Smartda0436e2009-05-22 14:51:39 -04005119 /* This will be set to correct value after the read_config mbox */
5120 phba->max_vports = 0;
5121
5122 /* Program the default value of vlan_id and fc_map */
5123 phba->valid_vlan = 0;
5124 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5125 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5126 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5127
5128 /*
James Smart2a76a282012-08-03 12:35:54 -04005129 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
5130 * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple.
5131 */
5132 if (!phba->sli.ring)
5133 phba->sli.ring = kzalloc(
James Smart67d12732012-08-03 12:36:13 -04005134 (LPFC_SLI3_MAX_RING + phba->cfg_fcp_io_channel) *
James Smart2a76a282012-08-03 12:35:54 -04005135 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
5136 if (!phba->sli.ring)
5137 return -ENOMEM;
James Smart085c6472010-11-20 23:11:37 -05005138
James Smart09294d42013-04-17 20:16:05 -04005139 /*
5140 * It doesn't matter what family our adapter is in, we are
5141 * limited to 2 Pages, 512 SGEs, for our SGL.
5142 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
5143 */
5144 max_buf_size = (2 * SLI4_PAGE_SIZE);
5145 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2)
5146 phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2;
James Smart09294d42013-04-17 20:16:05 -04005147
James Smartda0436e2009-05-22 14:51:39 -04005148 /*
James Smart96f70772013-04-17 20:16:15 -04005149 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smartda0436e2009-05-22 14:51:39 -04005150 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart28baac72010-02-12 14:42:03 -05005151 */
James Smart085c6472010-11-20 23:11:37 -05005152
James Smart96f70772013-04-17 20:16:15 -04005153 if (phba->cfg_enable_bg) {
5154 /*
5155 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5156 * the FCP rsp, and a SGE for each. Sice we have no control
5157 * over how many protection data segments the SCSI Layer
5158 * will hand us (ie: there could be one for every block
5159 * in the IO), we just allocate enough SGEs to accomidate
5160 * our max amount and we need to limit lpfc_sg_seg_cnt to
5161 * minimize the risk of running out.
5162 */
5163 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5164 sizeof(struct fcp_rsp) + max_buf_size;
5165
5166 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
5167 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
5168
5169 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
5170 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
5171 } else {
5172 /*
5173 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5174 * the FCP rsp, a SGE for each, and a SGE for up to
5175 * cfg_sg_seg_cnt data segments.
5176 */
5177 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5178 sizeof(struct fcp_rsp) +
5179 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge));
5180
5181 /* Total SGEs for scsi_sg_list */
5182 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5183 /*
5184 * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only need
5185 * to post 1 page for the SGL.
5186 */
James Smart085c6472010-11-20 23:11:37 -05005187 }
James Smartacd68592012-01-18 16:25:09 -05005188
James Smart96f70772013-04-17 20:16:15 -04005189 /* Initialize the host templates with the updated values. */
5190 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5191 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5192
5193 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
5194 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
5195 else
5196 phba->cfg_sg_dma_buf_size =
5197 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
5198
5199 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5200 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
5201 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5202 phba->cfg_total_seg_cnt);
James Smartda0436e2009-05-22 14:51:39 -04005203
5204 /* Initialize buffer queue management fields */
5205 hbq_count = lpfc_sli_hbq_count();
5206 for (i = 0; i < hbq_count; ++i)
5207 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
5208 INIT_LIST_HEAD(&phba->rb_pend_list);
5209 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
5210 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
5211
5212 /*
5213 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
5214 */
5215 /* Initialize the Abort scsi buffer list used by driver */
5216 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
5217 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
5218 /* This abort list used by worker thread */
5219 spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
5220
5221 /*
James Smart6d368e52011-05-24 11:44:12 -04005222 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04005223 */
5224
5225 /* Driver internel slow-path CQ Event pool */
5226 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
5227 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04005228 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04005229 /* Asynchronous event CQ Event work queue list */
5230 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
5231 /* Fast-path XRI aborted CQ Event work queue list */
5232 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
5233 /* Slow-path XRI aborted CQ Event work queue list */
5234 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
5235 /* Receive queue CQ Event work queue list */
5236 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
5237
James Smart6d368e52011-05-24 11:44:12 -04005238 /* Initialize extent block lists. */
5239 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
5240 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
5241 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
5242 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
5243
James Smartda0436e2009-05-22 14:51:39 -04005244 /* Initialize the driver internal SLI layer lists. */
5245 lpfc_sli_setup(phba);
5246 lpfc_sli_queue_setup(phba);
5247
5248 /* Allocate device driver memory */
5249 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
5250 if (rc)
5251 return -ENOMEM;
5252
James Smart2fcee4b2010-12-15 17:57:46 -05005253 /* IF Type 2 ports get initialized now. */
5254 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5255 LPFC_SLI_INTF_IF_TYPE_2) {
5256 rc = lpfc_pci_function_reset(phba);
5257 if (unlikely(rc))
5258 return -ENODEV;
James Smart946727d2015-04-07 15:07:09 -04005259 phba->temp_sensor_support = 1;
James Smart2fcee4b2010-12-15 17:57:46 -05005260 }
5261
James Smartda0436e2009-05-22 14:51:39 -04005262 /* Create the bootstrap mailbox command */
5263 rc = lpfc_create_bootstrap_mbox(phba);
5264 if (unlikely(rc))
5265 goto out_free_mem;
5266
5267 /* Set up the host's endian order with the device. */
5268 rc = lpfc_setup_endian_order(phba);
5269 if (unlikely(rc))
5270 goto out_free_bsmbx;
5271
5272 /* Set up the hba's configuration parameters. */
5273 rc = lpfc_sli4_read_config(phba);
5274 if (unlikely(rc))
5275 goto out_free_bsmbx;
James Smartcff261f2013-12-17 20:29:47 -05005276 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
5277 if (unlikely(rc))
5278 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005279
James Smart2fcee4b2010-12-15 17:57:46 -05005280 /* IF Type 0 ports get initialized now. */
5281 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5282 LPFC_SLI_INTF_IF_TYPE_0) {
5283 rc = lpfc_pci_function_reset(phba);
5284 if (unlikely(rc))
5285 goto out_free_bsmbx;
5286 }
James Smartda0436e2009-05-22 14:51:39 -04005287
James Smartcb5172e2010-03-15 11:25:07 -04005288 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
5289 GFP_KERNEL);
5290 if (!mboxq) {
5291 rc = -ENOMEM;
5292 goto out_free_bsmbx;
5293 }
5294
James Smartfedd3b72011-02-16 12:39:24 -05005295 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04005296 lpfc_supported_pages(mboxq);
5297 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05005298 if (!rc) {
5299 mqe = &mboxq->u.mqe;
5300 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
5301 LPFC_MAX_SUPPORTED_PAGES);
5302 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
5303 switch (pn_page[i]) {
5304 case LPFC_SLI4_PARAMETERS:
5305 phba->sli4_hba.pc_sli4_params.supported = 1;
5306 break;
5307 default:
5308 break;
5309 }
5310 }
5311 /* Read the port's SLI4 Parameters capabilities if supported. */
5312 if (phba->sli4_hba.pc_sli4_params.supported)
5313 rc = lpfc_pc_sli4_params_get(phba, mboxq);
5314 if (rc) {
5315 mempool_free(mboxq, phba->mbox_mem_pool);
5316 rc = -EIO;
5317 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04005318 }
5319 }
James Smartfedd3b72011-02-16 12:39:24 -05005320 /*
5321 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04005322 * If this call fails, it isn't critical unless the SLI4 parameters come
5323 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05005324 */
James Smart6d368e52011-05-24 11:44:12 -04005325 rc = lpfc_get_sli4_parameters(phba, mboxq);
5326 if (rc) {
5327 if (phba->sli4_hba.extents_in_use &&
5328 phba->sli4_hba.rpi_hdrs_in_use) {
5329 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5330 "2999 Unsupported SLI4 Parameters "
5331 "Extents and RPI headers enabled.\n");
5332 goto out_free_bsmbx;
5333 }
5334 }
James Smartcb5172e2010-03-15 11:25:07 -04005335 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -05005336
5337 /* Verify OAS is supported */
5338 lpfc_sli4_oas_verify(phba);
5339 if (phba->cfg_fof)
5340 fof_vectors = 1;
5341
James Smart5350d872011-10-10 21:33:49 -04005342 /* Verify all the SLI4 queues */
5343 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04005344 if (rc)
5345 goto out_free_bsmbx;
5346
5347 /* Create driver internal CQE event pool */
5348 rc = lpfc_sli4_cq_event_pool_create(phba);
5349 if (rc)
James Smart5350d872011-10-10 21:33:49 -04005350 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005351
James Smart8a9d2e82012-05-09 21:16:12 -04005352 /* Initialize sgl lists per host */
5353 lpfc_init_sgl_list(phba);
5354
5355 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04005356 rc = lpfc_init_active_sgl_array(phba);
5357 if (rc) {
5358 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5359 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04005360 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04005361 }
James Smartda0436e2009-05-22 14:51:39 -04005362 rc = lpfc_sli4_init_rpi_hdrs(phba);
5363 if (rc) {
5364 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5365 "1432 Failed to initialize rpi headers.\n");
5366 goto out_free_active_sgl;
5367 }
5368
James Smarta93ff372010-10-22 11:06:08 -04005369 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05005370 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
5371 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
5372 GFP_KERNEL);
5373 if (!phba->fcf.fcf_rr_bmask) {
5374 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5375 "2759 Failed allocate memory for FCF round "
5376 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04005377 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05005378 goto out_remove_rpi_hdrs;
5379 }
5380
James Smart67d12732012-08-03 12:36:13 -04005381 phba->sli4_hba.fcp_eq_hdl =
5382 kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
James Smart1ba981f2014-02-20 09:56:45 -05005383 (fof_vectors + phba->cfg_fcp_io_channel)),
5384 GFP_KERNEL);
James Smart67d12732012-08-03 12:36:13 -04005385 if (!phba->sli4_hba.fcp_eq_hdl) {
5386 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5387 "2572 Failed allocate memory for "
5388 "fast-path per-EQ handle array\n");
5389 rc = -ENOMEM;
5390 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04005391 }
5392
5393 phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
James Smart1ba981f2014-02-20 09:56:45 -05005394 (fof_vectors +
5395 phba->cfg_fcp_io_channel)), GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04005396 if (!phba->sli4_hba.msix_entries) {
5397 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5398 "2573 Failed allocate memory for msi-x "
5399 "interrupt vector entries\n");
James Smart05580562011-05-24 11:40:48 -04005400 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04005401 goto out_free_fcp_eq_hdl;
5402 }
5403
James Smart7bb03bb2013-04-17 20:19:16 -04005404 phba->sli4_hba.cpu_map = kzalloc((sizeof(struct lpfc_vector_map_info) *
5405 phba->sli4_hba.num_present_cpu),
5406 GFP_KERNEL);
5407 if (!phba->sli4_hba.cpu_map) {
5408 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5409 "3327 Failed allocate memory for msi-x "
5410 "interrupt vector mapping\n");
5411 rc = -ENOMEM;
5412 goto out_free_msix;
5413 }
James Smartb246de12013-05-31 17:03:07 -04005414 if (lpfc_used_cpu == NULL) {
5415 lpfc_used_cpu = kzalloc((sizeof(uint16_t) * lpfc_present_cpu),
5416 GFP_KERNEL);
5417 if (!lpfc_used_cpu) {
5418 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5419 "3335 Failed allocate memory for msi-x "
5420 "interrupt vector mapping\n");
5421 kfree(phba->sli4_hba.cpu_map);
5422 rc = -ENOMEM;
5423 goto out_free_msix;
5424 }
5425 for (i = 0; i < lpfc_present_cpu; i++)
5426 lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
5427 }
5428
James Smart7bb03bb2013-04-17 20:19:16 -04005429 /* Initialize io channels for round robin */
5430 cpup = phba->sli4_hba.cpu_map;
5431 rc = 0;
5432 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
5433 cpup->channel_id = rc;
5434 rc++;
5435 if (rc >= phba->cfg_fcp_io_channel)
5436 rc = 0;
5437 }
5438
James Smart912e3ac2011-05-24 11:42:11 -04005439 /*
5440 * Enable sr-iov virtual functions if supported and configured
5441 * through the module parameter.
5442 */
5443 if (phba->cfg_sriov_nr_virtfn > 0) {
5444 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5445 phba->cfg_sriov_nr_virtfn);
5446 if (rc) {
5447 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5448 "3020 Requested number of SR-IOV "
5449 "virtual functions (%d) is not "
5450 "supported\n",
5451 phba->cfg_sriov_nr_virtfn);
5452 phba->cfg_sriov_nr_virtfn = 0;
5453 }
5454 }
5455
James Smart5248a742011-07-22 18:37:06 -04005456 return 0;
James Smartda0436e2009-05-22 14:51:39 -04005457
James Smart7bb03bb2013-04-17 20:19:16 -04005458out_free_msix:
5459 kfree(phba->sli4_hba.msix_entries);
James Smartda0436e2009-05-22 14:51:39 -04005460out_free_fcp_eq_hdl:
5461 kfree(phba->sli4_hba.fcp_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05005462out_free_fcf_rr_bmask:
5463 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04005464out_remove_rpi_hdrs:
5465 lpfc_sli4_remove_rpi_hdrs(phba);
5466out_free_active_sgl:
5467 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04005468out_destroy_cq_event_pool:
5469 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04005470out_free_bsmbx:
5471 lpfc_destroy_bootstrap_mbox(phba);
5472out_free_mem:
5473 lpfc_mem_free(phba);
5474 return rc;
5475}
5476
5477/**
5478 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
5479 * @phba: pointer to lpfc hba data structure.
5480 *
5481 * This routine is invoked to unset the driver internal resources set up
5482 * specific for supporting the SLI-4 HBA device it attached to.
5483 **/
5484static void
5485lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
5486{
5487 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
5488
James Smart7bb03bb2013-04-17 20:19:16 -04005489 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
5490 kfree(phba->sli4_hba.cpu_map);
5491 phba->sli4_hba.num_present_cpu = 0;
5492 phba->sli4_hba.num_online_cpu = 0;
James Smart76fd07a2014-02-20 09:57:18 -05005493 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04005494
James Smartda0436e2009-05-22 14:51:39 -04005495 /* Free memory allocated for msi-x interrupt vector entries */
5496 kfree(phba->sli4_hba.msix_entries);
5497
5498 /* Free memory allocated for fast-path work queue handles */
5499 kfree(phba->sli4_hba.fcp_eq_hdl);
5500
5501 /* Free the allocated rpi headers. */
5502 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04005503 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04005504
James Smart0c9ab6f2010-02-26 14:15:57 -05005505 /* Free eligible FCF index bmask */
5506 kfree(phba->fcf.fcf_rr_bmask);
5507
James Smartda0436e2009-05-22 14:51:39 -04005508 /* Free the ELS sgl list */
5509 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04005510 lpfc_free_els_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04005511
James Smartda0436e2009-05-22 14:51:39 -04005512 /* Free the completion queue EQ event pool */
5513 lpfc_sli4_cq_event_release_all(phba);
5514 lpfc_sli4_cq_event_pool_destroy(phba);
5515
James Smart6d368e52011-05-24 11:44:12 -04005516 /* Release resource identifiers. */
5517 lpfc_sli4_dealloc_resource_identifiers(phba);
5518
James Smartda0436e2009-05-22 14:51:39 -04005519 /* Free the bsmbx region. */
5520 lpfc_destroy_bootstrap_mbox(phba);
5521
5522 /* Free the SLI Layer memory with SLI4 HBAs */
5523 lpfc_mem_free_all(phba);
5524
5525 /* Free the current connect table */
5526 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04005527 &phba->fcf_conn_rec_list, list) {
5528 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04005529 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04005530 }
James Smartda0436e2009-05-22 14:51:39 -04005531
5532 return;
5533}
5534
5535/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005536 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04005537 * @phba: The hba struct for which this call is being executed.
5538 * @dev_grp: The HBA PCI-Device group number.
5539 *
5540 * This routine sets up the device INIT interface API function jump table
5541 * in @phba struct.
5542 *
5543 * Returns: 0 - success, -ENODEV - failure.
5544 **/
5545int
5546lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5547{
James Smart84d1b002010-02-12 14:42:33 -05005548 phba->lpfc_hba_init_link = lpfc_hba_init_link;
5549 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05005550 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04005551 switch (dev_grp) {
5552 case LPFC_PCI_DEV_LP:
5553 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
5554 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
5555 phba->lpfc_stop_port = lpfc_stop_port_s3;
5556 break;
James Smartda0436e2009-05-22 14:51:39 -04005557 case LPFC_PCI_DEV_OC:
5558 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
5559 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
5560 phba->lpfc_stop_port = lpfc_stop_port_s4;
5561 break;
James Smart3772a992009-05-22 14:50:54 -04005562 default:
5563 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5564 "1431 Invalid HBA PCI-device group: 0x%x\n",
5565 dev_grp);
5566 return -ENODEV;
5567 break;
5568 }
5569 return 0;
5570}
5571
5572/**
5573 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
5574 * @phba: pointer to lpfc hba data structure.
5575 *
5576 * This routine is invoked to set up the driver internal resources before the
5577 * device specific resource setup to support the HBA device it attached to.
5578 *
5579 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005580 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005581 * other values - error
5582 **/
5583static int
5584lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
5585{
5586 /*
5587 * Driver resources common to all SLI revisions
5588 */
James Smartea2151b2008-09-07 11:52:10 -04005589 atomic_set(&phba->fast_event_count, 0);
James Smart2e0fef82007-06-17 19:56:36 -05005590 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005591
James Smarte47c9092008-02-08 18:49:26 -05005592 /* Initialize ndlp management spinlock */
5593 spin_lock_init(&phba->ndlp_lock);
5594
James Smart2e0fef82007-06-17 19:56:36 -05005595 INIT_LIST_HEAD(&phba->port_list);
James Smart3772a992009-05-22 14:50:54 -04005596 INIT_LIST_HEAD(&phba->work_list);
James Smart84774a42008-08-24 21:50:06 -04005597 init_waitqueue_head(&phba->wait_4_mlo_m_q);
dea31012005-04-17 16:05:31 -05005598
James Smart3772a992009-05-22 14:50:54 -04005599 /* Initialize the wait queue head for the kernel thread */
5600 init_waitqueue_head(&phba->work_waitq);
James Smart858c9f62007-06-17 19:56:39 -05005601
James Smart3772a992009-05-22 14:50:54 -04005602 /* Initialize the scsi buffer list used by driver for scsi IO */
James Smarta40fc5f2013-04-17 20:17:40 -04005603 spin_lock_init(&phba->scsi_buf_list_get_lock);
5604 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5605 spin_lock_init(&phba->scsi_buf_list_put_lock);
5606 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
dea31012005-04-17 16:05:31 -05005607
James Smart3772a992009-05-22 14:50:54 -04005608 /* Initialize the fabric iocb list */
5609 INIT_LIST_HEAD(&phba->fabric_iocb_list);
dea31012005-04-17 16:05:31 -05005610
James Smart3772a992009-05-22 14:50:54 -04005611 /* Initialize list to save ELS buffers */
5612 INIT_LIST_HEAD(&phba->elsbuf);
dea31012005-04-17 16:05:31 -05005613
James Smart3772a992009-05-22 14:50:54 -04005614 /* Initialize FCF connection rec list */
5615 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
dea31012005-04-17 16:05:31 -05005616
James Smart1ba981f2014-02-20 09:56:45 -05005617 /* Initialize OAS configuration list */
5618 spin_lock_init(&phba->devicelock);
5619 INIT_LIST_HEAD(&phba->luns);
5620
James Smart3772a992009-05-22 14:50:54 -04005621 return 0;
5622}
dea31012005-04-17 16:05:31 -05005623
James Smart3772a992009-05-22 14:50:54 -04005624/**
5625 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
5626 * @phba: pointer to lpfc hba data structure.
5627 *
5628 * This routine is invoked to set up the driver internal resources after the
5629 * device specific resource setup to support the HBA device it attached to.
5630 *
5631 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005632 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005633 * other values - error
5634 **/
5635static int
5636lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
5637{
5638 int error;
5639
5640 /* Startup the kernel thread for this host adapter. */
5641 phba->worker_thread = kthread_run(lpfc_do_work, phba,
5642 "lpfc_worker_%d", phba->brd_no);
5643 if (IS_ERR(phba->worker_thread)) {
5644 error = PTR_ERR(phba->worker_thread);
5645 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005646 }
5647
James Smart3772a992009-05-22 14:50:54 -04005648 return 0;
5649}
5650
5651/**
5652 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
5653 * @phba: pointer to lpfc hba data structure.
5654 *
5655 * This routine is invoked to unset the driver internal resources set up after
5656 * the device specific resource setup for supporting the HBA device it
5657 * attached to.
5658 **/
5659static void
5660lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
5661{
5662 /* Stop kernel worker thread */
5663 kthread_stop(phba->worker_thread);
5664}
5665
5666/**
5667 * lpfc_free_iocb_list - Free iocb list.
5668 * @phba: pointer to lpfc hba data structure.
5669 *
5670 * This routine is invoked to free the driver's IOCB list and memory.
5671 **/
5672static void
5673lpfc_free_iocb_list(struct lpfc_hba *phba)
5674{
5675 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
5676
5677 spin_lock_irq(&phba->hbalock);
5678 list_for_each_entry_safe(iocbq_entry, iocbq_next,
5679 &phba->lpfc_iocb_list, list) {
5680 list_del(&iocbq_entry->list);
5681 kfree(iocbq_entry);
5682 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005683 }
James Smart3772a992009-05-22 14:50:54 -04005684 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005685
James Smart3772a992009-05-22 14:50:54 -04005686 return;
5687}
dea31012005-04-17 16:05:31 -05005688
James Smart3772a992009-05-22 14:50:54 -04005689/**
5690 * lpfc_init_iocb_list - Allocate and initialize iocb list.
5691 * @phba: pointer to lpfc hba data structure.
5692 *
5693 * This routine is invoked to allocate and initizlize the driver's IOCB
5694 * list and set up the IOCB tag array accordingly.
5695 *
5696 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005697 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005698 * other values - error
5699 **/
5700static int
5701lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
5702{
5703 struct lpfc_iocbq *iocbq_entry = NULL;
5704 uint16_t iotag;
5705 int i;
dea31012005-04-17 16:05:31 -05005706
5707 /* Initialize and populate the iocb list per host. */
5708 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04005709 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07005710 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05005711 if (iocbq_entry == NULL) {
5712 printk(KERN_ERR "%s: only allocated %d iocbs of "
5713 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07005714 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05005715 goto out_free_iocbq;
5716 }
5717
James Bottomley604a3e32005-10-29 10:28:33 -05005718 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
5719 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04005720 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05005721 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04005722 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05005723 goto out_free_iocbq;
5724 }
James Smart6d368e52011-05-24 11:44:12 -04005725 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04005726 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05005727
5728 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005729 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
5730 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05005731 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005732 }
5733
James Smart3772a992009-05-22 14:50:54 -04005734 return 0;
5735
5736out_free_iocbq:
5737 lpfc_free_iocb_list(phba);
5738
5739 return -ENOMEM;
5740}
5741
5742/**
James Smart8a9d2e82012-05-09 21:16:12 -04005743 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04005744 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04005745 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04005746 *
James Smart8a9d2e82012-05-09 21:16:12 -04005747 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04005748 **/
James Smart8a9d2e82012-05-09 21:16:12 -04005749void
5750lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04005751{
5752 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04005753
5754 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
5755 list_del(&sglq_entry->list);
5756 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
5757 kfree(sglq_entry);
5758 }
5759}
5760
5761/**
5762 * lpfc_free_els_sgl_list - Free els sgl list.
5763 * @phba: pointer to lpfc hba data structure.
5764 *
5765 * This routine is invoked to free the driver's els sgl list and memory.
5766 **/
5767static void
5768lpfc_free_els_sgl_list(struct lpfc_hba *phba)
5769{
James Smartda0436e2009-05-22 14:51:39 -04005770 LIST_HEAD(sglq_list);
James Smartdafe8ce2014-09-03 12:56:40 -04005771 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smartda0436e2009-05-22 14:51:39 -04005772
James Smart8a9d2e82012-05-09 21:16:12 -04005773 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04005774 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04005775 spin_lock(&pring->ring_lock);
James Smartda0436e2009-05-22 14:51:39 -04005776 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
James Smartdafe8ce2014-09-03 12:56:40 -04005777 spin_unlock(&pring->ring_lock);
James Smartda0436e2009-05-22 14:51:39 -04005778 spin_unlock_irq(&phba->hbalock);
5779
James Smart8a9d2e82012-05-09 21:16:12 -04005780 /* Now free the sgl list */
5781 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04005782}
5783
5784/**
5785 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
5786 * @phba: pointer to lpfc hba data structure.
5787 *
5788 * This routine is invoked to allocate the driver's active sgl memory.
5789 * This array will hold the sglq_entry's for active IOs.
5790 **/
5791static int
5792lpfc_init_active_sgl_array(struct lpfc_hba *phba)
5793{
5794 int size;
5795 size = sizeof(struct lpfc_sglq *);
5796 size *= phba->sli4_hba.max_cfg_param.max_xri;
5797
5798 phba->sli4_hba.lpfc_sglq_active_list =
5799 kzalloc(size, GFP_KERNEL);
5800 if (!phba->sli4_hba.lpfc_sglq_active_list)
5801 return -ENOMEM;
5802 return 0;
5803}
5804
5805/**
5806 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
5807 * @phba: pointer to lpfc hba data structure.
5808 *
5809 * This routine is invoked to walk through the array of active sglq entries
5810 * and free all of the resources.
5811 * This is just a place holder for now.
5812 **/
5813static void
5814lpfc_free_active_sgl(struct lpfc_hba *phba)
5815{
5816 kfree(phba->sli4_hba.lpfc_sglq_active_list);
5817}
5818
5819/**
5820 * lpfc_init_sgl_list - Allocate and initialize sgl list.
5821 * @phba: pointer to lpfc hba data structure.
5822 *
5823 * This routine is invoked to allocate and initizlize the driver's sgl
5824 * list and set up the sgl xritag tag array accordingly.
5825 *
James Smartda0436e2009-05-22 14:51:39 -04005826 **/
James Smart8a9d2e82012-05-09 21:16:12 -04005827static void
James Smartda0436e2009-05-22 14:51:39 -04005828lpfc_init_sgl_list(struct lpfc_hba *phba)
5829{
James Smartda0436e2009-05-22 14:51:39 -04005830 /* Initialize and populate the sglq list per host/VF. */
5831 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
5832 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
5833
James Smart8a9d2e82012-05-09 21:16:12 -04005834 /* els xri-sgl book keeping */
5835 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04005836
James Smart8a9d2e82012-05-09 21:16:12 -04005837 /* scsi xri-buffer book keeping */
James Smartda0436e2009-05-22 14:51:39 -04005838 phba->sli4_hba.scsi_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04005839}
5840
5841/**
5842 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
5843 * @phba: pointer to lpfc hba data structure.
5844 *
5845 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04005846 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04005847 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04005848 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
5849 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04005850 *
5851 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005852 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04005853 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04005854 **/
5855int
5856lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
5857{
5858 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04005859 struct lpfc_rpi_hdr *rpi_hdr;
5860
5861 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05005862 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04005863 return rc;
James Smart6d368e52011-05-24 11:44:12 -04005864 if (phba->sli4_hba.extents_in_use)
5865 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04005866
5867 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
5868 if (!rpi_hdr) {
5869 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5870 "0391 Error during rpi post operation\n");
5871 lpfc_sli4_remove_rpis(phba);
5872 rc = -ENODEV;
5873 }
5874
5875 return rc;
5876}
5877
5878/**
5879 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
5880 * @phba: pointer to lpfc hba data structure.
5881 *
5882 * This routine is invoked to allocate a single 4KB memory region to
5883 * support rpis and stores them in the phba. This single region
5884 * provides support for up to 64 rpis. The region is used globally
5885 * by the device.
5886 *
5887 * Returns:
5888 * A valid rpi hdr on success.
5889 * A NULL pointer on any failure.
5890 **/
5891struct lpfc_rpi_hdr *
5892lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
5893{
5894 uint16_t rpi_limit, curr_rpi_range;
5895 struct lpfc_dmabuf *dmabuf;
5896 struct lpfc_rpi_hdr *rpi_hdr;
James Smart9589b0622011-04-16 11:03:17 -04005897 uint32_t rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04005898
James Smart6d368e52011-05-24 11:44:12 -04005899 /*
5900 * If the SLI4 port supports extents, posting the rpi header isn't
5901 * required. Set the expected maximum count and let the actual value
5902 * get set when extents are fully allocated.
5903 */
5904 if (!phba->sli4_hba.rpi_hdrs_in_use)
5905 return NULL;
5906 if (phba->sli4_hba.extents_in_use)
5907 return NULL;
5908
5909 /* The limit on the logical index is just the max_rpi count. */
James Smartda0436e2009-05-22 14:51:39 -04005910 rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
James Smart6d368e52011-05-24 11:44:12 -04005911 phba->sli4_hba.max_cfg_param.max_rpi - 1;
James Smartda0436e2009-05-22 14:51:39 -04005912
5913 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04005914 /*
5915 * Establish the starting RPI in this header block. The starting
5916 * rpi is normalized to a zero base because the physical rpi is
5917 * port based.
5918 */
James Smart97f2ecf2012-03-01 22:35:23 -05005919 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04005920 spin_unlock_irq(&phba->hbalock);
5921
5922 /*
5923 * The port has a limited number of rpis. The increment here
5924 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
5925 * and to allow the full max_rpi range per port.
5926 */
5927 if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
James Smart9589b0622011-04-16 11:03:17 -04005928 rpi_count = rpi_limit - curr_rpi_range;
5929 else
5930 rpi_count = LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04005931
James Smart6d368e52011-05-24 11:44:12 -04005932 if (!rpi_count)
5933 return NULL;
James Smartda0436e2009-05-22 14:51:39 -04005934 /*
5935 * First allocate the protocol header region for the port. The
5936 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
5937 */
5938 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5939 if (!dmabuf)
5940 return NULL;
5941
Joe Perches1aee3832014-09-03 12:56:12 -04005942 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
5943 LPFC_HDR_TEMPLATE_SIZE,
5944 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04005945 if (!dmabuf->virt) {
5946 rpi_hdr = NULL;
5947 goto err_free_dmabuf;
5948 }
5949
James Smartda0436e2009-05-22 14:51:39 -04005950 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
5951 rpi_hdr = NULL;
5952 goto err_free_coherent;
5953 }
5954
5955 /* Save the rpi header data for cleanup later. */
5956 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
5957 if (!rpi_hdr)
5958 goto err_free_coherent;
5959
5960 rpi_hdr->dmabuf = dmabuf;
5961 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
5962 rpi_hdr->page_count = 1;
5963 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04005964
5965 /* The rpi_hdr stores the logical index only. */
5966 rpi_hdr->start_rpi = curr_rpi_range;
James Smartda0436e2009-05-22 14:51:39 -04005967 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
5968
5969 /*
James Smart6d368e52011-05-24 11:44:12 -04005970 * The next_rpi stores the next logical module-64 rpi value used
5971 * to post physical rpis in subsequent rpi postings.
James Smartda0436e2009-05-22 14:51:39 -04005972 */
James Smart9589b0622011-04-16 11:03:17 -04005973 phba->sli4_hba.next_rpi += rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04005974 spin_unlock_irq(&phba->hbalock);
5975 return rpi_hdr;
5976
5977 err_free_coherent:
5978 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
5979 dmabuf->virt, dmabuf->phys);
5980 err_free_dmabuf:
5981 kfree(dmabuf);
5982 return NULL;
5983}
5984
5985/**
5986 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
5987 * @phba: pointer to lpfc hba data structure.
5988 *
5989 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04005990 * to support rpis for SLI4 ports not supporting extents. This routine
5991 * presumes the caller has released all rpis consumed by fabric or port
5992 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04005993 **/
5994void
5995lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
5996{
5997 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
5998
James Smart6d368e52011-05-24 11:44:12 -04005999 if (!phba->sli4_hba.rpi_hdrs_in_use)
6000 goto exit;
6001
James Smartda0436e2009-05-22 14:51:39 -04006002 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
6003 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
6004 list_del(&rpi_hdr->list);
6005 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
6006 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
6007 kfree(rpi_hdr->dmabuf);
6008 kfree(rpi_hdr);
6009 }
James Smart6d368e52011-05-24 11:44:12 -04006010 exit:
6011 /* There are no rpis available to the port now. */
6012 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04006013}
6014
6015/**
James Smart3772a992009-05-22 14:50:54 -04006016 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
6017 * @pdev: pointer to pci device data structure.
6018 *
6019 * This routine is invoked to allocate the driver hba data structure for an
6020 * HBA device. If the allocation is successful, the phba reference to the
6021 * PCI device data structure is set.
6022 *
6023 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006024 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04006025 * NULL - error
6026 **/
6027static struct lpfc_hba *
6028lpfc_hba_alloc(struct pci_dev *pdev)
6029{
6030 struct lpfc_hba *phba;
6031
6032 /* Allocate memory for HBA structure */
6033 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
6034 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02006035 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04006036 return NULL;
6037 }
6038
6039 /* Set reference to PCI device in HBA structure */
6040 phba->pcidev = pdev;
6041
6042 /* Assign an unused board number */
6043 phba->brd_no = lpfc_get_instance();
6044 if (phba->brd_no < 0) {
6045 kfree(phba);
6046 return NULL;
6047 }
6048
James Smart4fede782010-01-26 23:08:55 -05006049 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04006050 INIT_LIST_HEAD(&phba->ct_ev_waiters);
6051
James Smart3772a992009-05-22 14:50:54 -04006052 return phba;
6053}
6054
6055/**
6056 * lpfc_hba_free - Free driver hba data structure with a device.
6057 * @phba: pointer to lpfc hba data structure.
6058 *
6059 * This routine is invoked to free the driver hba data structure with an
6060 * HBA device.
6061 **/
6062static void
6063lpfc_hba_free(struct lpfc_hba *phba)
6064{
6065 /* Release the driver assigned board number */
6066 idr_remove(&lpfc_hba_index, phba->brd_no);
6067
James Smart2a76a282012-08-03 12:35:54 -04006068 /* Free memory allocated with sli rings */
6069 kfree(phba->sli.ring);
6070 phba->sli.ring = NULL;
6071
James Smart3772a992009-05-22 14:50:54 -04006072 kfree(phba);
6073 return;
6074}
6075
6076/**
6077 * lpfc_create_shost - Create hba physical port with associated scsi host.
6078 * @phba: pointer to lpfc hba data structure.
6079 *
6080 * This routine is invoked to create HBA physical port and associate a SCSI
6081 * host with it.
6082 *
6083 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006084 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006085 * other values - error
6086 **/
6087static int
6088lpfc_create_shost(struct lpfc_hba *phba)
6089{
6090 struct lpfc_vport *vport;
6091 struct Scsi_Host *shost;
6092
6093 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05006094 phba->fc_edtov = FF_DEF_EDTOV;
6095 phba->fc_ratov = FF_DEF_RATOV;
6096 phba->fc_altov = FF_DEF_ALTOV;
6097 phba->fc_arbtov = FF_DEF_ARBTOV;
6098
James Smartd7c47992010-06-08 18:31:54 -04006099 atomic_set(&phba->sdev_cnt, 0);
James Smart3de2a652007-08-02 11:09:59 -04006100 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05006101 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04006102 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05006103
6104 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05006105 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05006106 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04006107 /* Put reference to SCSI host to driver's device private data */
6108 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05006109
James Smart3772a992009-05-22 14:50:54 -04006110 return 0;
6111}
dea31012005-04-17 16:05:31 -05006112
James Smart3772a992009-05-22 14:50:54 -04006113/**
6114 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
6115 * @phba: pointer to lpfc hba data structure.
6116 *
6117 * This routine is invoked to destroy HBA physical port and the associated
6118 * SCSI host.
6119 **/
6120static void
6121lpfc_destroy_shost(struct lpfc_hba *phba)
6122{
6123 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04006124
James Smart3772a992009-05-22 14:50:54 -04006125 /* Destroy physical port that associated with the SCSI host */
6126 destroy_port(vport);
6127
6128 return;
6129}
6130
6131/**
6132 * lpfc_setup_bg - Setup Block guard structures and debug areas.
6133 * @phba: pointer to lpfc hba data structure.
6134 * @shost: the shost to be used to detect Block guard settings.
6135 *
6136 * This routine sets up the local Block guard protocol settings for @shost.
6137 * This routine also allocates memory for debugging bg buffers.
6138 **/
6139static void
6140lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
6141{
James Smartbbeb79b2012-06-12 13:54:27 -04006142 uint32_t old_mask;
6143 uint32_t old_guard;
6144
James Smart3772a992009-05-22 14:50:54 -04006145 int pagecnt = 10;
6146 if (lpfc_prot_mask && lpfc_prot_guard) {
6147 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6148 "1478 Registering BlockGuard with the "
6149 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04006150
6151 old_mask = lpfc_prot_mask;
6152 old_guard = lpfc_prot_guard;
6153
6154 /* Only allow supported values */
6155 lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
6156 SHOST_DIX_TYPE0_PROTECTION |
6157 SHOST_DIX_TYPE1_PROTECTION);
6158 lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC);
6159
6160 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
6161 if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
6162 lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
6163
6164 if (lpfc_prot_mask && lpfc_prot_guard) {
6165 if ((old_mask != lpfc_prot_mask) ||
6166 (old_guard != lpfc_prot_guard))
6167 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6168 "1475 Registering BlockGuard with the "
6169 "SCSI layer: mask %d guard %d\n",
6170 lpfc_prot_mask, lpfc_prot_guard);
6171
6172 scsi_host_set_prot(shost, lpfc_prot_mask);
6173 scsi_host_set_guard(shost, lpfc_prot_guard);
6174 } else
6175 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6176 "1479 Not Registering BlockGuard with the SCSI "
6177 "layer, Bad protection parameters: %d %d\n",
6178 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04006179 }
James Smartbbeb79b2012-06-12 13:54:27 -04006180
James Smart81301a92008-12-04 22:39:46 -05006181 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05006182 while (pagecnt) {
6183 spin_lock_init(&_dump_buf_lock);
6184 _dump_buf_data =
6185 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6186 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04006187 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6188 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04006189 "_dump_buf_data at 0x%p\n",
6190 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05006191 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04006192 memset(_dump_buf_data, 0,
6193 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05006194 break;
James Smart3772a992009-05-22 14:50:54 -04006195 } else
James Smart81301a92008-12-04 22:39:46 -05006196 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05006197 }
James Smart81301a92008-12-04 22:39:46 -05006198 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04006199 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6200 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04006201 "memory for hexdump\n");
6202 } else
James Smart6a9c52c2009-10-02 15:16:51 -04006203 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6204 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05006205 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05006206 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05006207 while (pagecnt) {
6208 _dump_buf_dif =
6209 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6210 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04006211 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6212 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04006213 "_dump_buf_dif at 0x%p\n",
6214 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05006215 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04006216 memset(_dump_buf_dif, 0,
6217 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05006218 break;
James Smart3772a992009-05-22 14:50:54 -04006219 } else
James Smart81301a92008-12-04 22:39:46 -05006220 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05006221 }
James Smart81301a92008-12-04 22:39:46 -05006222 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04006223 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6224 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04006225 "memory for hexdump\n");
6226 } else
James Smart6a9c52c2009-10-02 15:16:51 -04006227 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6228 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04006229 _dump_buf_dif);
6230}
6231
6232/**
6233 * lpfc_post_init_setup - Perform necessary device post initialization setup.
6234 * @phba: pointer to lpfc hba data structure.
6235 *
6236 * This routine is invoked to perform all the necessary post initialization
6237 * setup for the device.
6238 **/
6239static void
6240lpfc_post_init_setup(struct lpfc_hba *phba)
6241{
6242 struct Scsi_Host *shost;
6243 struct lpfc_adapter_event_header adapter_event;
6244
6245 /* Get the default values for Model Name and Description */
6246 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
6247
6248 /*
6249 * hba setup may have changed the hba_queue_depth so we need to
6250 * adjust the value of can_queue.
6251 */
6252 shost = pci_get_drvdata(phba->pcidev);
6253 shost->can_queue = phba->cfg_hba_queue_depth - 10;
6254 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
6255 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05006256
6257 lpfc_host_attrib_init(shost);
6258
James Smart2e0fef82007-06-17 19:56:36 -05006259 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
6260 spin_lock_irq(shost->host_lock);
6261 lpfc_poll_start_timer(phba);
6262 spin_unlock_irq(shost->host_lock);
6263 }
James Smart8f6d98d2006-08-01 07:34:00 -04006264
James Smart93996272008-08-24 21:50:30 -04006265 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6266 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04006267 /* Send board arrival event to upper layer */
6268 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
6269 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
6270 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04006271 sizeof(adapter_event),
6272 (char *) &adapter_event,
6273 LPFC_NL_VENDOR_ID);
6274 return;
6275}
6276
6277/**
6278 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
6279 * @phba: pointer to lpfc hba data structure.
6280 *
6281 * This routine is invoked to set up the PCI device memory space for device
6282 * with SLI-3 interface spec.
6283 *
6284 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006285 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006286 * other values - error
6287 **/
6288static int
6289lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
6290{
6291 struct pci_dev *pdev;
6292 unsigned long bar0map_len, bar2map_len;
6293 int i, hbq_count;
6294 void *ptr;
6295 int error = -ENODEV;
6296
6297 /* Obtain PCI device reference */
6298 if (!phba->pcidev)
6299 return error;
6300 else
6301 pdev = phba->pcidev;
6302
6303 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05006304 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
6305 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
6306 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
6307 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smart3772a992009-05-22 14:50:54 -04006308 return error;
Michael Reed8e685972009-09-18 12:02:05 -05006309 }
6310 }
James Smart3772a992009-05-22 14:50:54 -04006311
6312 /* Get the bus address of Bar0 and Bar2 and the number of bytes
6313 * required by each mapping.
6314 */
6315 phba->pci_bar0_map = pci_resource_start(pdev, 0);
6316 bar0map_len = pci_resource_len(pdev, 0);
6317
6318 phba->pci_bar2_map = pci_resource_start(pdev, 2);
6319 bar2map_len = pci_resource_len(pdev, 2);
6320
6321 /* Map HBA SLIM to a kernel virtual address. */
6322 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
6323 if (!phba->slim_memmap_p) {
6324 dev_printk(KERN_ERR, &pdev->dev,
6325 "ioremap failed for SLIM memory.\n");
6326 goto out;
6327 }
6328
6329 /* Map HBA Control Registers to a kernel virtual address. */
6330 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
6331 if (!phba->ctrl_regs_memmap_p) {
6332 dev_printk(KERN_ERR, &pdev->dev,
6333 "ioremap failed for HBA control registers.\n");
6334 goto out_iounmap_slim;
6335 }
6336
6337 /* Allocate memory for SLI-2 structures */
Joe Perches1aee3832014-09-03 12:56:12 -04006338 phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6339 &phba->slim2p.phys, GFP_KERNEL);
James Smart3772a992009-05-22 14:50:54 -04006340 if (!phba->slim2p.virt)
6341 goto out_iounmap;
6342
James Smart3772a992009-05-22 14:50:54 -04006343 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04006344 phba->mbox_ext = (phba->slim2p.virt +
6345 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04006346 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
6347 phba->IOCBs = (phba->slim2p.virt +
6348 offsetof(struct lpfc_sli2_slim, IOCBs));
6349
6350 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
6351 lpfc_sli_hbq_size(),
6352 &phba->hbqslimp.phys,
6353 GFP_KERNEL);
6354 if (!phba->hbqslimp.virt)
6355 goto out_free_slim;
6356
6357 hbq_count = lpfc_sli_hbq_count();
6358 ptr = phba->hbqslimp.virt;
6359 for (i = 0; i < hbq_count; ++i) {
6360 phba->hbqs[i].hbq_virt = ptr;
6361 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
6362 ptr += (lpfc_hbq_defs[i]->entry_count *
6363 sizeof(struct lpfc_hbq_entry));
6364 }
6365 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
6366 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
6367
6368 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
6369
6370 INIT_LIST_HEAD(&phba->rb_pend_list);
6371
6372 phba->MBslimaddr = phba->slim_memmap_p;
6373 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
6374 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
6375 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
6376 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04006377
dea31012005-04-17 16:05:31 -05006378 return 0;
6379
dea31012005-04-17 16:05:31 -05006380out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04006381 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6382 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05006383out_iounmap:
6384 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006385out_iounmap_slim:
dea31012005-04-17 16:05:31 -05006386 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05006387out:
6388 return error;
6389}
6390
James Smarte59058c2008-08-24 21:49:00 -04006391/**
James Smart3772a992009-05-22 14:50:54 -04006392 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
6393 * @phba: pointer to lpfc hba data structure.
6394 *
6395 * This routine is invoked to unset the PCI device memory space for device
6396 * with SLI-3 interface spec.
6397 **/
6398static void
6399lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
6400{
6401 struct pci_dev *pdev;
6402
6403 /* Obtain PCI device reference */
6404 if (!phba->pcidev)
6405 return;
6406 else
6407 pdev = phba->pcidev;
6408
6409 /* Free coherent DMA memory allocated */
6410 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
6411 phba->hbqslimp.virt, phba->hbqslimp.phys);
6412 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6413 phba->slim2p.virt, phba->slim2p.phys);
6414
6415 /* I/O memory unmap */
6416 iounmap(phba->ctrl_regs_memmap_p);
6417 iounmap(phba->slim_memmap_p);
6418
6419 return;
6420}
6421
6422/**
James Smartda0436e2009-05-22 14:51:39 -04006423 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
6424 * @phba: pointer to lpfc hba data structure.
6425 *
6426 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
6427 * done and check status.
6428 *
6429 * Return 0 if successful, otherwise -ENODEV.
6430 **/
6431int
6432lpfc_sli4_post_status_check(struct lpfc_hba *phba)
6433{
James Smart2fcee4b2010-12-15 17:57:46 -05006434 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
6435 struct lpfc_register reg_data;
6436 int i, port_error = 0;
6437 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04006438
James Smart9940b972011-03-11 16:06:12 -05006439 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
6440 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05006441 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04006442 return -ENODEV;
6443
James Smartda0436e2009-05-22 14:51:39 -04006444 /* Wait up to 30 seconds for the SLI Port POST done and ready */
6445 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05006446 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
6447 &portsmphr_reg.word0) ||
6448 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006449 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04006450 port_error = -ENODEV;
6451 break;
6452 }
James Smart2fcee4b2010-12-15 17:57:46 -05006453 if (LPFC_POST_STAGE_PORT_READY ==
6454 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04006455 break;
James Smartda0436e2009-05-22 14:51:39 -04006456 msleep(10);
6457 }
6458
James Smart2fcee4b2010-12-15 17:57:46 -05006459 /*
6460 * If there was a port error during POST, then don't proceed with
6461 * other register reads as the data may not be valid. Just exit.
6462 */
6463 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04006464 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006465 "1408 Port Failed POST - portsmphr=0x%x, "
6466 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
6467 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
6468 portsmphr_reg.word0,
6469 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
6470 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
6471 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
6472 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
6473 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
6474 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
6475 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
6476 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
6477 } else {
James Smart28baac72010-02-12 14:42:03 -05006478 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006479 "2534 Device Info: SLIFamily=0x%x, "
6480 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
6481 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05006482 bf_get(lpfc_sli_intf_sli_family,
6483 &phba->sli4_hba.sli_intf),
6484 bf_get(lpfc_sli_intf_slirev,
6485 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006486 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05006487 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006488 bf_get(lpfc_sli_intf_sli_hint1,
6489 &phba->sli4_hba.sli_intf),
6490 bf_get(lpfc_sli_intf_sli_hint2,
6491 &phba->sli4_hba.sli_intf),
6492 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05006493 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05006494 /*
6495 * Check for other Port errors during the initialization
6496 * process. Fail the load if the port did not come up
6497 * correctly.
6498 */
6499 if_type = bf_get(lpfc_sli_intf_if_type,
6500 &phba->sli4_hba.sli_intf);
6501 switch (if_type) {
6502 case LPFC_SLI_INTF_IF_TYPE_0:
6503 phba->sli4_hba.ue_mask_lo =
6504 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
6505 phba->sli4_hba.ue_mask_hi =
6506 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
6507 uerrlo_reg.word0 =
6508 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
6509 uerrhi_reg.word0 =
6510 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
6511 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
6512 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
6513 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6514 "1422 Unrecoverable Error "
6515 "Detected during POST "
6516 "uerr_lo_reg=0x%x, "
6517 "uerr_hi_reg=0x%x, "
6518 "ue_mask_lo_reg=0x%x, "
6519 "ue_mask_hi_reg=0x%x\n",
6520 uerrlo_reg.word0,
6521 uerrhi_reg.word0,
6522 phba->sli4_hba.ue_mask_lo,
6523 phba->sli4_hba.ue_mask_hi);
6524 port_error = -ENODEV;
6525 }
6526 break;
6527 case LPFC_SLI_INTF_IF_TYPE_2:
6528 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05006529 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
6530 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04006531 (bf_get(lpfc_sliport_status_err, &reg_data) &&
6532 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006533 phba->work_status[0] =
6534 readl(phba->sli4_hba.u.if_type2.
6535 ERR1regaddr);
6536 phba->work_status[1] =
6537 readl(phba->sli4_hba.u.if_type2.
6538 ERR2regaddr);
6539 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05006540 "2888 Unrecoverable port error "
6541 "following POST: port status reg "
6542 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05006543 "error 1=0x%x, error 2=0x%x\n",
6544 reg_data.word0,
6545 portsmphr_reg.word0,
6546 phba->work_status[0],
6547 phba->work_status[1]);
6548 port_error = -ENODEV;
6549 }
6550 break;
6551 case LPFC_SLI_INTF_IF_TYPE_1:
6552 default:
6553 break;
6554 }
James Smart28baac72010-02-12 14:42:03 -05006555 }
James Smartda0436e2009-05-22 14:51:39 -04006556 return port_error;
6557}
6558
6559/**
6560 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
6561 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05006562 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04006563 *
6564 * This routine is invoked to set up SLI4 BAR0 PCI config space register
6565 * memory map.
6566 **/
6567static void
James Smart2fcee4b2010-12-15 17:57:46 -05006568lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04006569{
James Smart2fcee4b2010-12-15 17:57:46 -05006570 switch (if_type) {
6571 case LPFC_SLI_INTF_IF_TYPE_0:
6572 phba->sli4_hba.u.if_type0.UERRLOregaddr =
6573 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
6574 phba->sli4_hba.u.if_type0.UERRHIregaddr =
6575 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
6576 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
6577 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
6578 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
6579 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
6580 phba->sli4_hba.SLIINTFregaddr =
6581 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6582 break;
6583 case LPFC_SLI_INTF_IF_TYPE_2:
6584 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006585 phba->sli4_hba.conf_regs_memmap_p +
6586 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006587 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006588 phba->sli4_hba.conf_regs_memmap_p +
6589 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006590 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006591 phba->sli4_hba.conf_regs_memmap_p +
6592 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006593 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006594 phba->sli4_hba.conf_regs_memmap_p +
6595 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006596 phba->sli4_hba.SLIINTFregaddr =
6597 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6598 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006599 phba->sli4_hba.conf_regs_memmap_p +
6600 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006601 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006602 phba->sli4_hba.conf_regs_memmap_p +
6603 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006604 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006605 phba->sli4_hba.conf_regs_memmap_p +
6606 LPFC_ULP0_WQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006607 phba->sli4_hba.EQCQDBregaddr =
6608 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
6609 phba->sli4_hba.MQDBregaddr =
6610 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
6611 phba->sli4_hba.BMBXregaddr =
6612 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
6613 break;
6614 case LPFC_SLI_INTF_IF_TYPE_1:
6615 default:
6616 dev_printk(KERN_ERR, &phba->pcidev->dev,
6617 "FATAL - unsupported SLI4 interface type - %d\n",
6618 if_type);
6619 break;
6620 }
James Smartda0436e2009-05-22 14:51:39 -04006621}
6622
6623/**
6624 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
6625 * @phba: pointer to lpfc hba data structure.
6626 *
6627 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
6628 * memory map.
6629 **/
6630static void
6631lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
6632{
James Smart2fcee4b2010-12-15 17:57:46 -05006633 phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
6634 LPFC_SLIPORT_IF0_SMPHR;
James Smartda0436e2009-05-22 14:51:39 -04006635 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006636 LPFC_HST_ISR0;
James Smartda0436e2009-05-22 14:51:39 -04006637 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006638 LPFC_HST_IMR0;
James Smartda0436e2009-05-22 14:51:39 -04006639 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006640 LPFC_HST_ISCR0;
James Smartda0436e2009-05-22 14:51:39 -04006641}
6642
6643/**
6644 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
6645 * @phba: pointer to lpfc hba data structure.
6646 * @vf: virtual function number
6647 *
6648 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
6649 * based on the given viftual function number, @vf.
6650 *
6651 * Return 0 if successful, otherwise -ENODEV.
6652 **/
6653static int
6654lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
6655{
6656 if (vf > LPFC_VIR_FUNC_MAX)
6657 return -ENODEV;
6658
6659 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05006660 vf * LPFC_VFR_PAGE_SIZE +
6661 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04006662 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05006663 vf * LPFC_VFR_PAGE_SIZE +
6664 LPFC_ULP0_WQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04006665 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6666 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
6667 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6668 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
6669 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6670 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
6671 return 0;
6672}
6673
6674/**
6675 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
6676 * @phba: pointer to lpfc hba data structure.
6677 *
6678 * This routine is invoked to create the bootstrap mailbox
6679 * region consistent with the SLI-4 interface spec. This
6680 * routine allocates all memory necessary to communicate
6681 * mailbox commands to the port and sets up all alignment
6682 * needs. No locks are expected to be held when calling
6683 * this routine.
6684 *
6685 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006686 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04006687 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04006688 **/
6689static int
6690lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
6691{
6692 uint32_t bmbx_size;
6693 struct lpfc_dmabuf *dmabuf;
6694 struct dma_address *dma_address;
6695 uint32_t pa_addr;
6696 uint64_t phys_addr;
6697
6698 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6699 if (!dmabuf)
6700 return -ENOMEM;
6701
6702 /*
6703 * The bootstrap mailbox region is comprised of 2 parts
6704 * plus an alignment restriction of 16 bytes.
6705 */
6706 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
Joe Perches1aee3832014-09-03 12:56:12 -04006707 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
6708 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04006709 if (!dmabuf->virt) {
6710 kfree(dmabuf);
6711 return -ENOMEM;
6712 }
James Smartda0436e2009-05-22 14:51:39 -04006713
6714 /*
6715 * Initialize the bootstrap mailbox pointers now so that the register
6716 * operations are simple later. The mailbox dma address is required
6717 * to be 16-byte aligned. Also align the virtual memory as each
6718 * maibox is copied into the bmbx mailbox region before issuing the
6719 * command to the port.
6720 */
6721 phba->sli4_hba.bmbx.dmabuf = dmabuf;
6722 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
6723
6724 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
6725 LPFC_ALIGN_16_BYTE);
6726 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
6727 LPFC_ALIGN_16_BYTE);
6728
6729 /*
6730 * Set the high and low physical addresses now. The SLI4 alignment
6731 * requirement is 16 bytes and the mailbox is posted to the port
6732 * as two 30-bit addresses. The other data is a bit marking whether
6733 * the 30-bit address is the high or low address.
6734 * Upcast bmbx aphys to 64bits so shift instruction compiles
6735 * clean on 32 bit machines.
6736 */
6737 dma_address = &phba->sli4_hba.bmbx.dma_address;
6738 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
6739 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
6740 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
6741 LPFC_BMBX_BIT1_ADDR_HI);
6742
6743 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
6744 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
6745 LPFC_BMBX_BIT1_ADDR_LO);
6746 return 0;
6747}
6748
6749/**
6750 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
6751 * @phba: pointer to lpfc hba data structure.
6752 *
6753 * This routine is invoked to teardown the bootstrap mailbox
6754 * region and release all host resources. This routine requires
6755 * the caller to ensure all mailbox commands recovered, no
6756 * additional mailbox comands are sent, and interrupts are disabled
6757 * before calling this routine.
6758 *
6759 **/
6760static void
6761lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
6762{
6763 dma_free_coherent(&phba->pcidev->dev,
6764 phba->sli4_hba.bmbx.bmbx_size,
6765 phba->sli4_hba.bmbx.dmabuf->virt,
6766 phba->sli4_hba.bmbx.dmabuf->phys);
6767
6768 kfree(phba->sli4_hba.bmbx.dmabuf);
6769 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
6770}
6771
6772/**
6773 * lpfc_sli4_read_config - Get the config parameters.
6774 * @phba: pointer to lpfc hba data structure.
6775 *
6776 * This routine is invoked to read the configuration parameters from the HBA.
6777 * The configuration parameters are used to set the base and maximum values
6778 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
6779 * allocation for the port.
6780 *
6781 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006782 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006783 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006784 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006785 **/
James Smartff78d8f2011-12-13 13:21:35 -05006786int
James Smartda0436e2009-05-22 14:51:39 -04006787lpfc_sli4_read_config(struct lpfc_hba *phba)
6788{
6789 LPFC_MBOXQ_t *pmb;
6790 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04006791 union lpfc_sli4_cfg_shdr *shdr;
6792 uint32_t shdr_status, shdr_add_status;
6793 struct lpfc_mbx_get_func_cfg *get_func_cfg;
6794 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04006795 char *pdesc_0;
James Smart8aa134a2012-08-14 14:25:29 -04006796 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04006797
6798 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6799 if (!pmb) {
6800 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6801 "2011 Unable to allocate memory for issuing "
6802 "SLI_CONFIG_SPECIAL mailbox command\n");
6803 return -ENOMEM;
6804 }
6805
6806 lpfc_read_config(phba, pmb);
6807
6808 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
6809 if (rc != MBX_SUCCESS) {
6810 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6811 "2012 Mailbox failed , mbxCmd x%x "
6812 "READ_CONFIG, mbxStatus x%x\n",
6813 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6814 bf_get(lpfc_mqe_status, &pmb->u.mqe));
6815 rc = -EIO;
6816 } else {
6817 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05006818 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
6819 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
6820 phba->sli4_hba.lnk_info.lnk_tp =
6821 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
6822 phba->sli4_hba.lnk_info.lnk_no =
6823 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
6824 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6825 "3081 lnk_type:%d, lnk_numb:%d\n",
6826 phba->sli4_hba.lnk_info.lnk_tp,
6827 phba->sli4_hba.lnk_info.lnk_no);
6828 } else
6829 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6830 "3082 Mailbox (x%x) returned ldv:x0\n",
6831 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart6d368e52011-05-24 11:44:12 -04006832 phba->sli4_hba.extents_in_use =
6833 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04006834 phba->sli4_hba.max_cfg_param.max_xri =
6835 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
6836 phba->sli4_hba.max_cfg_param.xri_base =
6837 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
6838 phba->sli4_hba.max_cfg_param.max_vpi =
6839 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
6840 phba->sli4_hba.max_cfg_param.vpi_base =
6841 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
6842 phba->sli4_hba.max_cfg_param.max_rpi =
6843 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
6844 phba->sli4_hba.max_cfg_param.rpi_base =
6845 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
6846 phba->sli4_hba.max_cfg_param.max_vfi =
6847 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
6848 phba->sli4_hba.max_cfg_param.vfi_base =
6849 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
6850 phba->sli4_hba.max_cfg_param.max_fcfi =
6851 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04006852 phba->sli4_hba.max_cfg_param.max_eq =
6853 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
6854 phba->sli4_hba.max_cfg_param.max_rq =
6855 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
6856 phba->sli4_hba.max_cfg_param.max_wq =
6857 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
6858 phba->sli4_hba.max_cfg_param.max_cq =
6859 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
6860 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
6861 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
6862 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
6863 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05006864 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
6865 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04006866 phba->max_vports = phba->max_vpi;
6867 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04006868 "2003 cfg params Extents? %d "
6869 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04006870 "VPI(B:%d M:%d) "
6871 "VFI(B:%d M:%d) "
6872 "RPI(B:%d M:%d) "
James Smart6d368e52011-05-24 11:44:12 -04006873 "FCFI(Count:%d)\n",
6874 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04006875 phba->sli4_hba.max_cfg_param.xri_base,
6876 phba->sli4_hba.max_cfg_param.max_xri,
6877 phba->sli4_hba.max_cfg_param.vpi_base,
6878 phba->sli4_hba.max_cfg_param.max_vpi,
6879 phba->sli4_hba.max_cfg_param.vfi_base,
6880 phba->sli4_hba.max_cfg_param.max_vfi,
6881 phba->sli4_hba.max_cfg_param.rpi_base,
6882 phba->sli4_hba.max_cfg_param.max_rpi,
James Smartda0436e2009-05-22 14:51:39 -04006883 phba->sli4_hba.max_cfg_param.max_fcfi);
6884 }
James Smart912e3ac2011-05-24 11:42:11 -04006885
6886 if (rc)
6887 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04006888
6889 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -04006890 length = phba->sli4_hba.max_cfg_param.max_xri -
6891 lpfc_sli4_get_els_iocb_cnt(phba);
6892 if (phba->cfg_hba_queue_depth > length) {
6893 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6894 "3361 HBA queue depth changed from %d to %d\n",
6895 phba->cfg_hba_queue_depth, length);
6896 phba->cfg_hba_queue_depth = length;
6897 }
James Smart912e3ac2011-05-24 11:42:11 -04006898
6899 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
6900 LPFC_SLI_INTF_IF_TYPE_2)
6901 goto read_cfg_out;
6902
6903 /* get the pf# and vf# for SLI4 if_type 2 port */
6904 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
6905 sizeof(struct lpfc_sli4_cfg_mhdr));
6906 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
6907 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
6908 length, LPFC_SLI4_MBX_EMBED);
6909
James Smart8aa134a2012-08-14 14:25:29 -04006910 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04006911 shdr = (union lpfc_sli4_cfg_shdr *)
6912 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
6913 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6914 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04006915 if (rc2 || shdr_status || shdr_add_status) {
James Smart912e3ac2011-05-24 11:42:11 -04006916 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6917 "3026 Mailbox failed , mbxCmd x%x "
6918 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
6919 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6920 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04006921 goto read_cfg_out;
6922 }
6923
6924 /* search for fc_fcoe resrouce descriptor */
6925 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
James Smart912e3ac2011-05-24 11:42:11 -04006926
James Smart8aa134a2012-08-14 14:25:29 -04006927 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
6928 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
6929 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
6930 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
6931 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
6932 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
6933 goto read_cfg_out;
6934
James Smart912e3ac2011-05-24 11:42:11 -04006935 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04006936 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04006937 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04006938 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04006939 phba->sli4_hba.iov.pf_number =
6940 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
6941 phba->sli4_hba.iov.vf_number =
6942 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
6943 break;
6944 }
6945 }
6946
6947 if (i < LPFC_RSRC_DESC_MAX_NUM)
6948 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6949 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
6950 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
6951 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04006952 else
James Smart912e3ac2011-05-24 11:42:11 -04006953 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6954 "3028 GET_FUNCTION_CONFIG: failed to find "
6955 "Resrouce Descriptor:x%x\n",
6956 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04006957
6958read_cfg_out:
6959 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04006960 return rc;
6961}
6962
6963/**
James Smart2fcee4b2010-12-15 17:57:46 -05006964 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04006965 * @phba: pointer to lpfc hba data structure.
6966 *
James Smart2fcee4b2010-12-15 17:57:46 -05006967 * This routine is invoked to setup the port-side endian order when
6968 * the port if_type is 0. This routine has no function for other
6969 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04006970 *
6971 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006972 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006973 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006974 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006975 **/
6976static int
6977lpfc_setup_endian_order(struct lpfc_hba *phba)
6978{
6979 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05006980 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04006981 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
6982 HOST_ENDIAN_HIGH_WORD1};
6983
James Smart2fcee4b2010-12-15 17:57:46 -05006984 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
6985 switch (if_type) {
6986 case LPFC_SLI_INTF_IF_TYPE_0:
6987 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
6988 GFP_KERNEL);
6989 if (!mboxq) {
6990 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6991 "0492 Unable to allocate memory for "
6992 "issuing SLI_CONFIG_SPECIAL mailbox "
6993 "command\n");
6994 return -ENOMEM;
6995 }
James Smartda0436e2009-05-22 14:51:39 -04006996
James Smart2fcee4b2010-12-15 17:57:46 -05006997 /*
6998 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
6999 * two words to contain special data values and no other data.
7000 */
7001 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
7002 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
7003 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7004 if (rc != MBX_SUCCESS) {
7005 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7006 "0493 SLI_CONFIG_SPECIAL mailbox "
7007 "failed with status x%x\n",
7008 rc);
7009 rc = -EIO;
7010 }
7011 mempool_free(mboxq, phba->mbox_mem_pool);
7012 break;
7013 case LPFC_SLI_INTF_IF_TYPE_2:
7014 case LPFC_SLI_INTF_IF_TYPE_1:
7015 default:
7016 break;
James Smartda0436e2009-05-22 14:51:39 -04007017 }
James Smartda0436e2009-05-22 14:51:39 -04007018 return rc;
7019}
7020
7021/**
James Smart5350d872011-10-10 21:33:49 -04007022 * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts
James Smartda0436e2009-05-22 14:51:39 -04007023 * @phba: pointer to lpfc hba data structure.
7024 *
James Smart5350d872011-10-10 21:33:49 -04007025 * This routine is invoked to check the user settable queue counts for EQs and
7026 * CQs. after this routine is called the counts will be set to valid values that
7027 * adhere to the constraints of the system's interrupt vectors and the port's
7028 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04007029 *
7030 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007031 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007032 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007033 **/
7034static int
James Smart5350d872011-10-10 21:33:49 -04007035lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04007036{
James Smart67d12732012-08-03 12:36:13 -04007037 int cfg_fcp_io_channel;
James Smart90695ee2012-08-14 14:25:36 -04007038 uint32_t cpu;
7039 uint32_t i = 0;
James Smart1ba981f2014-02-20 09:56:45 -05007040 int fof_vectors = phba->cfg_fof ? 1 : 0;
James Smartda0436e2009-05-22 14:51:39 -04007041
7042 /*
James Smart67d12732012-08-03 12:36:13 -04007043 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04007044 * device parameters
7045 */
7046
James Smart67d12732012-08-03 12:36:13 -04007047 /* Sanity check on HBA EQ parameters */
7048 cfg_fcp_io_channel = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04007049
James Smart7bb03bb2013-04-17 20:19:16 -04007050 /* It doesn't make sense to have more io channels then online CPUs */
7051 for_each_present_cpu(cpu) {
7052 if (cpu_online(cpu))
7053 i++;
James Smart90695ee2012-08-14 14:25:36 -04007054 }
James Smart7bb03bb2013-04-17 20:19:16 -04007055 phba->sli4_hba.num_online_cpu = i;
James Smartb246de12013-05-31 17:03:07 -04007056 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
James Smart76fd07a2014-02-20 09:57:18 -05007057 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04007058
James Smart90695ee2012-08-14 14:25:36 -04007059 if (i < cfg_fcp_io_channel) {
James Smart82c3e9b2012-09-29 11:29:50 -04007060 lpfc_printf_log(phba,
7061 KERN_ERR, LOG_INIT,
James Smart90695ee2012-08-14 14:25:36 -04007062 "3188 Reducing IO channels to match number of "
James Smart7bb03bb2013-04-17 20:19:16 -04007063 "online CPUs: from %d to %d\n",
7064 cfg_fcp_io_channel, i);
James Smart90695ee2012-08-14 14:25:36 -04007065 cfg_fcp_io_channel = i;
7066 }
7067
James Smart1ba981f2014-02-20 09:56:45 -05007068 if (cfg_fcp_io_channel + fof_vectors >
James Smart67d12732012-08-03 12:36:13 -04007069 phba->sli4_hba.max_cfg_param.max_eq) {
James Smart82c3e9b2012-09-29 11:29:50 -04007070 if (phba->sli4_hba.max_cfg_param.max_eq <
7071 LPFC_FCP_IO_CHAN_MIN) {
James Smartda0436e2009-05-22 14:51:39 -04007072 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7073 "2574 Not enough EQs (%d) from the "
7074 "pci function for supporting FCP "
7075 "EQs (%d)\n",
7076 phba->sli4_hba.max_cfg_param.max_eq,
James Smart67d12732012-08-03 12:36:13 -04007077 phba->cfg_fcp_io_channel);
James Smartda0436e2009-05-22 14:51:39 -04007078 goto out_error;
7079 }
James Smart82c3e9b2012-09-29 11:29:50 -04007080 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7081 "2575 Reducing IO channels to match number of "
7082 "available EQs: from %d to %d\n",
7083 cfg_fcp_io_channel,
7084 phba->sli4_hba.max_cfg_param.max_eq);
James Smart1ba981f2014-02-20 09:56:45 -05007085 cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq -
7086 fof_vectors;
James Smartda0436e2009-05-22 14:51:39 -04007087 }
James Smart67d12732012-08-03 12:36:13 -04007088
James Smartda0436e2009-05-22 14:51:39 -04007089 /* The actual number of FCP event queues adopted */
James Smart67d12732012-08-03 12:36:13 -04007090 phba->cfg_fcp_io_channel = cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04007091
James Smartda0436e2009-05-22 14:51:39 -04007092 /* Get EQ depth from module parameter, fake the default for now */
7093 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
7094 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
7095
James Smart5350d872011-10-10 21:33:49 -04007096 /* Get CQ depth from module parameter, fake the default for now */
7097 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
7098 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
7099
7100 return 0;
7101out_error:
7102 return -ENOMEM;
7103}
7104
7105/**
7106 * lpfc_sli4_queue_create - Create all the SLI4 queues
7107 * @phba: pointer to lpfc hba data structure.
7108 *
7109 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
7110 * operation. For each SLI4 queue type, the parameters such as queue entry
7111 * count (queue depth) shall be taken from the module parameter. For now,
7112 * we just use some constant number as place holder.
7113 *
7114 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07007115 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04007116 * -ENOMEM - No availble memory
7117 * -EIO - The mailbox failed to complete successfully.
7118 **/
7119int
7120lpfc_sli4_queue_create(struct lpfc_hba *phba)
7121{
7122 struct lpfc_queue *qdesc;
James Smart67d12732012-08-03 12:36:13 -04007123 int idx;
James Smart5350d872011-10-10 21:33:49 -04007124
7125 /*
James Smart67d12732012-08-03 12:36:13 -04007126 * Create HBA Record arrays.
James Smart5350d872011-10-10 21:33:49 -04007127 */
James Smart67d12732012-08-03 12:36:13 -04007128 if (!phba->cfg_fcp_io_channel)
7129 return -ERANGE;
James Smart5350d872011-10-10 21:33:49 -04007130
James Smart67d12732012-08-03 12:36:13 -04007131 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
7132 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
7133 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
7134 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
7135 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
7136 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
7137
7138 phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) *
7139 phba->cfg_fcp_io_channel), GFP_KERNEL);
7140 if (!phba->sli4_hba.hba_eq) {
James Smartda0436e2009-05-22 14:51:39 -04007141 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007142 "2576 Failed allocate memory for "
7143 "fast-path EQ record array\n");
James Smartda0436e2009-05-22 14:51:39 -04007144 goto out_error;
7145 }
James Smart67d12732012-08-03 12:36:13 -04007146
7147 phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
7148 phba->cfg_fcp_io_channel), GFP_KERNEL);
7149 if (!phba->sli4_hba.fcp_cq) {
7150 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7151 "2577 Failed allocate memory for fast-path "
7152 "CQ record array\n");
7153 goto out_error;
7154 }
7155
7156 phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
7157 phba->cfg_fcp_io_channel), GFP_KERNEL);
7158 if (!phba->sli4_hba.fcp_wq) {
7159 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7160 "2578 Failed allocate memory for fast-path "
7161 "WQ record array\n");
7162 goto out_error;
7163 }
James Smartda0436e2009-05-22 14:51:39 -04007164
James Smart5350d872011-10-10 21:33:49 -04007165 /*
James Smart67d12732012-08-03 12:36:13 -04007166 * Since the first EQ can have multiple CQs associated with it,
7167 * this array is used to quickly see if we have a FCP fast-path
7168 * CQ match.
James Smart5350d872011-10-10 21:33:49 -04007169 */
James Smart67d12732012-08-03 12:36:13 -04007170 phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) *
7171 phba->cfg_fcp_io_channel), GFP_KERNEL);
7172 if (!phba->sli4_hba.fcp_cq_map) {
7173 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7174 "2545 Failed allocate memory for fast-path "
7175 "CQ map\n");
7176 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007177 }
James Smart67d12732012-08-03 12:36:13 -04007178
7179 /*
7180 * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies
7181 * how many EQs to create.
7182 */
7183 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7184
7185 /* Create EQs */
James Smartda0436e2009-05-22 14:51:39 -04007186 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
7187 phba->sli4_hba.eq_ecount);
7188 if (!qdesc) {
7189 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007190 "0497 Failed allocate EQ (%d)\n", idx);
7191 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007192 }
James Smart67d12732012-08-03 12:36:13 -04007193 phba->sli4_hba.hba_eq[idx] = qdesc;
7194
7195 /* Create Fast Path FCP CQs */
7196 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7197 phba->sli4_hba.cq_ecount);
7198 if (!qdesc) {
7199 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7200 "0499 Failed allocate fast-path FCP "
7201 "CQ (%d)\n", idx);
7202 goto out_error;
7203 }
7204 phba->sli4_hba.fcp_cq[idx] = qdesc;
7205
7206 /* Create Fast Path FCP WQs */
7207 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
7208 phba->sli4_hba.wq_ecount);
7209 if (!qdesc) {
7210 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7211 "0503 Failed allocate fast-path FCP "
7212 "WQ (%d)\n", idx);
7213 goto out_error;
7214 }
7215 phba->sli4_hba.fcp_wq[idx] = qdesc;
James Smartda0436e2009-05-22 14:51:39 -04007216 }
7217
James Smart67d12732012-08-03 12:36:13 -04007218
James Smartda0436e2009-05-22 14:51:39 -04007219 /*
James Smart67d12732012-08-03 12:36:13 -04007220 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04007221 */
7222
James Smartda0436e2009-05-22 14:51:39 -04007223 /* Create slow-path Mailbox Command Complete Queue */
7224 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7225 phba->sli4_hba.cq_ecount);
7226 if (!qdesc) {
7227 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7228 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04007229 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007230 }
7231 phba->sli4_hba.mbx_cq = qdesc;
7232
7233 /* Create slow-path ELS Complete Queue */
7234 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7235 phba->sli4_hba.cq_ecount);
7236 if (!qdesc) {
7237 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7238 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -04007239 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007240 }
7241 phba->sli4_hba.els_cq = qdesc;
7242
James Smartda0436e2009-05-22 14:51:39 -04007243
James Smart5350d872011-10-10 21:33:49 -04007244 /*
James Smart67d12732012-08-03 12:36:13 -04007245 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04007246 */
James Smartda0436e2009-05-22 14:51:39 -04007247
7248 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04007249
7250 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
7251 phba->sli4_hba.mq_ecount);
7252 if (!qdesc) {
7253 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7254 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04007255 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007256 }
7257 phba->sli4_hba.mbx_wq = qdesc;
7258
7259 /*
James Smart67d12732012-08-03 12:36:13 -04007260 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04007261 */
James Smartda0436e2009-05-22 14:51:39 -04007262
7263 /* Create slow-path ELS Work Queue */
7264 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
7265 phba->sli4_hba.wq_ecount);
7266 if (!qdesc) {
7267 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7268 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04007269 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007270 }
7271 phba->sli4_hba.els_wq = qdesc;
7272
James Smartda0436e2009-05-22 14:51:39 -04007273 /*
7274 * Create Receive Queue (RQ)
7275 */
James Smartda0436e2009-05-22 14:51:39 -04007276
7277 /* Create Receive Queue for header */
7278 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
7279 phba->sli4_hba.rq_ecount);
7280 if (!qdesc) {
7281 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7282 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04007283 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007284 }
7285 phba->sli4_hba.hdr_rq = qdesc;
7286
7287 /* Create Receive Queue for data */
7288 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
7289 phba->sli4_hba.rq_ecount);
7290 if (!qdesc) {
7291 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7292 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04007293 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007294 }
7295 phba->sli4_hba.dat_rq = qdesc;
7296
James Smart1ba981f2014-02-20 09:56:45 -05007297 /* Create the Queues needed for Flash Optimized Fabric operations */
7298 if (phba->cfg_fof)
7299 lpfc_fof_queue_create(phba);
James Smartda0436e2009-05-22 14:51:39 -04007300 return 0;
7301
James Smartda0436e2009-05-22 14:51:39 -04007302out_error:
James Smart67d12732012-08-03 12:36:13 -04007303 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04007304 return -ENOMEM;
7305}
7306
7307/**
7308 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
7309 * @phba: pointer to lpfc hba data structure.
7310 *
7311 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
7312 * operation.
7313 *
7314 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007315 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007316 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007317 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007318 **/
James Smart5350d872011-10-10 21:33:49 -04007319void
James Smartda0436e2009-05-22 14:51:39 -04007320lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
7321{
James Smart67d12732012-08-03 12:36:13 -04007322 int idx;
7323
James Smart1ba981f2014-02-20 09:56:45 -05007324 if (phba->cfg_fof)
7325 lpfc_fof_queue_destroy(phba);
7326
James Smart67d12732012-08-03 12:36:13 -04007327 if (phba->sli4_hba.hba_eq != NULL) {
7328 /* Release HBA event queue */
7329 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7330 if (phba->sli4_hba.hba_eq[idx] != NULL) {
7331 lpfc_sli4_queue_free(
7332 phba->sli4_hba.hba_eq[idx]);
7333 phba->sli4_hba.hba_eq[idx] = NULL;
7334 }
7335 }
7336 kfree(phba->sli4_hba.hba_eq);
7337 phba->sli4_hba.hba_eq = NULL;
7338 }
7339
7340 if (phba->sli4_hba.fcp_cq != NULL) {
7341 /* Release FCP completion queue */
7342 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7343 if (phba->sli4_hba.fcp_cq[idx] != NULL) {
7344 lpfc_sli4_queue_free(
7345 phba->sli4_hba.fcp_cq[idx]);
7346 phba->sli4_hba.fcp_cq[idx] = NULL;
7347 }
7348 }
7349 kfree(phba->sli4_hba.fcp_cq);
7350 phba->sli4_hba.fcp_cq = NULL;
7351 }
7352
7353 if (phba->sli4_hba.fcp_wq != NULL) {
7354 /* Release FCP work queue */
7355 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7356 if (phba->sli4_hba.fcp_wq[idx] != NULL) {
7357 lpfc_sli4_queue_free(
7358 phba->sli4_hba.fcp_wq[idx]);
7359 phba->sli4_hba.fcp_wq[idx] = NULL;
7360 }
7361 }
7362 kfree(phba->sli4_hba.fcp_wq);
7363 phba->sli4_hba.fcp_wq = NULL;
7364 }
7365
7366 /* Release FCP CQ mapping array */
7367 if (phba->sli4_hba.fcp_cq_map != NULL) {
7368 kfree(phba->sli4_hba.fcp_cq_map);
7369 phba->sli4_hba.fcp_cq_map = NULL;
7370 }
James Smartda0436e2009-05-22 14:51:39 -04007371
7372 /* Release mailbox command work queue */
James Smart67d12732012-08-03 12:36:13 -04007373 if (phba->sli4_hba.mbx_wq != NULL) {
7374 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
7375 phba->sli4_hba.mbx_wq = NULL;
7376 }
James Smartda0436e2009-05-22 14:51:39 -04007377
7378 /* Release ELS work queue */
James Smart67d12732012-08-03 12:36:13 -04007379 if (phba->sli4_hba.els_wq != NULL) {
7380 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
7381 phba->sli4_hba.els_wq = NULL;
7382 }
James Smartda0436e2009-05-22 14:51:39 -04007383
7384 /* Release unsolicited receive queue */
James Smart67d12732012-08-03 12:36:13 -04007385 if (phba->sli4_hba.hdr_rq != NULL) {
7386 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
7387 phba->sli4_hba.hdr_rq = NULL;
7388 }
7389 if (phba->sli4_hba.dat_rq != NULL) {
7390 lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
7391 phba->sli4_hba.dat_rq = NULL;
7392 }
James Smartda0436e2009-05-22 14:51:39 -04007393
James Smartda0436e2009-05-22 14:51:39 -04007394 /* Release ELS complete queue */
James Smart67d12732012-08-03 12:36:13 -04007395 if (phba->sli4_hba.els_cq != NULL) {
7396 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
7397 phba->sli4_hba.els_cq = NULL;
7398 }
James Smartda0436e2009-05-22 14:51:39 -04007399
7400 /* Release mailbox command complete queue */
James Smart67d12732012-08-03 12:36:13 -04007401 if (phba->sli4_hba.mbx_cq != NULL) {
7402 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
7403 phba->sli4_hba.mbx_cq = NULL;
7404 }
James Smartda0436e2009-05-22 14:51:39 -04007405
7406 return;
7407}
7408
7409/**
7410 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
7411 * @phba: pointer to lpfc hba data structure.
7412 *
7413 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
7414 * operation.
7415 *
7416 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007417 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007418 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007419 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007420 **/
7421int
7422lpfc_sli4_queue_setup(struct lpfc_hba *phba)
7423{
James Smart2a76a282012-08-03 12:35:54 -04007424 struct lpfc_sli *psli = &phba->sli;
7425 struct lpfc_sli_ring *pring;
James Smartda0436e2009-05-22 14:51:39 -04007426 int rc = -ENOMEM;
7427 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
7428 int fcp_cq_index = 0;
James Smart962bc512013-01-03 15:44:00 -05007429 uint32_t shdr_status, shdr_add_status;
7430 union lpfc_sli4_cfg_shdr *shdr;
7431 LPFC_MBOXQ_t *mboxq;
7432 uint32_t length;
7433
7434 /* Check for dual-ULP support */
7435 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7436 if (!mboxq) {
7437 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7438 "3249 Unable to allocate memory for "
7439 "QUERY_FW_CFG mailbox command\n");
7440 return -ENOMEM;
7441 }
7442 length = (sizeof(struct lpfc_mbx_query_fw_config) -
7443 sizeof(struct lpfc_sli4_cfg_mhdr));
7444 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
7445 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
7446 length, LPFC_SLI4_MBX_EMBED);
7447
7448 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7449
7450 shdr = (union lpfc_sli4_cfg_shdr *)
7451 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
7452 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7453 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7454 if (shdr_status || shdr_add_status || rc) {
7455 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7456 "3250 QUERY_FW_CFG mailbox failed with status "
7457 "x%x add_status x%x, mbx status x%x\n",
7458 shdr_status, shdr_add_status, rc);
7459 if (rc != MBX_TIMEOUT)
7460 mempool_free(mboxq, phba->mbox_mem_pool);
7461 rc = -ENXIO;
7462 goto out_error;
7463 }
7464
7465 phba->sli4_hba.fw_func_mode =
7466 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
7467 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
7468 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
7469 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7470 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
7471 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
7472 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
7473
7474 if (rc != MBX_TIMEOUT)
7475 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04007476
7477 /*
James Smart67d12732012-08-03 12:36:13 -04007478 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04007479 */
7480
James Smart67d12732012-08-03 12:36:13 -04007481 /* Set up HBA event queue */
7482 if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) {
James Smart2e90f4b2011-12-13 13:22:37 -05007483 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7484 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007485 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007486 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05007487 }
James Smart67d12732012-08-03 12:36:13 -04007488 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
7489 if (!phba->sli4_hba.hba_eq[fcp_eqidx]) {
James Smartda0436e2009-05-22 14:51:39 -04007490 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7491 "0522 Fast-path EQ (%d) not "
7492 "allocated\n", fcp_eqidx);
James Smart1b511972011-12-13 13:23:09 -05007493 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007494 goto out_destroy_hba_eq;
James Smartda0436e2009-05-22 14:51:39 -04007495 }
James Smart67d12732012-08-03 12:36:13 -04007496 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx],
James Smartbf8dae82012-08-03 12:36:24 -04007497 (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel));
James Smartda0436e2009-05-22 14:51:39 -04007498 if (rc) {
7499 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7500 "0523 Failed setup of fast-path EQ "
James Smarta2fc4aef2014-09-03 12:57:55 -04007501 "(%d), rc = 0x%x\n", fcp_eqidx,
7502 (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007503 goto out_destroy_hba_eq;
James Smartda0436e2009-05-22 14:51:39 -04007504 }
7505 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007506 "2584 HBA EQ setup: "
James Smartda0436e2009-05-22 14:51:39 -04007507 "queue[%d]-id=%d\n", fcp_eqidx,
James Smart67d12732012-08-03 12:36:13 -04007508 phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007509 }
7510
James Smart67d12732012-08-03 12:36:13 -04007511 /* Set up fast-path FCP Response Complete Queue */
7512 if (!phba->sli4_hba.fcp_cq) {
7513 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7514 "3148 Fast-path FCP CQ array not "
7515 "allocated\n");
7516 rc = -ENOMEM;
7517 goto out_destroy_hba_eq;
7518 }
7519
7520 for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) {
7521 if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
7522 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7523 "0526 Fast-path FCP CQ (%d) not "
7524 "allocated\n", fcp_cqidx);
7525 rc = -ENOMEM;
7526 goto out_destroy_fcp_cq;
7527 }
7528 rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
7529 phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP);
7530 if (rc) {
7531 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7532 "0527 Failed setup of fast-path FCP "
James Smarta2fc4aef2014-09-03 12:57:55 -04007533 "CQ (%d), rc = 0x%x\n", fcp_cqidx,
7534 (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007535 goto out_destroy_fcp_cq;
7536 }
7537
7538 /* Setup fcp_cq_map for fast lookup */
7539 phba->sli4_hba.fcp_cq_map[fcp_cqidx] =
7540 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id;
7541
7542 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7543 "2588 FCP CQ setup: cq[%d]-id=%d, "
7544 "parent seq[%d]-id=%d\n",
7545 fcp_cqidx,
7546 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
7547 fcp_cqidx,
7548 phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id);
7549 }
7550
7551 /* Set up fast-path FCP Work Queue */
7552 if (!phba->sli4_hba.fcp_wq) {
7553 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7554 "3149 Fast-path FCP WQ array not "
7555 "allocated\n");
7556 rc = -ENOMEM;
7557 goto out_destroy_fcp_cq;
7558 }
7559
7560 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) {
7561 if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
7562 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7563 "0534 Fast-path FCP WQ (%d) not "
7564 "allocated\n", fcp_wqidx);
7565 rc = -ENOMEM;
7566 goto out_destroy_fcp_wq;
7567 }
7568 rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
7569 phba->sli4_hba.fcp_cq[fcp_wqidx],
7570 LPFC_FCP);
7571 if (rc) {
7572 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7573 "0535 Failed setup of fast-path FCP "
James Smarta2fc4aef2014-09-03 12:57:55 -04007574 "WQ (%d), rc = 0x%x\n", fcp_wqidx,
7575 (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007576 goto out_destroy_fcp_wq;
7577 }
7578
7579 /* Bind this WQ to the next FCP ring */
7580 pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx];
7581 pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx];
7582 phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring;
7583
7584 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7585 "2591 FCP WQ setup: wq[%d]-id=%d, "
7586 "parent cq[%d]-id=%d\n",
7587 fcp_wqidx,
7588 phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
7589 fcp_cq_index,
7590 phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id);
7591 }
James Smartda0436e2009-05-22 14:51:39 -04007592 /*
7593 * Set up Complete Queues (CQs)
7594 */
7595
7596 /* Set up slow-path MBOX Complete Queue as the first CQ */
7597 if (!phba->sli4_hba.mbx_cq) {
7598 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7599 "0528 Mailbox CQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007600 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007601 goto out_destroy_fcp_wq;
James Smartda0436e2009-05-22 14:51:39 -04007602 }
James Smart67d12732012-08-03 12:36:13 -04007603 rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq,
7604 phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04007605 if (rc) {
7606 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7607 "0529 Failed setup of slow-path mailbox CQ: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007608 "rc = 0x%x\n", (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007609 goto out_destroy_fcp_wq;
James Smartda0436e2009-05-22 14:51:39 -04007610 }
7611 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7612 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
7613 phba->sli4_hba.mbx_cq->queue_id,
James Smart67d12732012-08-03 12:36:13 -04007614 phba->sli4_hba.hba_eq[0]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007615
7616 /* Set up slow-path ELS Complete Queue */
7617 if (!phba->sli4_hba.els_cq) {
7618 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7619 "0530 ELS CQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007620 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007621 goto out_destroy_mbx_cq;
7622 }
James Smart67d12732012-08-03 12:36:13 -04007623 rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq,
7624 phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04007625 if (rc) {
7626 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7627 "0531 Failed setup of slow-path ELS CQ: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007628 "rc = 0x%x\n", (uint32_t)rc);
James Smartda0436e2009-05-22 14:51:39 -04007629 goto out_destroy_mbx_cq;
7630 }
7631 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7632 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
7633 phba->sli4_hba.els_cq->queue_id,
James Smart67d12732012-08-03 12:36:13 -04007634 phba->sli4_hba.hba_eq[0]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007635
7636 /*
7637 * Set up all the Work Queues (WQs)
7638 */
7639
7640 /* Set up Mailbox Command Queue */
7641 if (!phba->sli4_hba.mbx_wq) {
7642 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7643 "0538 Slow-path MQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007644 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007645 goto out_destroy_els_cq;
James Smartda0436e2009-05-22 14:51:39 -04007646 }
7647 rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
7648 phba->sli4_hba.mbx_cq, LPFC_MBOX);
7649 if (rc) {
7650 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7651 "0539 Failed setup of slow-path MQ: "
7652 "rc = 0x%x\n", rc);
James Smart67d12732012-08-03 12:36:13 -04007653 goto out_destroy_els_cq;
James Smartda0436e2009-05-22 14:51:39 -04007654 }
7655 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7656 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
7657 phba->sli4_hba.mbx_wq->queue_id,
7658 phba->sli4_hba.mbx_cq->queue_id);
7659
7660 /* Set up slow-path ELS Work Queue */
7661 if (!phba->sli4_hba.els_wq) {
7662 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7663 "0536 Slow-path ELS WQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007664 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007665 goto out_destroy_mbx_wq;
7666 }
7667 rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
7668 phba->sli4_hba.els_cq, LPFC_ELS);
7669 if (rc) {
7670 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7671 "0537 Failed setup of slow-path ELS WQ: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007672 "rc = 0x%x\n", (uint32_t)rc);
James Smartda0436e2009-05-22 14:51:39 -04007673 goto out_destroy_mbx_wq;
7674 }
James Smart2a76a282012-08-03 12:35:54 -04007675
7676 /* Bind this WQ to the ELS ring */
7677 pring = &psli->ring[LPFC_ELS_RING];
7678 pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq;
7679 phba->sli4_hba.els_cq->pring = pring;
7680
James Smartda0436e2009-05-22 14:51:39 -04007681 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7682 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
7683 phba->sli4_hba.els_wq->queue_id,
7684 phba->sli4_hba.els_cq->queue_id);
7685
James Smartda0436e2009-05-22 14:51:39 -04007686 /*
7687 * Create Receive Queue (RQ)
7688 */
7689 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
7690 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7691 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007692 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007693 goto out_destroy_els_wq;
James Smartda0436e2009-05-22 14:51:39 -04007694 }
James Smart73d91e52011-10-10 21:32:10 -04007695
7696 lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
7697 lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
7698
James Smartda0436e2009-05-22 14:51:39 -04007699 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04007700 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04007701 if (rc) {
7702 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7703 "0541 Failed setup of Receive Queue: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007704 "rc = 0x%x\n", (uint32_t)rc);
James Smartda0436e2009-05-22 14:51:39 -04007705 goto out_destroy_fcp_wq;
7706 }
James Smart73d91e52011-10-10 21:32:10 -04007707
James Smartda0436e2009-05-22 14:51:39 -04007708 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7709 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
7710 "parent cq-id=%d\n",
7711 phba->sli4_hba.hdr_rq->queue_id,
7712 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04007713 phba->sli4_hba.els_cq->queue_id);
James Smart1ba981f2014-02-20 09:56:45 -05007714
7715 if (phba->cfg_fof) {
7716 rc = lpfc_fof_queue_setup(phba);
7717 if (rc) {
7718 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7719 "0549 Failed setup of FOF Queues: "
7720 "rc = 0x%x\n", rc);
7721 goto out_destroy_els_rq;
7722 }
7723 }
James Smart2c9c5a02015-04-07 15:07:15 -04007724
7725 /*
7726 * Configure EQ delay multipier for interrupt coalescing using
7727 * MODIFY_EQ_DELAY for all EQs created, LPFC_MAX_EQ_DELAY at a time.
7728 */
7729 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel;
7730 fcp_eqidx += LPFC_MAX_EQ_DELAY)
7731 lpfc_modify_fcp_eq_delay(phba, fcp_eqidx);
James Smartda0436e2009-05-22 14:51:39 -04007732 return 0;
7733
James Smart1ba981f2014-02-20 09:56:45 -05007734out_destroy_els_rq:
7735 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
James Smart2e90f4b2011-12-13 13:22:37 -05007736out_destroy_els_wq:
James Smartda0436e2009-05-22 14:51:39 -04007737 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7738out_destroy_mbx_wq:
7739 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
James Smart2e90f4b2011-12-13 13:22:37 -05007740out_destroy_els_cq:
James Smartda0436e2009-05-22 14:51:39 -04007741 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
7742out_destroy_mbx_cq:
7743 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
James Smart67d12732012-08-03 12:36:13 -04007744out_destroy_fcp_wq:
7745 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
7746 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
7747out_destroy_fcp_cq:
7748 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
7749 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
7750out_destroy_hba_eq:
James Smartda0436e2009-05-22 14:51:39 -04007751 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
James Smart67d12732012-08-03 12:36:13 -04007752 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]);
James Smartda0436e2009-05-22 14:51:39 -04007753out_error:
7754 return rc;
7755}
7756
7757/**
7758 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
7759 * @phba: pointer to lpfc hba data structure.
7760 *
7761 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
7762 * operation.
7763 *
7764 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007765 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007766 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007767 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007768 **/
7769void
7770lpfc_sli4_queue_unset(struct lpfc_hba *phba)
7771{
7772 int fcp_qidx;
7773
James Smart1ba981f2014-02-20 09:56:45 -05007774 /* Unset the queues created for Flash Optimized Fabric operations */
7775 if (phba->cfg_fof)
7776 lpfc_fof_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04007777 /* Unset mailbox command work queue */
7778 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
7779 /* Unset ELS work queue */
7780 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7781 /* Unset unsolicited receive queue */
7782 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
7783 /* Unset FCP work queue */
James Smart67d12732012-08-03 12:36:13 -04007784 if (phba->sli4_hba.fcp_wq) {
7785 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
7786 fcp_qidx++)
7787 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
7788 }
James Smartda0436e2009-05-22 14:51:39 -04007789 /* Unset mailbox command complete queue */
7790 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
7791 /* Unset ELS complete queue */
7792 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
James Smartda0436e2009-05-22 14:51:39 -04007793 /* Unset FCP response complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05007794 if (phba->sli4_hba.fcp_cq) {
James Smart67d12732012-08-03 12:36:13 -04007795 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
7796 fcp_qidx++)
James Smart2e90f4b2011-12-13 13:22:37 -05007797 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
James Smart2e90f4b2011-12-13 13:22:37 -05007798 }
James Smartda0436e2009-05-22 14:51:39 -04007799 /* Unset fast-path event queue */
James Smart67d12732012-08-03 12:36:13 -04007800 if (phba->sli4_hba.hba_eq) {
7801 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
James Smart2e90f4b2011-12-13 13:22:37 -05007802 fcp_qidx++)
James Smart67d12732012-08-03 12:36:13 -04007803 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_qidx]);
James Smart2e90f4b2011-12-13 13:22:37 -05007804 }
James Smartda0436e2009-05-22 14:51:39 -04007805}
7806
7807/**
7808 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
7809 * @phba: pointer to lpfc hba data structure.
7810 *
7811 * This routine is invoked to allocate and set up a pool of completion queue
7812 * events. The body of the completion queue event is a completion queue entry
7813 * CQE. For now, this pool is used for the interrupt service routine to queue
7814 * the following HBA completion queue events for the worker thread to process:
7815 * - Mailbox asynchronous events
7816 * - Receive queue completion unsolicited events
7817 * Later, this can be used for all the slow-path events.
7818 *
7819 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007820 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007821 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007822 **/
7823static int
7824lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
7825{
7826 struct lpfc_cq_event *cq_event;
7827 int i;
7828
7829 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
7830 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
7831 if (!cq_event)
7832 goto out_pool_create_fail;
7833 list_add_tail(&cq_event->list,
7834 &phba->sli4_hba.sp_cqe_event_pool);
7835 }
7836 return 0;
7837
7838out_pool_create_fail:
7839 lpfc_sli4_cq_event_pool_destroy(phba);
7840 return -ENOMEM;
7841}
7842
7843/**
7844 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
7845 * @phba: pointer to lpfc hba data structure.
7846 *
7847 * This routine is invoked to free the pool of completion queue events at
7848 * driver unload time. Note that, it is the responsibility of the driver
7849 * cleanup routine to free all the outstanding completion-queue events
7850 * allocated from this pool back into the pool before invoking this routine
7851 * to destroy the pool.
7852 **/
7853static void
7854lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
7855{
7856 struct lpfc_cq_event *cq_event, *next_cq_event;
7857
7858 list_for_each_entry_safe(cq_event, next_cq_event,
7859 &phba->sli4_hba.sp_cqe_event_pool, list) {
7860 list_del(&cq_event->list);
7861 kfree(cq_event);
7862 }
7863}
7864
7865/**
7866 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7867 * @phba: pointer to lpfc hba data structure.
7868 *
7869 * This routine is the lock free version of the API invoked to allocate a
7870 * completion-queue event from the free pool.
7871 *
7872 * Return: Pointer to the newly allocated completion-queue event if successful
7873 * NULL otherwise.
7874 **/
7875struct lpfc_cq_event *
7876__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
7877{
7878 struct lpfc_cq_event *cq_event = NULL;
7879
7880 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
7881 struct lpfc_cq_event, list);
7882 return cq_event;
7883}
7884
7885/**
7886 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7887 * @phba: pointer to lpfc hba data structure.
7888 *
7889 * This routine is the lock version of the API invoked to allocate a
7890 * completion-queue event from the free pool.
7891 *
7892 * Return: Pointer to the newly allocated completion-queue event if successful
7893 * NULL otherwise.
7894 **/
7895struct lpfc_cq_event *
7896lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
7897{
7898 struct lpfc_cq_event *cq_event;
7899 unsigned long iflags;
7900
7901 spin_lock_irqsave(&phba->hbalock, iflags);
7902 cq_event = __lpfc_sli4_cq_event_alloc(phba);
7903 spin_unlock_irqrestore(&phba->hbalock, iflags);
7904 return cq_event;
7905}
7906
7907/**
7908 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7909 * @phba: pointer to lpfc hba data structure.
7910 * @cq_event: pointer to the completion queue event to be freed.
7911 *
7912 * This routine is the lock free version of the API invoked to release a
7913 * completion-queue event back into the free pool.
7914 **/
7915void
7916__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
7917 struct lpfc_cq_event *cq_event)
7918{
7919 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
7920}
7921
7922/**
7923 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7924 * @phba: pointer to lpfc hba data structure.
7925 * @cq_event: pointer to the completion queue event to be freed.
7926 *
7927 * This routine is the lock version of the API invoked to release a
7928 * completion-queue event back into the free pool.
7929 **/
7930void
7931lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
7932 struct lpfc_cq_event *cq_event)
7933{
7934 unsigned long iflags;
7935 spin_lock_irqsave(&phba->hbalock, iflags);
7936 __lpfc_sli4_cq_event_release(phba, cq_event);
7937 spin_unlock_irqrestore(&phba->hbalock, iflags);
7938}
7939
7940/**
7941 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
7942 * @phba: pointer to lpfc hba data structure.
7943 *
7944 * This routine is to free all the pending completion-queue events to the
7945 * back into the free pool for device reset.
7946 **/
7947static void
7948lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
7949{
7950 LIST_HEAD(cqelist);
7951 struct lpfc_cq_event *cqe;
7952 unsigned long iflags;
7953
7954 /* Retrieve all the pending WCQEs from pending WCQE lists */
7955 spin_lock_irqsave(&phba->hbalock, iflags);
7956 /* Pending FCP XRI abort events */
7957 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
7958 &cqelist);
7959 /* Pending ELS XRI abort events */
7960 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
7961 &cqelist);
7962 /* Pending asynnc events */
7963 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
7964 &cqelist);
7965 spin_unlock_irqrestore(&phba->hbalock, iflags);
7966
7967 while (!list_empty(&cqelist)) {
7968 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
7969 lpfc_sli4_cq_event_release(phba, cqe);
7970 }
7971}
7972
7973/**
7974 * lpfc_pci_function_reset - Reset pci function.
7975 * @phba: pointer to lpfc hba data structure.
7976 *
7977 * This routine is invoked to request a PCI function reset. It will destroys
7978 * all resources assigned to the PCI function which originates this request.
7979 *
7980 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007981 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007982 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007983 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007984 **/
7985int
7986lpfc_pci_function_reset(struct lpfc_hba *phba)
7987{
7988 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05007989 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04007990 uint32_t shdr_status, shdr_add_status;
James Smart2f6fa2c2014-09-03 12:57:08 -04007991 uint32_t rdy_chk;
7992 uint32_t port_reset = 0;
James Smartda0436e2009-05-22 14:51:39 -04007993 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05007994 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -05007995 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -04007996
James Smart2fcee4b2010-12-15 17:57:46 -05007997 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7998 switch (if_type) {
7999 case LPFC_SLI_INTF_IF_TYPE_0:
8000 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8001 GFP_KERNEL);
8002 if (!mboxq) {
8003 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8004 "0494 Unable to allocate memory for "
8005 "issuing SLI_FUNCTION_RESET mailbox "
8006 "command\n");
8007 return -ENOMEM;
8008 }
8009
8010 /* Setup PCI function reset mailbox-ioctl command */
8011 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8012 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
8013 LPFC_SLI4_MBX_EMBED);
8014 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8015 shdr = (union lpfc_sli4_cfg_shdr *)
8016 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
8017 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8018 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
8019 &shdr->response);
8020 if (rc != MBX_TIMEOUT)
8021 mempool_free(mboxq, phba->mbox_mem_pool);
8022 if (shdr_status || shdr_add_status || rc) {
8023 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8024 "0495 SLI_FUNCTION_RESET mailbox "
8025 "failed with status x%x add_status x%x,"
8026 " mbx status x%x\n",
8027 shdr_status, shdr_add_status, rc);
8028 rc = -ENXIO;
8029 }
8030 break;
8031 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2f6fa2c2014-09-03 12:57:08 -04008032wait:
8033 /*
8034 * Poll the Port Status Register and wait for RDY for
8035 * up to 30 seconds. If the port doesn't respond, treat
8036 * it as an error.
8037 */
James Smart77d093f2015-04-07 15:07:08 -04008038 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
James Smart2f6fa2c2014-09-03 12:57:08 -04008039 if (lpfc_readl(phba->sli4_hba.u.if_type2.
8040 STATUSregaddr, &reg_data.word0)) {
8041 rc = -ENODEV;
8042 goto out;
8043 }
8044 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
8045 break;
8046 msleep(20);
8047 }
8048
8049 if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
8050 phba->work_status[0] = readl(
8051 phba->sli4_hba.u.if_type2.ERR1regaddr);
8052 phba->work_status[1] = readl(
8053 phba->sli4_hba.u.if_type2.ERR2regaddr);
8054 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8055 "2890 Port not ready, port status reg "
8056 "0x%x error 1=0x%x, error 2=0x%x\n",
8057 reg_data.word0,
8058 phba->work_status[0],
8059 phba->work_status[1]);
8060 rc = -ENODEV;
8061 goto out;
8062 }
8063
8064 if (!port_reset) {
8065 /*
8066 * Reset the port now
8067 */
James Smart2fcee4b2010-12-15 17:57:46 -05008068 reg_data.word0 = 0;
8069 bf_set(lpfc_sliport_ctrl_end, &reg_data,
8070 LPFC_SLIPORT_LITTLE_ENDIAN);
8071 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
8072 LPFC_SLIPORT_INIT_PORT);
8073 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
8074 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -05008075 /* flush */
James Smart2b81f942012-03-01 22:37:18 -05008076 pci_read_config_word(phba->pcidev,
8077 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -05008078
James Smart2f6fa2c2014-09-03 12:57:08 -04008079 port_reset = 1;
8080 msleep(20);
8081 goto wait;
8082 } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
8083 rc = -ENODEV;
8084 goto out;
James Smart2fcee4b2010-12-15 17:57:46 -05008085 }
8086 break;
James Smart2f6fa2c2014-09-03 12:57:08 -04008087
James Smart2fcee4b2010-12-15 17:57:46 -05008088 case LPFC_SLI_INTF_IF_TYPE_1:
8089 default:
8090 break;
James Smartda0436e2009-05-22 14:51:39 -04008091 }
8092
James Smart73d91e52011-10-10 21:32:10 -04008093out:
James Smart2fcee4b2010-12-15 17:57:46 -05008094 /* Catch the not-ready port failure after a port reset. */
James Smart2f6fa2c2014-09-03 12:57:08 -04008095 if (rc) {
James Smart229adb02013-04-17 20:16:51 -04008096 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8097 "3317 HBA not functional: IP Reset Failed "
James Smart2f6fa2c2014-09-03 12:57:08 -04008098 "try: echo fw_reset > board_mode\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008099 rc = -ENODEV;
James Smart229adb02013-04-17 20:16:51 -04008100 }
James Smart2fcee4b2010-12-15 17:57:46 -05008101
James Smartda0436e2009-05-22 14:51:39 -04008102 return rc;
8103}
8104
8105/**
James Smartda0436e2009-05-22 14:51:39 -04008106 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
8107 * @phba: pointer to lpfc hba data structure.
8108 *
8109 * This routine is invoked to set up the PCI device memory space for device
8110 * with SLI-4 interface spec.
8111 *
8112 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008113 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008114 * other values - error
8115 **/
8116static int
8117lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
8118{
8119 struct pci_dev *pdev;
8120 unsigned long bar0map_len, bar1map_len, bar2map_len;
8121 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05008122 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04008123
8124 /* Obtain PCI device reference */
8125 if (!phba->pcidev)
8126 return error;
8127 else
8128 pdev = phba->pcidev;
8129
8130 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05008131 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
8132 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
8133 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
8134 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smartda0436e2009-05-22 14:51:39 -04008135 return error;
Michael Reed8e685972009-09-18 12:02:05 -05008136 }
8137 }
James Smartda0436e2009-05-22 14:51:39 -04008138
James Smart2fcee4b2010-12-15 17:57:46 -05008139 /*
8140 * The BARs and register set definitions and offset locations are
8141 * dependent on the if_type.
8142 */
8143 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
8144 &phba->sli4_hba.sli_intf.word0)) {
8145 return error;
8146 }
8147
8148 /* There is no SLI3 failback for SLI4 devices. */
8149 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
8150 LPFC_SLI_INTF_VALID) {
8151 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8152 "2894 SLI_INTF reg contents invalid "
8153 "sli_intf reg 0x%x\n",
8154 phba->sli4_hba.sli_intf.word0);
8155 return error;
8156 }
8157
8158 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8159 /*
8160 * Get the bus address of SLI4 device Bar regions and the
8161 * number of bytes required by each mapping. The mapping of the
8162 * particular PCI BARs regions is dependent on the type of
8163 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04008164 */
James Smartf5ca6f22013-09-06 12:21:09 -04008165 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
8166 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
8167 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
James Smart2fcee4b2010-12-15 17:57:46 -05008168
8169 /*
8170 * Map SLI4 PCI Config Space Register base to a kernel virtual
8171 * addr
8172 */
8173 phba->sli4_hba.conf_regs_memmap_p =
8174 ioremap(phba->pci_bar0_map, bar0map_len);
8175 if (!phba->sli4_hba.conf_regs_memmap_p) {
8176 dev_printk(KERN_ERR, &pdev->dev,
8177 "ioremap failed for SLI4 PCI config "
8178 "registers.\n");
8179 goto out;
8180 }
James Smartf5ca6f22013-09-06 12:21:09 -04008181 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008182 /* Set up BAR0 PCI config space register memory map */
8183 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05008184 } else {
8185 phba->pci_bar0_map = pci_resource_start(pdev, 1);
8186 bar0map_len = pci_resource_len(pdev, 1);
James Smart2fcee4b2010-12-15 17:57:46 -05008187 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
8188 dev_printk(KERN_ERR, &pdev->dev,
8189 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
8190 goto out;
8191 }
8192 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008193 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008194 if (!phba->sli4_hba.conf_regs_memmap_p) {
8195 dev_printk(KERN_ERR, &pdev->dev,
8196 "ioremap failed for SLI4 PCI config "
8197 "registers.\n");
8198 goto out;
8199 }
8200 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04008201 }
8202
James Smartc31098c2011-04-16 11:03:33 -04008203 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04008204 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
James Smart2fcee4b2010-12-15 17:57:46 -05008205 /*
8206 * Map SLI4 if type 0 HBA Control Register base to a kernel
8207 * virtual address and setup the registers.
8208 */
James Smartf5ca6f22013-09-06 12:21:09 -04008209 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
8210 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
James Smart2fcee4b2010-12-15 17:57:46 -05008211 phba->sli4_hba.ctrl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008212 ioremap(phba->pci_bar1_map, bar1map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008213 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
8214 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04008215 "ioremap failed for SLI4 HBA control registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008216 goto out_iounmap_conf;
8217 }
James Smartf5ca6f22013-09-06 12:21:09 -04008218 phba->pci_bar2_memmap_p = phba->sli4_hba.ctrl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008219 lpfc_sli4_bar1_register_memmap(phba);
James Smartda0436e2009-05-22 14:51:39 -04008220 }
8221
James Smartc31098c2011-04-16 11:03:33 -04008222 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04008223 (pci_resource_start(pdev, PCI_64BIT_BAR4))) {
James Smart2fcee4b2010-12-15 17:57:46 -05008224 /*
8225 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
8226 * virtual address and setup the registers.
8227 */
James Smartf5ca6f22013-09-06 12:21:09 -04008228 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
8229 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
James Smart2fcee4b2010-12-15 17:57:46 -05008230 phba->sli4_hba.drbl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008231 ioremap(phba->pci_bar2_map, bar2map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008232 if (!phba->sli4_hba.drbl_regs_memmap_p) {
8233 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04008234 "ioremap failed for SLI4 HBA doorbell registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008235 goto out_iounmap_ctrl;
8236 }
James Smartf5ca6f22013-09-06 12:21:09 -04008237 phba->pci_bar4_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008238 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
8239 if (error)
8240 goto out_iounmap_all;
James Smartda0436e2009-05-22 14:51:39 -04008241 }
8242
James Smartda0436e2009-05-22 14:51:39 -04008243 return 0;
8244
8245out_iounmap_all:
8246 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
8247out_iounmap_ctrl:
8248 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
8249out_iounmap_conf:
8250 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8251out:
8252 return error;
8253}
8254
8255/**
8256 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
8257 * @phba: pointer to lpfc hba data structure.
8258 *
8259 * This routine is invoked to unset the PCI device memory space for device
8260 * with SLI-4 interface spec.
8261 **/
8262static void
8263lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
8264{
James Smart2e90f4b2011-12-13 13:22:37 -05008265 uint32_t if_type;
8266 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -04008267
James Smart2e90f4b2011-12-13 13:22:37 -05008268 switch (if_type) {
8269 case LPFC_SLI_INTF_IF_TYPE_0:
8270 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
8271 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
8272 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8273 break;
8274 case LPFC_SLI_INTF_IF_TYPE_2:
8275 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8276 break;
8277 case LPFC_SLI_INTF_IF_TYPE_1:
8278 default:
8279 dev_printk(KERN_ERR, &phba->pcidev->dev,
8280 "FATAL - unsupported SLI4 interface type - %d\n",
8281 if_type);
8282 break;
8283 }
James Smartda0436e2009-05-22 14:51:39 -04008284}
8285
8286/**
James Smart3772a992009-05-22 14:50:54 -04008287 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
8288 * @phba: pointer to lpfc hba data structure.
8289 *
8290 * This routine is invoked to enable the MSI-X interrupt vectors to device
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008291 * with SLI-3 interface specs. The kernel function pci_enable_msix_exact()
8292 * is called to enable the MSI-X vectors. Note that pci_enable_msix_exact(),
8293 * once invoked, enables either all or nothing, depending on the current
James Smart3772a992009-05-22 14:50:54 -04008294 * availability of PCI vector resources. The device driver is responsible
8295 * for calling the individual request_irq() to register each MSI-X vector
8296 * with a interrupt handler, which is done in this function. Note that
8297 * later when device is unloading, the driver should always call free_irq()
8298 * on all MSI-X vectors it has done request_irq() on before calling
8299 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
8300 * will be left with MSI-X enabled and leaks its vectors.
8301 *
8302 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008303 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008304 * other values - error
8305 **/
8306static int
8307lpfc_sli_enable_msix(struct lpfc_hba *phba)
8308{
8309 int rc, i;
8310 LPFC_MBOXQ_t *pmb;
8311
8312 /* Set up MSI-X multi-message vectors */
8313 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8314 phba->msix_entries[i].entry = i;
8315
8316 /* Configure MSI-X capability structure */
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008317 rc = pci_enable_msix_exact(phba->pcidev, phba->msix_entries,
8318 LPFC_MSIX_VECTORS);
James Smart3772a992009-05-22 14:50:54 -04008319 if (rc) {
8320 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8321 "0420 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02008322 goto vec_fail_out;
James Smart3772a992009-05-22 14:50:54 -04008323 }
8324 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8325 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8326 "0477 MSI-X entry[%d]: vector=x%x "
8327 "message=%d\n", i,
8328 phba->msix_entries[i].vector,
8329 phba->msix_entries[i].entry);
8330 /*
8331 * Assign MSI-X vectors to interrupt handlers
8332 */
8333
8334 /* vector-0 is associated to slow-path handler */
8335 rc = request_irq(phba->msix_entries[0].vector,
8336 &lpfc_sli_sp_intr_handler, IRQF_SHARED,
8337 LPFC_SP_DRIVER_HANDLER_NAME, phba);
8338 if (rc) {
8339 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8340 "0421 MSI-X slow-path request_irq failed "
8341 "(%d)\n", rc);
8342 goto msi_fail_out;
8343 }
8344
8345 /* vector-1 is associated to fast-path handler */
8346 rc = request_irq(phba->msix_entries[1].vector,
8347 &lpfc_sli_fp_intr_handler, IRQF_SHARED,
8348 LPFC_FP_DRIVER_HANDLER_NAME, phba);
8349
8350 if (rc) {
8351 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8352 "0429 MSI-X fast-path request_irq failed "
8353 "(%d)\n", rc);
8354 goto irq_fail_out;
8355 }
8356
8357 /*
8358 * Configure HBA MSI-X attention conditions to messages
8359 */
8360 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8361
8362 if (!pmb) {
8363 rc = -ENOMEM;
8364 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8365 "0474 Unable to allocate memory for issuing "
8366 "MBOX_CONFIG_MSI command\n");
8367 goto mem_fail_out;
8368 }
8369 rc = lpfc_config_msi(phba, pmb);
8370 if (rc)
8371 goto mbx_fail_out;
8372 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
8373 if (rc != MBX_SUCCESS) {
8374 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
8375 "0351 Config MSI mailbox command failed, "
8376 "mbxCmd x%x, mbxStatus x%x\n",
8377 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
8378 goto mbx_fail_out;
8379 }
8380
8381 /* Free memory allocated for mailbox command */
8382 mempool_free(pmb, phba->mbox_mem_pool);
8383 return rc;
8384
8385mbx_fail_out:
8386 /* Free memory allocated for mailbox command */
8387 mempool_free(pmb, phba->mbox_mem_pool);
8388
8389mem_fail_out:
8390 /* free the irq already requested */
8391 free_irq(phba->msix_entries[1].vector, phba);
8392
8393irq_fail_out:
8394 /* free the irq already requested */
8395 free_irq(phba->msix_entries[0].vector, phba);
8396
8397msi_fail_out:
8398 /* Unconfigure MSI-X capability structure */
8399 pci_disable_msix(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02008400
8401vec_fail_out:
James Smart3772a992009-05-22 14:50:54 -04008402 return rc;
8403}
8404
8405/**
8406 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
8407 * @phba: pointer to lpfc hba data structure.
8408 *
8409 * This routine is invoked to release the MSI-X vectors and then disable the
8410 * MSI-X interrupt mode to device with SLI-3 interface spec.
8411 **/
8412static void
8413lpfc_sli_disable_msix(struct lpfc_hba *phba)
8414{
8415 int i;
8416
8417 /* Free up MSI-X multi-message vectors */
8418 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8419 free_irq(phba->msix_entries[i].vector, phba);
8420 /* Disable MSI-X */
8421 pci_disable_msix(phba->pcidev);
8422
8423 return;
8424}
8425
8426/**
8427 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
8428 * @phba: pointer to lpfc hba data structure.
8429 *
8430 * This routine is invoked to enable the MSI interrupt mode to device with
8431 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
8432 * enable the MSI vector. The device driver is responsible for calling the
8433 * request_irq() to register MSI vector with a interrupt the handler, which
8434 * is done in this function.
8435 *
8436 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008437 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008438 * other values - error
8439 */
8440static int
8441lpfc_sli_enable_msi(struct lpfc_hba *phba)
8442{
8443 int rc;
8444
8445 rc = pci_enable_msi(phba->pcidev);
8446 if (!rc)
8447 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8448 "0462 PCI enable MSI mode success.\n");
8449 else {
8450 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8451 "0471 PCI enable MSI mode failed (%d)\n", rc);
8452 return rc;
8453 }
8454
8455 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
8456 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8457 if (rc) {
8458 pci_disable_msi(phba->pcidev);
8459 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8460 "0478 MSI request_irq failed (%d)\n", rc);
8461 }
8462 return rc;
8463}
8464
8465/**
8466 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
8467 * @phba: pointer to lpfc hba data structure.
8468 *
8469 * This routine is invoked to disable the MSI interrupt mode to device with
8470 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
8471 * done request_irq() on before calling pci_disable_msi(). Failure to do so
8472 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
8473 * its vector.
8474 */
8475static void
8476lpfc_sli_disable_msi(struct lpfc_hba *phba)
8477{
8478 free_irq(phba->pcidev->irq, phba);
8479 pci_disable_msi(phba->pcidev);
8480 return;
8481}
8482
8483/**
8484 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
8485 * @phba: pointer to lpfc hba data structure.
8486 *
8487 * This routine is invoked to enable device interrupt and associate driver's
8488 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
8489 * spec. Depends on the interrupt mode configured to the driver, the driver
8490 * will try to fallback from the configured interrupt mode to an interrupt
8491 * mode which is supported by the platform, kernel, and device in the order
8492 * of:
8493 * MSI-X -> MSI -> IRQ.
8494 *
8495 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008496 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008497 * other values - error
8498 **/
8499static uint32_t
8500lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
8501{
8502 uint32_t intr_mode = LPFC_INTR_ERROR;
8503 int retval;
8504
8505 if (cfg_mode == 2) {
8506 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
8507 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
8508 if (!retval) {
8509 /* Now, try to enable MSI-X interrupt mode */
8510 retval = lpfc_sli_enable_msix(phba);
8511 if (!retval) {
8512 /* Indicate initialization to MSI-X mode */
8513 phba->intr_type = MSIX;
8514 intr_mode = 2;
8515 }
8516 }
8517 }
8518
8519 /* Fallback to MSI if MSI-X initialization failed */
8520 if (cfg_mode >= 1 && phba->intr_type == NONE) {
8521 retval = lpfc_sli_enable_msi(phba);
8522 if (!retval) {
8523 /* Indicate initialization to MSI mode */
8524 phba->intr_type = MSI;
8525 intr_mode = 1;
8526 }
8527 }
8528
8529 /* Fallback to INTx if both MSI-X/MSI initalization failed */
8530 if (phba->intr_type == NONE) {
8531 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
8532 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8533 if (!retval) {
8534 /* Indicate initialization to INTx mode */
8535 phba->intr_type = INTx;
8536 intr_mode = 0;
8537 }
8538 }
8539 return intr_mode;
8540}
8541
8542/**
8543 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
8544 * @phba: pointer to lpfc hba data structure.
8545 *
8546 * This routine is invoked to disable device interrupt and disassociate the
8547 * driver's interrupt handler(s) from interrupt vector(s) to device with
8548 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
8549 * release the interrupt vector(s) for the message signaled interrupt.
8550 **/
8551static void
8552lpfc_sli_disable_intr(struct lpfc_hba *phba)
8553{
8554 /* Disable the currently initialized interrupt mode */
8555 if (phba->intr_type == MSIX)
8556 lpfc_sli_disable_msix(phba);
8557 else if (phba->intr_type == MSI)
8558 lpfc_sli_disable_msi(phba);
8559 else if (phba->intr_type == INTx)
8560 free_irq(phba->pcidev->irq, phba);
8561
8562 /* Reset interrupt management states */
8563 phba->intr_type = NONE;
8564 phba->sli.slistat.sli_intr = 0;
8565
8566 return;
8567}
8568
8569/**
James Smart7bb03bb2013-04-17 20:19:16 -04008570 * lpfc_find_next_cpu - Find next available CPU that matches the phys_id
8571 * @phba: pointer to lpfc hba data structure.
8572 *
8573 * Find next available CPU to use for IRQ to CPU affinity.
8574 */
8575static int
8576lpfc_find_next_cpu(struct lpfc_hba *phba, uint32_t phys_id)
8577{
8578 struct lpfc_vector_map_info *cpup;
8579 int cpu;
8580
8581 cpup = phba->sli4_hba.cpu_map;
8582 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8583 /* CPU must be online */
8584 if (cpu_online(cpu)) {
8585 if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
8586 (lpfc_used_cpu[cpu] == LPFC_VECTOR_MAP_EMPTY) &&
8587 (cpup->phys_id == phys_id)) {
8588 return cpu;
8589 }
8590 }
8591 cpup++;
8592 }
8593
8594 /*
8595 * If we get here, we have used ALL CPUs for the specific
8596 * phys_id. Now we need to clear out lpfc_used_cpu and start
8597 * reusing CPUs.
8598 */
8599
8600 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8601 if (lpfc_used_cpu[cpu] == phys_id)
8602 lpfc_used_cpu[cpu] = LPFC_VECTOR_MAP_EMPTY;
8603 }
8604
8605 cpup = phba->sli4_hba.cpu_map;
8606 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8607 /* CPU must be online */
8608 if (cpu_online(cpu)) {
8609 if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
8610 (cpup->phys_id == phys_id)) {
8611 return cpu;
8612 }
8613 }
8614 cpup++;
8615 }
8616 return LPFC_VECTOR_MAP_EMPTY;
8617}
8618
8619/**
8620 * lpfc_sli4_set_affinity - Set affinity for HBA IRQ vectors
8621 * @phba: pointer to lpfc hba data structure.
8622 * @vectors: number of HBA vectors
8623 *
8624 * Affinitize MSIX IRQ vectors to CPUs. Try to equally spread vector
8625 * affinization across multple physical CPUs (numa nodes).
8626 * In addition, this routine will assign an IO channel for each CPU
8627 * to use when issuing I/Os.
8628 */
8629static int
8630lpfc_sli4_set_affinity(struct lpfc_hba *phba, int vectors)
8631{
8632 int i, idx, saved_chann, used_chann, cpu, phys_id;
James Smartec2087a2013-09-06 12:20:36 -04008633 int max_phys_id, min_phys_id;
8634 int num_io_channel, first_cpu, chan;
James Smart7bb03bb2013-04-17 20:19:16 -04008635 struct lpfc_vector_map_info *cpup;
8636#ifdef CONFIG_X86
8637 struct cpuinfo_x86 *cpuinfo;
8638#endif
8639 struct cpumask *mask;
8640 uint8_t chann[LPFC_FCP_IO_CHAN_MAX+1];
8641
8642 /* If there is no mapping, just return */
8643 if (!phba->cfg_fcp_cpu_map)
8644 return 1;
8645
8646 /* Init cpu_map array */
8647 memset(phba->sli4_hba.cpu_map, 0xff,
8648 (sizeof(struct lpfc_vector_map_info) *
8649 phba->sli4_hba.num_present_cpu));
8650
8651 max_phys_id = 0;
James Smartec2087a2013-09-06 12:20:36 -04008652 min_phys_id = 0xff;
James Smart7bb03bb2013-04-17 20:19:16 -04008653 phys_id = 0;
8654 num_io_channel = 0;
8655 first_cpu = LPFC_VECTOR_MAP_EMPTY;
8656
8657 /* Update CPU map with physical id and core id of each CPU */
8658 cpup = phba->sli4_hba.cpu_map;
8659 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8660#ifdef CONFIG_X86
8661 cpuinfo = &cpu_data(cpu);
8662 cpup->phys_id = cpuinfo->phys_proc_id;
8663 cpup->core_id = cpuinfo->cpu_core_id;
8664#else
8665 /* No distinction between CPUs for other platforms */
8666 cpup->phys_id = 0;
8667 cpup->core_id = 0;
8668#endif
8669
8670 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8671 "3328 CPU physid %d coreid %d\n",
8672 cpup->phys_id, cpup->core_id);
8673
8674 if (cpup->phys_id > max_phys_id)
8675 max_phys_id = cpup->phys_id;
James Smartec2087a2013-09-06 12:20:36 -04008676 if (cpup->phys_id < min_phys_id)
8677 min_phys_id = cpup->phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008678 cpup++;
8679 }
8680
James Smartec2087a2013-09-06 12:20:36 -04008681 phys_id = min_phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008682 /* Now associate the HBA vectors with specific CPUs */
8683 for (idx = 0; idx < vectors; idx++) {
8684 cpup = phba->sli4_hba.cpu_map;
8685 cpu = lpfc_find_next_cpu(phba, phys_id);
8686 if (cpu == LPFC_VECTOR_MAP_EMPTY) {
8687
8688 /* Try for all phys_id's */
8689 for (i = 1; i < max_phys_id; i++) {
8690 phys_id++;
8691 if (phys_id > max_phys_id)
James Smartec2087a2013-09-06 12:20:36 -04008692 phys_id = min_phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008693 cpu = lpfc_find_next_cpu(phba, phys_id);
8694 if (cpu == LPFC_VECTOR_MAP_EMPTY)
8695 continue;
8696 goto found;
8697 }
8698
James Smartec2087a2013-09-06 12:20:36 -04008699 /* Use round robin for scheduling */
8700 phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_ROUND_ROBIN;
8701 chan = 0;
8702 cpup = phba->sli4_hba.cpu_map;
8703 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
8704 cpup->channel_id = chan;
8705 cpup++;
8706 chan++;
8707 if (chan >= phba->cfg_fcp_io_channel)
8708 chan = 0;
8709 }
8710
James Smart7bb03bb2013-04-17 20:19:16 -04008711 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8712 "3329 Cannot set affinity:"
8713 "Error mapping vector %d (%d)\n",
8714 idx, vectors);
8715 return 0;
8716 }
8717found:
8718 cpup += cpu;
8719 if (phba->cfg_fcp_cpu_map == LPFC_DRIVER_CPU_MAP)
8720 lpfc_used_cpu[cpu] = phys_id;
8721
8722 /* Associate vector with selected CPU */
8723 cpup->irq = phba->sli4_hba.msix_entries[idx].vector;
8724
8725 /* Associate IO channel with selected CPU */
8726 cpup->channel_id = idx;
8727 num_io_channel++;
8728
8729 if (first_cpu == LPFC_VECTOR_MAP_EMPTY)
8730 first_cpu = cpu;
8731
8732 /* Now affinitize to the selected CPU */
8733 mask = &cpup->maskbits;
8734 cpumask_clear(mask);
8735 cpumask_set_cpu(cpu, mask);
8736 i = irq_set_affinity_hint(phba->sli4_hba.msix_entries[idx].
8737 vector, mask);
8738
8739 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8740 "3330 Set Affinity: CPU %d channel %d "
8741 "irq %d (%x)\n",
8742 cpu, cpup->channel_id,
8743 phba->sli4_hba.msix_entries[idx].vector, i);
8744
8745 /* Spread vector mapping across multple physical CPU nodes */
8746 phys_id++;
8747 if (phys_id > max_phys_id)
James Smartec2087a2013-09-06 12:20:36 -04008748 phys_id = min_phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008749 }
8750
8751 /*
8752 * Finally fill in the IO channel for any remaining CPUs.
8753 * At this point, all IO channels have been assigned to a specific
8754 * MSIx vector, mapped to a specific CPU.
8755 * Base the remaining IO channel assigned, to IO channels already
8756 * assigned to other CPUs on the same phys_id.
8757 */
James Smartec2087a2013-09-06 12:20:36 -04008758 for (i = min_phys_id; i <= max_phys_id; i++) {
James Smart7bb03bb2013-04-17 20:19:16 -04008759 /*
8760 * If there are no io channels already mapped to
8761 * this phys_id, just round robin thru the io_channels.
8762 * Setup chann[] for round robin.
8763 */
8764 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
8765 chann[idx] = idx;
8766
8767 saved_chann = 0;
8768 used_chann = 0;
8769
8770 /*
8771 * First build a list of IO channels already assigned
8772 * to this phys_id before reassigning the same IO
8773 * channels to the remaining CPUs.
8774 */
8775 cpup = phba->sli4_hba.cpu_map;
8776 cpu = first_cpu;
8777 cpup += cpu;
8778 for (idx = 0; idx < phba->sli4_hba.num_present_cpu;
8779 idx++) {
8780 if (cpup->phys_id == i) {
8781 /*
8782 * Save any IO channels that are
8783 * already mapped to this phys_id.
8784 */
8785 if (cpup->irq != LPFC_VECTOR_MAP_EMPTY) {
8786 chann[saved_chann] =
8787 cpup->channel_id;
8788 saved_chann++;
8789 goto out;
8790 }
8791
8792 /* See if we are using round-robin */
8793 if (saved_chann == 0)
8794 saved_chann =
8795 phba->cfg_fcp_io_channel;
8796
8797 /* Associate next IO channel with CPU */
8798 cpup->channel_id = chann[used_chann];
8799 num_io_channel++;
8800 used_chann++;
8801 if (used_chann == saved_chann)
8802 used_chann = 0;
8803
8804 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8805 "3331 Set IO_CHANN "
8806 "CPU %d channel %d\n",
8807 idx, cpup->channel_id);
8808 }
8809out:
8810 cpu++;
8811 if (cpu >= phba->sli4_hba.num_present_cpu) {
8812 cpup = phba->sli4_hba.cpu_map;
8813 cpu = 0;
8814 } else {
8815 cpup++;
8816 }
8817 }
8818 }
8819
8820 if (phba->sli4_hba.num_online_cpu != phba->sli4_hba.num_present_cpu) {
8821 cpup = phba->sli4_hba.cpu_map;
8822 for (idx = 0; idx < phba->sli4_hba.num_present_cpu; idx++) {
8823 if (cpup->channel_id == LPFC_VECTOR_MAP_EMPTY) {
8824 cpup->channel_id = 0;
8825 num_io_channel++;
8826
8827 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8828 "3332 Assign IO_CHANN "
8829 "CPU %d channel %d\n",
8830 idx, cpup->channel_id);
8831 }
8832 cpup++;
8833 }
8834 }
8835
8836 /* Sanity check */
8837 if (num_io_channel != phba->sli4_hba.num_present_cpu)
8838 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8839 "3333 Set affinity mismatch:"
James Smartec2087a2013-09-06 12:20:36 -04008840 "%d chann != %d cpus: %d vectors\n",
James Smart7bb03bb2013-04-17 20:19:16 -04008841 num_io_channel, phba->sli4_hba.num_present_cpu,
8842 vectors);
8843
James Smartec2087a2013-09-06 12:20:36 -04008844 /* Enable using cpu affinity for scheduling */
James Smart7bb03bb2013-04-17 20:19:16 -04008845 phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_BY_CPU;
8846 return 1;
8847}
8848
8849
8850/**
James Smartda0436e2009-05-22 14:51:39 -04008851 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
8852 * @phba: pointer to lpfc hba data structure.
8853 *
8854 * This routine is invoked to enable the MSI-X interrupt vectors to device
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008855 * with SLI-4 interface spec. The kernel function pci_enable_msix_range()
8856 * is called to enable the MSI-X vectors. The device driver is responsible
8857 * for calling the individual request_irq() to register each MSI-X vector
8858 * with a interrupt handler, which is done in this function. Note that
8859 * later when device is unloading, the driver should always call free_irq()
8860 * on all MSI-X vectors it has done request_irq() on before calling
8861 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
8862 * will be left with MSI-X enabled and leaks its vectors.
James Smartda0436e2009-05-22 14:51:39 -04008863 *
8864 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008865 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008866 * other values - error
8867 **/
8868static int
8869lpfc_sli4_enable_msix(struct lpfc_hba *phba)
8870{
James Smart75baf692010-06-08 18:31:21 -04008871 int vectors, rc, index;
James Smartda0436e2009-05-22 14:51:39 -04008872
8873 /* Set up MSI-X multi-message vectors */
James Smart82c3e9b2012-09-29 11:29:50 -04008874 for (index = 0; index < phba->cfg_fcp_io_channel; index++)
James Smartda0436e2009-05-22 14:51:39 -04008875 phba->sli4_hba.msix_entries[index].entry = index;
8876
8877 /* Configure MSI-X capability structure */
James Smart82c3e9b2012-09-29 11:29:50 -04008878 vectors = phba->cfg_fcp_io_channel;
James Smart1ba981f2014-02-20 09:56:45 -05008879 if (phba->cfg_fof) {
8880 phba->sli4_hba.msix_entries[index].entry = index;
8881 vectors++;
8882 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008883 rc = pci_enable_msix_range(phba->pcidev, phba->sli4_hba.msix_entries,
8884 2, vectors);
8885 if (rc < 0) {
James Smartda0436e2009-05-22 14:51:39 -04008886 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8887 "0484 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02008888 goto vec_fail_out;
James Smartda0436e2009-05-22 14:51:39 -04008889 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008890 vectors = rc;
James Smart75baf692010-06-08 18:31:21 -04008891
James Smartda0436e2009-05-22 14:51:39 -04008892 /* Log MSI-X vector assignment */
James Smart75baf692010-06-08 18:31:21 -04008893 for (index = 0; index < vectors; index++)
James Smartda0436e2009-05-22 14:51:39 -04008894 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8895 "0489 MSI-X entry[%d]: vector=x%x "
8896 "message=%d\n", index,
8897 phba->sli4_hba.msix_entries[index].vector,
8898 phba->sli4_hba.msix_entries[index].entry);
James Smart67d12732012-08-03 12:36:13 -04008899
James Smart7bb03bb2013-04-17 20:19:16 -04008900 /* Assign MSI-X vectors to interrupt handlers */
James Smart67d12732012-08-03 12:36:13 -04008901 for (index = 0; index < vectors; index++) {
James Smart4305f182012-08-03 12:36:33 -04008902 memset(&phba->sli4_hba.handler_name[index], 0, 16);
James Smarta2fc4aef2014-09-03 12:57:55 -04008903 snprintf((char *)&phba->sli4_hba.handler_name[index],
8904 LPFC_SLI4_HANDLER_NAME_SZ,
James Smart4305f182012-08-03 12:36:33 -04008905 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -04008906
James Smart67d12732012-08-03 12:36:13 -04008907 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
8908 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
James Smartba20c852012-08-03 12:36:52 -04008909 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].fcp_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -05008910 if (phba->cfg_fof && (index == (vectors - 1)))
8911 rc = request_irq(
8912 phba->sli4_hba.msix_entries[index].vector,
8913 &lpfc_sli4_fof_intr_handler, IRQF_SHARED,
8914 (char *)&phba->sli4_hba.handler_name[index],
8915 &phba->sli4_hba.fcp_eq_hdl[index]);
8916 else
8917 rc = request_irq(
8918 phba->sli4_hba.msix_entries[index].vector,
James Smart67d12732012-08-03 12:36:13 -04008919 &lpfc_sli4_hba_intr_handler, IRQF_SHARED,
James Smart4305f182012-08-03 12:36:33 -04008920 (char *)&phba->sli4_hba.handler_name[index],
James Smart67d12732012-08-03 12:36:13 -04008921 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -04008922 if (rc) {
8923 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8924 "0486 MSI-X fast-path (%d) "
8925 "request_irq failed (%d)\n", index, rc);
8926 goto cfg_fail_out;
8927 }
8928 }
8929
James Smart1ba981f2014-02-20 09:56:45 -05008930 if (phba->cfg_fof)
8931 vectors--;
8932
James Smart82c3e9b2012-09-29 11:29:50 -04008933 if (vectors != phba->cfg_fcp_io_channel) {
8934 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8935 "3238 Reducing IO channels to match number of "
8936 "MSI-X vectors, requested %d got %d\n",
8937 phba->cfg_fcp_io_channel, vectors);
8938 phba->cfg_fcp_io_channel = vectors;
8939 }
James Smart7bb03bb2013-04-17 20:19:16 -04008940
8941 lpfc_sli4_set_affinity(phba, vectors);
James Smartda0436e2009-05-22 14:51:39 -04008942 return rc;
8943
8944cfg_fail_out:
8945 /* free the irq already requested */
James Smartacbd8612013-09-06 12:21:19 -04008946 for (--index; index >= 0; index--) {
8947 irq_set_affinity_hint(phba->sli4_hba.msix_entries[index].
8948 vector, NULL);
James Smart67d12732012-08-03 12:36:13 -04008949 free_irq(phba->sli4_hba.msix_entries[index].vector,
8950 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartacbd8612013-09-06 12:21:19 -04008951 }
James Smartda0436e2009-05-22 14:51:39 -04008952
James Smartda0436e2009-05-22 14:51:39 -04008953 /* Unconfigure MSI-X capability structure */
8954 pci_disable_msix(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02008955
8956vec_fail_out:
James Smartda0436e2009-05-22 14:51:39 -04008957 return rc;
8958}
8959
8960/**
8961 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
8962 * @phba: pointer to lpfc hba data structure.
8963 *
8964 * This routine is invoked to release the MSI-X vectors and then disable the
8965 * MSI-X interrupt mode to device with SLI-4 interface spec.
8966 **/
8967static void
8968lpfc_sli4_disable_msix(struct lpfc_hba *phba)
8969{
8970 int index;
8971
8972 /* Free up MSI-X multi-message vectors */
James Smartacbd8612013-09-06 12:21:19 -04008973 for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
8974 irq_set_affinity_hint(phba->sli4_hba.msix_entries[index].
8975 vector, NULL);
James Smartda0436e2009-05-22 14:51:39 -04008976 free_irq(phba->sli4_hba.msix_entries[index].vector,
James Smart67d12732012-08-03 12:36:13 -04008977 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartacbd8612013-09-06 12:21:19 -04008978 }
James Smart1ba981f2014-02-20 09:56:45 -05008979 if (phba->cfg_fof) {
8980 free_irq(phba->sli4_hba.msix_entries[index].vector,
8981 &phba->sli4_hba.fcp_eq_hdl[index]);
8982 }
James Smartda0436e2009-05-22 14:51:39 -04008983 /* Disable MSI-X */
8984 pci_disable_msix(phba->pcidev);
8985
8986 return;
8987}
8988
8989/**
8990 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
8991 * @phba: pointer to lpfc hba data structure.
8992 *
8993 * This routine is invoked to enable the MSI interrupt mode to device with
8994 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
8995 * to enable the MSI vector. The device driver is responsible for calling
8996 * the request_irq() to register MSI vector with a interrupt the handler,
8997 * which is done in this function.
8998 *
8999 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009000 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009001 * other values - error
9002 **/
9003static int
9004lpfc_sli4_enable_msi(struct lpfc_hba *phba)
9005{
9006 int rc, index;
9007
9008 rc = pci_enable_msi(phba->pcidev);
9009 if (!rc)
9010 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9011 "0487 PCI enable MSI mode success.\n");
9012 else {
9013 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9014 "0488 PCI enable MSI mode failed (%d)\n", rc);
9015 return rc;
9016 }
9017
9018 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
9019 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9020 if (rc) {
9021 pci_disable_msi(phba->pcidev);
9022 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9023 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -04009024 return rc;
James Smartda0436e2009-05-22 14:51:39 -04009025 }
9026
James Smart67d12732012-08-03 12:36:13 -04009027 for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
James Smartda0436e2009-05-22 14:51:39 -04009028 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9029 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9030 }
9031
James Smart1ba981f2014-02-20 09:56:45 -05009032 if (phba->cfg_fof) {
9033 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9034 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9035 }
James Smart75baf692010-06-08 18:31:21 -04009036 return 0;
James Smartda0436e2009-05-22 14:51:39 -04009037}
9038
9039/**
9040 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
9041 * @phba: pointer to lpfc hba data structure.
9042 *
9043 * This routine is invoked to disable the MSI interrupt mode to device with
9044 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
9045 * done request_irq() on before calling pci_disable_msi(). Failure to do so
9046 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
9047 * its vector.
9048 **/
9049static void
9050lpfc_sli4_disable_msi(struct lpfc_hba *phba)
9051{
9052 free_irq(phba->pcidev->irq, phba);
9053 pci_disable_msi(phba->pcidev);
9054 return;
9055}
9056
9057/**
9058 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
9059 * @phba: pointer to lpfc hba data structure.
9060 *
9061 * This routine is invoked to enable device interrupt and associate driver's
9062 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
9063 * interface spec. Depends on the interrupt mode configured to the driver,
9064 * the driver will try to fallback from the configured interrupt mode to an
9065 * interrupt mode which is supported by the platform, kernel, and device in
9066 * the order of:
9067 * MSI-X -> MSI -> IRQ.
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 uint32_t
9074lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9075{
9076 uint32_t intr_mode = LPFC_INTR_ERROR;
9077 int retval, index;
9078
9079 if (cfg_mode == 2) {
9080 /* Preparation before conf_msi mbox cmd */
9081 retval = 0;
9082 if (!retval) {
9083 /* Now, try to enable MSI-X interrupt mode */
9084 retval = lpfc_sli4_enable_msix(phba);
9085 if (!retval) {
9086 /* Indicate initialization to MSI-X mode */
9087 phba->intr_type = MSIX;
9088 intr_mode = 2;
9089 }
9090 }
9091 }
9092
9093 /* Fallback to MSI if MSI-X initialization failed */
9094 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9095 retval = lpfc_sli4_enable_msi(phba);
9096 if (!retval) {
9097 /* Indicate initialization to MSI mode */
9098 phba->intr_type = MSI;
9099 intr_mode = 1;
9100 }
9101 }
9102
9103 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9104 if (phba->intr_type == NONE) {
9105 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
9106 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9107 if (!retval) {
9108 /* Indicate initialization to INTx mode */
9109 phba->intr_type = INTx;
9110 intr_mode = 0;
James Smart67d12732012-08-03 12:36:13 -04009111 for (index = 0; index < phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04009112 index++) {
9113 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9114 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
James Smartba20c852012-08-03 12:36:52 -04009115 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
9116 fcp_eq_in_use, 1);
James Smartda0436e2009-05-22 14:51:39 -04009117 }
James Smart1ba981f2014-02-20 09:56:45 -05009118 if (phba->cfg_fof) {
9119 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9120 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9121 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
9122 fcp_eq_in_use, 1);
9123 }
James Smartda0436e2009-05-22 14:51:39 -04009124 }
9125 }
9126 return intr_mode;
9127}
9128
9129/**
9130 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
9131 * @phba: pointer to lpfc hba data structure.
9132 *
9133 * This routine is invoked to disable device interrupt and disassociate
9134 * the driver's interrupt handler(s) from interrupt vector(s) to device
9135 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
9136 * will release the interrupt vector(s) for the message signaled interrupt.
9137 **/
9138static void
9139lpfc_sli4_disable_intr(struct lpfc_hba *phba)
9140{
9141 /* Disable the currently initialized interrupt mode */
9142 if (phba->intr_type == MSIX)
9143 lpfc_sli4_disable_msix(phba);
9144 else if (phba->intr_type == MSI)
9145 lpfc_sli4_disable_msi(phba);
9146 else if (phba->intr_type == INTx)
9147 free_irq(phba->pcidev->irq, phba);
9148
9149 /* Reset interrupt management states */
9150 phba->intr_type = NONE;
9151 phba->sli.slistat.sli_intr = 0;
9152
9153 return;
9154}
9155
9156/**
James Smart3772a992009-05-22 14:50:54 -04009157 * lpfc_unset_hba - Unset SLI3 hba device initialization
9158 * @phba: pointer to lpfc hba data structure.
9159 *
9160 * This routine is invoked to unset the HBA device initialization steps to
9161 * a device with SLI-3 interface spec.
9162 **/
9163static void
9164lpfc_unset_hba(struct lpfc_hba *phba)
9165{
9166 struct lpfc_vport *vport = phba->pport;
9167 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9168
9169 spin_lock_irq(shost->host_lock);
9170 vport->load_flag |= FC_UNLOADING;
9171 spin_unlock_irq(shost->host_lock);
9172
James Smart72859902012-01-18 16:25:38 -05009173 kfree(phba->vpi_bmask);
9174 kfree(phba->vpi_ids);
9175
James Smart3772a992009-05-22 14:50:54 -04009176 lpfc_stop_hba_timers(phba);
9177
9178 phba->pport->work_port_events = 0;
9179
9180 lpfc_sli_hba_down(phba);
9181
9182 lpfc_sli_brdrestart(phba);
9183
9184 lpfc_sli_disable_intr(phba);
9185
9186 return;
9187}
9188
9189/**
James Smart5af5eee2010-10-22 11:06:38 -04009190 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
9191 * @phba: Pointer to HBA context object.
9192 *
9193 * This function is called in the SLI4 code path to wait for completion
9194 * of device's XRIs exchange busy. It will check the XRI exchange busy
9195 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
9196 * that, it will check the XRI exchange busy on outstanding FCP and ELS
9197 * I/Os every 30 seconds, log error message, and wait forever. Only when
9198 * all XRI exchange busy complete, the driver unload shall proceed with
9199 * invoking the function reset ioctl mailbox command to the CNA and the
9200 * the rest of the driver unload resource release.
9201 **/
9202static void
9203lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
9204{
9205 int wait_time = 0;
9206 int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
9207 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9208
9209 while (!fcp_xri_cmpl || !els_xri_cmpl) {
9210 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
9211 if (!fcp_xri_cmpl)
9212 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9213 "2877 FCP XRI exchange busy "
9214 "wait time: %d seconds.\n",
9215 wait_time/1000);
9216 if (!els_xri_cmpl)
9217 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9218 "2878 ELS XRI exchange busy "
9219 "wait time: %d seconds.\n",
9220 wait_time/1000);
9221 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
9222 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
9223 } else {
9224 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
9225 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
9226 }
9227 fcp_xri_cmpl =
9228 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
9229 els_xri_cmpl =
9230 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9231 }
9232}
9233
9234/**
James Smartda0436e2009-05-22 14:51:39 -04009235 * lpfc_sli4_hba_unset - Unset the fcoe hba
9236 * @phba: Pointer to HBA context object.
9237 *
9238 * This function is called in the SLI4 code path to reset the HBA's FCoE
9239 * function. The caller is not required to hold any lock. This routine
9240 * issues PCI function reset mailbox command to reset the FCoE function.
9241 * At the end of the function, it calls lpfc_hba_down_post function to
9242 * free any pending commands.
9243 **/
9244static void
9245lpfc_sli4_hba_unset(struct lpfc_hba *phba)
9246{
9247 int wait_cnt = 0;
9248 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -04009249 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -04009250
9251 lpfc_stop_hba_timers(phba);
9252 phba->sli4_hba.intr_enable = 0;
9253
9254 /*
9255 * Gracefully wait out the potential current outstanding asynchronous
9256 * mailbox command.
9257 */
9258
9259 /* First, block any pending async mailbox command from posted */
9260 spin_lock_irq(&phba->hbalock);
9261 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
9262 spin_unlock_irq(&phba->hbalock);
9263 /* Now, trying to wait it out if we can */
9264 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9265 msleep(10);
9266 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
9267 break;
9268 }
9269 /* Forcefully release the outstanding mailbox command if timed out */
9270 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9271 spin_lock_irq(&phba->hbalock);
9272 mboxq = phba->sli.mbox_active;
9273 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
9274 __lpfc_mbox_cmpl_put(phba, mboxq);
9275 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9276 phba->sli.mbox_active = NULL;
9277 spin_unlock_irq(&phba->hbalock);
9278 }
9279
James Smart5af5eee2010-10-22 11:06:38 -04009280 /* Abort all iocbs associated with the hba */
9281 lpfc_sli_hba_iocb_abort(phba);
9282
9283 /* Wait for completion of device XRI exchange busy */
9284 lpfc_sli4_xri_exchange_busy_wait(phba);
9285
James Smartda0436e2009-05-22 14:51:39 -04009286 /* Disable PCI subsystem interrupt */
9287 lpfc_sli4_disable_intr(phba);
9288
James Smart912e3ac2011-05-24 11:42:11 -04009289 /* Disable SR-IOV if enabled */
9290 if (phba->cfg_sriov_nr_virtfn)
9291 pci_disable_sriov(pdev);
9292
James Smartda0436e2009-05-22 14:51:39 -04009293 /* Stop kthread signal shall trigger work_done one more time */
9294 kthread_stop(phba->worker_thread);
9295
James Smart3677a3a2010-09-29 11:19:14 -04009296 /* Reset SLI4 HBA FCoE function */
9297 lpfc_pci_function_reset(phba);
James Smart5350d872011-10-10 21:33:49 -04009298 lpfc_sli4_queue_destroy(phba);
James Smart3677a3a2010-09-29 11:19:14 -04009299
James Smartda0436e2009-05-22 14:51:39 -04009300 /* Stop the SLI4 device port */
9301 phba->pport->work_port_events = 0;
9302}
9303
James Smart28baac72010-02-12 14:42:03 -05009304 /**
9305 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
9306 * @phba: Pointer to HBA context object.
9307 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9308 *
9309 * This function is called in the SLI4 code path to read the port's
9310 * sli4 capabilities.
9311 *
9312 * This function may be be called from any context that can block-wait
9313 * for the completion. The expectation is that this routine is called
9314 * typically from probe_one or from the online routine.
9315 **/
9316int
9317lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9318{
9319 int rc;
9320 struct lpfc_mqe *mqe;
9321 struct lpfc_pc_sli4_params *sli4_params;
9322 uint32_t mbox_tmo;
9323
9324 rc = 0;
9325 mqe = &mboxq->u.mqe;
9326
9327 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -05009328 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -05009329 if (!phba->sli4_hba.intr_enable)
9330 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9331 else {
James Smarta183a152011-10-10 21:32:43 -04009332 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -05009333 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
9334 }
9335
9336 if (unlikely(rc))
9337 return 1;
9338
9339 sli4_params = &phba->sli4_hba.pc_sli4_params;
9340 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
9341 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
9342 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
9343 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
9344 &mqe->un.sli4_params);
9345 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
9346 &mqe->un.sli4_params);
9347 sli4_params->proto_types = mqe->un.sli4_params.word3;
9348 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
9349 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
9350 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
9351 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
9352 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
9353 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
9354 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
9355 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
9356 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
9357 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
9358 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
9359 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
9360 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
9361 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
9362 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
9363 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
9364 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
9365 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
9366 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
9367 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -04009368
9369 /* Make sure that sge_supp_len can be handled by the driver */
9370 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
9371 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
9372
James Smart28baac72010-02-12 14:42:03 -05009373 return rc;
9374}
9375
James Smartda0436e2009-05-22 14:51:39 -04009376/**
James Smartfedd3b72011-02-16 12:39:24 -05009377 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
9378 * @phba: Pointer to HBA context object.
9379 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9380 *
9381 * This function is called in the SLI4 code path to read the port's
9382 * sli4 capabilities.
9383 *
9384 * This function may be be called from any context that can block-wait
9385 * for the completion. The expectation is that this routine is called
9386 * typically from probe_one or from the online routine.
9387 **/
9388int
9389lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9390{
9391 int rc;
9392 struct lpfc_mqe *mqe = &mboxq->u.mqe;
9393 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -04009394 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -05009395 int length;
9396 struct lpfc_sli4_parameters *mbx_sli4_parameters;
9397
James Smart6d368e52011-05-24 11:44:12 -04009398 /*
9399 * By default, the driver assumes the SLI4 port requires RPI
9400 * header postings. The SLI4_PARAM response will correct this
9401 * assumption.
9402 */
9403 phba->sli4_hba.rpi_hdrs_in_use = 1;
9404
James Smartfedd3b72011-02-16 12:39:24 -05009405 /* Read the port's SLI4 Config Parameters */
9406 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
9407 sizeof(struct lpfc_sli4_cfg_mhdr));
9408 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9409 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
9410 length, LPFC_SLI4_MBX_EMBED);
9411 if (!phba->sli4_hba.intr_enable)
9412 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -04009413 else {
9414 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
9415 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
9416 }
James Smartfedd3b72011-02-16 12:39:24 -05009417 if (unlikely(rc))
9418 return rc;
9419 sli4_params = &phba->sli4_hba.pc_sli4_params;
9420 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
9421 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
9422 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
9423 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
9424 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
9425 mbx_sli4_parameters);
9426 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
9427 mbx_sli4_parameters);
9428 if (bf_get(cfg_phwq, mbx_sli4_parameters))
9429 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
9430 else
9431 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
9432 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
9433 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
James Smart1ba981f2014-02-20 09:56:45 -05009434 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -05009435 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
9436 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
9437 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
9438 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
James Smart0c651872013-07-15 18:33:23 -04009439 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -05009440 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
9441 mbx_sli4_parameters);
9442 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
9443 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -04009444 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
9445 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart05580562011-05-24 11:40:48 -04009446
9447 /* Make sure that sge_supp_len can be handled by the driver */
9448 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
9449 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
9450
James Smartfedd3b72011-02-16 12:39:24 -05009451 return 0;
9452}
9453
9454/**
James Smart3772a992009-05-22 14:50:54 -04009455 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
9456 * @pdev: pointer to PCI device
9457 * @pid: pointer to PCI device identifier
9458 *
9459 * This routine is to be called to attach a device with SLI-3 interface spec
9460 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9461 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
9462 * information of the device and driver to see if the driver state that it can
9463 * support this kind of device. If the match is successful, the driver core
9464 * invokes this routine. If this routine determines it can claim the HBA, it
9465 * does all the initialization that it needs to do to handle the HBA properly.
9466 *
9467 * Return code
9468 * 0 - driver can claim the device
9469 * negative value - driver can not claim the device
9470 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009471static int
James Smart3772a992009-05-22 14:50:54 -04009472lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
9473{
9474 struct lpfc_hba *phba;
9475 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -04009476 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -04009477 int error;
9478 uint32_t cfg_mode, intr_mode;
9479
9480 /* Allocate memory for HBA structure */
9481 phba = lpfc_hba_alloc(pdev);
9482 if (!phba)
9483 return -ENOMEM;
9484
9485 /* Perform generic PCI device enabling operation */
9486 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -04009487 if (error)
James Smart3772a992009-05-22 14:50:54 -04009488 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -04009489
9490 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
9491 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
9492 if (error)
9493 goto out_disable_pci_dev;
9494
9495 /* Set up SLI-3 specific device PCI memory space */
9496 error = lpfc_sli_pci_mem_setup(phba);
9497 if (error) {
9498 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9499 "1402 Failed to set up pci memory space.\n");
9500 goto out_disable_pci_dev;
9501 }
9502
9503 /* Set up phase-1 common device driver resources */
9504 error = lpfc_setup_driver_resource_phase1(phba);
9505 if (error) {
9506 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9507 "1403 Failed to set up driver resource.\n");
9508 goto out_unset_pci_mem_s3;
9509 }
9510
9511 /* Set up SLI-3 specific device driver resources */
9512 error = lpfc_sli_driver_resource_setup(phba);
9513 if (error) {
9514 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9515 "1404 Failed to set up driver resource.\n");
9516 goto out_unset_pci_mem_s3;
9517 }
9518
9519 /* Initialize and populate the iocb list per host */
9520 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
9521 if (error) {
9522 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9523 "1405 Failed to initialize iocb list.\n");
9524 goto out_unset_driver_resource_s3;
9525 }
9526
9527 /* Set up common device driver resources */
9528 error = lpfc_setup_driver_resource_phase2(phba);
9529 if (error) {
9530 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9531 "1406 Failed to set up driver resource.\n");
9532 goto out_free_iocb_list;
9533 }
9534
James Smart079b5c92011-08-21 21:48:49 -04009535 /* Get the default values for Model Name and Description */
9536 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
9537
James Smart3772a992009-05-22 14:50:54 -04009538 /* Create SCSI host to the physical port */
9539 error = lpfc_create_shost(phba);
9540 if (error) {
9541 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9542 "1407 Failed to create scsi host.\n");
9543 goto out_unset_driver_resource;
9544 }
9545
9546 /* Configure sysfs attributes */
9547 vport = phba->pport;
9548 error = lpfc_alloc_sysfs_attr(vport);
9549 if (error) {
9550 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9551 "1476 Failed to allocate sysfs attr\n");
9552 goto out_destroy_shost;
9553 }
9554
James Smart6669f9b2009-10-02 15:16:45 -04009555 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -04009556 /* Now, trying to enable interrupt and bring up the device */
9557 cfg_mode = phba->cfg_use_msi;
9558 while (true) {
9559 /* Put device to a known state before enabling interrupt */
9560 lpfc_stop_port(phba);
9561 /* Configure and enable interrupt */
9562 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
9563 if (intr_mode == LPFC_INTR_ERROR) {
9564 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9565 "0431 Failed to enable interrupt.\n");
9566 error = -ENODEV;
9567 goto out_free_sysfs_attr;
9568 }
9569 /* SLI-3 HBA setup */
9570 if (lpfc_sli_hba_setup(phba)) {
9571 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9572 "1477 Failed to set up hba\n");
9573 error = -ENODEV;
9574 goto out_remove_device;
9575 }
9576
9577 /* Wait 50ms for the interrupts of previous mailbox commands */
9578 msleep(50);
9579 /* Check active interrupts on message signaled interrupts */
9580 if (intr_mode == 0 ||
9581 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
9582 /* Log the current active interrupt mode */
9583 phba->intr_mode = intr_mode;
9584 lpfc_log_intr_mode(phba, intr_mode);
9585 break;
9586 } else {
9587 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9588 "0447 Configure interrupt mode (%d) "
9589 "failed active interrupt test.\n",
9590 intr_mode);
9591 /* Disable the current interrupt mode */
9592 lpfc_sli_disable_intr(phba);
9593 /* Try next level of interrupt mode */
9594 cfg_mode = --intr_mode;
9595 }
9596 }
9597
9598 /* Perform post initialization setup */
9599 lpfc_post_init_setup(phba);
9600
9601 /* Check if there are static vports to be created. */
9602 lpfc_create_static_vport(phba);
9603
9604 return 0;
9605
9606out_remove_device:
9607 lpfc_unset_hba(phba);
9608out_free_sysfs_attr:
9609 lpfc_free_sysfs_attr(vport);
9610out_destroy_shost:
9611 lpfc_destroy_shost(phba);
9612out_unset_driver_resource:
9613 lpfc_unset_driver_resource_phase2(phba);
9614out_free_iocb_list:
9615 lpfc_free_iocb_list(phba);
9616out_unset_driver_resource_s3:
9617 lpfc_sli_driver_resource_unset(phba);
9618out_unset_pci_mem_s3:
9619 lpfc_sli_pci_mem_unset(phba);
9620out_disable_pci_dev:
9621 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -04009622 if (shost)
9623 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -04009624out_free_phba:
9625 lpfc_hba_free(phba);
9626 return error;
9627}
9628
9629/**
9630 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -04009631 * @pdev: pointer to PCI device
9632 *
James Smart3772a992009-05-22 14:50:54 -04009633 * This routine is to be called to disattach a device with SLI-3 interface
9634 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9635 * removed from PCI bus, it performs all the necessary cleanup for the HBA
9636 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -04009637 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009638static void
James Smart3772a992009-05-22 14:50:54 -04009639lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -05009640{
James Smart2e0fef82007-06-17 19:56:36 -05009641 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9642 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -05009643 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -05009644 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -05009645 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05009646 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
9647
James Smart549e55c2007-08-02 11:09:51 -04009648 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04009649 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04009650 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05009651
James Smart858c9f62007-06-17 19:56:39 -05009652 lpfc_free_sysfs_attr(vport);
9653
James Smarteada2722008-12-04 22:39:13 -05009654 /* Release all the vports against this physical port */
9655 vports = lpfc_create_vport_work_array(phba);
9656 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -04009657 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9658 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
9659 continue;
James Smarteada2722008-12-04 22:39:13 -05009660 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -04009661 }
James Smarteada2722008-12-04 22:39:13 -05009662 lpfc_destroy_vport_work_array(phba, vports);
9663
9664 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -05009665 fc_remove_host(shost);
9666 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04009667 lpfc_cleanup(vport);
9668
James Smart2e0fef82007-06-17 19:56:36 -05009669 /*
9670 * Bring down the SLI Layer. This step disable all interrupts,
9671 * clears the rings, discards all mailbox commands, and resets
9672 * the HBA.
9673 */
James Smarta257bf92009-04-06 18:48:10 -04009674
Justin P. Mattock48e34d02010-12-30 15:07:58 -08009675 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -05009676 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -04009677 /* Stop kthread signal shall trigger work_done one more time */
9678 kthread_stop(phba->worker_thread);
9679 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -05009680 lpfc_sli_brdrestart(phba);
9681
James Smart72859902012-01-18 16:25:38 -05009682 kfree(phba->vpi_bmask);
9683 kfree(phba->vpi_ids);
9684
James Smart3772a992009-05-22 14:50:54 -04009685 lpfc_stop_hba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05009686 spin_lock_irq(&phba->hbalock);
9687 list_del_init(&vport->listentry);
9688 spin_unlock_irq(&phba->hbalock);
9689
James Smart858c9f62007-06-17 19:56:39 -05009690 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05009691
James Smart912e3ac2011-05-24 11:42:11 -04009692 /* Disable SR-IOV if enabled */
9693 if (phba->cfg_sriov_nr_virtfn)
9694 pci_disable_sriov(pdev);
9695
James Smart5b75da22008-12-04 22:39:35 -05009696 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009697 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -05009698
James Smart858c9f62007-06-17 19:56:39 -05009699 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05009700
9701 /*
9702 * Call scsi_free before mem_free since scsi bufs are released to their
9703 * corresponding pools here.
9704 */
9705 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -04009706 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -05009707
James Smart34b02dc2008-08-24 21:49:55 -04009708 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
9709 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -05009710
James Smart2e0fef82007-06-17 19:56:36 -05009711 /* Free resources associated with SLI2 interface */
9712 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -04009713 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -05009714
9715 /* unmap adapter SLIM and Control Registers */
9716 iounmap(phba->ctrl_regs_memmap_p);
9717 iounmap(phba->slim_memmap_p);
9718
James Smart3772a992009-05-22 14:50:54 -04009719 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -05009720
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05009721 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05009722 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05009723}
9724
Linas Vepstas8d63f372007-02-14 14:28:36 -06009725/**
James Smart3772a992009-05-22 14:50:54 -04009726 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05009727 * @pdev: pointer to PCI device
9728 * @msg: power management message
9729 *
James Smart3772a992009-05-22 14:50:54 -04009730 * This routine is to be called from the kernel's PCI subsystem to support
9731 * system Power Management (PM) to device with SLI-3 interface spec. When
9732 * PM invokes this method, it quiesces the device by stopping the driver's
9733 * worker thread for the device, turning off device's interrupt and DMA,
9734 * and bring the device offline. Note that as the driver implements the
9735 * minimum PM requirements to a power-aware driver's PM support for the
9736 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
9737 * to the suspend() method call will be treated as SUSPEND and the driver will
9738 * fully reinitialize its device during resume() method call, the driver will
9739 * set device to PCI_D3hot state in PCI config space instead of setting it
9740 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -05009741 *
9742 * Return code
James Smart3772a992009-05-22 14:50:54 -04009743 * 0 - driver suspended the device
9744 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05009745 **/
9746static int
James Smart3772a992009-05-22 14:50:54 -04009747lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -05009748{
9749 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9750 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9751
9752 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9753 "0473 PCI device Power Management suspend.\n");
9754
9755 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -04009756 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -05009757 lpfc_offline(phba);
9758 kthread_stop(phba->worker_thread);
9759
9760 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -04009761 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -05009762
9763 /* Save device state to PCI config space */
9764 pci_save_state(pdev);
9765 pci_set_power_state(pdev, PCI_D3hot);
9766
9767 return 0;
9768}
9769
9770/**
James Smart3772a992009-05-22 14:50:54 -04009771 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05009772 * @pdev: pointer to PCI device
9773 *
James Smart3772a992009-05-22 14:50:54 -04009774 * This routine is to be called from the kernel's PCI subsystem to support
9775 * system Power Management (PM) to device with SLI-3 interface spec. When PM
9776 * invokes this method, it restores the device's PCI config space state and
9777 * fully reinitializes the device and brings it online. Note that as the
9778 * driver implements the minimum PM requirements to a power-aware driver's
9779 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
9780 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
9781 * driver will fully reinitialize its device during resume() method call,
9782 * the device will be set to PCI_D0 directly in PCI config space before
9783 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -05009784 *
9785 * Return code
James Smart3772a992009-05-22 14:50:54 -04009786 * 0 - driver suspended the device
9787 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05009788 **/
9789static int
James Smart3772a992009-05-22 14:50:54 -04009790lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -05009791{
9792 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9793 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -05009794 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05009795 int error;
9796
9797 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9798 "0452 PCI device Power Management resume.\n");
9799
9800 /* Restore device state from PCI config space */
9801 pci_set_power_state(pdev, PCI_D0);
9802 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -04009803
James Smart1dfb5a42010-02-12 14:40:50 -05009804 /*
9805 * As the new kernel behavior of pci_restore_state() API call clears
9806 * device saved_state flag, need to save the restored state again.
9807 */
9808 pci_save_state(pdev);
9809
James Smart3a55b532008-12-04 22:38:54 -05009810 if (pdev->is_busmaster)
9811 pci_set_master(pdev);
9812
9813 /* Startup the kernel thread for this host adapter. */
9814 phba->worker_thread = kthread_run(lpfc_do_work, phba,
9815 "lpfc_worker_%d", phba->brd_no);
9816 if (IS_ERR(phba->worker_thread)) {
9817 error = PTR_ERR(phba->worker_thread);
9818 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9819 "0434 PM resume failed to start worker "
9820 "thread: error=x%x.\n", error);
9821 return error;
9822 }
9823
James Smart5b75da22008-12-04 22:39:35 -05009824 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009825 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05009826 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -05009827 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -05009828 "0430 PM resume Failed to enable interrupt\n");
9829 return -EIO;
9830 } else
9831 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05009832
9833 /* Restart HBA and bring it online */
9834 lpfc_sli_brdrestart(phba);
9835 lpfc_online(phba);
9836
James Smart5b75da22008-12-04 22:39:35 -05009837 /* Log the current active interrupt mode */
9838 lpfc_log_intr_mode(phba, phba->intr_mode);
9839
James Smart3a55b532008-12-04 22:38:54 -05009840 return 0;
9841}
9842
9843/**
James Smart891478a2009-11-18 15:40:23 -05009844 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
9845 * @phba: pointer to lpfc hba data structure.
9846 *
9847 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -04009848 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -05009849 **/
9850static void
9851lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
9852{
9853 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9854 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -04009855
9856 /*
9857 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
9858 * and let the SCSI mid-layer to retry them to recover.
9859 */
James Smartdb55fba2014-04-04 13:52:02 -04009860 lpfc_sli_abort_fcp_rings(phba);
James Smart891478a2009-11-18 15:40:23 -05009861}
9862
9863/**
James Smart0d878412009-10-02 15:16:56 -04009864 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
9865 * @phba: pointer to lpfc hba data structure.
9866 *
9867 * This routine is called to prepare the SLI3 device for PCI slot reset. It
9868 * disables the device interrupt and pci device, and aborts the internal FCP
9869 * pending I/Os.
9870 **/
9871static void
9872lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
9873{
James Smart0d878412009-10-02 15:16:56 -04009874 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -05009875 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -04009876
James Smart75baf692010-06-08 18:31:21 -04009877 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -04009878 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -04009879
James Smarte2af0d22010-03-15 11:25:32 -04009880 /* Block all SCSI devices' I/Os on the host */
9881 lpfc_scsi_dev_block(phba);
9882
James Smartea714f32013-04-17 20:18:47 -04009883 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9884 lpfc_sli_flush_fcp_rings(phba);
9885
James Smarte2af0d22010-03-15 11:25:32 -04009886 /* stop all timers */
9887 lpfc_stop_hba_timers(phba);
9888
James Smart0d878412009-10-02 15:16:56 -04009889 /* Disable interrupt and pci device */
9890 lpfc_sli_disable_intr(phba);
9891 pci_disable_device(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -04009892}
9893
9894/**
9895 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
9896 * @phba: pointer to lpfc hba data structure.
9897 *
9898 * This routine is called to prepare the SLI3 device for PCI slot permanently
9899 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
9900 * pending I/Os.
9901 **/
9902static void
James Smart75baf692010-06-08 18:31:21 -04009903lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -04009904{
9905 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -05009906 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -04009907 /* Block all SCSI devices' I/Os on the host */
9908 lpfc_scsi_dev_block(phba);
9909
9910 /* stop all timers */
9911 lpfc_stop_hba_timers(phba);
9912
James Smart0d878412009-10-02 15:16:56 -04009913 /* Clean up all driver's outstanding SCSI I/Os */
9914 lpfc_sli_flush_fcp_rings(phba);
9915}
9916
9917/**
James Smart3772a992009-05-22 14:50:54 -04009918 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -04009919 * @pdev: pointer to PCI device.
9920 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -06009921 *
James Smart3772a992009-05-22 14:50:54 -04009922 * This routine is called from the PCI subsystem for I/O error handling to
9923 * device with SLI-3 interface spec. This function is called by the PCI
9924 * subsystem after a PCI bus error affecting this device has been detected.
9925 * When this function is invoked, it will need to stop all the I/Os and
9926 * interrupt(s) to the device. Once that is done, it will return
9927 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
9928 * as desired.
James Smarte59058c2008-08-24 21:49:00 -04009929 *
9930 * Return codes
James Smart0d878412009-10-02 15:16:56 -04009931 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -04009932 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
9933 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -04009934 **/
James Smart3772a992009-05-22 14:50:54 -04009935static pci_ers_result_t
9936lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -06009937{
James Smart51ef4c22007-08-02 11:10:31 -04009938 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9939 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009940
James Smart0d878412009-10-02 15:16:56 -04009941 switch (state) {
9942 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -05009943 /* Non-fatal error, prepare for recovery */
9944 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -04009945 return PCI_ERS_RESULT_CAN_RECOVER;
9946 case pci_channel_io_frozen:
9947 /* Fatal error, prepare for slot reset */
9948 lpfc_sli_prep_dev_for_reset(phba);
9949 return PCI_ERS_RESULT_NEED_RESET;
9950 case pci_channel_io_perm_failure:
9951 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -04009952 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06009953 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -04009954 default:
9955 /* Unknown state, prepare and request slot reset */
9956 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9957 "0472 Unknown PCI error state: x%x\n", state);
9958 lpfc_sli_prep_dev_for_reset(phba);
9959 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -04009960 }
Linas Vepstas8d63f372007-02-14 14:28:36 -06009961}
9962
9963/**
James Smart3772a992009-05-22 14:50:54 -04009964 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -04009965 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -06009966 *
James Smart3772a992009-05-22 14:50:54 -04009967 * This routine is called from the PCI subsystem for error handling to
9968 * device with SLI-3 interface spec. This is called after PCI bus has been
9969 * reset to restart the PCI card from scratch, as if from a cold-boot.
9970 * During the PCI subsystem error recovery, after driver returns
9971 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
9972 * recovery and then call this routine before calling the .resume method
9973 * to recover the device. This function will initialize the HBA device,
9974 * enable the interrupt, but it will just put the HBA to offline state
9975 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -04009976 *
9977 * Return codes
James Smart3772a992009-05-22 14:50:54 -04009978 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
9979 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -06009980 */
James Smart3772a992009-05-22 14:50:54 -04009981static pci_ers_result_t
9982lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -06009983{
James Smart51ef4c22007-08-02 11:10:31 -04009984 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9985 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009986 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -05009987 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06009988
9989 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11009990 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -06009991 printk(KERN_ERR "lpfc: Cannot re-enable "
9992 "PCI device after reset.\n");
9993 return PCI_ERS_RESULT_DISCONNECT;
9994 }
9995
James Smart97207482008-12-04 22:39:19 -05009996 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -05009997
9998 /*
9999 * As the new kernel behavior of pci_restore_state() API call clears
10000 * device saved_state flag, need to save the restored state again.
10001 */
10002 pci_save_state(pdev);
10003
James Smart97207482008-12-04 22:39:19 -050010004 if (pdev->is_busmaster)
10005 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010006
James Smart92d7f7b2007-06-17 19:56:38 -050010007 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040010008 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -050010009 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010010
James Smart5b75da22008-12-04 22:39:35 -050010011 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040010012 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050010013 if (intr_mode == LPFC_INTR_ERROR) {
10014 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10015 "0427 Cannot re-enable interrupt after "
10016 "slot reset.\n");
10017 return PCI_ERS_RESULT_DISCONNECT;
10018 } else
10019 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010020
James Smart75baf692010-06-08 18:31:21 -040010021 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -040010022 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010023 lpfc_offline(phba);
10024 lpfc_sli_brdrestart(phba);
10025
James Smart5b75da22008-12-04 22:39:35 -050010026 /* Log the current active interrupt mode */
10027 lpfc_log_intr_mode(phba, phba->intr_mode);
10028
Linas Vepstas8d63f372007-02-14 14:28:36 -060010029 return PCI_ERS_RESULT_RECOVERED;
10030}
10031
10032/**
James Smart3772a992009-05-22 14:50:54 -040010033 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -040010034 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -060010035 *
James Smart3772a992009-05-22 14:50:54 -040010036 * This routine is called from the PCI subsystem for error handling to device
10037 * with SLI-3 interface spec. It is called when kernel error recovery tells
10038 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10039 * error recovery. After this call, traffic can start to flow from this device
10040 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010041 */
James Smart3772a992009-05-22 14:50:54 -040010042static void
10043lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010044{
James Smart51ef4c22007-08-02 11:10:31 -040010045 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10046 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010047
James Smarte2af0d22010-03-15 11:25:32 -040010048 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -040010049 lpfc_online(phba);
James Smart0d878412009-10-02 15:16:56 -040010050
10051 /* Clean up Advanced Error Reporting (AER) if needed */
10052 if (phba->hba_flag & HBA_AER_ENABLED)
10053 pci_cleanup_aer_uncorrect_error_status(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010054}
10055
James Smart3772a992009-05-22 14:50:54 -040010056/**
James Smartda0436e2009-05-22 14:51:39 -040010057 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
10058 * @phba: pointer to lpfc hba data structure.
10059 *
10060 * returns the number of ELS/CT IOCBs to reserve
10061 **/
10062int
10063lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
10064{
10065 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
10066
James Smartf1126682009-06-10 17:22:44 -040010067 if (phba->sli_rev == LPFC_SLI_REV4) {
10068 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -040010069 return 10;
James Smartf1126682009-06-10 17:22:44 -040010070 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -040010071 return 25;
James Smartf1126682009-06-10 17:22:44 -040010072 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -040010073 return 50;
James Smartf1126682009-06-10 17:22:44 -040010074 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -040010075 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -040010076 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -040010077 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -040010078 else if (max_xri <= 2048)
10079 return 200;
10080 else
10081 return 250;
James Smartf1126682009-06-10 17:22:44 -040010082 } else
10083 return 0;
James Smartda0436e2009-05-22 14:51:39 -040010084}
10085
10086/**
James Smart52d52442011-05-24 11:42:45 -040010087 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -040010088 * @fw: pointer to firmware image returned from request_firmware.
James Smartce396282012-09-29 11:30:56 -040010089 * @phba: pointer to lpfc hba data structure.
James Smart52d52442011-05-24 11:42:45 -040010090 *
James Smart52d52442011-05-24 11:42:45 -040010091 **/
James Smartce396282012-09-29 11:30:56 -040010092static void
10093lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -040010094{
James Smartce396282012-09-29 11:30:56 -040010095 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -050010096 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -040010097 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -040010098 struct list_head dma_buffer_list;
10099 int i, rc = 0;
10100 struct lpfc_dmabuf *dmabuf, *next;
10101 uint32_t offset = 0, temp_offset = 0;
10102
James Smartc71ab862012-10-31 14:44:33 -040010103 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -040010104 if (!fw) {
10105 rc = -ENXIO;
10106 goto out;
10107 }
10108 image = (struct lpfc_grp_hdr *)fw->data;
10109
James Smart52d52442011-05-24 11:42:45 -040010110 INIT_LIST_HEAD(&dma_buffer_list);
James Smart079b5c92011-08-21 21:48:49 -040010111 if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) ||
10112 (bf_get_be32(lpfc_grp_hdr_file_type, image) !=
10113 LPFC_FILE_TYPE_GROUP) ||
10114 (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) ||
10115 (be32_to_cpu(image->size) != fw->size)) {
James Smart52d52442011-05-24 11:42:45 -040010116 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10117 "3022 Invalid FW image found. "
James Smart079b5c92011-08-21 21:48:49 -040010118 "Magic:%x Type:%x ID:%x\n",
10119 be32_to_cpu(image->magic_number),
10120 bf_get_be32(lpfc_grp_hdr_file_type, image),
10121 bf_get_be32(lpfc_grp_hdr_id, image));
James Smartce396282012-09-29 11:30:56 -040010122 rc = -EINVAL;
10123 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010124 }
10125 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -040010126 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -040010127 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartce396282012-09-29 11:30:56 -040010128 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -040010129 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -040010130 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -040010131 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
10132 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
10133 GFP_KERNEL);
10134 if (!dmabuf) {
10135 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040010136 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010137 }
10138 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
10139 SLI4_PAGE_SIZE,
10140 &dmabuf->phys,
10141 GFP_KERNEL);
10142 if (!dmabuf->virt) {
10143 kfree(dmabuf);
10144 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040010145 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010146 }
10147 list_add_tail(&dmabuf->list, &dma_buffer_list);
10148 }
10149 while (offset < fw->size) {
10150 temp_offset = offset;
10151 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -040010152 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -040010153 memcpy(dmabuf->virt,
10154 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -040010155 fw->size - temp_offset);
10156 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -040010157 break;
10158 }
James Smart52d52442011-05-24 11:42:45 -040010159 memcpy(dmabuf->virt, fw->data + temp_offset,
10160 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -040010161 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -040010162 }
10163 rc = lpfc_wr_object(phba, &dma_buffer_list,
10164 (fw->size - offset), &offset);
James Smartce396282012-09-29 11:30:56 -040010165 if (rc)
10166 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010167 }
10168 rc = offset;
10169 }
James Smartce396282012-09-29 11:30:56 -040010170
10171release_out:
James Smart52d52442011-05-24 11:42:45 -040010172 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
10173 list_del(&dmabuf->list);
10174 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
10175 dmabuf->virt, dmabuf->phys);
10176 kfree(dmabuf);
10177 }
James Smartce396282012-09-29 11:30:56 -040010178 release_firmware(fw);
10179out:
10180 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc71ab862012-10-31 14:44:33 -040010181 "3024 Firmware update done: %d.\n", rc);
James Smartce396282012-09-29 11:30:56 -040010182 return;
James Smart52d52442011-05-24 11:42:45 -040010183}
10184
10185/**
James Smartc71ab862012-10-31 14:44:33 -040010186 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
10187 * @phba: pointer to lpfc hba data structure.
10188 *
10189 * This routine is called to perform Linux generic firmware upgrade on device
10190 * that supports such feature.
10191 **/
10192int
10193lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
10194{
10195 uint8_t file_name[ELX_MODEL_NAME_SIZE];
10196 int ret;
10197 const struct firmware *fw;
10198
10199 /* Only supported on SLI4 interface type 2 for now */
10200 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
10201 LPFC_SLI_INTF_IF_TYPE_2)
10202 return -EPERM;
10203
10204 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
10205
10206 if (fw_upgrade == INT_FW_UPGRADE) {
10207 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
10208 file_name, &phba->pcidev->dev,
10209 GFP_KERNEL, (void *)phba,
10210 lpfc_write_firmware);
10211 } else if (fw_upgrade == RUN_FW_UPGRADE) {
10212 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
10213 if (!ret)
10214 lpfc_write_firmware(fw, (void *)phba);
10215 } else {
10216 ret = -EINVAL;
10217 }
10218
10219 return ret;
10220}
10221
10222/**
James Smartda0436e2009-05-22 14:51:39 -040010223 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
10224 * @pdev: pointer to PCI device
10225 * @pid: pointer to PCI device identifier
10226 *
10227 * This routine is called from the kernel's PCI subsystem to device with
10228 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10229 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10230 * information of the device and driver to see if the driver state that it
10231 * can support this kind of device. If the match is successful, the driver
10232 * core invokes this routine. If this routine determines it can claim the HBA,
10233 * it does all the initialization that it needs to do to handle the HBA
10234 * properly.
10235 *
10236 * Return code
10237 * 0 - driver can claim the device
10238 * negative value - driver can not claim the device
10239 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010240static int
James Smartda0436e2009-05-22 14:51:39 -040010241lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
10242{
10243 struct lpfc_hba *phba;
10244 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040010245 struct Scsi_Host *shost = NULL;
James Smartce396282012-09-29 11:30:56 -040010246 int error, ret;
James Smartda0436e2009-05-22 14:51:39 -040010247 uint32_t cfg_mode, intr_mode;
James Smart67d12732012-08-03 12:36:13 -040010248 int adjusted_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -040010249
10250 /* Allocate memory for HBA structure */
10251 phba = lpfc_hba_alloc(pdev);
10252 if (!phba)
10253 return -ENOMEM;
10254
10255 /* Perform generic PCI device enabling operation */
10256 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040010257 if (error)
James Smartda0436e2009-05-22 14:51:39 -040010258 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -040010259
10260 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
10261 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
10262 if (error)
10263 goto out_disable_pci_dev;
10264
10265 /* Set up SLI-4 specific device PCI memory space */
10266 error = lpfc_sli4_pci_mem_setup(phba);
10267 if (error) {
10268 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10269 "1410 Failed to set up pci memory space.\n");
10270 goto out_disable_pci_dev;
10271 }
10272
10273 /* Set up phase-1 common device driver resources */
10274 error = lpfc_setup_driver_resource_phase1(phba);
10275 if (error) {
10276 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10277 "1411 Failed to set up driver resource.\n");
10278 goto out_unset_pci_mem_s4;
10279 }
10280
10281 /* Set up SLI-4 Specific device driver resources */
10282 error = lpfc_sli4_driver_resource_setup(phba);
10283 if (error) {
10284 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10285 "1412 Failed to set up driver resource.\n");
10286 goto out_unset_pci_mem_s4;
10287 }
10288
10289 /* Initialize and populate the iocb list per host */
James Smart2a9bf3d2010-06-07 15:24:45 -040010290
10291 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10292 "2821 initialize iocb list %d.\n",
10293 phba->cfg_iocb_cnt*1024);
10294 error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
10295
James Smartda0436e2009-05-22 14:51:39 -040010296 if (error) {
10297 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10298 "1413 Failed to initialize iocb list.\n");
10299 goto out_unset_driver_resource_s4;
10300 }
10301
James Smart19ca7602010-11-20 23:11:55 -050010302 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -040010303 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -050010304
James Smartda0436e2009-05-22 14:51:39 -040010305 /* Set up common device driver resources */
10306 error = lpfc_setup_driver_resource_phase2(phba);
10307 if (error) {
10308 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10309 "1414 Failed to set up driver resource.\n");
10310 goto out_free_iocb_list;
10311 }
10312
James Smart079b5c92011-08-21 21:48:49 -040010313 /* Get the default values for Model Name and Description */
10314 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
10315
James Smartda0436e2009-05-22 14:51:39 -040010316 /* Create SCSI host to the physical port */
10317 error = lpfc_create_shost(phba);
10318 if (error) {
10319 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10320 "1415 Failed to create scsi host.\n");
10321 goto out_unset_driver_resource;
10322 }
10323
10324 /* Configure sysfs attributes */
10325 vport = phba->pport;
10326 error = lpfc_alloc_sysfs_attr(vport);
10327 if (error) {
10328 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10329 "1416 Failed to allocate sysfs attr\n");
10330 goto out_destroy_shost;
10331 }
10332
James Smart6669f9b2009-10-02 15:16:45 -040010333 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -040010334 /* Now, trying to enable interrupt and bring up the device */
10335 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -040010336
James Smart7b15db32013-01-03 15:43:29 -050010337 /* Put device to a known state before enabling interrupt */
10338 lpfc_stop_port(phba);
10339 /* Configure and enable interrupt */
10340 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
10341 if (intr_mode == LPFC_INTR_ERROR) {
10342 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10343 "0426 Failed to enable interrupt.\n");
10344 error = -ENODEV;
10345 goto out_free_sysfs_attr;
James Smartda0436e2009-05-22 14:51:39 -040010346 }
James Smart7b15db32013-01-03 15:43:29 -050010347 /* Default to single EQ for non-MSI-X */
10348 if (phba->intr_type != MSIX)
10349 adjusted_fcp_io_channel = 1;
10350 else
10351 adjusted_fcp_io_channel = phba->cfg_fcp_io_channel;
10352 phba->cfg_fcp_io_channel = adjusted_fcp_io_channel;
10353 /* Set up SLI-4 HBA */
10354 if (lpfc_sli4_hba_setup(phba)) {
10355 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10356 "1421 Failed to set up hba\n");
10357 error = -ENODEV;
10358 goto out_disable_intr;
10359 }
10360
10361 /* Log the current active interrupt mode */
10362 phba->intr_mode = intr_mode;
10363 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -040010364
10365 /* Perform post initialization setup */
10366 lpfc_post_init_setup(phba);
10367
James Smartc71ab862012-10-31 14:44:33 -040010368 /* check for firmware upgrade or downgrade */
10369 if (phba->cfg_request_firmware_upgrade)
10370 ret = lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -040010371
James Smart1c6834a2009-07-19 10:01:26 -040010372 /* Check if there are static vports to be created. */
10373 lpfc_create_static_vport(phba);
James Smartda0436e2009-05-22 14:51:39 -040010374 return 0;
10375
10376out_disable_intr:
10377 lpfc_sli4_disable_intr(phba);
10378out_free_sysfs_attr:
10379 lpfc_free_sysfs_attr(vport);
10380out_destroy_shost:
10381 lpfc_destroy_shost(phba);
10382out_unset_driver_resource:
10383 lpfc_unset_driver_resource_phase2(phba);
10384out_free_iocb_list:
10385 lpfc_free_iocb_list(phba);
10386out_unset_driver_resource_s4:
10387 lpfc_sli4_driver_resource_unset(phba);
10388out_unset_pci_mem_s4:
10389 lpfc_sli4_pci_mem_unset(phba);
10390out_disable_pci_dev:
10391 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040010392 if (shost)
10393 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -040010394out_free_phba:
10395 lpfc_hba_free(phba);
10396 return error;
10397}
10398
10399/**
10400 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
10401 * @pdev: pointer to PCI device
10402 *
10403 * This routine is called from the kernel's PCI subsystem to device with
10404 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10405 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10406 * device to be removed from the PCI subsystem properly.
10407 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010408static void
James Smartda0436e2009-05-22 14:51:39 -040010409lpfc_pci_remove_one_s4(struct pci_dev *pdev)
10410{
10411 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10412 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
10413 struct lpfc_vport **vports;
10414 struct lpfc_hba *phba = vport->phba;
10415 int i;
10416
10417 /* Mark the device unloading flag */
10418 spin_lock_irq(&phba->hbalock);
10419 vport->load_flag |= FC_UNLOADING;
10420 spin_unlock_irq(&phba->hbalock);
10421
10422 /* Free the HBA sysfs attributes */
10423 lpfc_free_sysfs_attr(vport);
10424
10425 /* Release all the vports against this physical port */
10426 vports = lpfc_create_vport_work_array(phba);
10427 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040010428 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10429 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
10430 continue;
James Smartda0436e2009-05-22 14:51:39 -040010431 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040010432 }
James Smartda0436e2009-05-22 14:51:39 -040010433 lpfc_destroy_vport_work_array(phba, vports);
10434
10435 /* Remove FC host and then SCSI host with the physical port */
10436 fc_remove_host(shost);
10437 scsi_remove_host(shost);
10438
10439 /* Perform cleanup on the physical port */
10440 lpfc_cleanup(vport);
10441
10442 /*
10443 * Bring down the SLI Layer. This step disables all interrupts,
10444 * clears the rings, discards all mailbox commands, and resets
10445 * the HBA FCoE function.
10446 */
10447 lpfc_debugfs_terminate(vport);
10448 lpfc_sli4_hba_unset(phba);
10449
10450 spin_lock_irq(&phba->hbalock);
10451 list_del_init(&vport->listentry);
10452 spin_unlock_irq(&phba->hbalock);
10453
James Smart3677a3a2010-09-29 11:19:14 -040010454 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -040010455 * buffers are released to their corresponding pools here.
10456 */
10457 lpfc_scsi_free(phba);
James Smart67d12732012-08-03 12:36:13 -040010458
James Smartda0436e2009-05-22 14:51:39 -040010459 lpfc_sli4_driver_resource_unset(phba);
10460
10461 /* Unmap adapter Control and Doorbell registers */
10462 lpfc_sli4_pci_mem_unset(phba);
10463
10464 /* Release PCI resources and disable device's PCI function */
10465 scsi_host_put(shost);
10466 lpfc_disable_pci_dev(phba);
10467
10468 /* Finally, free the driver's device data structure */
10469 lpfc_hba_free(phba);
10470
10471 return;
10472}
10473
10474/**
10475 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
10476 * @pdev: pointer to PCI device
10477 * @msg: power management message
10478 *
10479 * This routine is called from the kernel's PCI subsystem to support system
10480 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
10481 * this method, it quiesces the device by stopping the driver's worker
10482 * thread for the device, turning off device's interrupt and DMA, and bring
10483 * the device offline. Note that as the driver implements the minimum PM
10484 * requirements to a power-aware driver's PM support for suspend/resume -- all
10485 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
10486 * method call will be treated as SUSPEND and the driver will fully
10487 * reinitialize its device during resume() method call, the driver will set
10488 * device to PCI_D3hot state in PCI config space instead of setting it
10489 * according to the @msg provided by the PM.
10490 *
10491 * Return code
10492 * 0 - driver suspended the device
10493 * Error otherwise
10494 **/
10495static int
10496lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
10497{
10498 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10499 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10500
10501 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -040010502 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -040010503
10504 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040010505 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -040010506 lpfc_offline(phba);
10507 kthread_stop(phba->worker_thread);
10508
10509 /* Disable interrupt from device */
10510 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040010511 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040010512
10513 /* Save device state to PCI config space */
10514 pci_save_state(pdev);
10515 pci_set_power_state(pdev, PCI_D3hot);
10516
10517 return 0;
10518}
10519
10520/**
10521 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
10522 * @pdev: pointer to PCI device
10523 *
10524 * This routine is called from the kernel's PCI subsystem to support system
10525 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
10526 * this method, it restores the device's PCI config space state and fully
10527 * reinitializes the device and brings it online. Note that as the driver
10528 * implements the minimum PM requirements to a power-aware driver's PM for
10529 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10530 * to the suspend() method call will be treated as SUSPEND and the driver
10531 * will fully reinitialize its device during resume() method call, the device
10532 * will be set to PCI_D0 directly in PCI config space before restoring the
10533 * state.
10534 *
10535 * Return code
10536 * 0 - driver suspended the device
10537 * Error otherwise
10538 **/
10539static int
10540lpfc_pci_resume_one_s4(struct pci_dev *pdev)
10541{
10542 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10543 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10544 uint32_t intr_mode;
10545 int error;
10546
10547 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10548 "0292 PCI device Power Management resume.\n");
10549
10550 /* Restore device state from PCI config space */
10551 pci_set_power_state(pdev, PCI_D0);
10552 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050010553
10554 /*
10555 * As the new kernel behavior of pci_restore_state() API call clears
10556 * device saved_state flag, need to save the restored state again.
10557 */
10558 pci_save_state(pdev);
10559
James Smartda0436e2009-05-22 14:51:39 -040010560 if (pdev->is_busmaster)
10561 pci_set_master(pdev);
10562
10563 /* Startup the kernel thread for this host adapter. */
10564 phba->worker_thread = kthread_run(lpfc_do_work, phba,
10565 "lpfc_worker_%d", phba->brd_no);
10566 if (IS_ERR(phba->worker_thread)) {
10567 error = PTR_ERR(phba->worker_thread);
10568 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10569 "0293 PM resume failed to start worker "
10570 "thread: error=x%x.\n", error);
10571 return error;
10572 }
10573
10574 /* Configure and enable interrupt */
10575 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
10576 if (intr_mode == LPFC_INTR_ERROR) {
10577 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10578 "0294 PM resume Failed to enable interrupt\n");
10579 return -EIO;
10580 } else
10581 phba->intr_mode = intr_mode;
10582
10583 /* Restart HBA and bring it online */
10584 lpfc_sli_brdrestart(phba);
10585 lpfc_online(phba);
10586
10587 /* Log the current active interrupt mode */
10588 lpfc_log_intr_mode(phba, phba->intr_mode);
10589
10590 return 0;
10591}
10592
10593/**
James Smart75baf692010-06-08 18:31:21 -040010594 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
10595 * @phba: pointer to lpfc hba data structure.
10596 *
10597 * This routine is called to prepare the SLI4 device for PCI slot recover. It
10598 * aborts all the outstanding SCSI I/Os to the pci device.
10599 **/
10600static void
10601lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
10602{
James Smart75baf692010-06-08 18:31:21 -040010603 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10604 "2828 PCI channel I/O abort preparing for recovery\n");
10605 /*
10606 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10607 * and let the SCSI mid-layer to retry them to recover.
10608 */
James Smartdb55fba2014-04-04 13:52:02 -040010609 lpfc_sli_abort_fcp_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040010610}
10611
10612/**
10613 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
10614 * @phba: pointer to lpfc hba data structure.
10615 *
10616 * This routine is called to prepare the SLI4 device for PCI slot reset. It
10617 * disables the device interrupt and pci device, and aborts the internal FCP
10618 * pending I/Os.
10619 **/
10620static void
10621lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
10622{
10623 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10624 "2826 PCI channel disable preparing for reset\n");
10625
10626 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040010627 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010628
10629 /* Block all SCSI devices' I/Os on the host */
10630 lpfc_scsi_dev_block(phba);
10631
James Smartea714f32013-04-17 20:18:47 -040010632 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10633 lpfc_sli_flush_fcp_rings(phba);
10634
James Smart75baf692010-06-08 18:31:21 -040010635 /* stop all timers */
10636 lpfc_stop_hba_timers(phba);
10637
10638 /* Disable interrupt and pci device */
10639 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040010640 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -040010641 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -040010642}
10643
10644/**
10645 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
10646 * @phba: pointer to lpfc hba data structure.
10647 *
10648 * This routine is called to prepare the SLI4 device for PCI slot permanently
10649 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10650 * pending I/Os.
10651 **/
10652static void
10653lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
10654{
10655 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10656 "2827 PCI channel permanent disable for failure\n");
10657
10658 /* Block all SCSI devices' I/Os on the host */
10659 lpfc_scsi_dev_block(phba);
10660
10661 /* stop all timers */
10662 lpfc_stop_hba_timers(phba);
10663
10664 /* Clean up all driver's outstanding SCSI I/Os */
10665 lpfc_sli_flush_fcp_rings(phba);
10666}
10667
10668/**
James Smartda0436e2009-05-22 14:51:39 -040010669 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
10670 * @pdev: pointer to PCI device.
10671 * @state: the current PCI connection state.
10672 *
10673 * This routine is called from the PCI subsystem for error handling to device
10674 * with SLI-4 interface spec. This function is called by the PCI subsystem
10675 * after a PCI bus error affecting this device has been detected. When this
10676 * function is invoked, it will need to stop all the I/Os and interrupt(s)
10677 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
10678 * for the PCI subsystem to perform proper recovery as desired.
10679 *
10680 * Return codes
10681 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10682 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10683 **/
10684static pci_ers_result_t
10685lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
10686{
James Smart75baf692010-06-08 18:31:21 -040010687 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10688 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10689
10690 switch (state) {
10691 case pci_channel_io_normal:
10692 /* Non-fatal error, prepare for recovery */
10693 lpfc_sli4_prep_dev_for_recover(phba);
10694 return PCI_ERS_RESULT_CAN_RECOVER;
10695 case pci_channel_io_frozen:
10696 /* Fatal error, prepare for slot reset */
10697 lpfc_sli4_prep_dev_for_reset(phba);
10698 return PCI_ERS_RESULT_NEED_RESET;
10699 case pci_channel_io_perm_failure:
10700 /* Permanent failure, prepare for device down */
10701 lpfc_sli4_prep_dev_for_perm_failure(phba);
10702 return PCI_ERS_RESULT_DISCONNECT;
10703 default:
10704 /* Unknown state, prepare and request slot reset */
10705 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10706 "2825 Unknown PCI error state: x%x\n", state);
10707 lpfc_sli4_prep_dev_for_reset(phba);
10708 return PCI_ERS_RESULT_NEED_RESET;
10709 }
James Smartda0436e2009-05-22 14:51:39 -040010710}
10711
10712/**
10713 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
10714 * @pdev: pointer to PCI device.
10715 *
10716 * This routine is called from the PCI subsystem for error handling to device
10717 * with SLI-4 interface spec. It is called after PCI bus has been reset to
10718 * restart the PCI card from scratch, as if from a cold-boot. During the
10719 * PCI subsystem error recovery, after the driver returns
10720 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10721 * recovery and then call this routine before calling the .resume method to
10722 * recover the device. This function will initialize the HBA device, enable
10723 * the interrupt, but it will just put the HBA to offline state without
10724 * passing any I/O traffic.
10725 *
10726 * Return codes
10727 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10728 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10729 */
10730static pci_ers_result_t
10731lpfc_io_slot_reset_s4(struct pci_dev *pdev)
10732{
James Smart75baf692010-06-08 18:31:21 -040010733 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10734 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10735 struct lpfc_sli *psli = &phba->sli;
10736 uint32_t intr_mode;
10737
10738 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
10739 if (pci_enable_device_mem(pdev)) {
10740 printk(KERN_ERR "lpfc: Cannot re-enable "
10741 "PCI device after reset.\n");
10742 return PCI_ERS_RESULT_DISCONNECT;
10743 }
10744
10745 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040010746
10747 /*
10748 * As the new kernel behavior of pci_restore_state() API call clears
10749 * device saved_state flag, need to save the restored state again.
10750 */
10751 pci_save_state(pdev);
10752
James Smart75baf692010-06-08 18:31:21 -040010753 if (pdev->is_busmaster)
10754 pci_set_master(pdev);
10755
10756 spin_lock_irq(&phba->hbalock);
10757 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
10758 spin_unlock_irq(&phba->hbalock);
10759
10760 /* Configure and enable interrupt */
10761 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
10762 if (intr_mode == LPFC_INTR_ERROR) {
10763 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10764 "2824 Cannot re-enable interrupt after "
10765 "slot reset.\n");
10766 return PCI_ERS_RESULT_DISCONNECT;
10767 } else
10768 phba->intr_mode = intr_mode;
10769
10770 /* Log the current active interrupt mode */
10771 lpfc_log_intr_mode(phba, phba->intr_mode);
10772
James Smartda0436e2009-05-22 14:51:39 -040010773 return PCI_ERS_RESULT_RECOVERED;
10774}
10775
10776/**
10777 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
10778 * @pdev: pointer to PCI device
10779 *
10780 * This routine is called from the PCI subsystem for error handling to device
10781 * with SLI-4 interface spec. It is called when kernel error recovery tells
10782 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10783 * error recovery. After this call, traffic can start to flow from this device
10784 * again.
10785 **/
10786static void
10787lpfc_io_resume_s4(struct pci_dev *pdev)
10788{
James Smart75baf692010-06-08 18:31:21 -040010789 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10790 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10791
10792 /*
10793 * In case of slot reset, as function reset is performed through
10794 * mailbox command which needs DMA to be enabled, this operation
10795 * has to be moved to the io resume phase. Taking device offline
10796 * will perform the necessary cleanup.
10797 */
10798 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
10799 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040010800 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010801 lpfc_offline(phba);
10802 lpfc_sli_brdrestart(phba);
10803 /* Bring the device back online */
10804 lpfc_online(phba);
10805 }
10806
10807 /* Clean up Advanced Error Reporting (AER) if needed */
10808 if (phba->hba_flag & HBA_AER_ENABLED)
10809 pci_cleanup_aer_uncorrect_error_status(pdev);
James Smartda0436e2009-05-22 14:51:39 -040010810}
10811
10812/**
James Smart3772a992009-05-22 14:50:54 -040010813 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
10814 * @pdev: pointer to PCI device
10815 * @pid: pointer to PCI device identifier
10816 *
10817 * This routine is to be registered to the kernel's PCI subsystem. When an
10818 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
10819 * at PCI device-specific information of the device and driver to see if the
10820 * driver state that it can support this kind of device. If the match is
10821 * successful, the driver core invokes this routine. This routine dispatches
10822 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
10823 * do all the initialization that it needs to do to handle the HBA device
10824 * properly.
10825 *
10826 * Return code
10827 * 0 - driver can claim the device
10828 * negative value - driver can not claim the device
10829 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010830static int
James Smart3772a992009-05-22 14:50:54 -040010831lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
10832{
10833 int rc;
James Smart8fa38512009-07-19 10:01:03 -040010834 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040010835
James Smart28baac72010-02-12 14:42:03 -050010836 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040010837 return -ENODEV;
10838
James Smart8fa38512009-07-19 10:01:03 -040010839 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050010840 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040010841 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040010842 else
James Smart3772a992009-05-22 14:50:54 -040010843 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040010844
James Smart3772a992009-05-22 14:50:54 -040010845 return rc;
10846}
10847
10848/**
10849 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
10850 * @pdev: pointer to PCI device
10851 *
10852 * This routine is to be registered to the kernel's PCI subsystem. When an
10853 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
10854 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
10855 * remove routine, which will perform all the necessary cleanup for the
10856 * device to be removed from the PCI subsystem properly.
10857 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010858static void
James Smart3772a992009-05-22 14:50:54 -040010859lpfc_pci_remove_one(struct pci_dev *pdev)
10860{
10861 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10862 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10863
10864 switch (phba->pci_dev_grp) {
10865 case LPFC_PCI_DEV_LP:
10866 lpfc_pci_remove_one_s3(pdev);
10867 break;
James Smartda0436e2009-05-22 14:51:39 -040010868 case LPFC_PCI_DEV_OC:
10869 lpfc_pci_remove_one_s4(pdev);
10870 break;
James Smart3772a992009-05-22 14:50:54 -040010871 default:
10872 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10873 "1424 Invalid PCI device group: 0x%x\n",
10874 phba->pci_dev_grp);
10875 break;
10876 }
10877 return;
10878}
10879
10880/**
10881 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
10882 * @pdev: pointer to PCI device
10883 * @msg: power management message
10884 *
10885 * This routine is to be registered to the kernel's PCI subsystem to support
10886 * system Power Management (PM). When PM invokes this method, it dispatches
10887 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
10888 * suspend the device.
10889 *
10890 * Return code
10891 * 0 - driver suspended the device
10892 * Error otherwise
10893 **/
10894static int
10895lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
10896{
10897 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10898 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10899 int rc = -ENODEV;
10900
10901 switch (phba->pci_dev_grp) {
10902 case LPFC_PCI_DEV_LP:
10903 rc = lpfc_pci_suspend_one_s3(pdev, msg);
10904 break;
James Smartda0436e2009-05-22 14:51:39 -040010905 case LPFC_PCI_DEV_OC:
10906 rc = lpfc_pci_suspend_one_s4(pdev, msg);
10907 break;
James Smart3772a992009-05-22 14:50:54 -040010908 default:
10909 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10910 "1425 Invalid PCI device group: 0x%x\n",
10911 phba->pci_dev_grp);
10912 break;
10913 }
10914 return rc;
10915}
10916
10917/**
10918 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
10919 * @pdev: pointer to PCI device
10920 *
10921 * This routine is to be registered to the kernel's PCI subsystem to support
10922 * system Power Management (PM). When PM invokes this method, it dispatches
10923 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
10924 * resume the device.
10925 *
10926 * Return code
10927 * 0 - driver suspended the device
10928 * Error otherwise
10929 **/
10930static int
10931lpfc_pci_resume_one(struct pci_dev *pdev)
10932{
10933 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10934 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10935 int rc = -ENODEV;
10936
10937 switch (phba->pci_dev_grp) {
10938 case LPFC_PCI_DEV_LP:
10939 rc = lpfc_pci_resume_one_s3(pdev);
10940 break;
James Smartda0436e2009-05-22 14:51:39 -040010941 case LPFC_PCI_DEV_OC:
10942 rc = lpfc_pci_resume_one_s4(pdev);
10943 break;
James Smart3772a992009-05-22 14:50:54 -040010944 default:
10945 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10946 "1426 Invalid PCI device group: 0x%x\n",
10947 phba->pci_dev_grp);
10948 break;
10949 }
10950 return rc;
10951}
10952
10953/**
10954 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
10955 * @pdev: pointer to PCI device.
10956 * @state: the current PCI connection state.
10957 *
10958 * This routine is registered to the PCI subsystem for error handling. This
10959 * function is called by the PCI subsystem after a PCI bus error affecting
10960 * this device has been detected. When this routine is invoked, it dispatches
10961 * the action to the proper SLI-3 or SLI-4 device error detected handling
10962 * routine, which will perform the proper error detected operation.
10963 *
10964 * Return codes
10965 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10966 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10967 **/
10968static pci_ers_result_t
10969lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
10970{
10971 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10972 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10973 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
10974
10975 switch (phba->pci_dev_grp) {
10976 case LPFC_PCI_DEV_LP:
10977 rc = lpfc_io_error_detected_s3(pdev, state);
10978 break;
James Smartda0436e2009-05-22 14:51:39 -040010979 case LPFC_PCI_DEV_OC:
10980 rc = lpfc_io_error_detected_s4(pdev, state);
10981 break;
James Smart3772a992009-05-22 14:50:54 -040010982 default:
10983 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10984 "1427 Invalid PCI device group: 0x%x\n",
10985 phba->pci_dev_grp);
10986 break;
10987 }
10988 return rc;
10989}
10990
10991/**
10992 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
10993 * @pdev: pointer to PCI device.
10994 *
10995 * This routine is registered to the PCI subsystem for error handling. This
10996 * function is called after PCI bus has been reset to restart the PCI card
10997 * from scratch, as if from a cold-boot. When this routine is invoked, it
10998 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
10999 * routine, which will perform the proper device reset.
11000 *
11001 * Return codes
11002 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11003 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11004 **/
11005static pci_ers_result_t
11006lpfc_io_slot_reset(struct pci_dev *pdev)
11007{
11008 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11009 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11010 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11011
11012 switch (phba->pci_dev_grp) {
11013 case LPFC_PCI_DEV_LP:
11014 rc = lpfc_io_slot_reset_s3(pdev);
11015 break;
James Smartda0436e2009-05-22 14:51:39 -040011016 case LPFC_PCI_DEV_OC:
11017 rc = lpfc_io_slot_reset_s4(pdev);
11018 break;
James Smart3772a992009-05-22 14:50:54 -040011019 default:
11020 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11021 "1428 Invalid PCI device group: 0x%x\n",
11022 phba->pci_dev_grp);
11023 break;
11024 }
11025 return rc;
11026}
11027
11028/**
11029 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
11030 * @pdev: pointer to PCI device
11031 *
11032 * This routine is registered to the PCI subsystem for error handling. It
11033 * is called when kernel error recovery tells the lpfc driver that it is
11034 * OK to resume normal PCI operation after PCI bus error recovery. When
11035 * this routine is invoked, it dispatches the action to the proper SLI-3
11036 * or SLI-4 device io_resume routine, which will resume the device operation.
11037 **/
11038static void
11039lpfc_io_resume(struct pci_dev *pdev)
11040{
11041 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11042 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11043
11044 switch (phba->pci_dev_grp) {
11045 case LPFC_PCI_DEV_LP:
11046 lpfc_io_resume_s3(pdev);
11047 break;
James Smartda0436e2009-05-22 14:51:39 -040011048 case LPFC_PCI_DEV_OC:
11049 lpfc_io_resume_s4(pdev);
11050 break;
James Smart3772a992009-05-22 14:50:54 -040011051 default:
11052 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11053 "1429 Invalid PCI device group: 0x%x\n",
11054 phba->pci_dev_grp);
11055 break;
11056 }
11057 return;
11058}
11059
James Smart1ba981f2014-02-20 09:56:45 -050011060/**
11061 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
11062 * @phba: pointer to lpfc hba data structure.
11063 *
11064 * This routine checks to see if OAS is supported for this adapter. If
11065 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
11066 * the enable oas flag is cleared and the pool created for OAS device data
11067 * is destroyed.
11068 *
11069 **/
11070void
11071lpfc_sli4_oas_verify(struct lpfc_hba *phba)
11072{
11073
11074 if (!phba->cfg_EnableXLane)
11075 return;
11076
11077 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
11078 phba->cfg_fof = 1;
11079 } else {
James Smartf38fa0b2014-04-04 13:52:21 -040011080 phba->cfg_fof = 0;
James Smart1ba981f2014-02-20 09:56:45 -050011081 if (phba->device_data_mem_pool)
11082 mempool_destroy(phba->device_data_mem_pool);
11083 phba->device_data_mem_pool = NULL;
11084 }
11085
11086 return;
11087}
11088
11089/**
11090 * lpfc_fof_queue_setup - Set up all the fof queues
11091 * @phba: pointer to lpfc hba data structure.
11092 *
11093 * This routine is invoked to set up all the fof queues for the FC HBA
11094 * operation.
11095 *
11096 * Return codes
11097 * 0 - successful
11098 * -ENOMEM - No available memory
11099 **/
11100int
11101lpfc_fof_queue_setup(struct lpfc_hba *phba)
11102{
11103 struct lpfc_sli *psli = &phba->sli;
11104 int rc;
11105
11106 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
11107 if (rc)
11108 return -ENOMEM;
11109
James Smartf38fa0b2014-04-04 13:52:21 -040011110 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050011111
11112 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
11113 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
11114 if (rc)
11115 goto out_oas_cq;
11116
11117 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
11118 phba->sli4_hba.oas_cq, LPFC_FCP);
11119 if (rc)
11120 goto out_oas_wq;
11121
11122 phba->sli4_hba.oas_cq->pring = &psli->ring[LPFC_FCP_OAS_RING];
11123 phba->sli4_hba.oas_ring = &psli->ring[LPFC_FCP_OAS_RING];
11124 }
11125
11126 return 0;
11127
11128out_oas_wq:
James Smartf38fa0b2014-04-04 13:52:21 -040011129 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
James Smart1ba981f2014-02-20 09:56:45 -050011130out_oas_cq:
11131 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
11132 return rc;
11133
11134}
11135
11136/**
11137 * lpfc_fof_queue_create - Create all the fof queues
11138 * @phba: pointer to lpfc hba data structure.
11139 *
11140 * This routine is invoked to allocate all the fof queues for the FC HBA
11141 * operation. For each SLI4 queue type, the parameters such as queue entry
11142 * count (queue depth) shall be taken from the module parameter. For now,
11143 * we just use some constant number as place holder.
11144 *
11145 * Return codes
11146 * 0 - successful
11147 * -ENOMEM - No availble memory
11148 * -EIO - The mailbox failed to complete successfully.
11149 **/
11150int
11151lpfc_fof_queue_create(struct lpfc_hba *phba)
11152{
11153 struct lpfc_queue *qdesc;
11154
11155 /* Create FOF EQ */
11156 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
11157 phba->sli4_hba.eq_ecount);
11158 if (!qdesc)
11159 goto out_error;
11160
11161 phba->sli4_hba.fof_eq = qdesc;
11162
James Smartf38fa0b2014-04-04 13:52:21 -040011163 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050011164
11165 /* Create OAS CQ */
11166 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
11167 phba->sli4_hba.cq_ecount);
11168 if (!qdesc)
11169 goto out_error;
11170
11171 phba->sli4_hba.oas_cq = qdesc;
11172
11173 /* Create OAS WQ */
11174 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
11175 phba->sli4_hba.wq_ecount);
11176 if (!qdesc)
11177 goto out_error;
11178
11179 phba->sli4_hba.oas_wq = qdesc;
11180
11181 }
11182 return 0;
11183
11184out_error:
11185 lpfc_fof_queue_destroy(phba);
11186 return -ENOMEM;
11187}
11188
11189/**
11190 * lpfc_fof_queue_destroy - Destroy all the fof queues
11191 * @phba: pointer to lpfc hba data structure.
11192 *
11193 * This routine is invoked to release all the SLI4 queues with the FC HBA
11194 * operation.
11195 *
11196 * Return codes
11197 * 0 - successful
11198 **/
11199int
11200lpfc_fof_queue_destroy(struct lpfc_hba *phba)
11201{
11202 /* Release FOF Event queue */
11203 if (phba->sli4_hba.fof_eq != NULL) {
11204 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
11205 phba->sli4_hba.fof_eq = NULL;
11206 }
11207
11208 /* Release OAS Completion queue */
11209 if (phba->sli4_hba.oas_cq != NULL) {
11210 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
11211 phba->sli4_hba.oas_cq = NULL;
11212 }
11213
11214 /* Release OAS Work queue */
11215 if (phba->sli4_hba.oas_wq != NULL) {
11216 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
11217 phba->sli4_hba.oas_wq = NULL;
11218 }
11219 return 0;
11220}
11221
dea31012005-04-17 16:05:31 -050011222static struct pci_device_id lpfc_id_table[] = {
11223 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
11224 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -040011225 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
11226 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011227 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
11228 PCI_ANY_ID, PCI_ANY_ID, },
11229 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
11230 PCI_ANY_ID, PCI_ANY_ID, },
11231 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
11232 PCI_ANY_ID, PCI_ANY_ID, },
11233 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
11234 PCI_ANY_ID, PCI_ANY_ID, },
11235 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
11236 PCI_ANY_ID, PCI_ANY_ID, },
11237 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
11238 PCI_ANY_ID, PCI_ANY_ID, },
11239 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
11240 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011241 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
11242 PCI_ANY_ID, PCI_ANY_ID, },
11243 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
11244 PCI_ANY_ID, PCI_ANY_ID, },
11245 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
11246 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011247 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
11248 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011249 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
11250 PCI_ANY_ID, PCI_ANY_ID, },
11251 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
11252 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011253 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
11254 PCI_ANY_ID, PCI_ANY_ID, },
11255 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
11256 PCI_ANY_ID, PCI_ANY_ID, },
11257 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
11258 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -040011259 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
11260 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011261 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
11262 PCI_ANY_ID, PCI_ANY_ID, },
11263 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
11264 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011265 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
11266 PCI_ANY_ID, PCI_ANY_ID, },
11267 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
11268 PCI_ANY_ID, PCI_ANY_ID, },
11269 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
11270 PCI_ANY_ID, PCI_ANY_ID, },
11271 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
11272 PCI_ANY_ID, PCI_ANY_ID, },
11273 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
11274 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011275 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
11276 PCI_ANY_ID, PCI_ANY_ID, },
11277 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
11278 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -040011279 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
11280 PCI_ANY_ID, PCI_ANY_ID, },
11281 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
11282 PCI_ANY_ID, PCI_ANY_ID, },
11283 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
11284 PCI_ANY_ID, PCI_ANY_ID, },
11285 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
11286 PCI_ANY_ID, PCI_ANY_ID, },
11287 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
11288 PCI_ANY_ID, PCI_ANY_ID, },
11289 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
11290 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -040011291 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
11292 PCI_ANY_ID, PCI_ANY_ID, },
11293 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
11294 PCI_ANY_ID, PCI_ANY_ID, },
11295 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
11296 PCI_ANY_ID, PCI_ANY_ID, },
James Smart3772a992009-05-22 14:50:54 -040011297 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
11298 PCI_ANY_ID, PCI_ANY_ID, },
James Smarta747c9c2009-11-18 15:41:10 -050011299 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT,
11300 PCI_ANY_ID, PCI_ANY_ID, },
11301 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON,
James Smart6669f9b2009-10-02 15:16:45 -040011302 PCI_ANY_ID, PCI_ANY_ID, },
James Smart98fc5dd2010-06-07 15:24:29 -040011303 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS,
11304 PCI_ANY_ID, PCI_ANY_ID, },
James Smart085c6472010-11-20 23:11:37 -050011305 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC,
11306 PCI_ANY_ID, PCI_ANY_ID, },
11307 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE,
11308 PCI_ANY_ID, PCI_ANY_ID, },
James Smartc0c11512011-05-24 11:41:34 -040011309 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF,
11310 PCI_ANY_ID, PCI_ANY_ID, },
11311 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF,
11312 PCI_ANY_ID, PCI_ANY_ID, },
James Smartf8cafd32012-08-03 12:42:51 -040011313 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK,
11314 PCI_ANY_ID, PCI_ANY_ID, },
11315 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF,
11316 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011317 { 0 }
11318};
11319
11320MODULE_DEVICE_TABLE(pci, lpfc_id_table);
11321
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070011322static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060011323 .error_detected = lpfc_io_error_detected,
11324 .slot_reset = lpfc_io_slot_reset,
11325 .resume = lpfc_io_resume,
11326};
11327
dea31012005-04-17 16:05:31 -050011328static struct pci_driver lpfc_driver = {
11329 .name = LPFC_DRIVER_NAME,
11330 .id_table = lpfc_id_table,
11331 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011332 .remove = lpfc_pci_remove_one,
James Smart3a55b532008-12-04 22:38:54 -050011333 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040011334 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050011335 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050011336};
11337
James Smart3ef6d242012-01-18 16:23:48 -050011338static const struct file_operations lpfc_mgmt_fop = {
Al Viro858feac2013-04-14 22:39:37 -040011339 .owner = THIS_MODULE,
James Smart3ef6d242012-01-18 16:23:48 -050011340};
11341
11342static struct miscdevice lpfc_mgmt_dev = {
11343 .minor = MISC_DYNAMIC_MINOR,
11344 .name = "lpfcmgmt",
11345 .fops = &lpfc_mgmt_fop,
11346};
11347
James Smarte59058c2008-08-24 21:49:00 -040011348/**
James Smart3621a712009-04-06 18:47:14 -040011349 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040011350 *
11351 * This routine is to be invoked when the lpfc module is loaded into the
11352 * kernel. The special kernel macro module_init() is used to indicate the
11353 * role of this routine to the kernel as lpfc module entry point.
11354 *
11355 * Return codes
11356 * 0 - successful
11357 * -ENOMEM - FC attach transport failed
11358 * all others - failed
11359 */
dea31012005-04-17 16:05:31 -050011360static int __init
11361lpfc_init(void)
11362{
James Smart7bb03bb2013-04-17 20:19:16 -040011363 int cpu;
dea31012005-04-17 16:05:31 -050011364 int error = 0;
11365
11366 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040011367 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050011368
James Smart3ef6d242012-01-18 16:23:48 -050011369 error = misc_register(&lpfc_mgmt_dev);
11370 if (error)
11371 printk(KERN_ERR "Could not register lpfcmgmt device, "
11372 "misc_register returned with status %d", error);
11373
James Smart7ee5d432007-10-27 13:37:17 -040011374 if (lpfc_enable_npiv) {
11375 lpfc_transport_functions.vport_create = lpfc_vport_create;
11376 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
11377 }
dea31012005-04-17 16:05:31 -050011378 lpfc_transport_template =
11379 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040011380 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050011381 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040011382 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -040011383 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -040011384 fc_attach_transport(&lpfc_vport_transport_functions);
11385 if (lpfc_vport_transport_template == NULL) {
11386 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040011387 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -040011388 }
James Smart7ee5d432007-10-27 13:37:17 -040011389 }
James Smart7bb03bb2013-04-17 20:19:16 -040011390
11391 /* Initialize in case vector mapping is needed */
James Smartb246de12013-05-31 17:03:07 -040011392 lpfc_used_cpu = NULL;
11393 lpfc_present_cpu = 0;
11394 for_each_present_cpu(cpu)
11395 lpfc_present_cpu++;
James Smart7bb03bb2013-04-17 20:19:16 -040011396
dea31012005-04-17 16:05:31 -050011397 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050011398 if (error) {
dea31012005-04-17 16:05:31 -050011399 fc_release_transport(lpfc_transport_template);
James Smartd7c255b2008-08-24 21:50:00 -040011400 if (lpfc_enable_npiv)
11401 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050011402 }
dea31012005-04-17 16:05:31 -050011403
11404 return error;
11405}
11406
James Smarte59058c2008-08-24 21:49:00 -040011407/**
James Smart3621a712009-04-06 18:47:14 -040011408 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040011409 *
11410 * This routine is invoked when the lpfc module is removed from the kernel.
11411 * The special kernel macro module_exit() is used to indicate the role of
11412 * this routine to the kernel as lpfc module exit point.
11413 */
dea31012005-04-17 16:05:31 -050011414static void __exit
11415lpfc_exit(void)
11416{
James Smart3ef6d242012-01-18 16:23:48 -050011417 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050011418 pci_unregister_driver(&lpfc_driver);
11419 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040011420 if (lpfc_enable_npiv)
11421 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050011422 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040011423 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
11424 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050011425 (1L << _dump_buf_data_order), _dump_buf_data);
11426 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
11427 }
11428
11429 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040011430 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
11431 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050011432 (1L << _dump_buf_dif_order), _dump_buf_dif);
11433 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
11434 }
James Smartb246de12013-05-31 17:03:07 -040011435 kfree(lpfc_used_cpu);
dea31012005-04-17 16:05:31 -050011436}
11437
11438module_init(lpfc_init);
11439module_exit(lpfc_exit);
11440MODULE_LICENSE("GPL");
11441MODULE_DESCRIPTION(LPFC_MODULE_DESC);
11442MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
11443MODULE_VERSION("0:" LPFC_DRIVER_VERSION);