blob: bce73b4964216692b510040213ae7dfc4736d42a [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart50611572016-03-31 14:12:34 -07004 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/delay.h>
24#include <linux/dma-mapping.h>
25#include <linux/idr.h>
26#include <linux/interrupt.h>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040027#include <linux/module.h>
dea31012005-04-17 16:05:31 -050028#include <linux/kthread.h>
29#include <linux/pci.h>
30#include <linux/spinlock.h>
James Smart92d7f7b2007-06-17 19:56:38 -050031#include <linux/ctype.h>
James Smart0d878412009-10-02 15:16:56 -040032#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
James Smart52d52442011-05-24 11:42:45 -040034#include <linux/firmware.h>
James Smart3ef6d242012-01-18 16:23:48 -050035#include <linux/miscdevice.h>
James Smart7bb03bb2013-04-17 20:19:16 -040036#include <linux/percpu.h>
dea31012005-04-17 16:05:31 -050037
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040038#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050039#include <scsi/scsi_device.h>
40#include <scsi/scsi_host.h>
41#include <scsi/scsi_transport_fc.h>
42
James Smartda0436e2009-05-22 14:51:39 -040043#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050044#include "lpfc_hw.h"
45#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040046#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040047#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050048#include "lpfc_disc.h"
49#include "lpfc_scsi.h"
50#include "lpfc.h"
51#include "lpfc_logmsg.h"
52#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050053#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050054#include "lpfc_version.h"
55
James Smart81301a92008-12-04 22:39:46 -050056char *_dump_buf_data;
57unsigned long _dump_buf_data_order;
58char *_dump_buf_dif;
59unsigned long _dump_buf_dif_order;
60spinlock_t _dump_buf_lock;
61
James Smart7bb03bb2013-04-17 20:19:16 -040062/* Used when mapping IRQ vectors in a driver centric manner */
James Smartb246de12013-05-31 17:03:07 -040063uint16_t *lpfc_used_cpu;
64uint32_t lpfc_present_cpu;
James Smart7bb03bb2013-04-17 20:19:16 -040065
dea31012005-04-17 16:05:31 -050066static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
67static int lpfc_post_rcv_buf(struct lpfc_hba *);
James Smart5350d872011-10-10 21:33:49 -040068static int lpfc_sli4_queue_verify(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040069static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
70static int lpfc_setup_endian_order(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040071static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040072static void lpfc_free_els_sgl_list(struct lpfc_hba *);
73static void lpfc_init_sgl_list(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040074static int lpfc_init_active_sgl_array(struct lpfc_hba *);
75static void lpfc_free_active_sgl(struct lpfc_hba *);
76static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
77static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
78static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
79static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
80static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
James Smart618a5232012-06-12 13:54:36 -040081static void lpfc_sli4_disable_intr(struct lpfc_hba *);
82static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
James Smart1ba981f2014-02-20 09:56:45 -050083static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
dea31012005-04-17 16:05:31 -050084
85static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050086static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -050087static DEFINE_IDR(lpfc_hba_index);
88
James Smarte59058c2008-08-24 21:49:00 -040089/**
James Smart3621a712009-04-06 18:47:14 -040090 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
James Smarte59058c2008-08-24 21:49:00 -040091 * @phba: pointer to lpfc hba data structure.
92 *
93 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
94 * mailbox command. It retrieves the revision information from the HBA and
95 * collects the Vital Product Data (VPD) about the HBA for preparing the
96 * configuration of the HBA.
97 *
98 * Return codes:
99 * 0 - success.
100 * -ERESTART - requests the SLI layer to reset the HBA and try again.
101 * Any other value - indicates an error.
102 **/
dea31012005-04-17 16:05:31 -0500103int
James Smart2e0fef82007-06-17 19:56:36 -0500104lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500105{
106 lpfc_vpd_t *vp = &phba->vpd;
107 int i = 0, rc;
108 LPFC_MBOXQ_t *pmb;
109 MAILBOX_t *mb;
110 char *lpfc_vpd_data = NULL;
111 uint16_t offset = 0;
112 static char licensed[56] =
113 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -0400114 static int init_key = 1;
dea31012005-04-17 16:05:31 -0500115
116 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
117 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500118 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500119 return -ENOMEM;
120 }
121
James Smart04c68492009-05-22 14:52:52 -0400122 mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -0500123 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -0500124
125 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -0400126 if (init_key) {
127 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -0500128
James Smart65a29c12006-07-06 15:50:50 -0400129 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
130 *ptext = cpu_to_be32(*ptext);
131 init_key = 0;
132 }
dea31012005-04-17 16:05:31 -0500133
134 lpfc_read_nv(phba, pmb);
135 memset((char*)mb->un.varRDnvp.rsvd3, 0,
136 sizeof (mb->un.varRDnvp.rsvd3));
137 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
138 sizeof (licensed));
139
140 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
141
142 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500143 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400144 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500145 "error, mbxCmd x%x READ_NVPARM, "
146 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500147 mb->mbxCommand, mb->mbxStatus);
148 mempool_free(pmb, phba->mbox_mem_pool);
149 return -ERESTART;
150 }
151 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500152 sizeof(phba->wwnn));
153 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
154 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500155 }
156
James Smart92d7f7b2007-06-17 19:56:38 -0500157 phba->sli3_options = 0x0;
158
dea31012005-04-17 16:05:31 -0500159 /* Setup and issue mailbox READ REV command */
160 lpfc_read_rev(phba, pmb);
161 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
162 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500163 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400164 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500165 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500166 mb->mbxCommand, mb->mbxStatus);
167 mempool_free( pmb, phba->mbox_mem_pool);
168 return -ERESTART;
169 }
170
James Smart92d7f7b2007-06-17 19:56:38 -0500171
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500172 /*
173 * The value of rr must be 1 since the driver set the cv field to 1.
174 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500175 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500176 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500177 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500178 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400179 "0440 Adapter failed to init, READ_REV has "
180 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500181 mempool_free(pmb, phba->mbox_mem_pool);
182 return -ERESTART;
dea31012005-04-17 16:05:31 -0500183 }
184
James Smart495a7142008-06-14 22:52:59 -0400185 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
186 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500187 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400188 }
James Smarted957682007-06-17 19:56:37 -0500189
dea31012005-04-17 16:05:31 -0500190 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500191 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500192 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500193 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
194 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
195 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
196 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500197 vp->rev.biuRev = mb->un.varRdRev.biuRev;
198 vp->rev.smRev = mb->un.varRdRev.smRev;
199 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
200 vp->rev.endecRev = mb->un.varRdRev.endecRev;
201 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
202 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
203 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
204 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
205 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
206 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
207
James Smart92d7f7b2007-06-17 19:56:38 -0500208 /* If the sli feature level is less then 9, we must
209 * tear down all RPIs and VPIs on link down if NPIV
210 * is enabled.
211 */
212 if (vp->rev.feaLevelHigh < 9)
213 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
214
dea31012005-04-17 16:05:31 -0500215 if (lpfc_is_LC_HBA(phba->pcidev->device))
216 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
217 sizeof (phba->RandomData));
218
dea31012005-04-17 16:05:31 -0500219 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500220 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
221 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400222 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500223 do {
James Smarta0c87cb2009-07-19 10:01:10 -0400224 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
dea31012005-04-17 16:05:31 -0500225 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
226
227 if (rc != MBX_SUCCESS) {
228 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400229 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500230 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500231 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500232 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500233 }
James Smart04c68492009-05-22 14:52:52 -0400234 /* dump mem may return a zero when finished or we got a
235 * mailbox error, either way we are done.
236 */
237 if (mb->un.varDmp.word_cnt == 0)
238 break;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500239 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
240 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400241 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
242 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500243 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500244 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500245 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
246 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500247
248 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500249out_free_mbox:
250 mempool_free(pmb, phba->mbox_mem_pool);
251 return 0;
252}
253
James Smarte59058c2008-08-24 21:49:00 -0400254/**
James Smart3621a712009-04-06 18:47:14 -0400255 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
James Smarte59058c2008-08-24 21:49:00 -0400256 * @phba: pointer to lpfc hba data structure.
257 * @pmboxq: pointer to the driver internal queue element for mailbox command.
258 *
259 * This is the completion handler for driver's configuring asynchronous event
260 * mailbox command to the device. If the mailbox command returns successfully,
261 * it will set internal async event support flag to 1; otherwise, it will
262 * set internal async event support flag to 0.
263 **/
James Smart57127f12007-10-27 13:37:05 -0400264static void
265lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
266{
James Smart04c68492009-05-22 14:52:52 -0400267 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
James Smart57127f12007-10-27 13:37:05 -0400268 phba->temp_sensor_support = 1;
269 else
270 phba->temp_sensor_support = 0;
271 mempool_free(pmboxq, phba->mbox_mem_pool);
272 return;
273}
274
James Smarte59058c2008-08-24 21:49:00 -0400275/**
James Smart3621a712009-04-06 18:47:14 -0400276 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
James Smart97207482008-12-04 22:39:19 -0500277 * @phba: pointer to lpfc hba data structure.
278 * @pmboxq: pointer to the driver internal queue element for mailbox command.
279 *
280 * This is the completion handler for dump mailbox command for getting
281 * wake up parameters. When this command complete, the response contain
282 * Option rom version of the HBA. This function translate the version number
283 * into a human readable string and store it in OptionROMVersion.
284 **/
285static void
286lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
287{
288 struct prog_id *prg;
289 uint32_t prog_id_word;
290 char dist = ' ';
291 /* character array used for decoding dist type. */
292 char dist_char[] = "nabx";
293
James Smart04c68492009-05-22 14:52:52 -0400294 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
James Smart9f1e1b52008-12-04 22:39:40 -0500295 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500296 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500297 }
James Smart97207482008-12-04 22:39:19 -0500298
299 prg = (struct prog_id *) &prog_id_word;
300
301 /* word 7 contain option rom version */
James Smart04c68492009-05-22 14:52:52 -0400302 prog_id_word = pmboxq->u.mb.un.varWords[7];
James Smart97207482008-12-04 22:39:19 -0500303
304 /* Decode the Option rom version word to a readable string */
305 if (prg->dist < 4)
306 dist = dist_char[prg->dist];
307
308 if ((prg->dist == 3) && (prg->num == 0))
James Smarta2fc4aef2014-09-03 12:57:55 -0400309 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
James Smart97207482008-12-04 22:39:19 -0500310 prg->ver, prg->rev, prg->lev);
311 else
James Smarta2fc4aef2014-09-03 12:57:55 -0400312 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
James Smart97207482008-12-04 22:39:19 -0500313 prg->ver, prg->rev, prg->lev,
314 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500315 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500316 return;
317}
318
319/**
James Smart05580562011-05-24 11:40:48 -0400320 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
321 * cfg_soft_wwnn, cfg_soft_wwpn
322 * @vport: pointer to lpfc vport data structure.
323 *
324 *
325 * Return codes
326 * None.
327 **/
328void
329lpfc_update_vport_wwn(struct lpfc_vport *vport)
330{
331 /* If the soft name exists then update it using the service params */
332 if (vport->phba->cfg_soft_wwnn)
333 u64_to_wwn(vport->phba->cfg_soft_wwnn,
334 vport->fc_sparam.nodeName.u.wwn);
335 if (vport->phba->cfg_soft_wwpn)
336 u64_to_wwn(vport->phba->cfg_soft_wwpn,
337 vport->fc_sparam.portName.u.wwn);
338
339 /*
340 * If the name is empty or there exists a soft name
341 * then copy the service params name, otherwise use the fc name
342 */
343 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
344 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
345 sizeof(struct lpfc_name));
346 else
347 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
348 sizeof(struct lpfc_name));
349
350 if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn)
351 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
352 sizeof(struct lpfc_name));
353 else
354 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
355 sizeof(struct lpfc_name));
356}
357
358/**
James Smart3621a712009-04-06 18:47:14 -0400359 * lpfc_config_port_post - Perform lpfc initialization after config port
James Smarte59058c2008-08-24 21:49:00 -0400360 * @phba: pointer to lpfc hba data structure.
361 *
362 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
363 * command call. It performs all internal resource and state setups on the
364 * port: post IOCB buffers, enable appropriate host interrupt attentions,
365 * ELS ring timers, etc.
366 *
367 * Return codes
368 * 0 - success.
369 * Any other value - error.
370 **/
dea31012005-04-17 16:05:31 -0500371int
James Smart2e0fef82007-06-17 19:56:36 -0500372lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500373{
James Smart2e0fef82007-06-17 19:56:36 -0500374 struct lpfc_vport *vport = phba->pport;
James Smarta257bf92009-04-06 18:48:10 -0400375 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500376 LPFC_MBOXQ_t *pmb;
377 MAILBOX_t *mb;
378 struct lpfc_dmabuf *mp;
379 struct lpfc_sli *psli = &phba->sli;
380 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500381 int i, j;
382 int rc;
dea31012005-04-17 16:05:31 -0500383
James Smart7af67052007-10-27 13:38:11 -0400384 spin_lock_irq(&phba->hbalock);
385 /*
386 * If the Config port completed correctly the HBA is not
387 * over heated any more.
388 */
389 if (phba->over_temp_state == HBA_OVER_TEMP)
390 phba->over_temp_state = HBA_NORMAL_TEMP;
391 spin_unlock_irq(&phba->hbalock);
392
dea31012005-04-17 16:05:31 -0500393 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
394 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500395 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500396 return -ENOMEM;
397 }
James Smart04c68492009-05-22 14:52:52 -0400398 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500399
dea31012005-04-17 16:05:31 -0500400 /* Get login parameters for NID. */
James Smart9f1177a2010-02-26 14:12:57 -0500401 rc = lpfc_read_sparam(phba, pmb, 0);
402 if (rc) {
403 mempool_free(pmb, phba->mbox_mem_pool);
404 return -ENOMEM;
405 }
406
James Smarted957682007-06-17 19:56:37 -0500407 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500408 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500409 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400410 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500411 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500412 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500413 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500414 mp = (struct lpfc_dmabuf *) pmb->context1;
James Smart9f1177a2010-02-26 14:12:57 -0500415 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500416 lpfc_mbuf_free(phba, mp->virt, mp->phys);
417 kfree(mp);
418 return -EIO;
419 }
420
421 mp = (struct lpfc_dmabuf *) pmb->context1;
422
James Smart2e0fef82007-06-17 19:56:36 -0500423 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500424 lpfc_mbuf_free(phba, mp->virt, mp->phys);
425 kfree(mp);
426 pmb->context1 = NULL;
James Smart05580562011-05-24 11:40:48 -0400427 lpfc_update_vport_wwn(vport);
James Smarta257bf92009-04-06 18:48:10 -0400428
429 /* Update the fc_host data structures with new wwn. */
430 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
431 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart21e9a0a2009-05-22 14:53:21 -0400432 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smarta257bf92009-04-06 18:48:10 -0400433
dea31012005-04-17 16:05:31 -0500434 /* If no serial number in VPD data, use low 6 bytes of WWNN */
435 /* This should be consolidated into parse_vpd ? - mr */
436 if (phba->SerialNumber[0] == 0) {
437 uint8_t *outptr;
438
James Smart2e0fef82007-06-17 19:56:36 -0500439 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500440 for (i = 0; i < 12; i++) {
441 status = *outptr++;
442 j = ((status & 0xf0) >> 4);
443 if (j <= 9)
444 phba->SerialNumber[i] =
445 (char)((uint8_t) 0x30 + (uint8_t) j);
446 else
447 phba->SerialNumber[i] =
448 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
449 i++;
450 j = (status & 0xf);
451 if (j <= 9)
452 phba->SerialNumber[i] =
453 (char)((uint8_t) 0x30 + (uint8_t) j);
454 else
455 phba->SerialNumber[i] =
456 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
457 }
458 }
459
dea31012005-04-17 16:05:31 -0500460 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500461 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500462 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500463 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400464 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500465 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500466 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500467 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500468 mempool_free( pmb, phba->mbox_mem_pool);
469 return -EIO;
470 }
471
James Smarta0c87cb2009-07-19 10:01:10 -0400472 /* Check if the port is disabled */
473 lpfc_sli_read_link_ste(phba);
474
dea31012005-04-17 16:05:31 -0500475 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -0400476 i = (mb->un.varRdConfig.max_xri + 1);
477 if (phba->cfg_hba_queue_depth > i) {
478 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
479 "3359 HBA queue depth changed from %d to %d\n",
480 phba->cfg_hba_queue_depth, i);
481 phba->cfg_hba_queue_depth = i;
482 }
483
484 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
485 i = (mb->un.varRdConfig.max_xri >> 3);
486 if (phba->pport->cfg_lun_queue_depth > i) {
487 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
488 "3360 LUN queue depth changed from %d to %d\n",
489 phba->pport->cfg_lun_queue_depth, i);
490 phba->pport->cfg_lun_queue_depth = i;
491 }
dea31012005-04-17 16:05:31 -0500492
493 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500494
495 /* Get the default values for Model Name and Description */
496 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
497
James Smart2e0fef82007-06-17 19:56:36 -0500498 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500499
James Smart0b727fe2007-10-27 13:37:25 -0400500 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smart7e56aa22012-08-03 12:35:34 -0400501 if (psli->ring[psli->extra_ring].sli.sli3.cmdringaddr)
James Smarta4bc3372006-12-02 13:34:16 -0500502 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
James Smart7e56aa22012-08-03 12:35:34 -0400503 if (psli->ring[psli->fcp_ring].sli.sli3.cmdringaddr)
dea31012005-04-17 16:05:31 -0500504 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
James Smart7e56aa22012-08-03 12:35:34 -0400505 if (psli->ring[psli->next_ring].sli.sli3.cmdringaddr)
dea31012005-04-17 16:05:31 -0500506 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
507
508 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500509 if (phba->sli_rev != 3)
510 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500511
James Smart93996272008-08-24 21:50:30 -0400512 /*
513 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
514 */
515 if (phba->intr_type == MSIX) {
516 rc = lpfc_config_msi(phba, pmb);
517 if (rc) {
518 mempool_free(pmb, phba->mbox_mem_pool);
519 return -EIO;
520 }
521 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
522 if (rc != MBX_SUCCESS) {
523 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
524 "0352 Config MSI mailbox command "
525 "failed, mbxCmd x%x, mbxStatus x%x\n",
James Smart04c68492009-05-22 14:52:52 -0400526 pmb->u.mb.mbxCommand,
527 pmb->u.mb.mbxStatus);
James Smart93996272008-08-24 21:50:30 -0400528 mempool_free(pmb, phba->mbox_mem_pool);
529 return -EIO;
530 }
531 }
532
James Smart04c68492009-05-22 14:52:52 -0400533 spin_lock_irq(&phba->hbalock);
James Smart93996272008-08-24 21:50:30 -0400534 /* Initialize ERATT handling flag */
535 phba->hba_flag &= ~HBA_ERATT_HANDLED;
536
dea31012005-04-17 16:05:31 -0500537 /* Enable appropriate host interrupts */
James Smart9940b972011-03-11 16:06:12 -0500538 if (lpfc_readl(phba->HCregaddr, &status)) {
539 spin_unlock_irq(&phba->hbalock);
540 return -EIO;
541 }
dea31012005-04-17 16:05:31 -0500542 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
543 if (psli->num_rings > 0)
544 status |= HC_R0INT_ENA;
545 if (psli->num_rings > 1)
546 status |= HC_R1INT_ENA;
547 if (psli->num_rings > 2)
548 status |= HC_R2INT_ENA;
549 if (psli->num_rings > 3)
550 status |= HC_R3INT_ENA;
551
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500552 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
553 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400554 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500555
dea31012005-04-17 16:05:31 -0500556 writel(status, phba->HCregaddr);
557 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500558 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500559
James Smart93996272008-08-24 21:50:30 -0400560 /* Set up ring-0 (ELS) timer */
561 timeout = phba->fc_ratov * 2;
James Smart256ec0d2013-04-17 20:14:58 -0400562 mod_timer(&vport->els_tmofunc,
563 jiffies + msecs_to_jiffies(1000 * timeout));
James Smart93996272008-08-24 21:50:30 -0400564 /* Set up heart beat (HB) timer */
James Smart256ec0d2013-04-17 20:14:58 -0400565 mod_timer(&phba->hb_tmofunc,
566 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -0500567 phba->hb_outstanding = 0;
568 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400569 /* Set up error attention (ERATT) polling timer */
James Smart256ec0d2013-04-17 20:14:58 -0400570 mod_timer(&phba->eratt_poll,
571 jiffies + msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL));
dea31012005-04-17 16:05:31 -0500572
James Smarta0c87cb2009-07-19 10:01:10 -0400573 if (phba->hba_flag & LINK_DISABLED) {
574 lpfc_printf_log(phba,
575 KERN_ERR, LOG_INIT,
576 "2598 Adapter Link is disabled.\n");
577 lpfc_down_link(phba, pmb);
578 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
579 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
580 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
581 lpfc_printf_log(phba,
582 KERN_ERR, LOG_INIT,
583 "2599 Adapter failed to issue DOWN_LINK"
584 " mbox command rc 0x%x\n", rc);
585
586 mempool_free(pmb, phba->mbox_mem_pool);
587 return -EIO;
588 }
James Smarte40a02c2010-02-26 14:13:54 -0500589 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
James Smart026abb82011-12-13 13:20:45 -0500590 mempool_free(pmb, phba->mbox_mem_pool);
591 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
592 if (rc)
593 return rc;
dea31012005-04-17 16:05:31 -0500594 }
595 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400596 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500597 if (!pmb) {
598 phba->link_state = LPFC_HBA_ERROR;
599 return -ENOMEM;
600 }
601
James Smart57127f12007-10-27 13:37:05 -0400602 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
603 pmb->mbox_cmpl = lpfc_config_async_cmpl;
604 pmb->vport = phba->pport;
605 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500606
James Smart57127f12007-10-27 13:37:05 -0400607 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
608 lpfc_printf_log(phba,
609 KERN_ERR,
610 LOG_INIT,
611 "0456 Adapter failed to issue "
James Smarte4e74272009-07-19 10:01:38 -0400612 "ASYNCEVT_ENABLE mbox status x%x\n",
James Smart57127f12007-10-27 13:37:05 -0400613 rc);
614 mempool_free(pmb, phba->mbox_mem_pool);
615 }
James Smart97207482008-12-04 22:39:19 -0500616
617 /* Get Option rom version */
618 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500619 if (!pmb) {
620 phba->link_state = LPFC_HBA_ERROR;
621 return -ENOMEM;
622 }
623
James Smart97207482008-12-04 22:39:19 -0500624 lpfc_dump_wakeup_param(phba, pmb);
625 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
626 pmb->vport = phba->pport;
627 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
628
629 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
630 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
James Smarte4e74272009-07-19 10:01:38 -0400631 "to get Option ROM version status x%x\n", rc);
James Smart97207482008-12-04 22:39:19 -0500632 mempool_free(pmb, phba->mbox_mem_pool);
633 }
634
James Smartd7c255b2008-08-24 21:50:00 -0400635 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400636}
637
James Smarte59058c2008-08-24 21:49:00 -0400638/**
James Smart84d1b002010-02-12 14:42:33 -0500639 * lpfc_hba_init_link - Initialize the FC link
640 * @phba: pointer to lpfc hba data structure.
James Smart6e7288d2010-06-07 15:23:35 -0400641 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500642 *
643 * This routine will issue the INIT_LINK mailbox command call.
644 * It is available to other drivers through the lpfc_hba data
645 * structure for use as a delayed link up mechanism with the
646 * module parameter lpfc_suppress_link_up.
647 *
648 * Return code
649 * 0 - success
650 * Any other value - error
651 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400652static int
James Smart6e7288d2010-06-07 15:23:35 -0400653lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500654{
James Smart1b511972011-12-13 13:23:09 -0500655 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
656}
657
658/**
659 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
660 * @phba: pointer to lpfc hba data structure.
661 * @fc_topology: desired fc topology.
662 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
663 *
664 * This routine will issue the INIT_LINK mailbox command call.
665 * It is available to other drivers through the lpfc_hba data
666 * structure for use as a delayed link up mechanism with the
667 * module parameter lpfc_suppress_link_up.
668 *
669 * Return code
670 * 0 - success
671 * Any other value - error
672 **/
673int
674lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
675 uint32_t flag)
676{
James Smart84d1b002010-02-12 14:42:33 -0500677 struct lpfc_vport *vport = phba->pport;
678 LPFC_MBOXQ_t *pmb;
679 MAILBOX_t *mb;
680 int rc;
681
682 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
683 if (!pmb) {
684 phba->link_state = LPFC_HBA_ERROR;
685 return -ENOMEM;
686 }
687 mb = &pmb->u.mb;
688 pmb->vport = vport;
689
James Smart026abb82011-12-13 13:20:45 -0500690 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
691 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
692 !(phba->lmt & LMT_1Gb)) ||
693 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
694 !(phba->lmt & LMT_2Gb)) ||
695 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
696 !(phba->lmt & LMT_4Gb)) ||
697 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
698 !(phba->lmt & LMT_8Gb)) ||
699 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
700 !(phba->lmt & LMT_10Gb)) ||
701 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
James Smartd38dd522015-08-31 16:48:17 -0400702 !(phba->lmt & LMT_16Gb)) ||
703 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
704 !(phba->lmt & LMT_32Gb))) {
James Smart026abb82011-12-13 13:20:45 -0500705 /* Reset link speed to auto */
706 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
707 "1302 Invalid speed for this board:%d "
708 "Reset link speed to auto.\n",
709 phba->cfg_link_speed);
710 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
711 }
James Smart1b511972011-12-13 13:23:09 -0500712 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
James Smart84d1b002010-02-12 14:42:33 -0500713 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart1b511972011-12-13 13:23:09 -0500714 if (phba->sli_rev < LPFC_SLI_REV4)
715 lpfc_set_loopback_flag(phba);
James Smart6e7288d2010-06-07 15:23:35 -0400716 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart76a95d72010-11-20 23:11:48 -0500717 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
James Smart84d1b002010-02-12 14:42:33 -0500718 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
719 "0498 Adapter failed to init, mbxCmd x%x "
720 "INIT_LINK, mbxStatus x%x\n",
721 mb->mbxCommand, mb->mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -0500722 if (phba->sli_rev <= LPFC_SLI_REV3) {
723 /* Clear all interrupt enable conditions */
724 writel(0, phba->HCregaddr);
725 readl(phba->HCregaddr); /* flush */
726 /* Clear all pending interrupts */
727 writel(0xffffffff, phba->HAregaddr);
728 readl(phba->HAregaddr); /* flush */
729 }
James Smart84d1b002010-02-12 14:42:33 -0500730 phba->link_state = LPFC_HBA_ERROR;
James Smart6e7288d2010-06-07 15:23:35 -0400731 if (rc != MBX_BUSY || flag == MBX_POLL)
James Smart84d1b002010-02-12 14:42:33 -0500732 mempool_free(pmb, phba->mbox_mem_pool);
733 return -EIO;
734 }
James Smarte40a02c2010-02-26 14:13:54 -0500735 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
James Smart6e7288d2010-06-07 15:23:35 -0400736 if (flag == MBX_POLL)
737 mempool_free(pmb, phba->mbox_mem_pool);
James Smart84d1b002010-02-12 14:42:33 -0500738
739 return 0;
740}
741
742/**
743 * lpfc_hba_down_link - this routine downs the FC link
James Smart6e7288d2010-06-07 15:23:35 -0400744 * @phba: pointer to lpfc hba data structure.
745 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500746 *
747 * This routine will issue the DOWN_LINK mailbox command call.
748 * It is available to other drivers through the lpfc_hba data
749 * structure for use to stop the link.
750 *
751 * Return code
752 * 0 - success
753 * Any other value - error
754 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400755static int
James Smart6e7288d2010-06-07 15:23:35 -0400756lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500757{
758 LPFC_MBOXQ_t *pmb;
759 int rc;
760
761 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
762 if (!pmb) {
763 phba->link_state = LPFC_HBA_ERROR;
764 return -ENOMEM;
765 }
766
767 lpfc_printf_log(phba,
768 KERN_ERR, LOG_INIT,
769 "0491 Adapter Link is disabled.\n");
770 lpfc_down_link(phba, pmb);
771 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart6e7288d2010-06-07 15:23:35 -0400772 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart84d1b002010-02-12 14:42:33 -0500773 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
774 lpfc_printf_log(phba,
775 KERN_ERR, LOG_INIT,
776 "2522 Adapter failed to issue DOWN_LINK"
777 " mbox command rc 0x%x\n", rc);
778
779 mempool_free(pmb, phba->mbox_mem_pool);
780 return -EIO;
781 }
James Smart6e7288d2010-06-07 15:23:35 -0400782 if (flag == MBX_POLL)
783 mempool_free(pmb, phba->mbox_mem_pool);
784
James Smart84d1b002010-02-12 14:42:33 -0500785 return 0;
786}
787
788/**
James Smart3621a712009-04-06 18:47:14 -0400789 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400790 * @phba: pointer to lpfc HBA data structure.
791 *
792 * This routine will do LPFC uninitialization before the HBA is reset when
793 * bringing down the SLI Layer.
794 *
795 * Return codes
796 * 0 - success.
797 * Any other value - error.
798 **/
dea31012005-04-17 16:05:31 -0500799int
James Smart2e0fef82007-06-17 19:56:36 -0500800lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500801{
James Smart1b32f6a2008-02-08 18:49:39 -0500802 struct lpfc_vport **vports;
803 int i;
James Smart3772a992009-05-22 14:50:54 -0400804
805 if (phba->sli_rev <= LPFC_SLI_REV3) {
806 /* Disable interrupts */
807 writel(0, phba->HCregaddr);
808 readl(phba->HCregaddr); /* flush */
809 }
dea31012005-04-17 16:05:31 -0500810
James Smart1b32f6a2008-02-08 18:49:39 -0500811 if (phba->pport->load_flag & FC_UNLOADING)
812 lpfc_cleanup_discovery_resources(phba->pport);
813 else {
814 vports = lpfc_create_vport_work_array(phba);
815 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -0400816 for (i = 0; i <= phba->max_vports &&
817 vports[i] != NULL; i++)
James Smart1b32f6a2008-02-08 18:49:39 -0500818 lpfc_cleanup_discovery_resources(vports[i]);
819 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500820 }
821 return 0;
dea31012005-04-17 16:05:31 -0500822}
823
James Smarte59058c2008-08-24 21:49:00 -0400824/**
James Smart68e814f2014-05-21 08:04:59 -0400825 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
826 * rspiocb which got deferred
827 *
828 * @phba: pointer to lpfc HBA data structure.
829 *
830 * This routine will cleanup completed slow path events after HBA is reset
831 * when bringing down the SLI Layer.
832 *
833 *
834 * Return codes
835 * void.
836 **/
837static void
838lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
839{
840 struct lpfc_iocbq *rspiocbq;
841 struct hbq_dmabuf *dmabuf;
842 struct lpfc_cq_event *cq_event;
843
844 spin_lock_irq(&phba->hbalock);
845 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
846 spin_unlock_irq(&phba->hbalock);
847
848 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
849 /* Get the response iocb from the head of work queue */
850 spin_lock_irq(&phba->hbalock);
851 list_remove_head(&phba->sli4_hba.sp_queue_event,
852 cq_event, struct lpfc_cq_event, list);
853 spin_unlock_irq(&phba->hbalock);
854
855 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
856 case CQE_CODE_COMPL_WQE:
857 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
858 cq_event);
859 lpfc_sli_release_iocbq(phba, rspiocbq);
860 break;
861 case CQE_CODE_RECEIVE:
862 case CQE_CODE_RECEIVE_V1:
863 dmabuf = container_of(cq_event, struct hbq_dmabuf,
864 cq_event);
865 lpfc_in_buf_free(phba, &dmabuf->dbuf);
866 }
867 }
868}
869
870/**
James Smartbcece5f2014-04-04 13:51:34 -0400871 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
872 * @phba: pointer to lpfc HBA data structure.
873 *
874 * This routine will cleanup posted ELS buffers after the HBA is reset
875 * when bringing down the SLI Layer.
876 *
877 *
878 * Return codes
879 * void.
880 **/
881static void
882lpfc_hba_free_post_buf(struct lpfc_hba *phba)
883{
884 struct lpfc_sli *psli = &phba->sli;
885 struct lpfc_sli_ring *pring;
886 struct lpfc_dmabuf *mp, *next_mp;
James Smart07eab622014-04-04 13:51:44 -0400887 LIST_HEAD(buflist);
888 int count;
James Smartbcece5f2014-04-04 13:51:34 -0400889
890 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
891 lpfc_sli_hbqbuf_free_all(phba);
892 else {
893 /* Cleanup preposted buffers on the ELS ring */
James Smartbcece5f2014-04-04 13:51:34 -0400894 pring = &psli->ring[LPFC_ELS_RING];
James Smart07eab622014-04-04 13:51:44 -0400895 spin_lock_irq(&phba->hbalock);
896 list_splice_init(&pring->postbufq, &buflist);
897 spin_unlock_irq(&phba->hbalock);
898
899 count = 0;
900 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
James Smartbcece5f2014-04-04 13:51:34 -0400901 list_del(&mp->list);
James Smart07eab622014-04-04 13:51:44 -0400902 count++;
James Smartbcece5f2014-04-04 13:51:34 -0400903 lpfc_mbuf_free(phba, mp->virt, mp->phys);
904 kfree(mp);
905 }
James Smart07eab622014-04-04 13:51:44 -0400906
907 spin_lock_irq(&phba->hbalock);
908 pring->postbufq_cnt -= count;
James Smartbcece5f2014-04-04 13:51:34 -0400909 spin_unlock_irq(&phba->hbalock);
910 }
911}
912
913/**
914 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
915 * @phba: pointer to lpfc HBA data structure.
916 *
917 * This routine will cleanup the txcmplq after the HBA is reset when bringing
918 * down the SLI Layer.
919 *
920 * Return codes
921 * void
922 **/
923static void
924lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
925{
926 struct lpfc_sli *psli = &phba->sli;
927 struct lpfc_sli_ring *pring;
928 LIST_HEAD(completions);
929 int i;
930
James Smartbcece5f2014-04-04 13:51:34 -0400931 for (i = 0; i < psli->num_rings; i++) {
932 pring = &psli->ring[i];
933 if (phba->sli_rev >= LPFC_SLI_REV4)
934 spin_lock_irq(&pring->ring_lock);
935 else
936 spin_lock_irq(&phba->hbalock);
937 /* At this point in time the HBA is either reset or DOA. Either
938 * way, nothing should be on txcmplq as it will NEVER complete.
939 */
940 list_splice_init(&pring->txcmplq, &completions);
James Smartdb55fba2014-04-04 13:52:02 -0400941 pring->txcmplq_cnt = 0;
James Smartbcece5f2014-04-04 13:51:34 -0400942
943 if (phba->sli_rev >= LPFC_SLI_REV4)
944 spin_unlock_irq(&pring->ring_lock);
945 else
946 spin_unlock_irq(&phba->hbalock);
947
948 /* Cancel all the IOCBs from the completions list */
949 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
950 IOERR_SLI_ABORTED);
951 lpfc_sli_abort_iocb_ring(phba, pring);
952 }
953}
954
955/**
James Smart3772a992009-05-22 14:50:54 -0400956 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smartbcece5f2014-04-04 13:51:34 -0400957 int i;
James Smarte59058c2008-08-24 21:49:00 -0400958 * @phba: pointer to lpfc HBA data structure.
959 *
960 * This routine will do uninitialization after the HBA is reset when bring
961 * down the SLI Layer.
962 *
963 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200964 * 0 - success.
James Smarte59058c2008-08-24 21:49:00 -0400965 * Any other value - error.
966 **/
James Smart3772a992009-05-22 14:50:54 -0400967static int
968lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500969{
James Smartbcece5f2014-04-04 13:51:34 -0400970 lpfc_hba_free_post_buf(phba);
971 lpfc_hba_clean_txcmplq(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500972 return 0;
973}
James Smart5af5eee2010-10-22 11:06:38 -0400974
James Smartda0436e2009-05-22 14:51:39 -0400975/**
976 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
977 * @phba: pointer to lpfc HBA data structure.
978 *
979 * This routine will do uninitialization after the HBA is reset when bring
980 * down the SLI Layer.
981 *
982 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200983 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -0400984 * Any other value - error.
985 **/
986static int
987lpfc_hba_down_post_s4(struct lpfc_hba *phba)
988{
989 struct lpfc_scsi_buf *psb, *psb_next;
990 LIST_HEAD(aborts);
James Smartda0436e2009-05-22 14:51:39 -0400991 unsigned long iflag = 0;
James Smart0f65ff62010-02-26 14:14:23 -0500992 struct lpfc_sglq *sglq_entry = NULL;
James Smartdafe8ce2014-09-03 12:56:40 -0400993 struct lpfc_sli *psli = &phba->sli;
994 struct lpfc_sli_ring *pring;
James Smart0f65ff62010-02-26 14:14:23 -0500995
James Smartbcece5f2014-04-04 13:51:34 -0400996 lpfc_hba_free_post_buf(phba);
997 lpfc_hba_clean_txcmplq(phba);
James Smartdafe8ce2014-09-03 12:56:40 -0400998 pring = &psli->ring[LPFC_ELS_RING];
James Smartbcece5f2014-04-04 13:51:34 -0400999
James Smartda0436e2009-05-22 14:51:39 -04001000 /* At this point in time the HBA is either reset or DOA. Either
1001 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
1002 * on the lpfc_sgl_list so that it can either be freed if the
1003 * driver is unloading or reposted if the driver is restarting
1004 * the port.
1005 */
1006 spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */
1007 /* scsl_buf_list */
1008 /* abts_sgl_list_lock required because worker thread uses this
1009 * list.
1010 */
1011 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05001012 list_for_each_entry(sglq_entry,
1013 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1014 sglq_entry->state = SGL_FREED;
1015
James Smartdafe8ce2014-09-03 12:56:40 -04001016 spin_lock(&pring->ring_lock);
James Smartda0436e2009-05-22 14:51:39 -04001017 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
1018 &phba->sli4_hba.lpfc_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04001019 spin_unlock(&pring->ring_lock);
James Smartda0436e2009-05-22 14:51:39 -04001020 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
1021 /* abts_scsi_buf_list_lock required because worker thread uses this
1022 * list.
1023 */
1024 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1025 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
1026 &aborts);
1027 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1028 spin_unlock_irq(&phba->hbalock);
1029
1030 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1031 psb->pCmd = NULL;
1032 psb->status = IOSTAT_SUCCESS;
1033 }
James Smarta40fc5f2013-04-17 20:17:40 -04001034 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1035 list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
1036 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
James Smart68e814f2014-05-21 08:04:59 -04001037
1038 lpfc_sli4_free_sp_events(phba);
James Smartda0436e2009-05-22 14:51:39 -04001039 return 0;
1040}
1041
1042/**
1043 * lpfc_hba_down_post - Wrapper func for hba down post routine
1044 * @phba: pointer to lpfc HBA data structure.
1045 *
1046 * This routine wraps the actual SLI3 or SLI4 routine for performing
1047 * uninitialization after the HBA is reset when bring down the SLI Layer.
1048 *
1049 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001050 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001051 * Any other value - error.
1052 **/
1053int
1054lpfc_hba_down_post(struct lpfc_hba *phba)
1055{
1056 return (*phba->lpfc_hba_down_post)(phba);
1057}
Jamie Wellnitz41415862006-02-28 19:25:27 -05001058
James Smarte59058c2008-08-24 21:49:00 -04001059/**
James Smart3621a712009-04-06 18:47:14 -04001060 * lpfc_hb_timeout - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001061 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1062 *
1063 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1064 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1065 * work-port-events bitmap and the worker thread is notified. This timeout
1066 * event will be used by the worker thread to invoke the actual timeout
1067 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1068 * be performed in the timeout handler and the HBA timeout event bit shall
1069 * be cleared by the worker thread after it has taken the event bitmap out.
1070 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001071static void
James Smart858c9f62007-06-17 19:56:39 -05001072lpfc_hb_timeout(unsigned long ptr)
1073{
1074 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001075 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -05001076 unsigned long iflag;
1077
1078 phba = (struct lpfc_hba *)ptr;
James Smart93996272008-08-24 21:50:30 -04001079
1080 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -05001081 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001082 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1083 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -05001084 phba->pport->work_port_events |= WORKER_HB_TMO;
1085 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1086
James Smart93996272008-08-24 21:50:30 -04001087 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -04001088 if (!tmo_posted)
1089 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -05001090 return;
1091}
1092
James Smarte59058c2008-08-24 21:49:00 -04001093/**
James Smart19ca7602010-11-20 23:11:55 -05001094 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1095 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1096 *
1097 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1098 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1099 * work-port-events bitmap and the worker thread is notified. This timeout
1100 * event will be used by the worker thread to invoke the actual timeout
1101 * handler routine, lpfc_rrq_handler. Any periodical operations will
1102 * be performed in the timeout handler and the RRQ timeout event bit shall
1103 * be cleared by the worker thread after it has taken the event bitmap out.
1104 **/
1105static void
1106lpfc_rrq_timeout(unsigned long ptr)
1107{
1108 struct lpfc_hba *phba;
James Smart19ca7602010-11-20 23:11:55 -05001109 unsigned long iflag;
1110
1111 phba = (struct lpfc_hba *)ptr;
1112 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001113 if (!(phba->pport->load_flag & FC_UNLOADING))
1114 phba->hba_flag |= HBA_RRQ_ACTIVE;
1115 else
1116 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
James Smart19ca7602010-11-20 23:11:55 -05001117 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001118
1119 if (!(phba->pport->load_flag & FC_UNLOADING))
1120 lpfc_worker_wake_up(phba);
James Smart19ca7602010-11-20 23:11:55 -05001121}
1122
1123/**
James Smart3621a712009-04-06 18:47:14 -04001124 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -04001125 * @phba: pointer to lpfc hba data structure.
1126 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1127 *
1128 * This is the callback function to the lpfc heart-beat mailbox command.
1129 * If configured, the lpfc driver issues the heart-beat mailbox command to
1130 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1131 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1132 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1133 * heart-beat outstanding state. Once the mailbox command comes back and
1134 * no error conditions detected, the heart-beat mailbox command timer is
1135 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1136 * state is cleared for the next heart-beat. If the timer expired with the
1137 * heart-beat outstanding state set, the driver will put the HBA offline.
1138 **/
James Smart858c9f62007-06-17 19:56:39 -05001139static void
1140lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1141{
1142 unsigned long drvr_flag;
1143
1144 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1145 phba->hb_outstanding = 0;
1146 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1147
James Smart93996272008-08-24 21:50:30 -04001148 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -05001149 mempool_free(pmboxq, phba->mbox_mem_pool);
1150 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1151 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -04001152 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -05001153 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001154 jiffies +
1155 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001156 return;
1157}
1158
James Smarte59058c2008-08-24 21:49:00 -04001159/**
James Smart3621a712009-04-06 18:47:14 -04001160 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001161 * @phba: pointer to lpfc hba data structure.
1162 *
1163 * This is the actual HBA-timer timeout handler to be invoked by the worker
1164 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1165 * handler performs any periodic operations needed for the device. If such
1166 * periodic event has already been attended to either in the interrupt handler
1167 * or by processing slow-ring or fast-ring events within the HBA-timer
1168 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1169 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1170 * is configured and there is no heart-beat mailbox command outstanding, a
1171 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1172 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1173 * to offline.
1174 **/
James Smart858c9f62007-06-17 19:56:39 -05001175void
1176lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1177{
James Smart45ed1192009-10-02 15:17:02 -04001178 struct lpfc_vport **vports;
James Smart858c9f62007-06-17 19:56:39 -05001179 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -05001180 struct lpfc_dmabuf *buf_ptr;
James Smart45ed1192009-10-02 15:17:02 -04001181 int retval, i;
James Smart858c9f62007-06-17 19:56:39 -05001182 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -05001183 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -05001184
James Smart45ed1192009-10-02 15:17:02 -04001185 vports = lpfc_create_vport_work_array(phba);
1186 if (vports != NULL)
James Smart4258e982015-12-16 18:11:58 -05001187 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart45ed1192009-10-02 15:17:02 -04001188 lpfc_rcv_seq_check_edtov(vports[i]);
James Smart4258e982015-12-16 18:11:58 -05001189 lpfc_fdmi_num_disc_check(vports[i]);
1190 }
James Smart45ed1192009-10-02 15:17:02 -04001191 lpfc_destroy_vport_work_array(phba, vports);
1192
James Smart858c9f62007-06-17 19:56:39 -05001193 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -04001194 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -05001195 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1196 return;
1197
1198 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -05001199
James Smart256ec0d2013-04-17 20:14:58 -04001200 if (time_after(phba->last_completion_time +
1201 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1202 jiffies)) {
James Smart858c9f62007-06-17 19:56:39 -05001203 spin_unlock_irq(&phba->pport->work_port_lock);
1204 if (!phba->hb_outstanding)
1205 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001206 jiffies +
1207 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001208 else
1209 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001210 jiffies +
1211 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001212 return;
1213 }
1214 spin_unlock_irq(&phba->pport->work_port_lock);
1215
James Smart0ff10d42008-01-11 01:52:36 -05001216 if (phba->elsbuf_cnt &&
1217 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1218 spin_lock_irq(&phba->hbalock);
1219 list_splice_init(&phba->elsbuf, &completions);
1220 phba->elsbuf_cnt = 0;
1221 phba->elsbuf_prev_cnt = 0;
1222 spin_unlock_irq(&phba->hbalock);
1223
1224 while (!list_empty(&completions)) {
1225 list_remove_head(&completions, buf_ptr,
1226 struct lpfc_dmabuf, list);
1227 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1228 kfree(buf_ptr);
1229 }
1230 }
1231 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1232
James Smart858c9f62007-06-17 19:56:39 -05001233 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -05001234 if (phba->cfg_enable_hba_heartbeat) {
1235 if (!phba->hb_outstanding) {
James Smartbc739052010-08-04 16:11:18 -04001236 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1237 (list_empty(&psli->mboxq))) {
1238 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1239 GFP_KERNEL);
1240 if (!pmboxq) {
1241 mod_timer(&phba->hb_tmofunc,
1242 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001243 msecs_to_jiffies(1000 *
1244 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001245 return;
1246 }
James Smart13815c82008-01-11 01:52:48 -05001247
James Smartbc739052010-08-04 16:11:18 -04001248 lpfc_heart_beat(phba, pmboxq);
1249 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1250 pmboxq->vport = phba->pport;
1251 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1252 MBX_NOWAIT);
James Smart13815c82008-01-11 01:52:48 -05001253
James Smartbc739052010-08-04 16:11:18 -04001254 if (retval != MBX_BUSY &&
1255 retval != MBX_SUCCESS) {
1256 mempool_free(pmboxq,
1257 phba->mbox_mem_pool);
1258 mod_timer(&phba->hb_tmofunc,
1259 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001260 msecs_to_jiffies(1000 *
1261 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001262 return;
1263 }
1264 phba->skipped_hb = 0;
1265 phba->hb_outstanding = 1;
1266 } else if (time_before_eq(phba->last_completion_time,
1267 phba->skipped_hb)) {
1268 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1269 "2857 Last completion time not "
1270 " updated in %d ms\n",
1271 jiffies_to_msecs(jiffies
1272 - phba->last_completion_time));
1273 } else
1274 phba->skipped_hb = jiffies;
1275
James Smart858c9f62007-06-17 19:56:39 -05001276 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001277 jiffies +
1278 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001279 return;
James Smart13815c82008-01-11 01:52:48 -05001280 } else {
1281 /*
1282 * If heart beat timeout called with hb_outstanding set
James Smartdcf2a4e2010-09-29 11:18:53 -04001283 * we need to give the hb mailbox cmd a chance to
1284 * complete or TMO.
James Smart13815c82008-01-11 01:52:48 -05001285 */
James Smartdcf2a4e2010-09-29 11:18:53 -04001286 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1287 "0459 Adapter heartbeat still out"
1288 "standing:last compl time was %d ms.\n",
1289 jiffies_to_msecs(jiffies
1290 - phba->last_completion_time));
1291 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001292 jiffies +
1293 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001294 }
James Smart4258e982015-12-16 18:11:58 -05001295 } else {
1296 mod_timer(&phba->hb_tmofunc,
1297 jiffies +
1298 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001299 }
1300}
1301
James Smarte59058c2008-08-24 21:49:00 -04001302/**
James Smart3621a712009-04-06 18:47:14 -04001303 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -04001304 * @phba: pointer to lpfc hba data structure.
1305 *
1306 * This routine is called to bring the HBA offline when HBA hardware error
1307 * other than Port Error 6 has been detected.
1308 **/
James Smart09372822008-01-11 01:52:54 -05001309static void
1310lpfc_offline_eratt(struct lpfc_hba *phba)
1311{
1312 struct lpfc_sli *psli = &phba->sli;
1313
1314 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001315 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -05001316 spin_unlock_irq(&phba->hbalock);
James Smart618a5232012-06-12 13:54:36 -04001317 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart09372822008-01-11 01:52:54 -05001318
1319 lpfc_offline(phba);
1320 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001321 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001322 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001323 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001324 lpfc_hba_down_post(phba);
1325 lpfc_sli_brdready(phba, HS_MBRDY);
1326 lpfc_unblock_mgmt_io(phba);
1327 phba->link_state = LPFC_HBA_ERROR;
1328 return;
1329}
1330
James Smarte59058c2008-08-24 21:49:00 -04001331/**
James Smartda0436e2009-05-22 14:51:39 -04001332 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1333 * @phba: pointer to lpfc hba data structure.
1334 *
1335 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1336 * other than Port Error 6 has been detected.
1337 **/
James Smarta88dbb62013-04-17 20:18:39 -04001338void
James Smartda0436e2009-05-22 14:51:39 -04001339lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1340{
James Smart946727d2015-04-07 15:07:09 -04001341 spin_lock_irq(&phba->hbalock);
1342 phba->link_state = LPFC_HBA_ERROR;
1343 spin_unlock_irq(&phba->hbalock);
1344
James Smart618a5232012-06-12 13:54:36 -04001345 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smartda0436e2009-05-22 14:51:39 -04001346 lpfc_offline(phba);
James Smartda0436e2009-05-22 14:51:39 -04001347 lpfc_hba_down_post(phba);
James Smartda0436e2009-05-22 14:51:39 -04001348 lpfc_unblock_mgmt_io(phba);
James Smartda0436e2009-05-22 14:51:39 -04001349}
1350
1351/**
James Smarta257bf92009-04-06 18:48:10 -04001352 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1353 * @phba: pointer to lpfc hba data structure.
1354 *
1355 * This routine is invoked to handle the deferred HBA hardware error
1356 * conditions. This type of error is indicated by HBA by setting ER1
1357 * and another ER bit in the host status register. The driver will
1358 * wait until the ER1 bit clears before handling the error condition.
1359 **/
1360static void
1361lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1362{
1363 uint32_t old_host_status = phba->work_hs;
James Smarta257bf92009-04-06 18:48:10 -04001364 struct lpfc_sli *psli = &phba->sli;
1365
James Smartf4b4c682009-05-22 14:53:12 -04001366 /* If the pci channel is offline, ignore possible errors,
1367 * since we cannot communicate with the pci card anyway.
1368 */
1369 if (pci_channel_offline(phba->pcidev)) {
1370 spin_lock_irq(&phba->hbalock);
1371 phba->hba_flag &= ~DEFER_ERATT;
1372 spin_unlock_irq(&phba->hbalock);
1373 return;
1374 }
1375
James Smarta257bf92009-04-06 18:48:10 -04001376 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1377 "0479 Deferred Adapter Hardware Error "
1378 "Data: x%x x%x x%x\n",
1379 phba->work_hs,
1380 phba->work_status[0], phba->work_status[1]);
1381
1382 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001383 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001384 spin_unlock_irq(&phba->hbalock);
1385
1386
1387 /*
1388 * Firmware stops when it triggred erratt. That could cause the I/Os
1389 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1390 * SCSI layer retry it after re-establishing link.
1391 */
James Smartdb55fba2014-04-04 13:52:02 -04001392 lpfc_sli_abort_fcp_rings(phba);
James Smarta257bf92009-04-06 18:48:10 -04001393
1394 /*
1395 * There was a firmware error. Take the hba offline and then
1396 * attempt to restart it.
1397 */
James Smart618a5232012-06-12 13:54:36 -04001398 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smarta257bf92009-04-06 18:48:10 -04001399 lpfc_offline(phba);
1400
1401 /* Wait for the ER1 bit to clear.*/
1402 while (phba->work_hs & HS_FFER1) {
1403 msleep(100);
James Smart9940b972011-03-11 16:06:12 -05001404 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1405 phba->work_hs = UNPLUG_ERR ;
1406 break;
1407 }
James Smarta257bf92009-04-06 18:48:10 -04001408 /* If driver is unloading let the worker thread continue */
1409 if (phba->pport->load_flag & FC_UNLOADING) {
1410 phba->work_hs = 0;
1411 break;
1412 }
1413 }
1414
1415 /*
1416 * This is to ptrotect against a race condition in which
1417 * first write to the host attention register clear the
1418 * host status register.
1419 */
1420 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1421 phba->work_hs = old_host_status & ~HS_FFER1;
1422
James Smart3772a992009-05-22 14:50:54 -04001423 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001424 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001425 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001426 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1427 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1428}
1429
James Smart3772a992009-05-22 14:50:54 -04001430static void
1431lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1432{
1433 struct lpfc_board_event_header board_event;
1434 struct Scsi_Host *shost;
1435
1436 board_event.event_type = FC_REG_BOARD_EVENT;
1437 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1438 shost = lpfc_shost_from_vport(phba->pport);
1439 fc_host_post_vendor_event(shost, fc_get_event_number(),
1440 sizeof(board_event),
1441 (char *) &board_event,
1442 LPFC_NL_VENDOR_ID);
1443}
1444
James Smarta257bf92009-04-06 18:48:10 -04001445/**
James Smart3772a992009-05-22 14:50:54 -04001446 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001447 * @phba: pointer to lpfc hba data structure.
1448 *
1449 * This routine is invoked to handle the following HBA hardware error
1450 * conditions:
1451 * 1 - HBA error attention interrupt
1452 * 2 - DMA ring index out of range
1453 * 3 - Mailbox command came back as unknown
1454 **/
James Smart3772a992009-05-22 14:50:54 -04001455static void
1456lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001457{
James Smart2e0fef82007-06-17 19:56:36 -05001458 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001459 struct lpfc_sli *psli = &phba->sli;
James Smartd2873e42006-08-18 17:46:43 -04001460 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001461 unsigned long temperature;
1462 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001463 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001464
Linas Vepstas8d63f372007-02-14 14:28:36 -06001465 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001466 * since we cannot communicate with the pci card anyway.
1467 */
1468 if (pci_channel_offline(phba->pcidev)) {
1469 spin_lock_irq(&phba->hbalock);
1470 phba->hba_flag &= ~DEFER_ERATT;
1471 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001472 return;
James Smart3772a992009-05-22 14:50:54 -04001473 }
1474
James Smart13815c82008-01-11 01:52:48 -05001475 /* If resets are disabled then leave the HBA alone and return */
1476 if (!phba->cfg_enable_hba_reset)
1477 return;
dea31012005-04-17 16:05:31 -05001478
James Smartea2151b2008-09-07 11:52:10 -04001479 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001480 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001481
James Smarta257bf92009-04-06 18:48:10 -04001482 if (phba->hba_flag & DEFER_ERATT)
1483 lpfc_handle_deferred_eratt(phba);
1484
James Smartdcf2a4e2010-09-29 11:18:53 -04001485 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1486 if (phba->work_hs & HS_FFER6)
1487 /* Re-establishing Link */
1488 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1489 "1301 Re-establishing Link "
1490 "Data: x%x x%x x%x\n",
1491 phba->work_hs, phba->work_status[0],
1492 phba->work_status[1]);
1493 if (phba->work_hs & HS_FFER8)
1494 /* Device Zeroization */
1495 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1496 "2861 Host Authentication device "
1497 "zeroization Data:x%x x%x x%x\n",
1498 phba->work_hs, phba->work_status[0],
1499 phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001500
James Smart92d7f7b2007-06-17 19:56:38 -05001501 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001502 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001503 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001504
1505 /*
1506 * Firmware stops when it triggled erratt with HS_FFER6.
1507 * That could cause the I/Os dropped by the firmware.
1508 * Error iocb (I/O) on txcmplq and let the SCSI layer
1509 * retry it after re-establishing link.
1510 */
James Smartdb55fba2014-04-04 13:52:02 -04001511 lpfc_sli_abort_fcp_rings(phba);
dea31012005-04-17 16:05:31 -05001512
dea31012005-04-17 16:05:31 -05001513 /*
1514 * There was a firmware error. Take the hba offline and then
1515 * attempt to restart it.
1516 */
James Smart618a5232012-06-12 13:54:36 -04001517 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
dea31012005-04-17 16:05:31 -05001518 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001519 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001520 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001521 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001522 return;
1523 }
James Smart46fa3112007-04-25 09:51:45 -04001524 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001525 } else if (phba->work_hs & HS_CRIT_TEMP) {
1526 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1527 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1528 temp_event_data.event_code = LPFC_CRIT_TEMP;
1529 temp_event_data.data = (uint32_t)temperature;
1530
1531 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001532 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001533 "(%ld), taking this port offline "
1534 "Data: x%x x%x x%x\n",
1535 temperature, phba->work_hs,
1536 phba->work_status[0], phba->work_status[1]);
1537
1538 shost = lpfc_shost_from_vport(phba->pport);
1539 fc_host_post_vendor_event(shost, fc_get_event_number(),
1540 sizeof(temp_event_data),
1541 (char *) &temp_event_data,
1542 SCSI_NL_VID_TYPE_PCI
1543 | PCI_VENDOR_ID_EMULEX);
1544
James Smart7af67052007-10-27 13:38:11 -04001545 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001546 phba->over_temp_state = HBA_OVER_TEMP;
1547 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001548 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001549
dea31012005-04-17 16:05:31 -05001550 } else {
1551 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001552 * failure is a value other than FFER6. Do not call the offline
1553 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001554 */
1555 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001556 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001557 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001558 phba->work_hs,
dea31012005-04-17 16:05:31 -05001559 phba->work_status[0], phba->work_status[1]);
1560
James Smartd2873e42006-08-18 17:46:43 -04001561 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001562 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001563 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001564 sizeof(event_data), (char *) &event_data,
1565 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1566
James Smart09372822008-01-11 01:52:54 -05001567 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001568 }
James Smart93996272008-08-24 21:50:30 -04001569 return;
dea31012005-04-17 16:05:31 -05001570}
1571
James Smarte59058c2008-08-24 21:49:00 -04001572/**
James Smart618a5232012-06-12 13:54:36 -04001573 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1574 * @phba: pointer to lpfc hba data structure.
1575 * @mbx_action: flag for mailbox shutdown action.
1576 *
1577 * This routine is invoked to perform an SLI4 port PCI function reset in
1578 * response to port status register polling attention. It waits for port
1579 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1580 * During this process, interrupt vectors are freed and later requested
1581 * for handling possible port resource change.
1582 **/
1583static int
James Smarte10b2022014-02-20 09:57:43 -05001584lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1585 bool en_rn_msg)
James Smart618a5232012-06-12 13:54:36 -04001586{
1587 int rc;
1588 uint32_t intr_mode;
1589
1590 /*
1591 * On error status condition, driver need to wait for port
1592 * ready before performing reset.
1593 */
1594 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1595 if (!rc) {
1596 /* need reset: attempt for port recovery */
James Smarte10b2022014-02-20 09:57:43 -05001597 if (en_rn_msg)
1598 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1599 "2887 Reset Needed: Attempting Port "
1600 "Recovery...\n");
James Smart618a5232012-06-12 13:54:36 -04001601 lpfc_offline_prep(phba, mbx_action);
1602 lpfc_offline(phba);
1603 /* release interrupt for possible resource change */
1604 lpfc_sli4_disable_intr(phba);
1605 lpfc_sli_brdrestart(phba);
1606 /* request and enable interrupt */
1607 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1608 if (intr_mode == LPFC_INTR_ERROR) {
1609 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1610 "3175 Failed to enable interrupt\n");
1611 return -EIO;
1612 } else {
1613 phba->intr_mode = intr_mode;
1614 }
1615 rc = lpfc_online(phba);
1616 if (rc == 0)
1617 lpfc_unblock_mgmt_io(phba);
1618 }
1619 return rc;
1620}
1621
1622/**
James Smartda0436e2009-05-22 14:51:39 -04001623 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1624 * @phba: pointer to lpfc hba data structure.
1625 *
1626 * This routine is invoked to handle the SLI4 HBA hardware error attention
1627 * conditions.
1628 **/
1629static void
1630lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1631{
1632 struct lpfc_vport *vport = phba->pport;
1633 uint32_t event_data;
1634 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001635 uint32_t if_type;
James Smart2e90f4b2011-12-13 13:22:37 -05001636 struct lpfc_register portstat_reg = {0};
1637 uint32_t reg_err1, reg_err2;
1638 uint32_t uerrlo_reg, uemasklo_reg;
1639 uint32_t pci_rd_rc1, pci_rd_rc2;
James Smarte10b2022014-02-20 09:57:43 -05001640 bool en_rn_msg = true;
James Smart946727d2015-04-07 15:07:09 -04001641 struct temp_event temp_event_data;
James Smart73d91e52011-10-10 21:32:10 -04001642 int rc;
James Smartda0436e2009-05-22 14:51:39 -04001643
1644 /* If the pci channel is offline, ignore possible errors, since
1645 * we cannot communicate with the pci card anyway.
1646 */
1647 if (pci_channel_offline(phba->pcidev))
1648 return;
James Smartda0436e2009-05-22 14:51:39 -04001649
James Smart2fcee4b2010-12-15 17:57:46 -05001650 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1651 switch (if_type) {
1652 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart2e90f4b2011-12-13 13:22:37 -05001653 pci_rd_rc1 = lpfc_readl(
1654 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1655 &uerrlo_reg);
1656 pci_rd_rc2 = lpfc_readl(
1657 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1658 &uemasklo_reg);
1659 /* consider PCI bus read error as pci_channel_offline */
1660 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1661 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001662 lpfc_sli4_offline_eratt(phba);
1663 break;
James Smart946727d2015-04-07 15:07:09 -04001664
James Smart2fcee4b2010-12-15 17:57:46 -05001665 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2e90f4b2011-12-13 13:22:37 -05001666 pci_rd_rc1 = lpfc_readl(
1667 phba->sli4_hba.u.if_type2.STATUSregaddr,
1668 &portstat_reg.word0);
1669 /* consider PCI bus read error as pci_channel_offline */
James Smart6b5151f2012-01-18 16:24:06 -05001670 if (pci_rd_rc1 == -EIO) {
1671 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1672 "3151 PCI bus read access failure: x%x\n",
1673 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
James Smart2e90f4b2011-12-13 13:22:37 -05001674 return;
James Smart6b5151f2012-01-18 16:24:06 -05001675 }
James Smart2e90f4b2011-12-13 13:22:37 -05001676 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1677 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
James Smart2fcee4b2010-12-15 17:57:46 -05001678 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
James Smart2fcee4b2010-12-15 17:57:46 -05001679 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1680 "2889 Port Overtemperature event, "
James Smart946727d2015-04-07 15:07:09 -04001681 "taking port offline Data: x%x x%x\n",
1682 reg_err1, reg_err2);
1683
James Smart310429e2016-07-06 12:35:54 -07001684 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04001685 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1686 temp_event_data.event_code = LPFC_CRIT_TEMP;
1687 temp_event_data.data = 0xFFFFFFFF;
1688
1689 shost = lpfc_shost_from_vport(phba->pport);
1690 fc_host_post_vendor_event(shost, fc_get_event_number(),
1691 sizeof(temp_event_data),
1692 (char *)&temp_event_data,
1693 SCSI_NL_VID_TYPE_PCI
1694 | PCI_VENDOR_ID_EMULEX);
1695
James Smart2fcee4b2010-12-15 17:57:46 -05001696 spin_lock_irq(&phba->hbalock);
1697 phba->over_temp_state = HBA_OVER_TEMP;
1698 spin_unlock_irq(&phba->hbalock);
1699 lpfc_sli4_offline_eratt(phba);
James Smart946727d2015-04-07 15:07:09 -04001700 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001701 }
James Smart2e90f4b2011-12-13 13:22:37 -05001702 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smarte10b2022014-02-20 09:57:43 -05001703 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
James Smart2e90f4b2011-12-13 13:22:37 -05001704 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte10b2022014-02-20 09:57:43 -05001705 "3143 Port Down: Firmware Update "
1706 "Detected\n");
1707 en_rn_msg = false;
1708 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smart2e90f4b2011-12-13 13:22:37 -05001709 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1710 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1711 "3144 Port Down: Debug Dump\n");
1712 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1713 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1714 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1715 "3145 Port Down: Provisioning\n");
James Smart618a5232012-06-12 13:54:36 -04001716
James Smart946727d2015-04-07 15:07:09 -04001717 /* If resets are disabled then leave the HBA alone and return */
1718 if (!phba->cfg_enable_hba_reset)
1719 return;
1720
James Smart618a5232012-06-12 13:54:36 -04001721 /* Check port status register for function reset */
James Smarte10b2022014-02-20 09:57:43 -05001722 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1723 en_rn_msg);
James Smart618a5232012-06-12 13:54:36 -04001724 if (rc == 0) {
1725 /* don't report event on forced debug dump */
1726 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1727 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1728 return;
1729 else
1730 break;
James Smart2fcee4b2010-12-15 17:57:46 -05001731 }
James Smart618a5232012-06-12 13:54:36 -04001732 /* fall through for not able to recover */
James Smart6b5151f2012-01-18 16:24:06 -05001733 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1734 "3152 Unrecoverable error, bring the port "
1735 "offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05001736 lpfc_sli4_offline_eratt(phba);
1737 break;
1738 case LPFC_SLI_INTF_IF_TYPE_1:
1739 default:
1740 break;
1741 }
James Smart2e90f4b2011-12-13 13:22:37 -05001742 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1743 "3123 Report dump event to upper layer\n");
1744 /* Send an internal error event to mgmt application */
1745 lpfc_board_errevt_to_mgmt(phba);
1746
1747 event_data = FC_REG_DUMP_EVENT;
1748 shost = lpfc_shost_from_vport(vport);
1749 fc_host_post_vendor_event(shost, fc_get_event_number(),
1750 sizeof(event_data), (char *) &event_data,
1751 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
James Smartda0436e2009-05-22 14:51:39 -04001752}
1753
1754/**
1755 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1756 * @phba: pointer to lpfc HBA data structure.
1757 *
1758 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1759 * routine from the API jump table function pointer from the lpfc_hba struct.
1760 *
1761 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001762 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001763 * Any other value - error.
1764 **/
1765void
1766lpfc_handle_eratt(struct lpfc_hba *phba)
1767{
1768 (*phba->lpfc_handle_eratt)(phba);
1769}
1770
1771/**
James Smart3621a712009-04-06 18:47:14 -04001772 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04001773 * @phba: pointer to lpfc hba data structure.
1774 *
1775 * This routine is invoked from the worker thread to handle a HBA host
1776 * attention link event.
1777 **/
dea31012005-04-17 16:05:31 -05001778void
James Smart2e0fef82007-06-17 19:56:36 -05001779lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001780{
James Smart2e0fef82007-06-17 19:56:36 -05001781 struct lpfc_vport *vport = phba->pport;
1782 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001783 LPFC_MBOXQ_t *pmb;
1784 volatile uint32_t control;
1785 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05001786 int rc = 0;
dea31012005-04-17 16:05:31 -05001787
1788 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001789 if (!pmb) {
1790 rc = 1;
dea31012005-04-17 16:05:31 -05001791 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05001792 }
dea31012005-04-17 16:05:31 -05001793
1794 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001795 if (!mp) {
1796 rc = 2;
dea31012005-04-17 16:05:31 -05001797 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05001798 }
dea31012005-04-17 16:05:31 -05001799
1800 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05001801 if (!mp->virt) {
1802 rc = 3;
dea31012005-04-17 16:05:31 -05001803 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05001804 }
dea31012005-04-17 16:05:31 -05001805
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001806 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04001807 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05001808
1809 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05001810 lpfc_read_topology(phba, pmb, mp);
1811 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05001812 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04001813 /* Block ELS IOCBs until we have processed this mbox command */
1814 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04001815 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05001816 if (rc == MBX_NOT_FINISHED) {
1817 rc = 4;
James Smart14691152006-12-02 13:34:28 -05001818 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05001819 }
dea31012005-04-17 16:05:31 -05001820
1821 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05001822 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001823 writel(HA_LATT, phba->HAregaddr);
1824 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001825 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001826
1827 return;
1828
James Smart14691152006-12-02 13:34:28 -05001829lpfc_handle_latt_free_mbuf:
James Smart0d2b6b82008-06-14 22:52:47 -04001830 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05001831 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05001832lpfc_handle_latt_free_mp:
1833 kfree(mp);
1834lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04001835 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001836lpfc_handle_latt_err_exit:
1837 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001838 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001839 psli->sli_flag |= LPFC_PROCESS_LA;
1840 control = readl(phba->HCregaddr);
1841 control |= HC_LAINT_ENA;
1842 writel(control, phba->HCregaddr);
1843 readl(phba->HCregaddr); /* flush */
1844
1845 /* Clear Link Attention in HA REG */
1846 writel(HA_LATT, phba->HAregaddr);
1847 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001848 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001849 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001850 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001851
James Smart09372822008-01-11 01:52:54 -05001852 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1853 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05001854
1855 return;
1856}
1857
James Smarte59058c2008-08-24 21:49:00 -04001858/**
James Smart3621a712009-04-06 18:47:14 -04001859 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04001860 * @phba: pointer to lpfc hba data structure.
1861 * @vpd: pointer to the vital product data.
1862 * @len: length of the vital product data in bytes.
1863 *
1864 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1865 * an array of characters. In this routine, the ModelName, ProgramType, and
1866 * ModelDesc, etc. fields of the phba data structure will be populated.
1867 *
1868 * Return codes
1869 * 0 - pointer to the VPD passed in is NULL
1870 * 1 - success
1871 **/
James Smart3772a992009-05-22 14:50:54 -04001872int
James Smart2e0fef82007-06-17 19:56:36 -05001873lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05001874{
1875 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05001876 int Length;
dea31012005-04-17 16:05:31 -05001877 int i, j;
1878 int finished = 0;
1879 int index = 0;
1880
1881 if (!vpd)
1882 return 0;
1883
1884 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05001885 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001886 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001887 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
1888 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001889 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05001890 switch (vpd[index]) {
1891 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001892 case 0x91:
dea31012005-04-17 16:05:31 -05001893 index += 1;
1894 lenlo = vpd[index];
1895 index += 1;
1896 lenhi = vpd[index];
1897 index += 1;
1898 i = ((((unsigned short)lenhi) << 8) + lenlo);
1899 index += i;
1900 break;
1901 case 0x90:
1902 index += 1;
1903 lenlo = vpd[index];
1904 index += 1;
1905 lenhi = vpd[index];
1906 index += 1;
1907 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001908 if (Length > len - index)
1909 Length = len - index;
dea31012005-04-17 16:05:31 -05001910 while (Length > 0) {
1911 /* Look for Serial Number */
1912 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
1913 index += 2;
1914 i = vpd[index];
1915 index += 1;
1916 j = 0;
1917 Length -= (3+i);
1918 while(i--) {
1919 phba->SerialNumber[j++] = vpd[index++];
1920 if (j == 31)
1921 break;
1922 }
1923 phba->SerialNumber[j] = 0;
1924 continue;
1925 }
1926 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
1927 phba->vpd_flag |= VPD_MODEL_DESC;
1928 index += 2;
1929 i = vpd[index];
1930 index += 1;
1931 j = 0;
1932 Length -= (3+i);
1933 while(i--) {
1934 phba->ModelDesc[j++] = vpd[index++];
1935 if (j == 255)
1936 break;
1937 }
1938 phba->ModelDesc[j] = 0;
1939 continue;
1940 }
1941 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
1942 phba->vpd_flag |= VPD_MODEL_NAME;
1943 index += 2;
1944 i = vpd[index];
1945 index += 1;
1946 j = 0;
1947 Length -= (3+i);
1948 while(i--) {
1949 phba->ModelName[j++] = vpd[index++];
1950 if (j == 79)
1951 break;
1952 }
1953 phba->ModelName[j] = 0;
1954 continue;
1955 }
1956 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
1957 phba->vpd_flag |= VPD_PROGRAM_TYPE;
1958 index += 2;
1959 i = vpd[index];
1960 index += 1;
1961 j = 0;
1962 Length -= (3+i);
1963 while(i--) {
1964 phba->ProgramType[j++] = vpd[index++];
1965 if (j == 255)
1966 break;
1967 }
1968 phba->ProgramType[j] = 0;
1969 continue;
1970 }
1971 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1972 phba->vpd_flag |= VPD_PORT;
1973 index += 2;
1974 i = vpd[index];
1975 index += 1;
1976 j = 0;
1977 Length -= (3+i);
1978 while(i--) {
James Smartcd1c8302011-10-10 21:33:25 -04001979 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1980 (phba->sli4_hba.pport_name_sta ==
1981 LPFC_SLI4_PPNAME_GET)) {
1982 j++;
1983 index++;
1984 } else
1985 phba->Port[j++] = vpd[index++];
1986 if (j == 19)
1987 break;
dea31012005-04-17 16:05:31 -05001988 }
James Smartcd1c8302011-10-10 21:33:25 -04001989 if ((phba->sli_rev != LPFC_SLI_REV4) ||
1990 (phba->sli4_hba.pport_name_sta ==
1991 LPFC_SLI4_PPNAME_NON))
1992 phba->Port[j] = 0;
dea31012005-04-17 16:05:31 -05001993 continue;
1994 }
1995 else {
1996 index += 2;
1997 i = vpd[index];
1998 index += 1;
1999 index += i;
2000 Length -= (3 + i);
2001 }
2002 }
2003 finished = 0;
2004 break;
2005 case 0x78:
2006 finished = 1;
2007 break;
2008 default:
2009 index ++;
2010 break;
2011 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002012 }
dea31012005-04-17 16:05:31 -05002013
2014 return(1);
2015}
2016
James Smarte59058c2008-08-24 21:49:00 -04002017/**
James Smart3621a712009-04-06 18:47:14 -04002018 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04002019 * @phba: pointer to lpfc hba data structure.
2020 * @mdp: pointer to the data structure to hold the derived model name.
2021 * @descp: pointer to the data structure to hold the derived description.
2022 *
2023 * This routine retrieves HBA's description based on its registered PCI device
2024 * ID. The @descp passed into this function points to an array of 256 chars. It
2025 * shall be returned with the model name, maximum speed, and the host bus type.
2026 * The @mdp passed into this function points to an array of 80 chars. When the
2027 * function returns, the @mdp will be filled with the model name.
2028 **/
dea31012005-04-17 16:05:31 -05002029static void
James Smart2e0fef82007-06-17 19:56:36 -05002030lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05002031{
2032 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05002033 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002034 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04002035 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04002036 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002037 struct {
James Smarta747c9c2009-11-18 15:41:10 -05002038 char *name;
2039 char *bus;
2040 char *function;
2041 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002042
2043 if (mdp && mdp[0] != '\0'
2044 && descp && descp[0] != '\0')
2045 return;
2046
James Smartd38dd522015-08-31 16:48:17 -04002047 if (phba->lmt & LMT_32Gb)
2048 max_speed = 32;
2049 else if (phba->lmt & LMT_16Gb)
James Smartc0c11512011-05-24 11:41:34 -04002050 max_speed = 16;
2051 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002052 max_speed = 10;
2053 else if (phba->lmt & LMT_8Gb)
2054 max_speed = 8;
2055 else if (phba->lmt & LMT_4Gb)
2056 max_speed = 4;
2057 else if (phba->lmt & LMT_2Gb)
2058 max_speed = 2;
James Smart4169d862012-09-29 11:32:09 -04002059 else if (phba->lmt & LMT_1Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002060 max_speed = 1;
James Smart4169d862012-09-29 11:32:09 -04002061 else
2062 max_speed = 0;
dea31012005-04-17 16:05:31 -05002063
2064 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05002065
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002066 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002067 case PCI_DEVICE_ID_FIREFLY:
James Smart12222f42014-05-21 08:05:19 -04002068 m = (typeof(m)){"LP6000", "PCI",
2069 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002070 break;
dea31012005-04-17 16:05:31 -05002071 case PCI_DEVICE_ID_SUPERFLY:
2072 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart12222f42014-05-21 08:05:19 -04002073 m = (typeof(m)){"LP7000", "PCI", ""};
dea31012005-04-17 16:05:31 -05002074 else
James Smart12222f42014-05-21 08:05:19 -04002075 m = (typeof(m)){"LP7000E", "PCI", ""};
2076 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002077 break;
2078 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002079 m = (typeof(m)){"LP8000", "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_CENTAUR:
2083 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart12222f42014-05-21 08:05:19 -04002084 m = (typeof(m)){"LP9002", "PCI", ""};
dea31012005-04-17 16:05:31 -05002085 else
James Smart12222f42014-05-21 08:05:19 -04002086 m = (typeof(m)){"LP9000", "PCI", ""};
2087 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002088 break;
2089 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002090 m = (typeof(m)){"LP952", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002091 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002092 break;
2093 case PCI_DEVICE_ID_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05002094 m = (typeof(m)){"LP9802", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002095 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002096 break;
2097 case PCI_DEVICE_ID_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05002098 m = (typeof(m)){"LP10000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002099 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002100 break;
2101 case PCI_DEVICE_ID_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05002102 m = (typeof(m)){"LPX1000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002103 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002104 break;
2105 case PCI_DEVICE_ID_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002106 m = (typeof(m)){"LP982", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002107 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002108 break;
2109 case PCI_DEVICE_ID_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002110 m = (typeof(m)){"LP1050", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002111 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002112 break;
2113 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05002114 m = (typeof(m)){"LP11000", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002115 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002116 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002117 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002118 m = (typeof(m)){"LP11000-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002119 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002120 break;
2121 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002122 m = (typeof(m)){"LP11002-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002123 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002124 break;
2125 case PCI_DEVICE_ID_NEPTUNE:
James Smart12222f42014-05-21 08:05:19 -04002126 m = (typeof(m)){"LPe1000", "PCIe",
2127 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002128 break;
2129 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart12222f42014-05-21 08:05:19 -04002130 m = (typeof(m)){"LPe1000-SP", "PCIe",
2131 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002132 break;
2133 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart12222f42014-05-21 08:05:19 -04002134 m = (typeof(m)){"LPe1002-SP", "PCIe",
2135 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002136 break;
dea31012005-04-17 16:05:31 -05002137 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05002138 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002139 break;
2140 case PCI_DEVICE_ID_BSMB:
James Smart12222f42014-05-21 08:05:19 -04002141 m = (typeof(m)){"LP111", "PCI-X2",
2142 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002143 break;
2144 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05002145 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002146 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002147 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002148 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002149 break;
2150 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002151 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04002152 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002153 break;
dea31012005-04-17 16:05:31 -05002154 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05002155 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002156 break;
2157 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05002158 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002159 break;
2160 case PCI_DEVICE_ID_LP101:
James Smart12222f42014-05-21 08:05:19 -04002161 m = (typeof(m)){"LP101", "PCI-X",
2162 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002163 break;
2164 case PCI_DEVICE_ID_LP10000S:
James Smart12222f42014-05-21 08:05:19 -04002165 m = (typeof(m)){"LP10000-S", "PCI",
2166 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002167 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002168 case PCI_DEVICE_ID_LP11000S:
James Smart12222f42014-05-21 08:05:19 -04002169 m = (typeof(m)){"LP11000-S", "PCI-X2",
2170 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05002171 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002172 case PCI_DEVICE_ID_LPE11000S:
James Smart12222f42014-05-21 08:05:19 -04002173 m = (typeof(m)){"LPe11000-S", "PCIe",
2174 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002175 break;
James Smartb87eab32007-04-25 09:53:28 -04002176 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05002177 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002178 break;
2179 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05002180 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002181 break;
2182 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05002183 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002184 break;
2185 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002186 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002187 break;
2188 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002189 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002190 break;
2191 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05002192 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002193 break;
James Smart84774a42008-08-24 21:50:06 -04002194 case PCI_DEVICE_ID_HORNET:
James Smart12222f42014-05-21 08:05:19 -04002195 m = (typeof(m)){"LP21000", "PCIe",
2196 "Obsolete, Unsupported FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002197 GE = 1;
2198 break;
2199 case PCI_DEVICE_ID_PROTEUS_VF:
James Smarta747c9c2009-11-18 15:41:10 -05002200 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002201 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002202 break;
2203 case PCI_DEVICE_ID_PROTEUS_PF:
James Smarta747c9c2009-11-18 15:41:10 -05002204 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002205 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002206 break;
2207 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05002208 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002209 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002210 break;
James Smartda0436e2009-05-22 14:51:39 -04002211 case PCI_DEVICE_ID_TIGERSHARK:
2212 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002213 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04002214 break;
James Smarta747c9c2009-11-18 15:41:10 -05002215 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04002216 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002217 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2218 break;
2219 case PCI_DEVICE_ID_FALCON:
2220 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2221 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04002222 break;
James Smart98fc5dd2010-06-07 15:24:29 -04002223 case PCI_DEVICE_ID_BALIUS:
2224 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
James Smart12222f42014-05-21 08:05:19 -04002225 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart98fc5dd2010-06-07 15:24:29 -04002226 break;
James Smart085c6472010-11-20 23:11:37 -05002227 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04002228 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05002229 break;
James Smart12222f42014-05-21 08:05:19 -04002230 case PCI_DEVICE_ID_LANCER_FC_VF:
2231 m = (typeof(m)){"LPe16000", "PCIe",
2232 "Obsolete, Unsupported Fibre Channel Adapter"};
2233 break;
James Smart085c6472010-11-20 23:11:37 -05002234 case PCI_DEVICE_ID_LANCER_FCOE:
2235 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04002236 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05002237 break;
James Smart12222f42014-05-21 08:05:19 -04002238 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2239 oneConnect = 1;
2240 m = (typeof(m)){"OCe15100", "PCIe",
2241 "Obsolete, Unsupported FCoE"};
2242 break;
James Smartd38dd522015-08-31 16:48:17 -04002243 case PCI_DEVICE_ID_LANCER_G6_FC:
2244 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2245 break;
James Smartf8cafd32012-08-03 12:42:51 -04002246 case PCI_DEVICE_ID_SKYHAWK:
2247 case PCI_DEVICE_ID_SKYHAWK_VF:
2248 oneConnect = 1;
2249 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2250 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002251 default:
James Smarta747c9c2009-11-18 15:41:10 -05002252 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002253 break;
dea31012005-04-17 16:05:31 -05002254 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002255
2256 if (mdp && mdp[0] == '\0')
2257 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04002258 /*
2259 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04002260 * and we put the port number on the end
2261 */
2262 if (descp && descp[0] == '\0') {
2263 if (oneConnect)
2264 snprintf(descp, 255,
James Smart4169d862012-09-29 11:32:09 -04002265 "Emulex OneConnect %s, %s Initiator %s",
James Smarta747c9c2009-11-18 15:41:10 -05002266 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04002267 phba->Port);
James Smart4169d862012-09-29 11:32:09 -04002268 else if (max_speed == 0)
2269 snprintf(descp, 255,
Sebastian Herbszt290237d2015-08-31 16:48:08 -04002270 "Emulex %s %s %s",
James Smart4169d862012-09-29 11:32:09 -04002271 m.name, m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002272 else
2273 snprintf(descp, 255,
2274 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05002275 m.name, max_speed, (GE) ? "GE" : "Gb",
2276 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002277 }
dea31012005-04-17 16:05:31 -05002278}
2279
James Smarte59058c2008-08-24 21:49:00 -04002280/**
James Smart3621a712009-04-06 18:47:14 -04002281 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04002282 * @phba: pointer to lpfc hba data structure.
2283 * @pring: pointer to a IOCB ring.
2284 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2285 *
2286 * This routine posts a given number of IOCBs with the associated DMA buffer
2287 * descriptors specified by the cnt argument to the given IOCB ring.
2288 *
2289 * Return codes
2290 * The number of IOCBs NOT able to be posted to the IOCB ring.
2291 **/
dea31012005-04-17 16:05:31 -05002292int
James Smart495a7142008-06-14 22:52:59 -04002293lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002294{
2295 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002296 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002297 struct lpfc_dmabuf *mp1, *mp2;
2298
2299 cnt += pring->missbufcnt;
2300
2301 /* While there are buffers to post */
2302 while (cnt > 0) {
2303 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002304 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002305 if (iocb == NULL) {
2306 pring->missbufcnt = cnt;
2307 return cnt;
2308 }
dea31012005-04-17 16:05:31 -05002309 icmd = &iocb->iocb;
2310
2311 /* 2 buffers can be posted per command */
2312 /* Allocate buffer to post */
2313 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2314 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002315 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2316 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002317 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002318 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002319 pring->missbufcnt = cnt;
2320 return cnt;
2321 }
2322
2323 INIT_LIST_HEAD(&mp1->list);
2324 /* Allocate buffer to post */
2325 if (cnt > 1) {
2326 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2327 if (mp2)
2328 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2329 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002330 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002331 kfree(mp2);
dea31012005-04-17 16:05:31 -05002332 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2333 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002334 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002335 pring->missbufcnt = cnt;
2336 return cnt;
2337 }
2338
2339 INIT_LIST_HEAD(&mp2->list);
2340 } else {
2341 mp2 = NULL;
2342 }
2343
2344 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2345 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2346 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2347 icmd->ulpBdeCount = 1;
2348 cnt--;
2349 if (mp2) {
2350 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2351 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2352 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2353 cnt--;
2354 icmd->ulpBdeCount = 2;
2355 }
2356
2357 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2358 icmd->ulpLe = 1;
2359
James Smart3772a992009-05-22 14:50:54 -04002360 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2361 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002362 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2363 kfree(mp1);
2364 cnt++;
2365 if (mp2) {
2366 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2367 kfree(mp2);
2368 cnt++;
2369 }
James Bottomley604a3e32005-10-29 10:28:33 -05002370 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002371 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002372 return cnt;
2373 }
dea31012005-04-17 16:05:31 -05002374 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002375 if (mp2)
dea31012005-04-17 16:05:31 -05002376 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002377 }
2378 pring->missbufcnt = 0;
2379 return 0;
2380}
2381
James Smarte59058c2008-08-24 21:49:00 -04002382/**
James Smart3621a712009-04-06 18:47:14 -04002383 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002384 * @phba: pointer to lpfc hba data structure.
2385 *
2386 * This routine posts initial receive IOCB buffers to the ELS ring. The
2387 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2388 * set to 64 IOCBs.
2389 *
2390 * Return codes
2391 * 0 - success (currently always success)
2392 **/
dea31012005-04-17 16:05:31 -05002393static int
James Smart2e0fef82007-06-17 19:56:36 -05002394lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002395{
2396 struct lpfc_sli *psli = &phba->sli;
2397
2398 /* Ring 0, ELS / CT buffers */
James Smart495a7142008-06-14 22:52:59 -04002399 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002400 /* Ring 2 - FCP no buffers needed */
2401
2402 return 0;
2403}
2404
2405#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2406
James Smarte59058c2008-08-24 21:49:00 -04002407/**
James Smart3621a712009-04-06 18:47:14 -04002408 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002409 * @HashResultPointer: pointer to an array as hash table.
2410 *
2411 * This routine sets up the initial values to the array of hash table entries
2412 * for the LC HBAs.
2413 **/
dea31012005-04-17 16:05:31 -05002414static void
2415lpfc_sha_init(uint32_t * HashResultPointer)
2416{
2417 HashResultPointer[0] = 0x67452301;
2418 HashResultPointer[1] = 0xEFCDAB89;
2419 HashResultPointer[2] = 0x98BADCFE;
2420 HashResultPointer[3] = 0x10325476;
2421 HashResultPointer[4] = 0xC3D2E1F0;
2422}
2423
James Smarte59058c2008-08-24 21:49:00 -04002424/**
James Smart3621a712009-04-06 18:47:14 -04002425 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002426 * @HashResultPointer: pointer to an initial/result hash table.
2427 * @HashWorkingPointer: pointer to an working hash table.
2428 *
2429 * This routine iterates an initial hash table pointed by @HashResultPointer
2430 * with the values from the working hash table pointeed by @HashWorkingPointer.
2431 * The results are putting back to the initial hash table, returned through
2432 * the @HashResultPointer as the result hash table.
2433 **/
dea31012005-04-17 16:05:31 -05002434static void
2435lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2436{
2437 int t;
2438 uint32_t TEMP;
2439 uint32_t A, B, C, D, E;
2440 t = 16;
2441 do {
2442 HashWorkingPointer[t] =
2443 S(1,
2444 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2445 8] ^
2446 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2447 } while (++t <= 79);
2448 t = 0;
2449 A = HashResultPointer[0];
2450 B = HashResultPointer[1];
2451 C = HashResultPointer[2];
2452 D = HashResultPointer[3];
2453 E = HashResultPointer[4];
2454
2455 do {
2456 if (t < 20) {
2457 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2458 } else if (t < 40) {
2459 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2460 } else if (t < 60) {
2461 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2462 } else {
2463 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2464 }
2465 TEMP += S(5, A) + E + HashWorkingPointer[t];
2466 E = D;
2467 D = C;
2468 C = S(30, B);
2469 B = A;
2470 A = TEMP;
2471 } while (++t <= 79);
2472
2473 HashResultPointer[0] += A;
2474 HashResultPointer[1] += B;
2475 HashResultPointer[2] += C;
2476 HashResultPointer[3] += D;
2477 HashResultPointer[4] += E;
2478
2479}
2480
James Smarte59058c2008-08-24 21:49:00 -04002481/**
James Smart3621a712009-04-06 18:47:14 -04002482 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002483 * @RandomChallenge: pointer to the entry of host challenge random number array.
2484 * @HashWorking: pointer to the entry of the working hash array.
2485 *
2486 * This routine calculates the working hash array referred by @HashWorking
2487 * from the challenge random numbers associated with the host, referred by
2488 * @RandomChallenge. The result is put into the entry of the working hash
2489 * array and returned by reference through @HashWorking.
2490 **/
dea31012005-04-17 16:05:31 -05002491static void
2492lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2493{
2494 *HashWorking = (*RandomChallenge ^ *HashWorking);
2495}
2496
James Smarte59058c2008-08-24 21:49:00 -04002497/**
James Smart3621a712009-04-06 18:47:14 -04002498 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002499 * @phba: pointer to lpfc hba data structure.
2500 * @hbainit: pointer to an array of unsigned 32-bit integers.
2501 *
2502 * This routine performs the special handling for LC HBA initialization.
2503 **/
dea31012005-04-17 16:05:31 -05002504void
2505lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2506{
2507 int t;
2508 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002509 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002510
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002511 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002512 if (!HashWorking)
2513 return;
2514
dea31012005-04-17 16:05:31 -05002515 HashWorking[0] = HashWorking[78] = *pwwnn++;
2516 HashWorking[1] = HashWorking[79] = *pwwnn;
2517
2518 for (t = 0; t < 7; t++)
2519 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2520
2521 lpfc_sha_init(hbainit);
2522 lpfc_sha_iterate(hbainit, HashWorking);
2523 kfree(HashWorking);
2524}
2525
James Smarte59058c2008-08-24 21:49:00 -04002526/**
James Smart3621a712009-04-06 18:47:14 -04002527 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002528 * @vport: pointer to a virtual N_Port data structure.
2529 *
2530 * This routine performs the necessary cleanups before deleting the @vport.
2531 * It invokes the discovery state machine to perform necessary state
2532 * transitions and to release the ndlps associated with the @vport. Note,
2533 * the physical port is treated as @vport 0.
2534 **/
James Smart87af33f2007-10-27 13:37:43 -04002535void
James Smart2e0fef82007-06-17 19:56:36 -05002536lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002537{
James Smart87af33f2007-10-27 13:37:43 -04002538 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002539 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002540 int i = 0;
dea31012005-04-17 16:05:31 -05002541
James Smart87af33f2007-10-27 13:37:43 -04002542 if (phba->link_state > LPFC_LINK_DOWN)
2543 lpfc_port_link_failure(vport);
2544
2545 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002546 if (!NLP_CHK_NODE_ACT(ndlp)) {
2547 ndlp = lpfc_enable_node(vport, ndlp,
2548 NLP_STE_UNUSED_NODE);
2549 if (!ndlp)
2550 continue;
2551 spin_lock_irq(&phba->ndlp_lock);
2552 NLP_SET_FREE_REQ(ndlp);
2553 spin_unlock_irq(&phba->ndlp_lock);
2554 /* Trigger the release of the ndlp memory */
2555 lpfc_nlp_put(ndlp);
2556 continue;
2557 }
2558 spin_lock_irq(&phba->ndlp_lock);
2559 if (NLP_CHK_FREE_REQ(ndlp)) {
2560 /* The ndlp should not be in memory free mode already */
2561 spin_unlock_irq(&phba->ndlp_lock);
2562 continue;
2563 } else
2564 /* Indicate request for freeing ndlp memory */
2565 NLP_SET_FREE_REQ(ndlp);
2566 spin_unlock_irq(&phba->ndlp_lock);
2567
James Smart58da1ff2008-04-07 10:15:56 -04002568 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2569 ndlp->nlp_DID == Fabric_DID) {
2570 /* Just free up ndlp with Fabric_DID for vports */
2571 lpfc_nlp_put(ndlp);
2572 continue;
2573 }
2574
James Smarteff4a012012-01-18 16:25:25 -05002575 /* take care of nodes in unused state before the state
2576 * machine taking action.
2577 */
2578 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2579 lpfc_nlp_put(ndlp);
2580 continue;
2581 }
2582
James Smart87af33f2007-10-27 13:37:43 -04002583 if (ndlp->nlp_type & NLP_FABRIC)
2584 lpfc_disc_state_machine(vport, ndlp, NULL,
2585 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002586
James Smart87af33f2007-10-27 13:37:43 -04002587 lpfc_disc_state_machine(vport, ndlp, NULL,
2588 NLP_EVT_DEVICE_RM);
2589 }
2590
James Smarta8adb832007-10-27 13:37:53 -04002591 /* At this point, ALL ndlp's should be gone
2592 * because of the previous NLP_EVT_DEVICE_RM.
2593 * Lets wait for this to happen, if needed.
2594 */
James Smart87af33f2007-10-27 13:37:43 -04002595 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002596 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04002597 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04002598 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002599 list_for_each_entry_safe(ndlp, next_ndlp,
2600 &vport->fc_nodes, nlp_listp) {
2601 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2602 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04002603 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05002604 "usgmap:x%x refcnt:%d\n",
2605 ndlp->nlp_DID, (void *)ndlp,
2606 ndlp->nlp_usg_map,
2607 atomic_read(
2608 &ndlp->kref.refcount));
2609 }
James Smarta8adb832007-10-27 13:37:53 -04002610 break;
James Smart87af33f2007-10-27 13:37:43 -04002611 }
James Smarta8adb832007-10-27 13:37:53 -04002612
2613 /* Wait for any activity on ndlps to settle */
2614 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002615 }
James Smart1151e3e2011-02-16 12:39:35 -05002616 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002617}
2618
James Smarte59058c2008-08-24 21:49:00 -04002619/**
James Smart3621a712009-04-06 18:47:14 -04002620 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002621 * @vport: pointer to a virtual N_Port data structure.
2622 *
2623 * This routine stops all the timers associated with a @vport. This function
2624 * is invoked before disabling or deleting a @vport. Note that the physical
2625 * port is treated as @vport 0.
2626 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002627void
2628lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002629{
James Smart92d7f7b2007-06-17 19:56:38 -05002630 del_timer_sync(&vport->els_tmofunc);
James Smart92494142011-02-16 12:39:44 -05002631 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002632 lpfc_can_disctmo(vport);
2633 return;
dea31012005-04-17 16:05:31 -05002634}
2635
James Smarte59058c2008-08-24 21:49:00 -04002636/**
James Smartecfd03c2010-02-12 14:41:27 -05002637 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2638 * @phba: pointer to lpfc hba data structure.
2639 *
2640 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2641 * caller of this routine should already hold the host lock.
2642 **/
2643void
2644__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2645{
James Smart5ac6b302010-10-22 11:05:36 -04002646 /* Clear pending FCF rediscovery wait flag */
2647 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2648
James Smartecfd03c2010-02-12 14:41:27 -05002649 /* Now, try to stop the timer */
2650 del_timer(&phba->fcf.redisc_wait);
2651}
2652
2653/**
2654 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2655 * @phba: pointer to lpfc hba data structure.
2656 *
2657 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2658 * checks whether the FCF rediscovery wait timer is pending with the host
2659 * lock held before proceeding with disabling the timer and clearing the
2660 * wait timer pendig flag.
2661 **/
2662void
2663lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2664{
2665 spin_lock_irq(&phba->hbalock);
2666 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2667 /* FCF rediscovery timer already fired or stopped */
2668 spin_unlock_irq(&phba->hbalock);
2669 return;
2670 }
2671 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002672 /* Clear failover in progress flags */
2673 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002674 spin_unlock_irq(&phba->hbalock);
2675}
2676
2677/**
James Smart3772a992009-05-22 14:50:54 -04002678 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002679 * @phba: pointer to lpfc hba data structure.
2680 *
2681 * This routine stops all the timers associated with a HBA. This function is
2682 * invoked before either putting a HBA offline or unloading the driver.
2683 **/
James Smart3772a992009-05-22 14:50:54 -04002684void
2685lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002686{
James Smart51ef4c22007-08-02 11:10:31 -04002687 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05002688 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002689 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002690 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002691 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002692 if (phba->sli_rev == LPFC_SLI_REV4) {
2693 del_timer_sync(&phba->rrq_tmr);
2694 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2695 }
James Smart3772a992009-05-22 14:50:54 -04002696 phba->hb_outstanding = 0;
2697
2698 switch (phba->pci_dev_grp) {
2699 case LPFC_PCI_DEV_LP:
2700 /* Stop any LightPulse device specific driver timers */
2701 del_timer_sync(&phba->fcp_poll_timer);
2702 break;
2703 case LPFC_PCI_DEV_OC:
2704 /* Stop any OneConnect device sepcific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002705 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002706 break;
2707 default:
2708 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2709 "0297 Invalid device group (x%x)\n",
2710 phba->pci_dev_grp);
2711 break;
2712 }
James Smart2e0fef82007-06-17 19:56:36 -05002713 return;
dea31012005-04-17 16:05:31 -05002714}
2715
James Smarte59058c2008-08-24 21:49:00 -04002716/**
James Smart3621a712009-04-06 18:47:14 -04002717 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002718 * @phba: pointer to lpfc hba data structure.
2719 *
2720 * This routine marks a HBA's management interface as blocked. Once the HBA's
2721 * management interface is marked as blocked, all the user space access to
2722 * the HBA, whether they are from sysfs interface or libdfc interface will
2723 * all be blocked. The HBA is set to block the management interface when the
2724 * driver prepares the HBA interface for online or offline.
2725 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01002726static void
James Smart618a5232012-06-12 13:54:36 -04002727lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
Adrian Bunka6ababd2007-11-05 18:07:33 +01002728{
2729 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04002730 uint8_t actcmd = MBX_HEARTBEAT;
2731 unsigned long timeout;
2732
Adrian Bunka6ababd2007-11-05 18:07:33 +01002733 spin_lock_irqsave(&phba->hbalock, iflag);
2734 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart618a5232012-06-12 13:54:36 -04002735 spin_unlock_irqrestore(&phba->hbalock, iflag);
2736 if (mbx_action == LPFC_MBX_NO_WAIT)
2737 return;
2738 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2739 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002740 if (phba->sli.mbox_active) {
James Smart6e7288d2010-06-07 15:23:35 -04002741 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
James Smarta183a152011-10-10 21:32:43 -04002742 /* Determine how long we might wait for the active mailbox
2743 * command to be gracefully completed by firmware.
2744 */
2745 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
2746 phba->sli.mbox_active) * 1000) + jiffies;
2747 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002748 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002749
James Smart6e7288d2010-06-07 15:23:35 -04002750 /* Wait for the outstnading mailbox command to complete */
2751 while (phba->sli.mbox_active) {
2752 /* Check active mailbox complete status every 2ms */
2753 msleep(2);
2754 if (time_after(jiffies, timeout)) {
2755 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2756 "2813 Mgmt IO is Blocked %x "
2757 "- mbox cmd %x still active\n",
2758 phba->sli.sli_flag, actcmd);
2759 break;
2760 }
2761 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002762}
2763
James Smarte59058c2008-08-24 21:49:00 -04002764/**
James Smart6b5151f2012-01-18 16:24:06 -05002765 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
2766 * @phba: pointer to lpfc hba data structure.
2767 *
2768 * Allocate RPIs for all active remote nodes. This is needed whenever
2769 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
2770 * is to fixup the temporary rpi assignments.
2771 **/
2772void
2773lpfc_sli4_node_prep(struct lpfc_hba *phba)
2774{
2775 struct lpfc_nodelist *ndlp, *next_ndlp;
2776 struct lpfc_vport **vports;
2777 int i;
2778
2779 if (phba->sli_rev != LPFC_SLI_REV4)
2780 return;
2781
2782 vports = lpfc_create_vport_work_array(phba);
2783 if (vports != NULL) {
2784 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2785 if (vports[i]->load_flag & FC_UNLOADING)
2786 continue;
2787
2788 list_for_each_entry_safe(ndlp, next_ndlp,
2789 &vports[i]->fc_nodes,
2790 nlp_listp) {
James Smartbe6bb942015-04-07 15:07:22 -04002791 if (NLP_CHK_NODE_ACT(ndlp)) {
James Smart6b5151f2012-01-18 16:24:06 -05002792 ndlp->nlp_rpi =
2793 lpfc_sli4_alloc_rpi(phba);
James Smartbe6bb942015-04-07 15:07:22 -04002794 lpfc_printf_vlog(ndlp->vport, KERN_INFO,
2795 LOG_NODE,
2796 "0009 rpi:%x DID:%x "
2797 "flg:%x map:%x %p\n",
2798 ndlp->nlp_rpi,
2799 ndlp->nlp_DID,
2800 ndlp->nlp_flag,
2801 ndlp->nlp_usg_map,
2802 ndlp);
2803 }
James Smart6b5151f2012-01-18 16:24:06 -05002804 }
2805 }
2806 }
2807 lpfc_destroy_vport_work_array(phba, vports);
2808}
2809
2810/**
James Smart3621a712009-04-06 18:47:14 -04002811 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04002812 * @phba: pointer to lpfc hba data structure.
2813 *
2814 * This routine initializes the HBA and brings a HBA online. During this
2815 * process, the management interface is blocked to prevent user space access
2816 * to the HBA interfering with the driver initialization.
2817 *
2818 * Return codes
2819 * 0 - successful
2820 * 1 - failed
2821 **/
dea31012005-04-17 16:05:31 -05002822int
James Smart2e0fef82007-06-17 19:56:36 -05002823lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002824{
Julia Lawall372bd282008-12-16 16:15:08 +01002825 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04002826 struct lpfc_vport **vports;
2827 int i;
James Smart16a3a202013-04-17 20:14:38 -04002828 bool vpis_cleared = false;
James Smart2e0fef82007-06-17 19:56:36 -05002829
dea31012005-04-17 16:05:31 -05002830 if (!phba)
2831 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01002832 vport = phba->pport;
dea31012005-04-17 16:05:31 -05002833
James Smart2e0fef82007-06-17 19:56:36 -05002834 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05002835 return 0;
2836
James Smarted957682007-06-17 19:56:37 -05002837 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002838 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05002839
James Smart618a5232012-06-12 13:54:36 -04002840 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05002841
James Smart46fa3112007-04-25 09:51:45 -04002842 if (!lpfc_sli_queue_setup(phba)) {
2843 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002844 return 1;
James Smart46fa3112007-04-25 09:51:45 -04002845 }
2846
James Smartda0436e2009-05-22 14:51:39 -04002847 if (phba->sli_rev == LPFC_SLI_REV4) {
2848 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
2849 lpfc_unblock_mgmt_io(phba);
2850 return 1;
2851 }
James Smart16a3a202013-04-17 20:14:38 -04002852 spin_lock_irq(&phba->hbalock);
2853 if (!phba->sli4_hba.max_cfg_param.vpi_used)
2854 vpis_cleared = true;
2855 spin_unlock_irq(&phba->hbalock);
James Smartda0436e2009-05-22 14:51:39 -04002856 } else {
2857 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
2858 lpfc_unblock_mgmt_io(phba);
2859 return 1;
2860 }
James Smart46fa3112007-04-25 09:51:45 -04002861 }
dea31012005-04-17 16:05:31 -05002862
James Smart549e55c2007-08-02 11:09:51 -04002863 vports = lpfc_create_vport_work_array(phba);
Arnd Bergmannaeb66412016-03-14 15:29:44 +01002864 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04002865 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002866 struct Scsi_Host *shost;
2867 shost = lpfc_shost_from_vport(vports[i]);
2868 spin_lock_irq(shost->host_lock);
2869 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
2870 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2871 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart16a3a202013-04-17 20:14:38 -04002872 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart1c6834a2009-07-19 10:01:26 -04002873 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart16a3a202013-04-17 20:14:38 -04002874 if ((vpis_cleared) &&
2875 (vports[i]->port_type !=
2876 LPFC_PHYSICAL_PORT))
2877 vports[i]->vpi = 0;
2878 }
James Smart549e55c2007-08-02 11:09:51 -04002879 spin_unlock_irq(shost->host_lock);
2880 }
Arnd Bergmannaeb66412016-03-14 15:29:44 +01002881 }
2882 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002883
James Smart46fa3112007-04-25 09:51:45 -04002884 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002885 return 0;
2886}
2887
James Smarte59058c2008-08-24 21:49:00 -04002888/**
James Smart3621a712009-04-06 18:47:14 -04002889 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04002890 * @phba: pointer to lpfc hba data structure.
2891 *
2892 * This routine marks a HBA's management interface as not blocked. Once the
2893 * HBA's management interface is marked as not blocked, all the user space
2894 * access to the HBA, whether they are from sysfs interface or libdfc
2895 * interface will be allowed. The HBA is set to block the management interface
2896 * when the driver prepares the HBA interface for online or offline and then
2897 * set to unblock the management interface afterwards.
2898 **/
James Smart46fa3112007-04-25 09:51:45 -04002899void
James Smart46fa3112007-04-25 09:51:45 -04002900lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
2901{
2902 unsigned long iflag;
2903
James Smart2e0fef82007-06-17 19:56:36 -05002904 spin_lock_irqsave(&phba->hbalock, iflag);
2905 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
2906 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04002907}
2908
James Smarte59058c2008-08-24 21:49:00 -04002909/**
James Smart3621a712009-04-06 18:47:14 -04002910 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04002911 * @phba: pointer to lpfc hba data structure.
2912 *
2913 * This routine is invoked to prepare a HBA to be brought offline. It performs
2914 * unregistration login to all the nodes on all vports and flushes the mailbox
2915 * queue to make it ready to be brought offline.
2916 **/
James Smart46fa3112007-04-25 09:51:45 -04002917void
James Smart618a5232012-06-12 13:54:36 -04002918lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04002919{
James Smart2e0fef82007-06-17 19:56:36 -05002920 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04002921 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04002922 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05002923 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04002924 int i;
dea31012005-04-17 16:05:31 -05002925
James Smart2e0fef82007-06-17 19:56:36 -05002926 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002927 return;
dea31012005-04-17 16:05:31 -05002928
James Smart618a5232012-06-12 13:54:36 -04002929 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05002930
2931 lpfc_linkdown(phba);
2932
James Smart87af33f2007-10-27 13:37:43 -04002933 /* Issue an unreg_login to all nodes on all vports */
2934 vports = lpfc_create_vport_work_array(phba);
2935 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04002936 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04002937 if (vports[i]->load_flag & FC_UNLOADING)
2938 continue;
James Smart72100cc2010-02-12 14:43:01 -05002939 shost = lpfc_shost_from_vport(vports[i]);
2940 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05002941 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002942 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2943 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05002944 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05002945
James Smart87af33f2007-10-27 13:37:43 -04002946 shost = lpfc_shost_from_vport(vports[i]);
2947 list_for_each_entry_safe(ndlp, next_ndlp,
2948 &vports[i]->fc_nodes,
2949 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002950 if (!NLP_CHK_NODE_ACT(ndlp))
2951 continue;
James Smart87af33f2007-10-27 13:37:43 -04002952 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2953 continue;
2954 if (ndlp->nlp_type & NLP_FABRIC) {
2955 lpfc_disc_state_machine(vports[i], ndlp,
2956 NULL, NLP_EVT_DEVICE_RECOVERY);
2957 lpfc_disc_state_machine(vports[i], ndlp,
2958 NULL, NLP_EVT_DEVICE_RM);
2959 }
2960 spin_lock_irq(shost->host_lock);
2961 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart401ee0c2012-03-01 22:35:34 -05002962 spin_unlock_irq(shost->host_lock);
James Smart6b5151f2012-01-18 16:24:06 -05002963 /*
2964 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05002965 * RPI. Get a new RPI when the adapter port
2966 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05002967 */
James Smartbe6bb942015-04-07 15:07:22 -04002968 if (phba->sli_rev == LPFC_SLI_REV4) {
2969 lpfc_printf_vlog(ndlp->vport,
2970 KERN_INFO, LOG_NODE,
2971 "0011 lpfc_offline: "
2972 "ndlp:x%p did %x "
2973 "usgmap:x%x rpi:%x\n",
2974 ndlp, ndlp->nlp_DID,
2975 ndlp->nlp_usg_map,
2976 ndlp->nlp_rpi);
2977
James Smart6b5151f2012-01-18 16:24:06 -05002978 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smartbe6bb942015-04-07 15:07:22 -04002979 }
James Smart87af33f2007-10-27 13:37:43 -04002980 lpfc_unreg_rpi(vports[i], ndlp);
2981 }
2982 }
2983 }
James Smart09372822008-01-11 01:52:54 -05002984 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002985
James Smart618a5232012-06-12 13:54:36 -04002986 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
James Smart46fa3112007-04-25 09:51:45 -04002987}
2988
James Smarte59058c2008-08-24 21:49:00 -04002989/**
James Smart3621a712009-04-06 18:47:14 -04002990 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04002991 * @phba: pointer to lpfc hba data structure.
2992 *
2993 * This routine actually brings a HBA offline. It stops all the timers
2994 * associated with the HBA, brings down the SLI layer, and eventually
2995 * marks the HBA as in offline state for the upper layer protocol.
2996 **/
James Smart46fa3112007-04-25 09:51:45 -04002997void
James Smart2e0fef82007-06-17 19:56:36 -05002998lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04002999{
James Smart549e55c2007-08-02 11:09:51 -04003000 struct Scsi_Host *shost;
3001 struct lpfc_vport **vports;
3002 int i;
James Smart46fa3112007-04-25 09:51:45 -04003003
James Smart549e55c2007-08-02 11:09:51 -04003004 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003005 return;
James Smart688a8862006-07-06 15:49:56 -04003006
James Smartda0436e2009-05-22 14:51:39 -04003007 /* stop port and all timers associated with this hba */
3008 lpfc_stop_port(phba);
James Smart51ef4c22007-08-02 11:10:31 -04003009 vports = lpfc_create_vport_work_array(phba);
3010 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003011 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04003012 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05003013 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05003014 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003015 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05003016 /* Bring down the SLI Layer and cleanup. The HBA is offline
3017 now. */
3018 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003019 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04003020 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003021 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04003022 vports = lpfc_create_vport_work_array(phba);
3023 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003024 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003025 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04003026 spin_lock_irq(shost->host_lock);
3027 vports[i]->work_port_events = 0;
3028 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3029 spin_unlock_irq(shost->host_lock);
3030 }
James Smart09372822008-01-11 01:52:54 -05003031 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003032}
3033
James Smarte59058c2008-08-24 21:49:00 -04003034/**
James Smart3621a712009-04-06 18:47:14 -04003035 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04003036 * @phba: pointer to lpfc hba data structure.
3037 *
3038 * This routine is to free all the SCSI buffers and IOCBs from the driver
3039 * list back to kernel. It is called from lpfc_pci_remove_one to free
3040 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04003041 **/
James Smart8a9d2e82012-05-09 21:16:12 -04003042static void
James Smart2e0fef82007-06-17 19:56:36 -05003043lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003044{
3045 struct lpfc_scsi_buf *sb, *sb_next;
3046 struct lpfc_iocbq *io, *io_next;
3047
James Smart2e0fef82007-06-17 19:56:36 -05003048 spin_lock_irq(&phba->hbalock);
James Smarta40fc5f2013-04-17 20:17:40 -04003049
dea31012005-04-17 16:05:31 -05003050 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smarta40fc5f2013-04-17 20:17:40 -04003051
3052 spin_lock(&phba->scsi_buf_list_put_lock);
3053 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3054 list) {
dea31012005-04-17 16:05:31 -05003055 list_del(&sb->list);
3056 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05003057 sb->dma_handle);
dea31012005-04-17 16:05:31 -05003058 kfree(sb);
3059 phba->total_scsi_bufs--;
3060 }
James Smarta40fc5f2013-04-17 20:17:40 -04003061 spin_unlock(&phba->scsi_buf_list_put_lock);
3062
3063 spin_lock(&phba->scsi_buf_list_get_lock);
3064 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3065 list) {
3066 list_del(&sb->list);
3067 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
3068 sb->dma_handle);
3069 kfree(sb);
3070 phba->total_scsi_bufs--;
3071 }
3072 spin_unlock(&phba->scsi_buf_list_get_lock);
dea31012005-04-17 16:05:31 -05003073
3074 /* Release all the lpfc_iocbq entries maintained by this host. */
3075 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
3076 list_del(&io->list);
3077 kfree(io);
3078 phba->total_iocbq_bufs--;
3079 }
James Smart6d368e52011-05-24 11:44:12 -04003080
James Smart2e0fef82007-06-17 19:56:36 -05003081 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003082}
3083
3084/**
3085 * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping
3086 * @phba: pointer to lpfc hba data structure.
3087 *
3088 * This routine first calculates the sizes of the current els and allocated
3089 * scsi sgl lists, and then goes through all sgls to updates the physical
3090 * XRIs assigned due to port function reset. During port initialization, the
3091 * current els and allocated scsi sgl lists are 0s.
3092 *
3093 * Return codes
3094 * 0 - successful (for now, it always returns 0)
3095 **/
3096int
3097lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba)
3098{
3099 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3100 struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL;
3101 uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt;
3102 LIST_HEAD(els_sgl_list);
3103 LIST_HEAD(scsi_sgl_list);
3104 int rc;
James Smartdafe8ce2014-09-03 12:56:40 -04003105 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart8a9d2e82012-05-09 21:16:12 -04003106
3107 /*
3108 * update on pci function's els xri-sgl list
3109 */
3110 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3111 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3112 /* els xri-sgl expanded */
3113 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3114 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3115 "3157 ELS xri-sgl count increased from "
3116 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3117 els_xri_cnt);
3118 /* allocate the additional els sgls */
3119 for (i = 0; i < xri_cnt; i++) {
3120 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3121 GFP_KERNEL);
3122 if (sglq_entry == NULL) {
3123 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3124 "2562 Failure to allocate an "
3125 "ELS sgl entry:%d\n", i);
3126 rc = -ENOMEM;
3127 goto out_free_mem;
3128 }
3129 sglq_entry->buff_type = GEN_BUFF_TYPE;
3130 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3131 &sglq_entry->phys);
3132 if (sglq_entry->virt == NULL) {
3133 kfree(sglq_entry);
3134 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3135 "2563 Failure to allocate an "
3136 "ELS mbuf:%d\n", i);
3137 rc = -ENOMEM;
3138 goto out_free_mem;
3139 }
3140 sglq_entry->sgl = sglq_entry->virt;
3141 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3142 sglq_entry->state = SGL_FREED;
3143 list_add_tail(&sglq_entry->list, &els_sgl_list);
3144 }
James Smart38c20672013-03-01 16:37:44 -05003145 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04003146 spin_lock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003147 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04003148 spin_unlock(&pring->ring_lock);
James Smart38c20672013-03-01 16:37:44 -05003149 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003150 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3151 /* els xri-sgl shrinked */
3152 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3153 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3154 "3158 ELS xri-sgl count decreased from "
3155 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3156 els_xri_cnt);
3157 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04003158 spin_lock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003159 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04003160 spin_unlock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003161 spin_unlock_irq(&phba->hbalock);
3162 /* release extra els sgls from list */
3163 for (i = 0; i < xri_cnt; i++) {
3164 list_remove_head(&els_sgl_list,
3165 sglq_entry, struct lpfc_sglq, list);
3166 if (sglq_entry) {
3167 lpfc_mbuf_free(phba, sglq_entry->virt,
3168 sglq_entry->phys);
3169 kfree(sglq_entry);
3170 }
3171 }
3172 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04003173 spin_lock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003174 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04003175 spin_unlock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003176 spin_unlock_irq(&phba->hbalock);
3177 } else
3178 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3179 "3163 ELS xri-sgl count unchanged: %d\n",
3180 els_xri_cnt);
3181 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3182
3183 /* update xris to els sgls on the list */
3184 sglq_entry = NULL;
3185 sglq_entry_next = NULL;
3186 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3187 &phba->sli4_hba.lpfc_sgl_list, list) {
3188 lxri = lpfc_sli4_next_xritag(phba);
3189 if (lxri == NO_XRI) {
3190 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3191 "2400 Failed to allocate xri for "
3192 "ELS sgl\n");
3193 rc = -ENOMEM;
3194 goto out_free_mem;
3195 }
3196 sglq_entry->sli4_lxritag = lxri;
3197 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3198 }
3199
3200 /*
3201 * update on pci function's allocated scsi xri-sgl list
3202 */
3203 phba->total_scsi_bufs = 0;
3204
3205 /* maximum number of xris available for scsi buffers */
3206 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3207 els_xri_cnt;
3208
3209 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3210 "2401 Current allocated SCSI xri-sgl count:%d, "
3211 "maximum SCSI xri count:%d\n",
3212 phba->sli4_hba.scsi_xri_cnt,
3213 phba->sli4_hba.scsi_xri_max);
3214
James Smarta40fc5f2013-04-17 20:17:40 -04003215 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003216 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003217 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3218 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
James Smart164cecd2013-09-06 12:22:38 -04003219 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003220 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003221
3222 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3223 /* max scsi xri shrinked below the allocated scsi buffers */
3224 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3225 phba->sli4_hba.scsi_xri_max;
3226 /* release the extra allocated scsi buffers */
3227 for (i = 0; i < scsi_xri_cnt; i++) {
3228 list_remove_head(&scsi_sgl_list, psb,
3229 struct lpfc_scsi_buf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04003230 if (psb) {
3231 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
3232 psb->data, psb->dma_handle);
3233 kfree(psb);
3234 }
James Smart8a9d2e82012-05-09 21:16:12 -04003235 }
James Smarta40fc5f2013-04-17 20:17:40 -04003236 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003237 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
James Smarta40fc5f2013-04-17 20:17:40 -04003238 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003239 }
3240
3241 /* update xris associated to remaining allocated scsi buffers */
3242 psb = NULL;
3243 psb_next = NULL;
3244 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3245 lxri = lpfc_sli4_next_xritag(phba);
3246 if (lxri == NO_XRI) {
3247 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3248 "2560 Failed to allocate xri for "
3249 "scsi buffer\n");
3250 rc = -ENOMEM;
3251 goto out_free_mem;
3252 }
3253 psb->cur_iocbq.sli4_lxritag = lxri;
3254 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3255 }
James Smarta40fc5f2013-04-17 20:17:40 -04003256 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003257 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003258 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3259 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
James Smart164cecd2013-09-06 12:22:38 -04003260 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003261 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003262
dea31012005-04-17 16:05:31 -05003263 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003264
3265out_free_mem:
3266 lpfc_free_els_sgl_list(phba);
3267 lpfc_scsi_free(phba);
3268 return rc;
dea31012005-04-17 16:05:31 -05003269}
3270
James Smarte59058c2008-08-24 21:49:00 -04003271/**
James Smart3621a712009-04-06 18:47:14 -04003272 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04003273 * @phba: pointer to lpfc hba data structure.
3274 * @instance: a unique integer ID to this FC port.
3275 * @dev: pointer to the device data structure.
3276 *
3277 * This routine creates a FC port for the upper layer protocol. The FC port
3278 * can be created on top of either a physical port or a virtual port provided
3279 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3280 * and associates the FC port created before adding the shost into the SCSI
3281 * layer.
3282 *
3283 * Return codes
3284 * @vport - pointer to the virtual N_Port data structure.
3285 * NULL - port create failed.
3286 **/
James Smart2e0fef82007-06-17 19:56:36 -05003287struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04003288lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04003289{
James Smart2e0fef82007-06-17 19:56:36 -05003290 struct lpfc_vport *vport;
3291 struct Scsi_Host *shost;
3292 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04003293
James Smartea4142f2015-04-07 15:07:13 -04003294 if (dev != &phba->pcidev->dev) {
James Smart3de2a652007-08-02 11:09:59 -04003295 shost = scsi_host_alloc(&lpfc_vport_template,
3296 sizeof(struct lpfc_vport));
James Smartea4142f2015-04-07 15:07:13 -04003297 } else {
3298 if (phba->sli_rev == LPFC_SLI_REV4)
3299 shost = scsi_host_alloc(&lpfc_template,
James Smart3de2a652007-08-02 11:09:59 -04003300 sizeof(struct lpfc_vport));
James Smartea4142f2015-04-07 15:07:13 -04003301 else
3302 shost = scsi_host_alloc(&lpfc_template_s3,
3303 sizeof(struct lpfc_vport));
3304 }
James Smart2e0fef82007-06-17 19:56:36 -05003305 if (!shost)
3306 goto out;
James Smart47a86172007-04-25 09:53:22 -04003307
James Smart2e0fef82007-06-17 19:56:36 -05003308 vport = (struct lpfc_vport *) shost->hostdata;
3309 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05003310 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05003311 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05003312 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04003313
James Smart3de2a652007-08-02 11:09:59 -04003314 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05003315 shost->unique_id = instance;
3316 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04003317 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05003318 shost->this_id = -1;
3319 shost->max_cmd_len = 16;
James Smart8b0dff12015-05-22 10:42:38 -04003320 shost->nr_hw_queues = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04003321 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05003322 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04003323 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smartda0436e2009-05-22 14:51:39 -04003324 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
3325 }
James Smart81301a92008-12-04 22:39:46 -05003326
James Smart47a86172007-04-25 09:53:22 -04003327 /*
James Smart2e0fef82007-06-17 19:56:36 -05003328 * Set initial can_queue value since 0 is no longer supported and
3329 * scsi_add_host will fail. This will be adjusted later based on the
3330 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04003331 */
James Smart2e0fef82007-06-17 19:56:36 -05003332 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04003333 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05003334 shost->transportt = lpfc_vport_transport_template;
3335 vport->port_type = LPFC_NPIV_PORT;
3336 } else {
3337 shost->transportt = lpfc_transport_template;
3338 vport->port_type = LPFC_PHYSICAL_PORT;
3339 }
James Smart47a86172007-04-25 09:53:22 -04003340
James Smart2e0fef82007-06-17 19:56:36 -05003341 /* Initialize all internally managed lists. */
3342 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04003343 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05003344 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04003345
James Smart2e0fef82007-06-17 19:56:36 -05003346 init_timer(&vport->fc_disctmo);
3347 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003348 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04003349
James Smart2e0fef82007-06-17 19:56:36 -05003350 init_timer(&vport->els_tmofunc);
3351 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003352 vport->els_tmofunc.data = (unsigned long)vport;
James Smart92494142011-02-16 12:39:44 -05003353
3354 init_timer(&vport->delayed_disc_tmo);
3355 vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
3356 vport->delayed_disc_tmo.data = (unsigned long)vport;
3357
James Bottomleyd139b9b2009-11-05 13:33:12 -06003358 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05003359 if (error)
3360 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04003361
James Smart549e55c2007-08-02 11:09:51 -04003362 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003363 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04003364 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003365 return vport;
James Smart47a86172007-04-25 09:53:22 -04003366
James Smart2e0fef82007-06-17 19:56:36 -05003367out_put_shost:
3368 scsi_host_put(shost);
3369out:
3370 return NULL;
James Smart47a86172007-04-25 09:53:22 -04003371}
3372
James Smarte59058c2008-08-24 21:49:00 -04003373/**
James Smart3621a712009-04-06 18:47:14 -04003374 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04003375 * @vport: pointer to an lpfc virtual N_Port data structure.
3376 *
3377 * This routine destroys a FC port from the upper layer protocol. All the
3378 * resources associated with the port are released.
3379 **/
James Smart2e0fef82007-06-17 19:56:36 -05003380void
3381destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04003382{
James Smart92d7f7b2007-06-17 19:56:38 -05003383 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3384 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003385
James Smart858c9f62007-06-17 19:56:39 -05003386 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05003387 fc_remove_host(shost);
3388 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04003389
James Smart92d7f7b2007-06-17 19:56:38 -05003390 spin_lock_irq(&phba->hbalock);
3391 list_del_init(&vport->listentry);
3392 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04003393
James Smart92d7f7b2007-06-17 19:56:38 -05003394 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04003395 return;
James Smart47a86172007-04-25 09:53:22 -04003396}
3397
James Smarte59058c2008-08-24 21:49:00 -04003398/**
James Smart3621a712009-04-06 18:47:14 -04003399 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04003400 *
3401 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3402 * uses the kernel idr facility to perform the task.
3403 *
3404 * Return codes:
3405 * instance - a unique integer ID allocated as the new instance.
3406 * -1 - lpfc get instance failed.
3407 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003408int
3409lpfc_get_instance(void)
3410{
Tejun Heoab516032013-02-27 17:04:44 -08003411 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003412
Tejun Heoab516032013-02-27 17:04:44 -08003413 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
3414 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003415}
3416
James Smarte59058c2008-08-24 21:49:00 -04003417/**
James Smart3621a712009-04-06 18:47:14 -04003418 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04003419 * @shost: pointer to SCSI host data structure.
3420 * @time: elapsed time of the scan in jiffies.
3421 *
3422 * This routine is called by the SCSI layer with a SCSI host to determine
3423 * whether the scan host is finished.
3424 *
3425 * Note: there is no scan_start function as adapter initialization will have
3426 * asynchronously kicked off the link initialization.
3427 *
3428 * Return codes
3429 * 0 - SCSI host scan is not over yet.
3430 * 1 - SCSI host scan is over.
3431 **/
James Smart47a86172007-04-25 09:53:22 -04003432int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
3433{
James Smart2e0fef82007-06-17 19:56:36 -05003434 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3435 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05003436 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04003437
James Smart858c9f62007-06-17 19:56:39 -05003438 spin_lock_irq(shost->host_lock);
3439
James Smart51ef4c22007-08-02 11:10:31 -04003440 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05003441 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003442 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05003443 }
James Smart256ec0d2013-04-17 20:14:58 -04003444 if (time >= msecs_to_jiffies(30 * 1000)) {
James Smart2e0fef82007-06-17 19:56:36 -05003445 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003446 "0461 Scanning longer than 30 "
3447 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003448 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003449 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003450 }
James Smart256ec0d2013-04-17 20:14:58 -04003451 if (time >= msecs_to_jiffies(15 * 1000) &&
3452 phba->link_state <= LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05003453 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003454 "0465 Link down longer than 15 "
3455 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003456 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05003457 goto finished;
James Smart47a86172007-04-25 09:53:22 -04003458 }
3459
James Smart2e0fef82007-06-17 19:56:36 -05003460 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05003461 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003462 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05003463 goto finished;
James Smart256ec0d2013-04-17 20:14:58 -04003464 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
James Smart858c9f62007-06-17 19:56:39 -05003465 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003466 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05003467 goto finished;
3468
3469 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003470
3471finished:
James Smart858c9f62007-06-17 19:56:39 -05003472 spin_unlock_irq(shost->host_lock);
3473 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003474}
3475
James Smarte59058c2008-08-24 21:49:00 -04003476/**
James Smart3621a712009-04-06 18:47:14 -04003477 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04003478 * @shost: pointer to SCSI host data structure.
3479 *
3480 * This routine initializes a given SCSI host attributes on a FC port. The
3481 * SCSI host can be either on top of a physical port or a virtual port.
3482 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003483void lpfc_host_attrib_init(struct Scsi_Host *shost)
3484{
3485 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3486 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003487 /*
James Smart2e0fef82007-06-17 19:56:36 -05003488 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04003489 */
3490
James Smart2e0fef82007-06-17 19:56:36 -05003491 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
3492 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04003493 fc_host_supported_classes(shost) = FC_COS_CLASS3;
3494
3495 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003496 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003497 fc_host_supported_fc4s(shost)[2] = 1;
3498 fc_host_supported_fc4s(shost)[7] = 1;
3499
James Smart92d7f7b2007-06-17 19:56:38 -05003500 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
3501 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04003502
3503 fc_host_supported_speeds(shost) = 0;
James Smartd38dd522015-08-31 16:48:17 -04003504 if (phba->lmt & LMT_32Gb)
3505 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
James Smart88a2cfb2011-07-22 18:36:33 -04003506 if (phba->lmt & LMT_16Gb)
3507 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
James Smart47a86172007-04-25 09:53:22 -04003508 if (phba->lmt & LMT_10Gb)
3509 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04003510 if (phba->lmt & LMT_8Gb)
3511 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04003512 if (phba->lmt & LMT_4Gb)
3513 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
3514 if (phba->lmt & LMT_2Gb)
3515 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
3516 if (phba->lmt & LMT_1Gb)
3517 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
3518
3519 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05003520 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
3521 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04003522
Mike Christie0af5d702010-09-15 16:52:31 -05003523 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
3524
James Smart47a86172007-04-25 09:53:22 -04003525 /* This value is also unchanging */
3526 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003527 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003528 fc_host_active_fc4s(shost)[2] = 1;
3529 fc_host_active_fc4s(shost)[7] = 1;
3530
James Smart92d7f7b2007-06-17 19:56:38 -05003531 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04003532 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04003533 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04003534 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04003535}
dea31012005-04-17 16:05:31 -05003536
James Smarte59058c2008-08-24 21:49:00 -04003537/**
James Smartda0436e2009-05-22 14:51:39 -04003538 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04003539 * @phba: pointer to lpfc hba data structure.
3540 *
James Smartda0436e2009-05-22 14:51:39 -04003541 * This routine is invoked to stop an SLI3 device port, it stops the device
3542 * from generating interrupts and stops the device driver's timers for the
3543 * device.
James Smarte59058c2008-08-24 21:49:00 -04003544 **/
James Smartdb2378e2008-02-08 18:49:51 -05003545static void
James Smartda0436e2009-05-22 14:51:39 -04003546lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05003547{
James Smartda0436e2009-05-22 14:51:39 -04003548 /* Clear all interrupt enable conditions */
3549 writel(0, phba->HCregaddr);
3550 readl(phba->HCregaddr); /* flush */
3551 /* Clear all pending interrupts */
3552 writel(0xffffffff, phba->HAregaddr);
3553 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04003554
James Smartda0436e2009-05-22 14:51:39 -04003555 /* Reset some HBA SLI setup states */
3556 lpfc_stop_hba_timers(phba);
3557 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05003558}
3559
James Smarte59058c2008-08-24 21:49:00 -04003560/**
James Smartda0436e2009-05-22 14:51:39 -04003561 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05003562 * @phba: pointer to lpfc hba data structure.
3563 *
James Smartda0436e2009-05-22 14:51:39 -04003564 * This routine is invoked to stop an SLI4 device port, it stops the device
3565 * from generating interrupts and stops the device driver's timers for the
3566 * device.
3567 **/
3568static void
3569lpfc_stop_port_s4(struct lpfc_hba *phba)
3570{
3571 /* Reset some HBA SLI4 setup states */
3572 lpfc_stop_hba_timers(phba);
3573 phba->pport->work_port_events = 0;
3574 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04003575}
3576
3577/**
3578 * lpfc_stop_port - Wrapper function for stopping hba port
3579 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05003580 *
James Smartda0436e2009-05-22 14:51:39 -04003581 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3582 * the API jump table function pointer from the lpfc_hba struct.
3583 **/
3584void
3585lpfc_stop_port(struct lpfc_hba *phba)
3586{
3587 phba->lpfc_stop_port(phba);
3588}
3589
3590/**
James Smartecfd03c2010-02-12 14:41:27 -05003591 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3592 * @phba: Pointer to hba for which this call is being executed.
3593 *
3594 * This routine starts the timer waiting for the FCF rediscovery to complete.
3595 **/
3596void
3597lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
3598{
3599 unsigned long fcf_redisc_wait_tmo =
3600 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
3601 /* Start fcf rediscovery wait period timer */
3602 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
3603 spin_lock_irq(&phba->hbalock);
3604 /* Allow action to new fcf asynchronous event */
3605 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
3606 /* Mark the FCF rediscovery pending state */
3607 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
3608 spin_unlock_irq(&phba->hbalock);
3609}
3610
3611/**
3612 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
3613 * @ptr: Map to lpfc_hba data structure pointer.
3614 *
3615 * This routine is invoked when waiting for FCF table rediscover has been
3616 * timed out. If new FCF record(s) has (have) been discovered during the
3617 * wait period, a new FCF event shall be added to the FCOE async event
3618 * list, and then worker thread shall be waked up for processing from the
3619 * worker thread context.
3620 **/
Rashika Kheriae399b222014-09-03 12:55:28 -04003621static void
James Smartecfd03c2010-02-12 14:41:27 -05003622lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
3623{
3624 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
3625
3626 /* Don't send FCF rediscovery event if timer cancelled */
3627 spin_lock_irq(&phba->hbalock);
3628 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
3629 spin_unlock_irq(&phba->hbalock);
3630 return;
3631 }
3632 /* Clear FCF rediscovery timer pending flag */
3633 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
3634 /* FCF rediscovery event to worker thread */
3635 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
3636 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003637 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04003638 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05003639 /* wake up worker thread */
3640 lpfc_worker_wake_up(phba);
3641}
3642
3643/**
James Smartda0436e2009-05-22 14:51:39 -04003644 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
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 link fault code and
3649 * translate it into the base driver's read link attention mailbox command
3650 * status.
3651 *
3652 * Return: Link-attention status in terms of base driver's coding.
3653 **/
3654static uint16_t
3655lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
3656 struct lpfc_acqe_link *acqe_link)
3657{
3658 uint16_t latt_fault;
3659
3660 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
3661 case LPFC_ASYNC_LINK_FAULT_NONE:
3662 case LPFC_ASYNC_LINK_FAULT_LOCAL:
3663 case LPFC_ASYNC_LINK_FAULT_REMOTE:
3664 latt_fault = 0;
3665 break;
3666 default:
3667 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3668 "0398 Invalid link fault code: x%x\n",
3669 bf_get(lpfc_acqe_link_fault, acqe_link));
3670 latt_fault = MBXERR_ERROR;
3671 break;
3672 }
3673 return latt_fault;
3674}
3675
3676/**
3677 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
3678 * @phba: pointer to lpfc hba data structure.
3679 * @acqe_link: pointer to the async link completion queue entry.
3680 *
3681 * This routine is to parse the SLI4 link attention type and translate it
3682 * into the base driver's link attention type coding.
3683 *
3684 * Return: Link attention type in terms of base driver's coding.
3685 **/
3686static uint8_t
3687lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
3688 struct lpfc_acqe_link *acqe_link)
3689{
3690 uint8_t att_type;
3691
3692 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
3693 case LPFC_ASYNC_LINK_STATUS_DOWN:
3694 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05003695 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04003696 break;
3697 case LPFC_ASYNC_LINK_STATUS_UP:
3698 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05003699 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003700 break;
3701 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05003702 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04003703 break;
3704 default:
3705 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3706 "0399 Invalid link attention type: x%x\n",
3707 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003708 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003709 break;
3710 }
3711 return att_type;
3712}
3713
3714/**
James Smart8b68cd52012-09-29 11:32:37 -04003715 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
3716 * @phba: pointer to lpfc hba data structure.
3717 *
3718 * This routine is to get an SLI3 FC port's link speed in Mbps.
3719 *
3720 * Return: link speed in terms of Mbps.
3721 **/
3722uint32_t
3723lpfc_sli_port_speed_get(struct lpfc_hba *phba)
3724{
3725 uint32_t link_speed;
3726
3727 if (!lpfc_is_link_up(phba))
3728 return 0;
3729
James Smarta085e872015-12-16 18:12:02 -05003730 if (phba->sli_rev <= LPFC_SLI_REV3) {
3731 switch (phba->fc_linkspeed) {
3732 case LPFC_LINK_SPEED_1GHZ:
3733 link_speed = 1000;
3734 break;
3735 case LPFC_LINK_SPEED_2GHZ:
3736 link_speed = 2000;
3737 break;
3738 case LPFC_LINK_SPEED_4GHZ:
3739 link_speed = 4000;
3740 break;
3741 case LPFC_LINK_SPEED_8GHZ:
3742 link_speed = 8000;
3743 break;
3744 case LPFC_LINK_SPEED_10GHZ:
3745 link_speed = 10000;
3746 break;
3747 case LPFC_LINK_SPEED_16GHZ:
3748 link_speed = 16000;
3749 break;
3750 default:
3751 link_speed = 0;
3752 }
3753 } else {
3754 if (phba->sli4_hba.link_state.logical_speed)
3755 link_speed =
3756 phba->sli4_hba.link_state.logical_speed;
3757 else
3758 link_speed = phba->sli4_hba.link_state.speed;
James Smart8b68cd52012-09-29 11:32:37 -04003759 }
3760 return link_speed;
3761}
3762
3763/**
3764 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
3765 * @phba: pointer to lpfc hba data structure.
3766 * @evt_code: asynchronous event code.
3767 * @speed_code: asynchronous event link speed code.
3768 *
3769 * This routine is to parse the giving SLI4 async event link speed code into
3770 * value of Mbps for the link speed.
3771 *
3772 * Return: link speed in terms of Mbps.
3773 **/
3774static uint32_t
3775lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
3776 uint8_t speed_code)
3777{
3778 uint32_t port_speed;
3779
3780 switch (evt_code) {
3781 case LPFC_TRAILER_CODE_LINK:
3782 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04003783 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smart8b68cd52012-09-29 11:32:37 -04003784 port_speed = 0;
3785 break;
James Smart26d830e2015-04-07 15:07:17 -04003786 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04003787 port_speed = 10;
3788 break;
James Smart26d830e2015-04-07 15:07:17 -04003789 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04003790 port_speed = 100;
3791 break;
James Smart26d830e2015-04-07 15:07:17 -04003792 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04003793 port_speed = 1000;
3794 break;
James Smart26d830e2015-04-07 15:07:17 -04003795 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04003796 port_speed = 10000;
3797 break;
James Smart26d830e2015-04-07 15:07:17 -04003798 case LPFC_ASYNC_LINK_SPEED_20GBPS:
3799 port_speed = 20000;
3800 break;
3801 case LPFC_ASYNC_LINK_SPEED_25GBPS:
3802 port_speed = 25000;
3803 break;
3804 case LPFC_ASYNC_LINK_SPEED_40GBPS:
3805 port_speed = 40000;
3806 break;
James Smart8b68cd52012-09-29 11:32:37 -04003807 default:
3808 port_speed = 0;
3809 }
3810 break;
3811 case LPFC_TRAILER_CODE_FC:
3812 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04003813 case LPFC_FC_LA_SPEED_UNKNOWN:
James Smart8b68cd52012-09-29 11:32:37 -04003814 port_speed = 0;
3815 break;
James Smart26d830e2015-04-07 15:07:17 -04003816 case LPFC_FC_LA_SPEED_1G:
James Smart8b68cd52012-09-29 11:32:37 -04003817 port_speed = 1000;
3818 break;
James Smart26d830e2015-04-07 15:07:17 -04003819 case LPFC_FC_LA_SPEED_2G:
James Smart8b68cd52012-09-29 11:32:37 -04003820 port_speed = 2000;
3821 break;
James Smart26d830e2015-04-07 15:07:17 -04003822 case LPFC_FC_LA_SPEED_4G:
James Smart8b68cd52012-09-29 11:32:37 -04003823 port_speed = 4000;
3824 break;
James Smart26d830e2015-04-07 15:07:17 -04003825 case LPFC_FC_LA_SPEED_8G:
James Smart8b68cd52012-09-29 11:32:37 -04003826 port_speed = 8000;
3827 break;
James Smart26d830e2015-04-07 15:07:17 -04003828 case LPFC_FC_LA_SPEED_10G:
James Smart8b68cd52012-09-29 11:32:37 -04003829 port_speed = 10000;
3830 break;
James Smart26d830e2015-04-07 15:07:17 -04003831 case LPFC_FC_LA_SPEED_16G:
James Smart8b68cd52012-09-29 11:32:37 -04003832 port_speed = 16000;
3833 break;
James Smartd38dd522015-08-31 16:48:17 -04003834 case LPFC_FC_LA_SPEED_32G:
3835 port_speed = 32000;
3836 break;
James Smart8b68cd52012-09-29 11:32:37 -04003837 default:
3838 port_speed = 0;
3839 }
3840 break;
3841 default:
3842 port_speed = 0;
3843 }
3844 return port_speed;
3845}
3846
3847/**
James Smart70f3c072010-12-15 17:57:33 -05003848 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04003849 * @phba: pointer to lpfc hba data structure.
3850 * @acqe_link: pointer to the async link completion queue entry.
3851 *
James Smart70f3c072010-12-15 17:57:33 -05003852 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04003853 **/
3854static void
3855lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
3856 struct lpfc_acqe_link *acqe_link)
3857{
3858 struct lpfc_dmabuf *mp;
3859 LPFC_MBOXQ_t *pmb;
3860 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05003861 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04003862 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05003863 int rc;
James Smartda0436e2009-05-22 14:51:39 -04003864
3865 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05003866 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04003867 return;
James Smart32b97932009-07-19 10:01:21 -04003868 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04003869 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3870 if (!pmb) {
3871 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3872 "0395 The mboxq allocation failed\n");
3873 return;
3874 }
3875 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3876 if (!mp) {
3877 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3878 "0396 The lpfc_dmabuf allocation failed\n");
3879 goto out_free_pmb;
3880 }
3881 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
3882 if (!mp->virt) {
3883 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3884 "0397 The mbuf allocation failed\n");
3885 goto out_free_dmabuf;
3886 }
3887
3888 /* Cleanup any outstanding ELS commands */
3889 lpfc_els_flush_all_cmd(phba);
3890
3891 /* Block ELS IOCBs until we have done process link event */
3892 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
3893
3894 /* Update link event statistics */
3895 phba->sli.slistat.link_event++;
3896
James Smart76a95d72010-11-20 23:11:48 -05003897 /* Create lpfc_handle_latt mailbox command from link ACQE */
3898 lpfc_read_topology(phba, pmb, mp);
3899 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04003900 pmb->vport = phba->pport;
3901
James Smartda0436e2009-05-22 14:51:39 -04003902 /* Keep the link status for extra SLI4 state machine reference */
3903 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04003904 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
3905 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04003906 phba->sli4_hba.link_state.duplex =
3907 bf_get(lpfc_acqe_link_duplex, acqe_link);
3908 phba->sli4_hba.link_state.status =
3909 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05003910 phba->sli4_hba.link_state.type =
3911 bf_get(lpfc_acqe_link_type, acqe_link);
3912 phba->sli4_hba.link_state.number =
3913 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04003914 phba->sli4_hba.link_state.fault =
3915 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05003916 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04003917 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
3918
James Smart70f3c072010-12-15 17:57:33 -05003919 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04003920 "2900 Async FC/FCoE Link event - Speed:%dGBit "
3921 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
3922 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05003923 phba->sli4_hba.link_state.speed,
3924 phba->sli4_hba.link_state.topology,
3925 phba->sli4_hba.link_state.status,
3926 phba->sli4_hba.link_state.type,
3927 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04003928 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05003929 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05003930 /*
3931 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
3932 * topology info. Note: Optional for non FC-AL ports.
3933 */
3934 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3935 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3936 if (rc == MBX_NOT_FINISHED)
3937 goto out_free_dmabuf;
3938 return;
3939 }
3940 /*
3941 * For FCoE Mode: fill in all the topology information we need and call
3942 * the READ_TOPOLOGY completion routine to continue without actually
3943 * sending the READ_TOPOLOGY mailbox command to the port.
3944 */
3945 /* Parse and translate status field */
3946 mb = &pmb->u.mb;
3947 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
3948
3949 /* Parse and translate link attention fields */
3950 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3951 la->eventTag = acqe_link->event_tag;
3952 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
3953 bf_set(lpfc_mbx_read_top_link_spd, la,
James Smarta085e872015-12-16 18:12:02 -05003954 (bf_get(lpfc_acqe_link_speed, acqe_link)));
James Smart76a95d72010-11-20 23:11:48 -05003955
3956 /* Fake the the following irrelvant fields */
3957 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
3958 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
3959 bf_set(lpfc_mbx_read_top_il, la, 0);
3960 bf_set(lpfc_mbx_read_top_pb, la, 0);
3961 bf_set(lpfc_mbx_read_top_fa, la, 0);
3962 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04003963
3964 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05003965 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04003966
3967 return;
3968
3969out_free_dmabuf:
3970 kfree(mp);
3971out_free_pmb:
3972 mempool_free(pmb, phba->mbox_mem_pool);
3973}
3974
3975/**
James Smart70f3c072010-12-15 17:57:33 -05003976 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
3977 * @phba: pointer to lpfc hba data structure.
3978 * @acqe_fc: pointer to the async fc completion queue entry.
3979 *
3980 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
3981 * that the event was received and then issue a read_topology mailbox command so
3982 * that the rest of the driver will treat it the same as SLI3.
3983 **/
3984static void
3985lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
3986{
3987 struct lpfc_dmabuf *mp;
3988 LPFC_MBOXQ_t *pmb;
3989 int rc;
3990
3991 if (bf_get(lpfc_trailer_type, acqe_fc) !=
3992 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
3993 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3994 "2895 Non FC link Event detected.(%d)\n",
3995 bf_get(lpfc_trailer_type, acqe_fc));
3996 return;
3997 }
3998 /* Keep the link status for extra SLI4 state machine reference */
3999 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004000 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
4001 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05004002 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
4003 phba->sli4_hba.link_state.topology =
4004 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
4005 phba->sli4_hba.link_state.status =
4006 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
4007 phba->sli4_hba.link_state.type =
4008 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
4009 phba->sli4_hba.link_state.number =
4010 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
4011 phba->sli4_hba.link_state.fault =
4012 bf_get(lpfc_acqe_link_fault, acqe_fc);
4013 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004014 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart70f3c072010-12-15 17:57:33 -05004015 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4016 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4017 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4018 "%dMbps Fault:%d\n",
4019 phba->sli4_hba.link_state.speed,
4020 phba->sli4_hba.link_state.topology,
4021 phba->sli4_hba.link_state.status,
4022 phba->sli4_hba.link_state.type,
4023 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004024 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004025 phba->sli4_hba.link_state.fault);
4026 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4027 if (!pmb) {
4028 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4029 "2897 The mboxq allocation failed\n");
4030 return;
4031 }
4032 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4033 if (!mp) {
4034 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4035 "2898 The lpfc_dmabuf allocation failed\n");
4036 goto out_free_pmb;
4037 }
4038 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4039 if (!mp->virt) {
4040 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4041 "2899 The mbuf allocation failed\n");
4042 goto out_free_dmabuf;
4043 }
4044
4045 /* Cleanup any outstanding ELS commands */
4046 lpfc_els_flush_all_cmd(phba);
4047
4048 /* Block ELS IOCBs until we have done process link event */
4049 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
4050
4051 /* Update link event statistics */
4052 phba->sli.slistat.link_event++;
4053
4054 /* Create lpfc_handle_latt mailbox command from link ACQE */
4055 lpfc_read_topology(phba, pmb, mp);
4056 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4057 pmb->vport = phba->pport;
4058
4059 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4060 if (rc == MBX_NOT_FINISHED)
4061 goto out_free_dmabuf;
4062 return;
4063
4064out_free_dmabuf:
4065 kfree(mp);
4066out_free_pmb:
4067 mempool_free(pmb, phba->mbox_mem_pool);
4068}
4069
4070/**
4071 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4072 * @phba: pointer to lpfc hba data structure.
4073 * @acqe_fc: pointer to the async SLI completion queue entry.
4074 *
4075 * This routine is to handle the SLI4 asynchronous SLI events.
4076 **/
4077static void
4078lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
4079{
James Smart4b8bae02012-06-12 13:55:07 -04004080 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04004081 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04004082 uint8_t status;
James Smart946727d2015-04-07 15:07:09 -04004083 uint8_t evt_type;
James Smart448193b2015-12-16 18:12:05 -05004084 uint8_t operational = 0;
James Smart946727d2015-04-07 15:07:09 -04004085 struct temp_event temp_event_data;
James Smart4b8bae02012-06-12 13:55:07 -04004086 struct lpfc_acqe_misconfigured_event *misconfigured;
James Smart946727d2015-04-07 15:07:09 -04004087 struct Scsi_Host *shost;
James Smart4b8bae02012-06-12 13:55:07 -04004088
James Smart946727d2015-04-07 15:07:09 -04004089 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
4090
James Smart448193b2015-12-16 18:12:05 -05004091 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4092 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4093 "x%08x SLI Event Type:%d\n",
4094 acqe_sli->event_data1, acqe_sli->event_data2,
4095 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004096
4097 port_name = phba->Port[0];
4098 if (port_name == 0x00)
4099 port_name = '?'; /* get port name is empty */
4100
James Smart946727d2015-04-07 15:07:09 -04004101 switch (evt_type) {
4102 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
4103 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4104 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
4105 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4106
4107 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4108 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4109 acqe_sli->event_data1, port_name);
4110
James Smart310429e2016-07-06 12:35:54 -07004111 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04004112 shost = lpfc_shost_from_vport(phba->pport);
4113 fc_host_post_vendor_event(shost, fc_get_event_number(),
4114 sizeof(temp_event_data),
4115 (char *)&temp_event_data,
4116 SCSI_NL_VID_TYPE_PCI
4117 | PCI_VENDOR_ID_EMULEX);
4118 break;
4119 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
4120 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4121 temp_event_data.event_code = LPFC_NORMAL_TEMP;
4122 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4123
4124 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4125 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4126 acqe_sli->event_data1, port_name);
4127
4128 shost = lpfc_shost_from_vport(phba->pport);
4129 fc_host_post_vendor_event(shost, fc_get_event_number(),
4130 sizeof(temp_event_data),
4131 (char *)&temp_event_data,
4132 SCSI_NL_VID_TYPE_PCI
4133 | PCI_VENDOR_ID_EMULEX);
4134 break;
4135 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
4136 misconfigured = (struct lpfc_acqe_misconfigured_event *)
James Smart4b8bae02012-06-12 13:55:07 -04004137 &acqe_sli->event_data1;
4138
James Smart946727d2015-04-07 15:07:09 -04004139 /* fetch the status for this port */
4140 switch (phba->sli4_hba.lnk_info.lnk_no) {
4141 case LPFC_LINK_NUMBER_0:
James Smart448193b2015-12-16 18:12:05 -05004142 status = bf_get(lpfc_sli_misconfigured_port0_state,
4143 &misconfigured->theEvent);
4144 operational = bf_get(lpfc_sli_misconfigured_port0_op,
James Smart4b8bae02012-06-12 13:55:07 -04004145 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004146 break;
4147 case LPFC_LINK_NUMBER_1:
James Smart448193b2015-12-16 18:12:05 -05004148 status = bf_get(lpfc_sli_misconfigured_port1_state,
4149 &misconfigured->theEvent);
4150 operational = bf_get(lpfc_sli_misconfigured_port1_op,
James Smart4b8bae02012-06-12 13:55:07 -04004151 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004152 break;
4153 case LPFC_LINK_NUMBER_2:
James Smart448193b2015-12-16 18:12:05 -05004154 status = bf_get(lpfc_sli_misconfigured_port2_state,
4155 &misconfigured->theEvent);
4156 operational = bf_get(lpfc_sli_misconfigured_port2_op,
James Smart4b8bae02012-06-12 13:55:07 -04004157 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004158 break;
4159 case LPFC_LINK_NUMBER_3:
James Smart448193b2015-12-16 18:12:05 -05004160 status = bf_get(lpfc_sli_misconfigured_port3_state,
4161 &misconfigured->theEvent);
4162 operational = bf_get(lpfc_sli_misconfigured_port3_op,
James Smart4b8bae02012-06-12 13:55:07 -04004163 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004164 break;
4165 default:
James Smart448193b2015-12-16 18:12:05 -05004166 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4167 "3296 "
4168 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
4169 "event: Invalid link %d",
4170 phba->sli4_hba.lnk_info.lnk_no);
4171 return;
James Smart946727d2015-04-07 15:07:09 -04004172 }
James Smart4b8bae02012-06-12 13:55:07 -04004173
James Smart448193b2015-12-16 18:12:05 -05004174 /* Skip if optic state unchanged */
4175 if (phba->sli4_hba.lnk_info.optic_state == status)
4176 return;
4177
James Smart946727d2015-04-07 15:07:09 -04004178 switch (status) {
4179 case LPFC_SLI_EVENT_STATUS_VALID:
James Smart448193b2015-12-16 18:12:05 -05004180 sprintf(message, "Physical Link is functional");
4181 break;
James Smart946727d2015-04-07 15:07:09 -04004182 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
4183 sprintf(message, "Optics faulted/incorrectly "
4184 "installed/not installed - Reseat optics, "
4185 "if issue not resolved, replace.");
4186 break;
4187 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
4188 sprintf(message,
4189 "Optics of two types installed - Remove one "
4190 "optic or install matching pair of optics.");
4191 break;
4192 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
4193 sprintf(message, "Incompatible optics - Replace with "
James Smart292098b2012-09-29 11:31:41 -04004194 "compatible optics for card to function.");
James Smart946727d2015-04-07 15:07:09 -04004195 break;
James Smart448193b2015-12-16 18:12:05 -05004196 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
4197 sprintf(message, "Unqualified optics - Replace with "
4198 "Avago optics for Warranty and Technical "
4199 "Support - Link is%s operational",
4200 (operational) ? "" : " not");
4201 break;
4202 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
4203 sprintf(message, "Uncertified optics - Replace with "
4204 "Avago-certified optics to enable link "
4205 "operation - Link is%s operational",
4206 (operational) ? "" : " not");
4207 break;
James Smart946727d2015-04-07 15:07:09 -04004208 default:
4209 /* firmware is reporting a status we don't know about */
4210 sprintf(message, "Unknown event status x%02x", status);
4211 break;
4212 }
James Smart448193b2015-12-16 18:12:05 -05004213 phba->sli4_hba.lnk_info.optic_state = status;
James Smart946727d2015-04-07 15:07:09 -04004214 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart448193b2015-12-16 18:12:05 -05004215 "3176 Port Name %c %s\n", port_name, message);
James Smart946727d2015-04-07 15:07:09 -04004216 break;
4217 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
4218 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4219 "3192 Remote DPort Test Initiated - "
4220 "Event Data1:x%08x Event Data2: x%08x\n",
4221 acqe_sli->event_data1, acqe_sli->event_data2);
James Smart4b8bae02012-06-12 13:55:07 -04004222 break;
4223 default:
James Smart946727d2015-04-07 15:07:09 -04004224 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4225 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
4226 "x%08x SLI Event Type:%d\n",
4227 acqe_sli->event_data1, acqe_sli->event_data2,
4228 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004229 break;
4230 }
James Smart70f3c072010-12-15 17:57:33 -05004231}
4232
4233/**
James Smartfc2b9892010-02-26 14:15:29 -05004234 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
4235 * @vport: pointer to vport data structure.
4236 *
4237 * This routine is to perform Clear Virtual Link (CVL) on a vport in
4238 * response to a CVL event.
4239 *
4240 * Return the pointer to the ndlp with the vport if successful, otherwise
4241 * return NULL.
4242 **/
4243static struct lpfc_nodelist *
4244lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
4245{
4246 struct lpfc_nodelist *ndlp;
4247 struct Scsi_Host *shost;
4248 struct lpfc_hba *phba;
4249
4250 if (!vport)
4251 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05004252 phba = vport->phba;
4253 if (!phba)
4254 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04004255 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4256 if (!ndlp) {
4257 /* Cannot find existing Fabric ndlp, so allocate a new one */
4258 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4259 if (!ndlp)
4260 return 0;
4261 lpfc_nlp_init(vport, ndlp, Fabric_DID);
4262 /* Set the node type */
4263 ndlp->nlp_type |= NLP_FABRIC;
4264 /* Put ndlp onto node list */
4265 lpfc_enqueue_node(vport, ndlp);
4266 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4267 /* re-setup ndlp without removing from node list */
4268 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4269 if (!ndlp)
4270 return 0;
4271 }
James Smart63e801c2010-11-20 23:14:19 -05004272 if ((phba->pport->port_state < LPFC_FLOGI) &&
4273 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004274 return NULL;
4275 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05004276 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
4277 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004278 return NULL;
4279 shost = lpfc_shost_from_vport(vport);
4280 if (!shost)
4281 return NULL;
4282 lpfc_linkdown_port(vport);
4283 lpfc_cleanup_pending_mbox(vport);
4284 spin_lock_irq(shost->host_lock);
4285 vport->fc_flag |= FC_VPORT_CVL_RCVD;
4286 spin_unlock_irq(shost->host_lock);
4287
4288 return ndlp;
4289}
4290
4291/**
4292 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4293 * @vport: pointer to lpfc hba data structure.
4294 *
4295 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4296 * response to a FCF dead event.
4297 **/
4298static void
4299lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
4300{
4301 struct lpfc_vport **vports;
4302 int i;
4303
4304 vports = lpfc_create_vport_work_array(phba);
4305 if (vports)
4306 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4307 lpfc_sli4_perform_vport_cvl(vports[i]);
4308 lpfc_destroy_vport_work_array(phba, vports);
4309}
4310
4311/**
James Smart76a95d72010-11-20 23:11:48 -05004312 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04004313 * @phba: pointer to lpfc hba data structure.
4314 * @acqe_link: pointer to the async fcoe completion queue entry.
4315 *
4316 * This routine is to handle the SLI4 asynchronous fcoe event.
4317 **/
4318static void
James Smart76a95d72010-11-20 23:11:48 -05004319lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05004320 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04004321{
James Smart70f3c072010-12-15 17:57:33 -05004322 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004323 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04004324 struct lpfc_vport *vport;
4325 struct lpfc_nodelist *ndlp;
4326 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05004327 int active_vlink_present;
4328 struct lpfc_vport **vports;
4329 int i;
James Smartda0436e2009-05-22 14:51:39 -04004330
James Smart70f3c072010-12-15 17:57:33 -05004331 phba->fc_eventTag = acqe_fip->event_tag;
4332 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004333 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05004334 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
4335 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
4336 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04004337 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4338 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004339 "2546 New FCF event, evt_tag:x%x, "
4340 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004341 acqe_fip->event_tag,
4342 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04004343 else
4344 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
4345 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004346 "2788 FCF param modified event, "
4347 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004348 acqe_fip->event_tag,
4349 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04004350 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004351 /*
4352 * During period of FCF discovery, read the FCF
4353 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04004354 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05004355 */
4356 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4357 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004358 "2779 Read FCF (x%x) for updating "
4359 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05004360 acqe_fip->index);
4361 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004362 }
James Smart38b92ef2010-08-04 16:11:39 -04004363
4364 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04004365 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04004366 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04004367 spin_unlock_irq(&phba->hbalock);
4368 break;
4369 }
4370 /* If fast FCF failover rescan event is pending, do nothing */
4371 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
4372 spin_unlock_irq(&phba->hbalock);
4373 break;
4374 }
4375
James Smartc2b97122013-05-31 17:05:36 -04004376 /* If the FCF has been in discovered state, do nothing. */
4377 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
James Smart3804dc82010-07-14 15:31:37 -04004378 spin_unlock_irq(&phba->hbalock);
4379 break;
4380 }
4381 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04004382
James Smart0c9ab6f2010-02-26 14:15:57 -05004383 /* Otherwise, scan the entire FCF table and re-discover SAN */
4384 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004385 "2770 Start FCF table scan per async FCF "
4386 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004387 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004388 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
4389 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04004390 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004391 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4392 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04004393 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04004394 break;
4395
James Smart70f3c072010-12-15 17:57:33 -05004396 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04004397 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04004398 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004399 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
4400 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004401 break;
4402
James Smart70f3c072010-12-15 17:57:33 -05004403 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05004404 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004405 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004406 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05004407 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04004408 /*
4409 * If we are in the middle of FCF failover process, clear
4410 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04004411 */
James Smartfc2b9892010-02-26 14:15:29 -05004412 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004413 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05004414 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004415 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05004416 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004417 break;
4418 }
James Smart38b92ef2010-08-04 16:11:39 -04004419 spin_unlock_irq(&phba->hbalock);
4420
4421 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05004422 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04004423 break;
4424
4425 /*
4426 * Otherwise, request the port to rediscover the entire FCF
4427 * table for a fast recovery from case that the current FCF
4428 * is no longer valid as we are not in the middle of FCF
4429 * failover process already.
4430 */
James Smartc2b97122013-05-31 17:05:36 -04004431 spin_lock_irq(&phba->hbalock);
4432 /* Mark the fast failover process in progress */
4433 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
4434 spin_unlock_irq(&phba->hbalock);
4435
4436 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
4437 "2771 Start FCF fast failover process due to "
4438 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
4439 "\n", acqe_fip->event_tag, acqe_fip->index);
4440 rc = lpfc_sli4_redisc_fcf_table(phba);
4441 if (rc) {
4442 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4443 LOG_DISCOVERY,
4444 "2772 Issue FCF rediscover mabilbox "
4445 "command failed, fail through to FCF "
4446 "dead event\n");
4447 spin_lock_irq(&phba->hbalock);
4448 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
4449 spin_unlock_irq(&phba->hbalock);
4450 /*
4451 * Last resort will fail over by treating this
4452 * as a link down to FCF registration.
4453 */
4454 lpfc_sli4_fcf_dead_failthrough(phba);
4455 } else {
4456 /* Reset FCF roundrobin bmask for new discovery */
4457 lpfc_sli4_clear_fcf_rr_bmask(phba);
4458 /*
4459 * Handling fast FCF failover to a DEAD FCF event is
4460 * considered equalivant to receiving CVL to all vports.
4461 */
4462 lpfc_sli4_perform_all_vport_cvl(phba);
4463 }
James Smartda0436e2009-05-22 14:51:39 -04004464 break;
James Smart70f3c072010-12-15 17:57:33 -05004465 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05004466 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004467 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04004468 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05004469 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04004470
James Smart6669f9b2009-10-02 15:16:45 -04004471 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04004472 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004473 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004474 if (!ndlp)
4475 break;
James Smart695a8142010-01-26 23:08:03 -05004476 active_vlink_present = 0;
4477
4478 vports = lpfc_create_vport_work_array(phba);
4479 if (vports) {
4480 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
4481 i++) {
4482 if ((!(vports[i]->fc_flag &
4483 FC_VPORT_CVL_RCVD)) &&
4484 (vports[i]->port_state > LPFC_FDISC)) {
4485 active_vlink_present = 1;
4486 break;
4487 }
4488 }
4489 lpfc_destroy_vport_work_array(phba, vports);
4490 }
4491
James Smartcc823552015-05-21 13:55:26 -04004492 /*
4493 * Don't re-instantiate if vport is marked for deletion.
4494 * If we are here first then vport_delete is going to wait
4495 * for discovery to complete.
4496 */
4497 if (!(vport->load_flag & FC_UNLOADING) &&
4498 active_vlink_present) {
James Smart695a8142010-01-26 23:08:03 -05004499 /*
4500 * If there are other active VLinks present,
4501 * re-instantiate the Vlink using FDISC.
4502 */
James Smart256ec0d2013-04-17 20:14:58 -04004503 mod_timer(&ndlp->nlp_delayfunc,
4504 jiffies + msecs_to_jiffies(1000));
James Smartfc2b9892010-02-26 14:15:29 -05004505 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004506 spin_lock_irq(shost->host_lock);
4507 ndlp->nlp_flag |= NLP_DELAY_TMO;
4508 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05004509 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
4510 vport->port_state = LPFC_FDISC;
4511 } else {
James Smartecfd03c2010-02-12 14:41:27 -05004512 /*
4513 * Otherwise, we request port to rediscover
4514 * the entire FCF table for a fast recovery
4515 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05004516 * is no longer valid if we are not already
4517 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05004518 */
James Smartfc2b9892010-02-26 14:15:29 -05004519 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004520 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05004521 spin_unlock_irq(&phba->hbalock);
4522 break;
4523 }
4524 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05004525 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004526 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004527 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4528 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004529 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05004530 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05004531 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05004532 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004533 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4534 LOG_DISCOVERY,
4535 "2774 Issue FCF rediscover "
4536 "mabilbox command failed, "
4537 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05004538 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004539 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004540 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05004541 /*
4542 * Last resort will be re-try on the
4543 * the current registered FCF entry.
4544 */
4545 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04004546 } else
4547 /*
4548 * Reset FCF roundrobin bmask for new
4549 * discovery.
4550 */
James Smart7d791df2011-07-22 18:37:52 -04004551 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04004552 }
4553 break;
James Smartda0436e2009-05-22 14:51:39 -04004554 default:
4555 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4556 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05004557 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004558 break;
4559 }
4560}
4561
4562/**
4563 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
4564 * @phba: pointer to lpfc hba data structure.
4565 * @acqe_link: pointer to the async dcbx completion queue entry.
4566 *
4567 * This routine is to handle the SLI4 asynchronous dcbx event.
4568 **/
4569static void
4570lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
4571 struct lpfc_acqe_dcbx *acqe_dcbx)
4572{
James Smart4d9ab992009-10-02 15:16:39 -04004573 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004574 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4575 "0290 The SLI4 DCBX asynchronous event is not "
4576 "handled yet\n");
4577}
4578
4579/**
James Smartb19a0612010-04-06 14:48:51 -04004580 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
4581 * @phba: pointer to lpfc hba data structure.
4582 * @acqe_link: pointer to the async grp5 completion queue entry.
4583 *
4584 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
4585 * is an asynchronous notified of a logical link speed change. The Port
4586 * reports the logical link speed in units of 10Mbps.
4587 **/
4588static void
4589lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
4590 struct lpfc_acqe_grp5 *acqe_grp5)
4591{
4592 uint16_t prev_ll_spd;
4593
4594 phba->fc_eventTag = acqe_grp5->event_tag;
4595 phba->fcoe_eventtag = acqe_grp5->event_tag;
4596 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
4597 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004598 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04004599 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4600 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04004601 "from %dMbps to %dMbps\n", prev_ll_spd,
4602 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04004603}
4604
4605/**
James Smartda0436e2009-05-22 14:51:39 -04004606 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
4607 * @phba: pointer to lpfc hba data structure.
4608 *
4609 * This routine is invoked by the worker thread to process all the pending
4610 * SLI4 asynchronous events.
4611 **/
4612void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
4613{
4614 struct lpfc_cq_event *cq_event;
4615
4616 /* First, declare the async event has been handled */
4617 spin_lock_irq(&phba->hbalock);
4618 phba->hba_flag &= ~ASYNC_EVENT;
4619 spin_unlock_irq(&phba->hbalock);
4620 /* Now, handle all the async events */
4621 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
4622 /* Get the first event from the head of the event queue */
4623 spin_lock_irq(&phba->hbalock);
4624 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
4625 cq_event, struct lpfc_cq_event, list);
4626 spin_unlock_irq(&phba->hbalock);
4627 /* Process the asynchronous event */
4628 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
4629 case LPFC_TRAILER_CODE_LINK:
4630 lpfc_sli4_async_link_evt(phba,
4631 &cq_event->cqe.acqe_link);
4632 break;
4633 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05004634 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004635 break;
4636 case LPFC_TRAILER_CODE_DCBX:
4637 lpfc_sli4_async_dcbx_evt(phba,
4638 &cq_event->cqe.acqe_dcbx);
4639 break;
James Smartb19a0612010-04-06 14:48:51 -04004640 case LPFC_TRAILER_CODE_GRP5:
4641 lpfc_sli4_async_grp5_evt(phba,
4642 &cq_event->cqe.acqe_grp5);
4643 break;
James Smart70f3c072010-12-15 17:57:33 -05004644 case LPFC_TRAILER_CODE_FC:
4645 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
4646 break;
4647 case LPFC_TRAILER_CODE_SLI:
4648 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
4649 break;
James Smartda0436e2009-05-22 14:51:39 -04004650 default:
4651 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4652 "1804 Invalid asynchrous event code: "
4653 "x%x\n", bf_get(lpfc_trailer_code,
4654 &cq_event->cqe.mcqe_cmpl));
4655 break;
4656 }
4657 /* Free the completion event processed to the free pool */
4658 lpfc_sli4_cq_event_release(phba, cq_event);
4659 }
4660}
4661
4662/**
James Smartecfd03c2010-02-12 14:41:27 -05004663 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
4664 * @phba: pointer to lpfc hba data structure.
4665 *
4666 * This routine is invoked by the worker thread to process FCF table
4667 * rediscovery pending completion event.
4668 **/
4669void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
4670{
4671 int rc;
4672
4673 spin_lock_irq(&phba->hbalock);
4674 /* Clear FCF rediscovery timeout event */
4675 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
4676 /* Clear driver fast failover FCF record flag */
4677 phba->fcf.failover_rec.flag = 0;
4678 /* Set state for FCF fast failover */
4679 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
4680 spin_unlock_irq(&phba->hbalock);
4681
4682 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05004683 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004684 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05004685 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05004686 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004687 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4688 "2747 Issue FCF scan read FCF mailbox "
4689 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05004690}
4691
4692/**
James Smartda0436e2009-05-22 14:51:39 -04004693 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
4694 * @phba: pointer to lpfc hba data structure.
4695 * @dev_grp: The HBA PCI-Device group number.
4696 *
4697 * This routine is invoked to set up the per HBA PCI-Device group function
4698 * API jump table entries.
4699 *
4700 * Return: 0 if success, otherwise -ENODEV
4701 **/
4702int
4703lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05004704{
4705 int rc;
4706
James Smartda0436e2009-05-22 14:51:39 -04004707 /* Set up lpfc PCI-device group */
4708 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05004709
James Smartda0436e2009-05-22 14:51:39 -04004710 /* The LPFC_PCI_DEV_OC uses SLI4 */
4711 if (dev_grp == LPFC_PCI_DEV_OC)
4712 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05004713
James Smartda0436e2009-05-22 14:51:39 -04004714 /* Set up device INIT API function jump table */
4715 rc = lpfc_init_api_table_setup(phba, dev_grp);
4716 if (rc)
4717 return -ENODEV;
4718 /* Set up SCSI API function jump table */
4719 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
4720 if (rc)
4721 return -ENODEV;
4722 /* Set up SLI API function jump table */
4723 rc = lpfc_sli_api_table_setup(phba, dev_grp);
4724 if (rc)
4725 return -ENODEV;
4726 /* Set up MBOX API function jump table */
4727 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
4728 if (rc)
4729 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05004730
James Smartda0436e2009-05-22 14:51:39 -04004731 return 0;
James Smart5b75da22008-12-04 22:39:35 -05004732}
4733
4734/**
James Smart3621a712009-04-06 18:47:14 -04004735 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05004736 * @phba: pointer to lpfc hba data structure.
4737 * @intr_mode: active interrupt mode adopted.
4738 *
4739 * This routine it invoked to log the currently used active interrupt mode
4740 * to the device.
James Smart3772a992009-05-22 14:50:54 -04004741 **/
4742static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05004743{
4744 switch (intr_mode) {
4745 case 0:
4746 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4747 "0470 Enable INTx interrupt mode.\n");
4748 break;
4749 case 1:
4750 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4751 "0481 Enabled MSI interrupt mode.\n");
4752 break;
4753 case 2:
4754 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4755 "0480 Enabled MSI-X interrupt mode.\n");
4756 break;
4757 default:
4758 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4759 "0482 Illegal interrupt mode.\n");
4760 break;
4761 }
4762 return;
4763}
4764
James Smart5b75da22008-12-04 22:39:35 -05004765/**
James Smart3772a992009-05-22 14:50:54 -04004766 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05004767 * @phba: pointer to lpfc hba data structure.
4768 *
James Smart3772a992009-05-22 14:50:54 -04004769 * This routine is invoked to enable the PCI device that is common to all
4770 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05004771 *
4772 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004773 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004774 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05004775 **/
James Smart3772a992009-05-22 14:50:54 -04004776static int
4777lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05004778{
James Smart3772a992009-05-22 14:50:54 -04004779 struct pci_dev *pdev;
James Smart079b5c92011-08-21 21:48:49 -04004780 int bars = 0;
James Smart5b75da22008-12-04 22:39:35 -05004781
James Smart3772a992009-05-22 14:50:54 -04004782 /* Obtain PCI device reference */
4783 if (!phba->pcidev)
4784 goto out_error;
4785 else
4786 pdev = phba->pcidev;
4787 /* Select PCI BARs */
4788 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4789 /* Enable PCI device */
4790 if (pci_enable_device_mem(pdev))
4791 goto out_error;
4792 /* Request PCI resource for the device */
4793 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
4794 goto out_disable_device;
4795 /* Set up device as PCI master and save state for EEH */
4796 pci_set_master(pdev);
4797 pci_try_set_mwi(pdev);
4798 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05004799
James Smart05580562011-05-24 11:40:48 -04004800 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
Jon Mason453193e2013-09-11 15:38:13 -07004801 if (pci_is_pcie(pdev))
James Smart05580562011-05-24 11:40:48 -04004802 pdev->needs_freset = 1;
4803
James Smart3772a992009-05-22 14:50:54 -04004804 return 0;
James Smart5b75da22008-12-04 22:39:35 -05004805
James Smart3772a992009-05-22 14:50:54 -04004806out_disable_device:
4807 pci_disable_device(pdev);
4808out_error:
James Smart079b5c92011-08-21 21:48:49 -04004809 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4810 "1401 Failed to enable pci device, bars:x%x\n", bars);
James Smart3772a992009-05-22 14:50:54 -04004811 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05004812}
4813
4814/**
James Smart3772a992009-05-22 14:50:54 -04004815 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05004816 * @phba: pointer to lpfc hba data structure.
4817 *
James Smart3772a992009-05-22 14:50:54 -04004818 * This routine is invoked to disable the PCI device that is common to all
4819 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05004820 **/
4821static void
James Smart3772a992009-05-22 14:50:54 -04004822lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05004823{
James Smart3772a992009-05-22 14:50:54 -04004824 struct pci_dev *pdev;
4825 int bars;
James Smart5b75da22008-12-04 22:39:35 -05004826
James Smart3772a992009-05-22 14:50:54 -04004827 /* Obtain PCI device reference */
4828 if (!phba->pcidev)
4829 return;
4830 else
4831 pdev = phba->pcidev;
4832 /* Select PCI BARs */
4833 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4834 /* Release PCI resource and disable PCI device */
4835 pci_release_selected_regions(pdev, bars);
4836 pci_disable_device(pdev);
James Smart5b75da22008-12-04 22:39:35 -05004837
4838 return;
4839}
4840
4841/**
James Smart3772a992009-05-22 14:50:54 -04004842 * lpfc_reset_hba - Reset a hba
4843 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04004844 *
James Smart3772a992009-05-22 14:50:54 -04004845 * This routine is invoked to reset a hba device. It brings the HBA
4846 * offline, performs a board restart, and then brings the board back
4847 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
4848 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04004849 **/
James Smart3772a992009-05-22 14:50:54 -04004850void
4851lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05004852{
James Smart3772a992009-05-22 14:50:54 -04004853 /* If resets are disabled then set error state and return. */
4854 if (!phba->cfg_enable_hba_reset) {
4855 phba->link_state = LPFC_HBA_ERROR;
4856 return;
4857 }
James Smartee620212014-04-04 13:51:53 -04004858 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
4859 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
4860 else
4861 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart3772a992009-05-22 14:50:54 -04004862 lpfc_offline(phba);
4863 lpfc_sli_brdrestart(phba);
4864 lpfc_online(phba);
4865 lpfc_unblock_mgmt_io(phba);
4866}
dea31012005-04-17 16:05:31 -05004867
James Smart3772a992009-05-22 14:50:54 -04004868/**
James Smart0a96e972011-07-22 18:37:28 -04004869 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
4870 * @phba: pointer to lpfc hba data structure.
4871 *
4872 * This function enables the PCI SR-IOV virtual functions to a physical
4873 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4874 * enable the number of virtual functions to the physical function. As
4875 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4876 * API call does not considered as an error condition for most of the device.
4877 **/
4878uint16_t
4879lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
4880{
4881 struct pci_dev *pdev = phba->pcidev;
4882 uint16_t nr_virtfn;
4883 int pos;
4884
James Smart0a96e972011-07-22 18:37:28 -04004885 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4886 if (pos == 0)
4887 return 0;
4888
4889 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
4890 return nr_virtfn;
4891}
4892
4893/**
James Smart912e3ac2011-05-24 11:42:11 -04004894 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
4895 * @phba: pointer to lpfc hba data structure.
4896 * @nr_vfn: number of virtual functions to be enabled.
4897 *
4898 * This function enables the PCI SR-IOV virtual functions to a physical
4899 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4900 * enable the number of virtual functions to the physical function. As
4901 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4902 * API call does not considered as an error condition for most of the device.
4903 **/
4904int
4905lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
4906{
4907 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04004908 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04004909 int rc;
4910
James Smart0a96e972011-07-22 18:37:28 -04004911 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
4912 if (nr_vfn > max_nr_vfn) {
4913 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4914 "3057 Requested vfs (%d) greater than "
4915 "supported vfs (%d)", nr_vfn, max_nr_vfn);
4916 return -EINVAL;
4917 }
4918
James Smart912e3ac2011-05-24 11:42:11 -04004919 rc = pci_enable_sriov(pdev, nr_vfn);
4920 if (rc) {
4921 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4922 "2806 Failed to enable sriov on this device "
4923 "with vfn number nr_vf:%d, rc:%d\n",
4924 nr_vfn, rc);
4925 } else
4926 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4927 "2807 Successful enable sriov on this device "
4928 "with vfn number nr_vf:%d\n", nr_vfn);
4929 return rc;
4930}
4931
4932/**
James Smart3772a992009-05-22 14:50:54 -04004933 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
4934 * @phba: pointer to lpfc hba data structure.
4935 *
4936 * This routine is invoked to set up the driver internal resources specific to
4937 * support the SLI-3 HBA device it attached to.
4938 *
4939 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004940 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004941 * other values - error
4942 **/
4943static int
4944lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
4945{
4946 struct lpfc_sli *psli;
James Smart912e3ac2011-05-24 11:42:11 -04004947 int rc;
dea31012005-04-17 16:05:31 -05004948
James Smart3772a992009-05-22 14:50:54 -04004949 /*
4950 * Initialize timers used by driver
4951 */
dea31012005-04-17 16:05:31 -05004952
James Smart3772a992009-05-22 14:50:54 -04004953 /* Heartbeat timer */
4954 init_timer(&phba->hb_tmofunc);
4955 phba->hb_tmofunc.function = lpfc_hb_timeout;
4956 phba->hb_tmofunc.data = (unsigned long)phba;
4957
4958 psli = &phba->sli;
4959 /* MBOX heartbeat timer */
4960 init_timer(&psli->mbox_tmo);
4961 psli->mbox_tmo.function = lpfc_mbox_timeout;
4962 psli->mbox_tmo.data = (unsigned long) phba;
4963 /* FCP polling mode timer */
4964 init_timer(&phba->fcp_poll_timer);
4965 phba->fcp_poll_timer.function = lpfc_poll_timeout;
4966 phba->fcp_poll_timer.data = (unsigned long) phba;
4967 /* Fabric block timer */
4968 init_timer(&phba->fabric_block_timer);
4969 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
4970 phba->fabric_block_timer.data = (unsigned long) phba;
4971 /* EA polling mode timer */
4972 init_timer(&phba->eratt_poll);
4973 phba->eratt_poll.function = lpfc_poll_eratt;
4974 phba->eratt_poll.data = (unsigned long) phba;
4975
4976 /* Host attention work mask setup */
4977 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
4978 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
4979
4980 /* Get all the module params for configuring this host */
4981 lpfc_get_cfgparam(phba);
James Smart49198b32010-04-06 15:04:33 -04004982 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
4983 phba->menlo_flag |= HBA_MENLO_SUPPORT;
4984 /* check for menlo minimum sg count */
4985 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
4986 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
4987 }
4988
James Smart2a76a282012-08-03 12:35:54 -04004989 if (!phba->sli.ring)
Firo Yangc6cb9b42015-08-31 16:48:09 -04004990 phba->sli.ring = kzalloc(LPFC_SLI3_MAX_RING *
James Smart2a76a282012-08-03 12:35:54 -04004991 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
4992 if (!phba->sli.ring)
4993 return -ENOMEM;
4994
James Smart3772a992009-05-22 14:50:54 -04004995 /*
James Smart96f70772013-04-17 20:16:15 -04004996 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smart3772a992009-05-22 14:50:54 -04004997 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart3772a992009-05-22 14:50:54 -04004998 */
James Smart3772a992009-05-22 14:50:54 -04004999
James Smart96f70772013-04-17 20:16:15 -04005000 /* Initialize the host templates the configured values. */
James Smart3772a992009-05-22 14:50:54 -04005001 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
Bodo Stroesser5f406fa2015-08-31 16:48:10 -04005002 lpfc_template_s3.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart3772a992009-05-22 14:50:54 -04005003
James Smart96f70772013-04-17 20:16:15 -04005004 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
5005 if (phba->cfg_enable_bg) {
5006 /*
5007 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5008 * the FCP rsp, and a BDE for each. Sice we have no control
5009 * over how many protection data segments the SCSI Layer
5010 * will hand us (ie: there could be one for every block
5011 * in the IO), we just allocate enough BDEs to accomidate
5012 * our max amount and we need to limit lpfc_sg_seg_cnt to
5013 * minimize the risk of running out.
5014 */
5015 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5016 sizeof(struct fcp_rsp) +
5017 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
5018
5019 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
5020 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
5021
5022 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
5023 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
5024 } else {
5025 /*
5026 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5027 * the FCP rsp, a BDE for each, and a BDE for up to
5028 * cfg_sg_seg_cnt data segments.
5029 */
5030 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5031 sizeof(struct fcp_rsp) +
5032 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
5033
5034 /* Total BDEs in BPL for scsi_sg_list */
5035 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5036 }
5037
5038 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5039 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
5040 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5041 phba->cfg_total_seg_cnt);
5042
James Smart3772a992009-05-22 14:50:54 -04005043 phba->max_vpi = LPFC_MAX_VPI;
5044 /* This will be set to correct value after config_port mbox */
5045 phba->max_vports = 0;
5046
5047 /*
5048 * Initialize the SLI Layer to run with lpfc HBAs.
5049 */
5050 lpfc_sli_setup(phba);
5051 lpfc_sli_queue_setup(phba);
5052
5053 /* Allocate device driver memory */
5054 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
5055 return -ENOMEM;
5056
James Smart912e3ac2011-05-24 11:42:11 -04005057 /*
5058 * Enable sr-iov virtual functions if supported and configured
5059 * through the module parameter.
5060 */
5061 if (phba->cfg_sriov_nr_virtfn > 0) {
5062 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5063 phba->cfg_sriov_nr_virtfn);
5064 if (rc) {
5065 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5066 "2808 Requested number of SR-IOV "
5067 "virtual functions (%d) is not "
5068 "supported\n",
5069 phba->cfg_sriov_nr_virtfn);
5070 phba->cfg_sriov_nr_virtfn = 0;
5071 }
5072 }
5073
James Smart3772a992009-05-22 14:50:54 -04005074 return 0;
5075}
5076
5077/**
5078 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
5079 * @phba: pointer to lpfc hba data structure.
5080 *
5081 * This routine is invoked to unset the driver internal resources set up
5082 * specific for supporting the SLI-3 HBA device it attached to.
5083 **/
5084static void
5085lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
5086{
5087 /* Free device driver memory allocated */
5088 lpfc_mem_free_all(phba);
5089
5090 return;
5091}
5092
5093/**
James Smartda0436e2009-05-22 14:51:39 -04005094 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
5095 * @phba: pointer to lpfc hba data structure.
5096 *
5097 * This routine is invoked to set up the driver internal resources specific to
5098 * support the SLI-4 HBA device it attached to.
5099 *
5100 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005101 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04005102 * other values - error
5103 **/
5104static int
5105lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5106{
James Smart7bb03bb2013-04-17 20:19:16 -04005107 struct lpfc_vector_map_info *cpup;
James Smartda0436e2009-05-22 14:51:39 -04005108 struct lpfc_sli *psli;
James Smart28baac72010-02-12 14:42:03 -05005109 LPFC_MBOXQ_t *mboxq;
James Smart96f70772013-04-17 20:16:15 -04005110 int rc, i, hbq_count, max_buf_size;
James Smart28baac72010-02-12 14:42:03 -05005111 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
5112 struct lpfc_mqe *mqe;
James Smart09294d42013-04-17 20:16:05 -04005113 int longs;
James Smart1ba981f2014-02-20 09:56:45 -05005114 int fof_vectors = 0;
James Smartda0436e2009-05-22 14:51:39 -04005115
James Smart716d3bc2013-09-06 12:18:28 -04005116 /* Get all the module params for configuring this host */
5117 lpfc_get_cfgparam(phba);
5118
James Smartda0436e2009-05-22 14:51:39 -04005119 /* Before proceed, wait for POST done and device ready */
5120 rc = lpfc_sli4_post_status_check(phba);
5121 if (rc)
5122 return -ENODEV;
5123
5124 /*
5125 * Initialize timers used by driver
5126 */
5127
5128 /* Heartbeat timer */
5129 init_timer(&phba->hb_tmofunc);
5130 phba->hb_tmofunc.function = lpfc_hb_timeout;
5131 phba->hb_tmofunc.data = (unsigned long)phba;
James Smart19ca7602010-11-20 23:11:55 -05005132 init_timer(&phba->rrq_tmr);
5133 phba->rrq_tmr.function = lpfc_rrq_timeout;
5134 phba->rrq_tmr.data = (unsigned long)phba;
James Smartda0436e2009-05-22 14:51:39 -04005135
5136 psli = &phba->sli;
5137 /* MBOX heartbeat timer */
5138 init_timer(&psli->mbox_tmo);
5139 psli->mbox_tmo.function = lpfc_mbox_timeout;
5140 psli->mbox_tmo.data = (unsigned long) phba;
5141 /* Fabric block timer */
5142 init_timer(&phba->fabric_block_timer);
5143 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
5144 phba->fabric_block_timer.data = (unsigned long) phba;
5145 /* EA polling mode timer */
5146 init_timer(&phba->eratt_poll);
5147 phba->eratt_poll.function = lpfc_poll_eratt;
5148 phba->eratt_poll.data = (unsigned long) phba;
James Smartecfd03c2010-02-12 14:41:27 -05005149 /* FCF rediscover timer */
5150 init_timer(&phba->fcf.redisc_wait);
5151 phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
5152 phba->fcf.redisc_wait.data = (unsigned long)phba;
5153
James Smartda0436e2009-05-22 14:51:39 -04005154 /*
James Smart7ad20aa2011-05-24 11:44:28 -04005155 * Control structure for handling external multi-buffer mailbox
5156 * command pass-through.
5157 */
5158 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
5159 sizeof(struct lpfc_mbox_ext_buf_ctx));
5160 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
5161
James Smartda0436e2009-05-22 14:51:39 -04005162 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04005163
James Smartda0436e2009-05-22 14:51:39 -04005164 /* This will be set to correct value after the read_config mbox */
5165 phba->max_vports = 0;
5166
5167 /* Program the default value of vlan_id and fc_map */
5168 phba->valid_vlan = 0;
5169 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5170 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5171 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5172
5173 /*
James Smart2a76a282012-08-03 12:35:54 -04005174 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
5175 * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple.
5176 */
5177 if (!phba->sli.ring)
5178 phba->sli.ring = kzalloc(
James Smart67d12732012-08-03 12:36:13 -04005179 (LPFC_SLI3_MAX_RING + phba->cfg_fcp_io_channel) *
James Smart2a76a282012-08-03 12:35:54 -04005180 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
5181 if (!phba->sli.ring)
5182 return -ENOMEM;
James Smart085c6472010-11-20 23:11:37 -05005183
James Smart09294d42013-04-17 20:16:05 -04005184 /*
5185 * It doesn't matter what family our adapter is in, we are
5186 * limited to 2 Pages, 512 SGEs, for our SGL.
5187 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
5188 */
5189 max_buf_size = (2 * SLI4_PAGE_SIZE);
5190 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2)
5191 phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2;
James Smart09294d42013-04-17 20:16:05 -04005192
James Smartda0436e2009-05-22 14:51:39 -04005193 /*
James Smart96f70772013-04-17 20:16:15 -04005194 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smartda0436e2009-05-22 14:51:39 -04005195 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart28baac72010-02-12 14:42:03 -05005196 */
James Smart085c6472010-11-20 23:11:37 -05005197
James Smart96f70772013-04-17 20:16:15 -04005198 if (phba->cfg_enable_bg) {
5199 /*
5200 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5201 * the FCP rsp, and a SGE for each. Sice we have no control
5202 * over how many protection data segments the SCSI Layer
5203 * will hand us (ie: there could be one for every block
5204 * in the IO), we just allocate enough SGEs to accomidate
5205 * our max amount and we need to limit lpfc_sg_seg_cnt to
5206 * minimize the risk of running out.
5207 */
5208 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5209 sizeof(struct fcp_rsp) + max_buf_size;
5210
5211 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
5212 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
5213
5214 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
5215 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
5216 } else {
5217 /*
5218 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5219 * the FCP rsp, a SGE for each, and a SGE for up to
5220 * cfg_sg_seg_cnt data segments.
5221 */
5222 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5223 sizeof(struct fcp_rsp) +
5224 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge));
5225
5226 /* Total SGEs for scsi_sg_list */
5227 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5228 /*
5229 * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only need
5230 * to post 1 page for the SGL.
5231 */
James Smart085c6472010-11-20 23:11:37 -05005232 }
James Smartacd68592012-01-18 16:25:09 -05005233
James Smart96f70772013-04-17 20:16:15 -04005234 /* Initialize the host templates with the updated values. */
5235 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5236 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5237
5238 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
5239 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
5240 else
5241 phba->cfg_sg_dma_buf_size =
5242 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
5243
5244 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5245 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
5246 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5247 phba->cfg_total_seg_cnt);
James Smartda0436e2009-05-22 14:51:39 -04005248
5249 /* Initialize buffer queue management fields */
5250 hbq_count = lpfc_sli_hbq_count();
5251 for (i = 0; i < hbq_count; ++i)
5252 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
5253 INIT_LIST_HEAD(&phba->rb_pend_list);
5254 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
5255 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
5256
5257 /*
5258 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
5259 */
5260 /* Initialize the Abort scsi buffer list used by driver */
5261 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
5262 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
5263 /* This abort list used by worker thread */
5264 spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
5265
5266 /*
James Smart6d368e52011-05-24 11:44:12 -04005267 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04005268 */
5269
5270 /* Driver internel slow-path CQ Event pool */
5271 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
5272 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04005273 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04005274 /* Asynchronous event CQ Event work queue list */
5275 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
5276 /* Fast-path XRI aborted CQ Event work queue list */
5277 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
5278 /* Slow-path XRI aborted CQ Event work queue list */
5279 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
5280 /* Receive queue CQ Event work queue list */
5281 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
5282
James Smart6d368e52011-05-24 11:44:12 -04005283 /* Initialize extent block lists. */
5284 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
5285 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
5286 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
5287 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
5288
James Smart448193b2015-12-16 18:12:05 -05005289 /* initialize optic_state to 0xFF */
5290 phba->sli4_hba.lnk_info.optic_state = 0xff;
5291
James Smartda0436e2009-05-22 14:51:39 -04005292 /* Initialize the driver internal SLI layer lists. */
5293 lpfc_sli_setup(phba);
5294 lpfc_sli_queue_setup(phba);
5295
5296 /* Allocate device driver memory */
5297 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
5298 if (rc)
5299 return -ENOMEM;
5300
James Smart2fcee4b2010-12-15 17:57:46 -05005301 /* IF Type 2 ports get initialized now. */
5302 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5303 LPFC_SLI_INTF_IF_TYPE_2) {
5304 rc = lpfc_pci_function_reset(phba);
5305 if (unlikely(rc))
5306 return -ENODEV;
James Smart946727d2015-04-07 15:07:09 -04005307 phba->temp_sensor_support = 1;
James Smart2fcee4b2010-12-15 17:57:46 -05005308 }
5309
James Smartda0436e2009-05-22 14:51:39 -04005310 /* Create the bootstrap mailbox command */
5311 rc = lpfc_create_bootstrap_mbox(phba);
5312 if (unlikely(rc))
5313 goto out_free_mem;
5314
5315 /* Set up the host's endian order with the device. */
5316 rc = lpfc_setup_endian_order(phba);
5317 if (unlikely(rc))
5318 goto out_free_bsmbx;
5319
5320 /* Set up the hba's configuration parameters. */
5321 rc = lpfc_sli4_read_config(phba);
5322 if (unlikely(rc))
5323 goto out_free_bsmbx;
James Smartcff261f2013-12-17 20:29:47 -05005324 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
5325 if (unlikely(rc))
5326 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005327
James Smart2fcee4b2010-12-15 17:57:46 -05005328 /* IF Type 0 ports get initialized now. */
5329 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5330 LPFC_SLI_INTF_IF_TYPE_0) {
5331 rc = lpfc_pci_function_reset(phba);
5332 if (unlikely(rc))
5333 goto out_free_bsmbx;
5334 }
James Smartda0436e2009-05-22 14:51:39 -04005335
James Smartcb5172e2010-03-15 11:25:07 -04005336 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
5337 GFP_KERNEL);
5338 if (!mboxq) {
5339 rc = -ENOMEM;
5340 goto out_free_bsmbx;
5341 }
5342
James Smartfedd3b72011-02-16 12:39:24 -05005343 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04005344 lpfc_supported_pages(mboxq);
5345 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05005346 if (!rc) {
5347 mqe = &mboxq->u.mqe;
5348 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
5349 LPFC_MAX_SUPPORTED_PAGES);
5350 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
5351 switch (pn_page[i]) {
5352 case LPFC_SLI4_PARAMETERS:
5353 phba->sli4_hba.pc_sli4_params.supported = 1;
5354 break;
5355 default:
5356 break;
5357 }
5358 }
5359 /* Read the port's SLI4 Parameters capabilities if supported. */
5360 if (phba->sli4_hba.pc_sli4_params.supported)
5361 rc = lpfc_pc_sli4_params_get(phba, mboxq);
5362 if (rc) {
5363 mempool_free(mboxq, phba->mbox_mem_pool);
5364 rc = -EIO;
5365 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04005366 }
5367 }
James Smartfedd3b72011-02-16 12:39:24 -05005368 /*
5369 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04005370 * If this call fails, it isn't critical unless the SLI4 parameters come
5371 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05005372 */
James Smart6d368e52011-05-24 11:44:12 -04005373 rc = lpfc_get_sli4_parameters(phba, mboxq);
5374 if (rc) {
5375 if (phba->sli4_hba.extents_in_use &&
5376 phba->sli4_hba.rpi_hdrs_in_use) {
5377 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5378 "2999 Unsupported SLI4 Parameters "
5379 "Extents and RPI headers enabled.\n");
5380 goto out_free_bsmbx;
5381 }
5382 }
James Smartcb5172e2010-03-15 11:25:07 -04005383 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -05005384
5385 /* Verify OAS is supported */
5386 lpfc_sli4_oas_verify(phba);
5387 if (phba->cfg_fof)
5388 fof_vectors = 1;
5389
James Smart5350d872011-10-10 21:33:49 -04005390 /* Verify all the SLI4 queues */
5391 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04005392 if (rc)
5393 goto out_free_bsmbx;
5394
5395 /* Create driver internal CQE event pool */
5396 rc = lpfc_sli4_cq_event_pool_create(phba);
5397 if (rc)
James Smart5350d872011-10-10 21:33:49 -04005398 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005399
James Smart8a9d2e82012-05-09 21:16:12 -04005400 /* Initialize sgl lists per host */
5401 lpfc_init_sgl_list(phba);
5402
5403 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04005404 rc = lpfc_init_active_sgl_array(phba);
5405 if (rc) {
5406 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5407 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04005408 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04005409 }
James Smartda0436e2009-05-22 14:51:39 -04005410 rc = lpfc_sli4_init_rpi_hdrs(phba);
5411 if (rc) {
5412 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5413 "1432 Failed to initialize rpi headers.\n");
5414 goto out_free_active_sgl;
5415 }
5416
James Smarta93ff372010-10-22 11:06:08 -04005417 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05005418 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
5419 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
5420 GFP_KERNEL);
5421 if (!phba->fcf.fcf_rr_bmask) {
5422 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5423 "2759 Failed allocate memory for FCF round "
5424 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04005425 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05005426 goto out_remove_rpi_hdrs;
5427 }
5428
James Smart67d12732012-08-03 12:36:13 -04005429 phba->sli4_hba.fcp_eq_hdl =
5430 kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
James Smart1ba981f2014-02-20 09:56:45 -05005431 (fof_vectors + phba->cfg_fcp_io_channel)),
5432 GFP_KERNEL);
James Smart67d12732012-08-03 12:36:13 -04005433 if (!phba->sli4_hba.fcp_eq_hdl) {
5434 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5435 "2572 Failed allocate memory for "
5436 "fast-path per-EQ handle array\n");
5437 rc = -ENOMEM;
5438 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04005439 }
5440
5441 phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
James Smart1ba981f2014-02-20 09:56:45 -05005442 (fof_vectors +
5443 phba->cfg_fcp_io_channel)), GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04005444 if (!phba->sli4_hba.msix_entries) {
5445 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5446 "2573 Failed allocate memory for msi-x "
5447 "interrupt vector entries\n");
James Smart05580562011-05-24 11:40:48 -04005448 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04005449 goto out_free_fcp_eq_hdl;
5450 }
5451
James Smart7bb03bb2013-04-17 20:19:16 -04005452 phba->sli4_hba.cpu_map = kzalloc((sizeof(struct lpfc_vector_map_info) *
5453 phba->sli4_hba.num_present_cpu),
5454 GFP_KERNEL);
5455 if (!phba->sli4_hba.cpu_map) {
5456 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5457 "3327 Failed allocate memory for msi-x "
5458 "interrupt vector mapping\n");
5459 rc = -ENOMEM;
5460 goto out_free_msix;
5461 }
James Smartb246de12013-05-31 17:03:07 -04005462 if (lpfc_used_cpu == NULL) {
5463 lpfc_used_cpu = kzalloc((sizeof(uint16_t) * lpfc_present_cpu),
5464 GFP_KERNEL);
5465 if (!lpfc_used_cpu) {
5466 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5467 "3335 Failed allocate memory for msi-x "
5468 "interrupt vector mapping\n");
5469 kfree(phba->sli4_hba.cpu_map);
5470 rc = -ENOMEM;
5471 goto out_free_msix;
5472 }
5473 for (i = 0; i < lpfc_present_cpu; i++)
5474 lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
5475 }
5476
James Smart7bb03bb2013-04-17 20:19:16 -04005477 /* Initialize io channels for round robin */
5478 cpup = phba->sli4_hba.cpu_map;
5479 rc = 0;
5480 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
5481 cpup->channel_id = rc;
5482 rc++;
5483 if (rc >= phba->cfg_fcp_io_channel)
5484 rc = 0;
5485 }
5486
James Smart912e3ac2011-05-24 11:42:11 -04005487 /*
5488 * Enable sr-iov virtual functions if supported and configured
5489 * through the module parameter.
5490 */
5491 if (phba->cfg_sriov_nr_virtfn > 0) {
5492 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5493 phba->cfg_sriov_nr_virtfn);
5494 if (rc) {
5495 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5496 "3020 Requested number of SR-IOV "
5497 "virtual functions (%d) is not "
5498 "supported\n",
5499 phba->cfg_sriov_nr_virtfn);
5500 phba->cfg_sriov_nr_virtfn = 0;
5501 }
5502 }
5503
James Smart5248a742011-07-22 18:37:06 -04005504 return 0;
James Smartda0436e2009-05-22 14:51:39 -04005505
James Smart7bb03bb2013-04-17 20:19:16 -04005506out_free_msix:
5507 kfree(phba->sli4_hba.msix_entries);
James Smartda0436e2009-05-22 14:51:39 -04005508out_free_fcp_eq_hdl:
5509 kfree(phba->sli4_hba.fcp_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05005510out_free_fcf_rr_bmask:
5511 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04005512out_remove_rpi_hdrs:
5513 lpfc_sli4_remove_rpi_hdrs(phba);
5514out_free_active_sgl:
5515 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04005516out_destroy_cq_event_pool:
5517 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04005518out_free_bsmbx:
5519 lpfc_destroy_bootstrap_mbox(phba);
5520out_free_mem:
5521 lpfc_mem_free(phba);
5522 return rc;
5523}
5524
5525/**
5526 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
5527 * @phba: pointer to lpfc hba data structure.
5528 *
5529 * This routine is invoked to unset the driver internal resources set up
5530 * specific for supporting the SLI-4 HBA device it attached to.
5531 **/
5532static void
5533lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
5534{
5535 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
5536
James Smart7bb03bb2013-04-17 20:19:16 -04005537 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
5538 kfree(phba->sli4_hba.cpu_map);
5539 phba->sli4_hba.num_present_cpu = 0;
5540 phba->sli4_hba.num_online_cpu = 0;
James Smart76fd07a2014-02-20 09:57:18 -05005541 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04005542
James Smartda0436e2009-05-22 14:51:39 -04005543 /* Free memory allocated for msi-x interrupt vector entries */
5544 kfree(phba->sli4_hba.msix_entries);
5545
5546 /* Free memory allocated for fast-path work queue handles */
5547 kfree(phba->sli4_hba.fcp_eq_hdl);
5548
5549 /* Free the allocated rpi headers. */
5550 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04005551 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04005552
James Smart0c9ab6f2010-02-26 14:15:57 -05005553 /* Free eligible FCF index bmask */
5554 kfree(phba->fcf.fcf_rr_bmask);
5555
James Smartda0436e2009-05-22 14:51:39 -04005556 /* Free the ELS sgl list */
5557 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04005558 lpfc_free_els_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04005559
James Smartda0436e2009-05-22 14:51:39 -04005560 /* Free the completion queue EQ event pool */
5561 lpfc_sli4_cq_event_release_all(phba);
5562 lpfc_sli4_cq_event_pool_destroy(phba);
5563
James Smart6d368e52011-05-24 11:44:12 -04005564 /* Release resource identifiers. */
5565 lpfc_sli4_dealloc_resource_identifiers(phba);
5566
James Smartda0436e2009-05-22 14:51:39 -04005567 /* Free the bsmbx region. */
5568 lpfc_destroy_bootstrap_mbox(phba);
5569
5570 /* Free the SLI Layer memory with SLI4 HBAs */
5571 lpfc_mem_free_all(phba);
5572
5573 /* Free the current connect table */
5574 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04005575 &phba->fcf_conn_rec_list, list) {
5576 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04005577 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04005578 }
James Smartda0436e2009-05-22 14:51:39 -04005579
5580 return;
5581}
5582
5583/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005584 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04005585 * @phba: The hba struct for which this call is being executed.
5586 * @dev_grp: The HBA PCI-Device group number.
5587 *
5588 * This routine sets up the device INIT interface API function jump table
5589 * in @phba struct.
5590 *
5591 * Returns: 0 - success, -ENODEV - failure.
5592 **/
5593int
5594lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5595{
James Smart84d1b002010-02-12 14:42:33 -05005596 phba->lpfc_hba_init_link = lpfc_hba_init_link;
5597 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05005598 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04005599 switch (dev_grp) {
5600 case LPFC_PCI_DEV_LP:
5601 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
5602 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
5603 phba->lpfc_stop_port = lpfc_stop_port_s3;
5604 break;
James Smartda0436e2009-05-22 14:51:39 -04005605 case LPFC_PCI_DEV_OC:
5606 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
5607 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
5608 phba->lpfc_stop_port = lpfc_stop_port_s4;
5609 break;
James Smart3772a992009-05-22 14:50:54 -04005610 default:
5611 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5612 "1431 Invalid HBA PCI-device group: 0x%x\n",
5613 dev_grp);
5614 return -ENODEV;
5615 break;
5616 }
5617 return 0;
5618}
5619
5620/**
5621 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
5622 * @phba: pointer to lpfc hba data structure.
5623 *
5624 * This routine is invoked to set up the driver internal resources before the
5625 * device specific resource setup to support the HBA device it attached to.
5626 *
5627 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005628 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005629 * other values - error
5630 **/
5631static int
5632lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
5633{
5634 /*
5635 * Driver resources common to all SLI revisions
5636 */
James Smartea2151b2008-09-07 11:52:10 -04005637 atomic_set(&phba->fast_event_count, 0);
James Smart2e0fef82007-06-17 19:56:36 -05005638 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005639
James Smarte47c9092008-02-08 18:49:26 -05005640 /* Initialize ndlp management spinlock */
5641 spin_lock_init(&phba->ndlp_lock);
5642
James Smart2e0fef82007-06-17 19:56:36 -05005643 INIT_LIST_HEAD(&phba->port_list);
James Smart3772a992009-05-22 14:50:54 -04005644 INIT_LIST_HEAD(&phba->work_list);
James Smart84774a42008-08-24 21:50:06 -04005645 init_waitqueue_head(&phba->wait_4_mlo_m_q);
dea31012005-04-17 16:05:31 -05005646
James Smart3772a992009-05-22 14:50:54 -04005647 /* Initialize the wait queue head for the kernel thread */
5648 init_waitqueue_head(&phba->work_waitq);
James Smart858c9f62007-06-17 19:56:39 -05005649
James Smart3772a992009-05-22 14:50:54 -04005650 /* Initialize the scsi buffer list used by driver for scsi IO */
James Smarta40fc5f2013-04-17 20:17:40 -04005651 spin_lock_init(&phba->scsi_buf_list_get_lock);
5652 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5653 spin_lock_init(&phba->scsi_buf_list_put_lock);
5654 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
dea31012005-04-17 16:05:31 -05005655
James Smart3772a992009-05-22 14:50:54 -04005656 /* Initialize the fabric iocb list */
5657 INIT_LIST_HEAD(&phba->fabric_iocb_list);
dea31012005-04-17 16:05:31 -05005658
James Smart3772a992009-05-22 14:50:54 -04005659 /* Initialize list to save ELS buffers */
5660 INIT_LIST_HEAD(&phba->elsbuf);
dea31012005-04-17 16:05:31 -05005661
James Smart3772a992009-05-22 14:50:54 -04005662 /* Initialize FCF connection rec list */
5663 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
dea31012005-04-17 16:05:31 -05005664
James Smart1ba981f2014-02-20 09:56:45 -05005665 /* Initialize OAS configuration list */
5666 spin_lock_init(&phba->devicelock);
5667 INIT_LIST_HEAD(&phba->luns);
5668
James Smart3772a992009-05-22 14:50:54 -04005669 return 0;
5670}
dea31012005-04-17 16:05:31 -05005671
James Smart3772a992009-05-22 14:50:54 -04005672/**
5673 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
5674 * @phba: pointer to lpfc hba data structure.
5675 *
5676 * This routine is invoked to set up the driver internal resources after the
5677 * device specific resource setup to support the HBA device it attached to.
5678 *
5679 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005680 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005681 * other values - error
5682 **/
5683static int
5684lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
5685{
5686 int error;
5687
5688 /* Startup the kernel thread for this host adapter. */
5689 phba->worker_thread = kthread_run(lpfc_do_work, phba,
5690 "lpfc_worker_%d", phba->brd_no);
5691 if (IS_ERR(phba->worker_thread)) {
5692 error = PTR_ERR(phba->worker_thread);
5693 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005694 }
5695
James Smart3772a992009-05-22 14:50:54 -04005696 return 0;
5697}
5698
5699/**
5700 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
5701 * @phba: pointer to lpfc hba data structure.
5702 *
5703 * This routine is invoked to unset the driver internal resources set up after
5704 * the device specific resource setup for supporting the HBA device it
5705 * attached to.
5706 **/
5707static void
5708lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
5709{
5710 /* Stop kernel worker thread */
5711 kthread_stop(phba->worker_thread);
5712}
5713
5714/**
5715 * lpfc_free_iocb_list - Free iocb list.
5716 * @phba: pointer to lpfc hba data structure.
5717 *
5718 * This routine is invoked to free the driver's IOCB list and memory.
5719 **/
5720static void
5721lpfc_free_iocb_list(struct lpfc_hba *phba)
5722{
5723 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
5724
5725 spin_lock_irq(&phba->hbalock);
5726 list_for_each_entry_safe(iocbq_entry, iocbq_next,
5727 &phba->lpfc_iocb_list, list) {
5728 list_del(&iocbq_entry->list);
5729 kfree(iocbq_entry);
5730 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005731 }
James Smart3772a992009-05-22 14:50:54 -04005732 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005733
James Smart3772a992009-05-22 14:50:54 -04005734 return;
5735}
dea31012005-04-17 16:05:31 -05005736
James Smart3772a992009-05-22 14:50:54 -04005737/**
5738 * lpfc_init_iocb_list - Allocate and initialize iocb list.
5739 * @phba: pointer to lpfc hba data structure.
5740 *
5741 * This routine is invoked to allocate and initizlize the driver's IOCB
5742 * list and set up the IOCB tag array accordingly.
5743 *
5744 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005745 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005746 * other values - error
5747 **/
5748static int
5749lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
5750{
5751 struct lpfc_iocbq *iocbq_entry = NULL;
5752 uint16_t iotag;
5753 int i;
dea31012005-04-17 16:05:31 -05005754
5755 /* Initialize and populate the iocb list per host. */
5756 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04005757 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07005758 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05005759 if (iocbq_entry == NULL) {
5760 printk(KERN_ERR "%s: only allocated %d iocbs of "
5761 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07005762 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05005763 goto out_free_iocbq;
5764 }
5765
James Bottomley604a3e32005-10-29 10:28:33 -05005766 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
5767 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04005768 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05005769 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04005770 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05005771 goto out_free_iocbq;
5772 }
James Smart6d368e52011-05-24 11:44:12 -04005773 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04005774 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05005775
5776 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005777 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
5778 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05005779 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005780 }
5781
James Smart3772a992009-05-22 14:50:54 -04005782 return 0;
5783
5784out_free_iocbq:
5785 lpfc_free_iocb_list(phba);
5786
5787 return -ENOMEM;
5788}
5789
5790/**
James Smart8a9d2e82012-05-09 21:16:12 -04005791 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04005792 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04005793 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04005794 *
James Smart8a9d2e82012-05-09 21:16:12 -04005795 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04005796 **/
James Smart8a9d2e82012-05-09 21:16:12 -04005797void
5798lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04005799{
5800 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04005801
5802 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
5803 list_del(&sglq_entry->list);
5804 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
5805 kfree(sglq_entry);
5806 }
5807}
5808
5809/**
5810 * lpfc_free_els_sgl_list - Free els sgl list.
5811 * @phba: pointer to lpfc hba data structure.
5812 *
5813 * This routine is invoked to free the driver's els sgl list and memory.
5814 **/
5815static void
5816lpfc_free_els_sgl_list(struct lpfc_hba *phba)
5817{
James Smartda0436e2009-05-22 14:51:39 -04005818 LIST_HEAD(sglq_list);
James Smartdafe8ce2014-09-03 12:56:40 -04005819 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smartda0436e2009-05-22 14:51:39 -04005820
James Smart8a9d2e82012-05-09 21:16:12 -04005821 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04005822 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04005823 spin_lock(&pring->ring_lock);
James Smartda0436e2009-05-22 14:51:39 -04005824 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
James Smartdafe8ce2014-09-03 12:56:40 -04005825 spin_unlock(&pring->ring_lock);
James Smartda0436e2009-05-22 14:51:39 -04005826 spin_unlock_irq(&phba->hbalock);
5827
James Smart8a9d2e82012-05-09 21:16:12 -04005828 /* Now free the sgl list */
5829 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04005830}
5831
5832/**
5833 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
5834 * @phba: pointer to lpfc hba data structure.
5835 *
5836 * This routine is invoked to allocate the driver's active sgl memory.
5837 * This array will hold the sglq_entry's for active IOs.
5838 **/
5839static int
5840lpfc_init_active_sgl_array(struct lpfc_hba *phba)
5841{
5842 int size;
5843 size = sizeof(struct lpfc_sglq *);
5844 size *= phba->sli4_hba.max_cfg_param.max_xri;
5845
5846 phba->sli4_hba.lpfc_sglq_active_list =
5847 kzalloc(size, GFP_KERNEL);
5848 if (!phba->sli4_hba.lpfc_sglq_active_list)
5849 return -ENOMEM;
5850 return 0;
5851}
5852
5853/**
5854 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
5855 * @phba: pointer to lpfc hba data structure.
5856 *
5857 * This routine is invoked to walk through the array of active sglq entries
5858 * and free all of the resources.
5859 * This is just a place holder for now.
5860 **/
5861static void
5862lpfc_free_active_sgl(struct lpfc_hba *phba)
5863{
5864 kfree(phba->sli4_hba.lpfc_sglq_active_list);
5865}
5866
5867/**
5868 * lpfc_init_sgl_list - Allocate and initialize sgl list.
5869 * @phba: pointer to lpfc hba data structure.
5870 *
5871 * This routine is invoked to allocate and initizlize the driver's sgl
5872 * list and set up the sgl xritag tag array accordingly.
5873 *
James Smartda0436e2009-05-22 14:51:39 -04005874 **/
James Smart8a9d2e82012-05-09 21:16:12 -04005875static void
James Smartda0436e2009-05-22 14:51:39 -04005876lpfc_init_sgl_list(struct lpfc_hba *phba)
5877{
James Smartda0436e2009-05-22 14:51:39 -04005878 /* Initialize and populate the sglq list per host/VF. */
5879 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
5880 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
5881
James Smart8a9d2e82012-05-09 21:16:12 -04005882 /* els xri-sgl book keeping */
5883 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04005884
James Smart8a9d2e82012-05-09 21:16:12 -04005885 /* scsi xri-buffer book keeping */
James Smartda0436e2009-05-22 14:51:39 -04005886 phba->sli4_hba.scsi_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04005887}
5888
5889/**
5890 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
5891 * @phba: pointer to lpfc hba data structure.
5892 *
5893 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04005894 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04005895 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04005896 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
5897 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04005898 *
5899 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005900 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04005901 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04005902 **/
5903int
5904lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
5905{
5906 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04005907 struct lpfc_rpi_hdr *rpi_hdr;
5908
5909 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05005910 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04005911 return rc;
James Smart6d368e52011-05-24 11:44:12 -04005912 if (phba->sli4_hba.extents_in_use)
5913 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04005914
5915 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
5916 if (!rpi_hdr) {
5917 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5918 "0391 Error during rpi post operation\n");
5919 lpfc_sli4_remove_rpis(phba);
5920 rc = -ENODEV;
5921 }
5922
5923 return rc;
5924}
5925
5926/**
5927 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
5928 * @phba: pointer to lpfc hba data structure.
5929 *
5930 * This routine is invoked to allocate a single 4KB memory region to
5931 * support rpis and stores them in the phba. This single region
5932 * provides support for up to 64 rpis. The region is used globally
5933 * by the device.
5934 *
5935 * Returns:
5936 * A valid rpi hdr on success.
5937 * A NULL pointer on any failure.
5938 **/
5939struct lpfc_rpi_hdr *
5940lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
5941{
5942 uint16_t rpi_limit, curr_rpi_range;
5943 struct lpfc_dmabuf *dmabuf;
5944 struct lpfc_rpi_hdr *rpi_hdr;
James Smart9589b0622011-04-16 11:03:17 -04005945 uint32_t rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04005946
James Smart6d368e52011-05-24 11:44:12 -04005947 /*
5948 * If the SLI4 port supports extents, posting the rpi header isn't
5949 * required. Set the expected maximum count and let the actual value
5950 * get set when extents are fully allocated.
5951 */
5952 if (!phba->sli4_hba.rpi_hdrs_in_use)
5953 return NULL;
5954 if (phba->sli4_hba.extents_in_use)
5955 return NULL;
5956
5957 /* The limit on the logical index is just the max_rpi count. */
James Smartda0436e2009-05-22 14:51:39 -04005958 rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
James Smart6d368e52011-05-24 11:44:12 -04005959 phba->sli4_hba.max_cfg_param.max_rpi - 1;
James Smartda0436e2009-05-22 14:51:39 -04005960
5961 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04005962 /*
5963 * Establish the starting RPI in this header block. The starting
5964 * rpi is normalized to a zero base because the physical rpi is
5965 * port based.
5966 */
James Smart97f2ecf2012-03-01 22:35:23 -05005967 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04005968 spin_unlock_irq(&phba->hbalock);
5969
5970 /*
5971 * The port has a limited number of rpis. The increment here
5972 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
5973 * and to allow the full max_rpi range per port.
5974 */
5975 if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
James Smart9589b0622011-04-16 11:03:17 -04005976 rpi_count = rpi_limit - curr_rpi_range;
5977 else
5978 rpi_count = LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04005979
James Smart6d368e52011-05-24 11:44:12 -04005980 if (!rpi_count)
5981 return NULL;
James Smartda0436e2009-05-22 14:51:39 -04005982 /*
5983 * First allocate the protocol header region for the port. The
5984 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
5985 */
5986 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5987 if (!dmabuf)
5988 return NULL;
5989
Joe Perches1aee3832014-09-03 12:56:12 -04005990 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
5991 LPFC_HDR_TEMPLATE_SIZE,
5992 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04005993 if (!dmabuf->virt) {
5994 rpi_hdr = NULL;
5995 goto err_free_dmabuf;
5996 }
5997
James Smartda0436e2009-05-22 14:51:39 -04005998 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
5999 rpi_hdr = NULL;
6000 goto err_free_coherent;
6001 }
6002
6003 /* Save the rpi header data for cleanup later. */
6004 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
6005 if (!rpi_hdr)
6006 goto err_free_coherent;
6007
6008 rpi_hdr->dmabuf = dmabuf;
6009 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
6010 rpi_hdr->page_count = 1;
6011 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006012
6013 /* The rpi_hdr stores the logical index only. */
6014 rpi_hdr->start_rpi = curr_rpi_range;
James Smartda0436e2009-05-22 14:51:39 -04006015 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
6016
6017 /*
James Smart6d368e52011-05-24 11:44:12 -04006018 * The next_rpi stores the next logical module-64 rpi value used
6019 * to post physical rpis in subsequent rpi postings.
James Smartda0436e2009-05-22 14:51:39 -04006020 */
James Smart9589b0622011-04-16 11:03:17 -04006021 phba->sli4_hba.next_rpi += rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04006022 spin_unlock_irq(&phba->hbalock);
6023 return rpi_hdr;
6024
6025 err_free_coherent:
6026 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
6027 dmabuf->virt, dmabuf->phys);
6028 err_free_dmabuf:
6029 kfree(dmabuf);
6030 return NULL;
6031}
6032
6033/**
6034 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
6035 * @phba: pointer to lpfc hba data structure.
6036 *
6037 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04006038 * to support rpis for SLI4 ports not supporting extents. This routine
6039 * presumes the caller has released all rpis consumed by fabric or port
6040 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04006041 **/
6042void
6043lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
6044{
6045 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
6046
James Smart6d368e52011-05-24 11:44:12 -04006047 if (!phba->sli4_hba.rpi_hdrs_in_use)
6048 goto exit;
6049
James Smartda0436e2009-05-22 14:51:39 -04006050 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
6051 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
6052 list_del(&rpi_hdr->list);
6053 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
6054 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
6055 kfree(rpi_hdr->dmabuf);
6056 kfree(rpi_hdr);
6057 }
James Smart6d368e52011-05-24 11:44:12 -04006058 exit:
6059 /* There are no rpis available to the port now. */
6060 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04006061}
6062
6063/**
James Smart3772a992009-05-22 14:50:54 -04006064 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
6065 * @pdev: pointer to pci device data structure.
6066 *
6067 * This routine is invoked to allocate the driver hba data structure for an
6068 * HBA device. If the allocation is successful, the phba reference to the
6069 * PCI device data structure is set.
6070 *
6071 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006072 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04006073 * NULL - error
6074 **/
6075static struct lpfc_hba *
6076lpfc_hba_alloc(struct pci_dev *pdev)
6077{
6078 struct lpfc_hba *phba;
6079
6080 /* Allocate memory for HBA structure */
6081 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
6082 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02006083 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04006084 return NULL;
6085 }
6086
6087 /* Set reference to PCI device in HBA structure */
6088 phba->pcidev = pdev;
6089
6090 /* Assign an unused board number */
6091 phba->brd_no = lpfc_get_instance();
6092 if (phba->brd_no < 0) {
6093 kfree(phba);
6094 return NULL;
6095 }
6096
James Smart4fede782010-01-26 23:08:55 -05006097 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04006098 INIT_LIST_HEAD(&phba->ct_ev_waiters);
6099
James Smart3772a992009-05-22 14:50:54 -04006100 return phba;
6101}
6102
6103/**
6104 * lpfc_hba_free - Free driver hba data structure with a device.
6105 * @phba: pointer to lpfc hba data structure.
6106 *
6107 * This routine is invoked to free the driver hba data structure with an
6108 * HBA device.
6109 **/
6110static void
6111lpfc_hba_free(struct lpfc_hba *phba)
6112{
6113 /* Release the driver assigned board number */
6114 idr_remove(&lpfc_hba_index, phba->brd_no);
6115
James Smart2a76a282012-08-03 12:35:54 -04006116 /* Free memory allocated with sli rings */
6117 kfree(phba->sli.ring);
6118 phba->sli.ring = NULL;
6119
James Smart3772a992009-05-22 14:50:54 -04006120 kfree(phba);
6121 return;
6122}
6123
6124/**
6125 * lpfc_create_shost - Create hba physical port with associated scsi host.
6126 * @phba: pointer to lpfc hba data structure.
6127 *
6128 * This routine is invoked to create HBA physical port and associate a SCSI
6129 * host with it.
6130 *
6131 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006132 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006133 * other values - error
6134 **/
6135static int
6136lpfc_create_shost(struct lpfc_hba *phba)
6137{
6138 struct lpfc_vport *vport;
6139 struct Scsi_Host *shost;
6140
6141 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05006142 phba->fc_edtov = FF_DEF_EDTOV;
6143 phba->fc_ratov = FF_DEF_RATOV;
6144 phba->fc_altov = FF_DEF_ALTOV;
6145 phba->fc_arbtov = FF_DEF_ARBTOV;
6146
James Smartd7c47992010-06-08 18:31:54 -04006147 atomic_set(&phba->sdev_cnt, 0);
James Smart3de2a652007-08-02 11:09:59 -04006148 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05006149 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04006150 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05006151
6152 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05006153 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05006154 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04006155 /* Put reference to SCSI host to driver's device private data */
6156 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05006157
James Smart4258e982015-12-16 18:11:58 -05006158 /*
6159 * At this point we are fully registered with PSA. In addition,
6160 * any initial discovery should be completed.
6161 */
6162 vport->load_flag |= FC_ALLOW_FDMI;
James Smart8663cbb2016-03-31 14:12:33 -07006163 if (phba->cfg_enable_SmartSAN ||
6164 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -05006165
6166 /* Setup appropriate attribute masks */
6167 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -07006168 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -05006169 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
6170 else
6171 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
6172 }
James Smart3772a992009-05-22 14:50:54 -04006173 return 0;
6174}
dea31012005-04-17 16:05:31 -05006175
James Smart3772a992009-05-22 14:50:54 -04006176/**
6177 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
6178 * @phba: pointer to lpfc hba data structure.
6179 *
6180 * This routine is invoked to destroy HBA physical port and the associated
6181 * SCSI host.
6182 **/
6183static void
6184lpfc_destroy_shost(struct lpfc_hba *phba)
6185{
6186 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04006187
James Smart3772a992009-05-22 14:50:54 -04006188 /* Destroy physical port that associated with the SCSI host */
6189 destroy_port(vport);
6190
6191 return;
6192}
6193
6194/**
6195 * lpfc_setup_bg - Setup Block guard structures and debug areas.
6196 * @phba: pointer to lpfc hba data structure.
6197 * @shost: the shost to be used to detect Block guard settings.
6198 *
6199 * This routine sets up the local Block guard protocol settings for @shost.
6200 * This routine also allocates memory for debugging bg buffers.
6201 **/
6202static void
6203lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
6204{
James Smartbbeb79b2012-06-12 13:54:27 -04006205 uint32_t old_mask;
6206 uint32_t old_guard;
6207
James Smart3772a992009-05-22 14:50:54 -04006208 int pagecnt = 10;
6209 if (lpfc_prot_mask && lpfc_prot_guard) {
6210 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6211 "1478 Registering BlockGuard with the "
6212 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04006213
6214 old_mask = lpfc_prot_mask;
6215 old_guard = lpfc_prot_guard;
6216
6217 /* Only allow supported values */
6218 lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
6219 SHOST_DIX_TYPE0_PROTECTION |
6220 SHOST_DIX_TYPE1_PROTECTION);
6221 lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC);
6222
6223 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
6224 if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
6225 lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
6226
6227 if (lpfc_prot_mask && lpfc_prot_guard) {
6228 if ((old_mask != lpfc_prot_mask) ||
6229 (old_guard != lpfc_prot_guard))
6230 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6231 "1475 Registering BlockGuard with the "
6232 "SCSI layer: mask %d guard %d\n",
6233 lpfc_prot_mask, lpfc_prot_guard);
6234
6235 scsi_host_set_prot(shost, lpfc_prot_mask);
6236 scsi_host_set_guard(shost, lpfc_prot_guard);
6237 } else
6238 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6239 "1479 Not Registering BlockGuard with the SCSI "
6240 "layer, Bad protection parameters: %d %d\n",
6241 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04006242 }
James Smartbbeb79b2012-06-12 13:54:27 -04006243
James Smart81301a92008-12-04 22:39:46 -05006244 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05006245 while (pagecnt) {
6246 spin_lock_init(&_dump_buf_lock);
6247 _dump_buf_data =
6248 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6249 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04006250 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6251 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04006252 "_dump_buf_data at 0x%p\n",
6253 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05006254 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04006255 memset(_dump_buf_data, 0,
6256 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05006257 break;
James Smart3772a992009-05-22 14:50:54 -04006258 } else
James Smart81301a92008-12-04 22:39:46 -05006259 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05006260 }
James Smart81301a92008-12-04 22:39:46 -05006261 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04006262 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6263 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04006264 "memory for hexdump\n");
6265 } else
James Smart6a9c52c2009-10-02 15:16:51 -04006266 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6267 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05006268 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05006269 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05006270 while (pagecnt) {
6271 _dump_buf_dif =
6272 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6273 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04006274 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6275 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04006276 "_dump_buf_dif at 0x%p\n",
6277 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05006278 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04006279 memset(_dump_buf_dif, 0,
6280 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05006281 break;
James Smart3772a992009-05-22 14:50:54 -04006282 } else
James Smart81301a92008-12-04 22:39:46 -05006283 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05006284 }
James Smart81301a92008-12-04 22:39:46 -05006285 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04006286 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6287 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04006288 "memory for hexdump\n");
6289 } else
James Smart6a9c52c2009-10-02 15:16:51 -04006290 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6291 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04006292 _dump_buf_dif);
6293}
6294
6295/**
6296 * lpfc_post_init_setup - Perform necessary device post initialization setup.
6297 * @phba: pointer to lpfc hba data structure.
6298 *
6299 * This routine is invoked to perform all the necessary post initialization
6300 * setup for the device.
6301 **/
6302static void
6303lpfc_post_init_setup(struct lpfc_hba *phba)
6304{
6305 struct Scsi_Host *shost;
6306 struct lpfc_adapter_event_header adapter_event;
6307
6308 /* Get the default values for Model Name and Description */
6309 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
6310
6311 /*
6312 * hba setup may have changed the hba_queue_depth so we need to
6313 * adjust the value of can_queue.
6314 */
6315 shost = pci_get_drvdata(phba->pcidev);
6316 shost->can_queue = phba->cfg_hba_queue_depth - 10;
6317 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
6318 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05006319
6320 lpfc_host_attrib_init(shost);
6321
James Smart2e0fef82007-06-17 19:56:36 -05006322 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
6323 spin_lock_irq(shost->host_lock);
6324 lpfc_poll_start_timer(phba);
6325 spin_unlock_irq(shost->host_lock);
6326 }
James Smart8f6d98d2006-08-01 07:34:00 -04006327
James Smart93996272008-08-24 21:50:30 -04006328 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6329 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04006330 /* Send board arrival event to upper layer */
6331 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
6332 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
6333 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04006334 sizeof(adapter_event),
6335 (char *) &adapter_event,
6336 LPFC_NL_VENDOR_ID);
6337 return;
6338}
6339
6340/**
6341 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
6342 * @phba: pointer to lpfc hba data structure.
6343 *
6344 * This routine is invoked to set up the PCI device memory space for device
6345 * with SLI-3 interface spec.
6346 *
6347 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006348 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006349 * other values - error
6350 **/
6351static int
6352lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
6353{
6354 struct pci_dev *pdev;
6355 unsigned long bar0map_len, bar2map_len;
6356 int i, hbq_count;
6357 void *ptr;
6358 int error = -ENODEV;
6359
6360 /* Obtain PCI device reference */
6361 if (!phba->pcidev)
6362 return error;
6363 else
6364 pdev = phba->pcidev;
6365
6366 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05006367 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
6368 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
6369 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
6370 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smart3772a992009-05-22 14:50:54 -04006371 return error;
Michael Reed8e685972009-09-18 12:02:05 -05006372 }
6373 }
James Smart3772a992009-05-22 14:50:54 -04006374
6375 /* Get the bus address of Bar0 and Bar2 and the number of bytes
6376 * required by each mapping.
6377 */
6378 phba->pci_bar0_map = pci_resource_start(pdev, 0);
6379 bar0map_len = pci_resource_len(pdev, 0);
6380
6381 phba->pci_bar2_map = pci_resource_start(pdev, 2);
6382 bar2map_len = pci_resource_len(pdev, 2);
6383
6384 /* Map HBA SLIM to a kernel virtual address. */
6385 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
6386 if (!phba->slim_memmap_p) {
6387 dev_printk(KERN_ERR, &pdev->dev,
6388 "ioremap failed for SLIM memory.\n");
6389 goto out;
6390 }
6391
6392 /* Map HBA Control Registers to a kernel virtual address. */
6393 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
6394 if (!phba->ctrl_regs_memmap_p) {
6395 dev_printk(KERN_ERR, &pdev->dev,
6396 "ioremap failed for HBA control registers.\n");
6397 goto out_iounmap_slim;
6398 }
6399
6400 /* Allocate memory for SLI-2 structures */
Joe Perches1aee3832014-09-03 12:56:12 -04006401 phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6402 &phba->slim2p.phys, GFP_KERNEL);
James Smart3772a992009-05-22 14:50:54 -04006403 if (!phba->slim2p.virt)
6404 goto out_iounmap;
6405
James Smart3772a992009-05-22 14:50:54 -04006406 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04006407 phba->mbox_ext = (phba->slim2p.virt +
6408 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04006409 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
6410 phba->IOCBs = (phba->slim2p.virt +
6411 offsetof(struct lpfc_sli2_slim, IOCBs));
6412
6413 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
6414 lpfc_sli_hbq_size(),
6415 &phba->hbqslimp.phys,
6416 GFP_KERNEL);
6417 if (!phba->hbqslimp.virt)
6418 goto out_free_slim;
6419
6420 hbq_count = lpfc_sli_hbq_count();
6421 ptr = phba->hbqslimp.virt;
6422 for (i = 0; i < hbq_count; ++i) {
6423 phba->hbqs[i].hbq_virt = ptr;
6424 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
6425 ptr += (lpfc_hbq_defs[i]->entry_count *
6426 sizeof(struct lpfc_hbq_entry));
6427 }
6428 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
6429 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
6430
6431 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
6432
6433 INIT_LIST_HEAD(&phba->rb_pend_list);
6434
6435 phba->MBslimaddr = phba->slim_memmap_p;
6436 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
6437 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
6438 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
6439 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04006440
dea31012005-04-17 16:05:31 -05006441 return 0;
6442
dea31012005-04-17 16:05:31 -05006443out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04006444 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6445 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05006446out_iounmap:
6447 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006448out_iounmap_slim:
dea31012005-04-17 16:05:31 -05006449 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05006450out:
6451 return error;
6452}
6453
James Smarte59058c2008-08-24 21:49:00 -04006454/**
James Smart3772a992009-05-22 14:50:54 -04006455 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
6456 * @phba: pointer to lpfc hba data structure.
6457 *
6458 * This routine is invoked to unset the PCI device memory space for device
6459 * with SLI-3 interface spec.
6460 **/
6461static void
6462lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
6463{
6464 struct pci_dev *pdev;
6465
6466 /* Obtain PCI device reference */
6467 if (!phba->pcidev)
6468 return;
6469 else
6470 pdev = phba->pcidev;
6471
6472 /* Free coherent DMA memory allocated */
6473 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
6474 phba->hbqslimp.virt, phba->hbqslimp.phys);
6475 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6476 phba->slim2p.virt, phba->slim2p.phys);
6477
6478 /* I/O memory unmap */
6479 iounmap(phba->ctrl_regs_memmap_p);
6480 iounmap(phba->slim_memmap_p);
6481
6482 return;
6483}
6484
6485/**
James Smartda0436e2009-05-22 14:51:39 -04006486 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
6487 * @phba: pointer to lpfc hba data structure.
6488 *
6489 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
6490 * done and check status.
6491 *
6492 * Return 0 if successful, otherwise -ENODEV.
6493 **/
6494int
6495lpfc_sli4_post_status_check(struct lpfc_hba *phba)
6496{
James Smart2fcee4b2010-12-15 17:57:46 -05006497 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
6498 struct lpfc_register reg_data;
6499 int i, port_error = 0;
6500 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04006501
James Smart9940b972011-03-11 16:06:12 -05006502 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
6503 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05006504 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04006505 return -ENODEV;
6506
James Smartda0436e2009-05-22 14:51:39 -04006507 /* Wait up to 30 seconds for the SLI Port POST done and ready */
6508 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05006509 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
6510 &portsmphr_reg.word0) ||
6511 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006512 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04006513 port_error = -ENODEV;
6514 break;
6515 }
James Smart2fcee4b2010-12-15 17:57:46 -05006516 if (LPFC_POST_STAGE_PORT_READY ==
6517 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04006518 break;
James Smartda0436e2009-05-22 14:51:39 -04006519 msleep(10);
6520 }
6521
James Smart2fcee4b2010-12-15 17:57:46 -05006522 /*
6523 * If there was a port error during POST, then don't proceed with
6524 * other register reads as the data may not be valid. Just exit.
6525 */
6526 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04006527 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006528 "1408 Port Failed POST - portsmphr=0x%x, "
6529 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
6530 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
6531 portsmphr_reg.word0,
6532 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
6533 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
6534 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
6535 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
6536 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
6537 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
6538 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
6539 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
6540 } else {
James Smart28baac72010-02-12 14:42:03 -05006541 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006542 "2534 Device Info: SLIFamily=0x%x, "
6543 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
6544 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05006545 bf_get(lpfc_sli_intf_sli_family,
6546 &phba->sli4_hba.sli_intf),
6547 bf_get(lpfc_sli_intf_slirev,
6548 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006549 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05006550 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006551 bf_get(lpfc_sli_intf_sli_hint1,
6552 &phba->sli4_hba.sli_intf),
6553 bf_get(lpfc_sli_intf_sli_hint2,
6554 &phba->sli4_hba.sli_intf),
6555 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05006556 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05006557 /*
6558 * Check for other Port errors during the initialization
6559 * process. Fail the load if the port did not come up
6560 * correctly.
6561 */
6562 if_type = bf_get(lpfc_sli_intf_if_type,
6563 &phba->sli4_hba.sli_intf);
6564 switch (if_type) {
6565 case LPFC_SLI_INTF_IF_TYPE_0:
6566 phba->sli4_hba.ue_mask_lo =
6567 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
6568 phba->sli4_hba.ue_mask_hi =
6569 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
6570 uerrlo_reg.word0 =
6571 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
6572 uerrhi_reg.word0 =
6573 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
6574 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
6575 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
6576 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6577 "1422 Unrecoverable Error "
6578 "Detected during POST "
6579 "uerr_lo_reg=0x%x, "
6580 "uerr_hi_reg=0x%x, "
6581 "ue_mask_lo_reg=0x%x, "
6582 "ue_mask_hi_reg=0x%x\n",
6583 uerrlo_reg.word0,
6584 uerrhi_reg.word0,
6585 phba->sli4_hba.ue_mask_lo,
6586 phba->sli4_hba.ue_mask_hi);
6587 port_error = -ENODEV;
6588 }
6589 break;
6590 case LPFC_SLI_INTF_IF_TYPE_2:
6591 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05006592 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
6593 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04006594 (bf_get(lpfc_sliport_status_err, &reg_data) &&
6595 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006596 phba->work_status[0] =
6597 readl(phba->sli4_hba.u.if_type2.
6598 ERR1regaddr);
6599 phba->work_status[1] =
6600 readl(phba->sli4_hba.u.if_type2.
6601 ERR2regaddr);
6602 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05006603 "2888 Unrecoverable port error "
6604 "following POST: port status reg "
6605 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05006606 "error 1=0x%x, error 2=0x%x\n",
6607 reg_data.word0,
6608 portsmphr_reg.word0,
6609 phba->work_status[0],
6610 phba->work_status[1]);
6611 port_error = -ENODEV;
6612 }
6613 break;
6614 case LPFC_SLI_INTF_IF_TYPE_1:
6615 default:
6616 break;
6617 }
James Smart28baac72010-02-12 14:42:03 -05006618 }
James Smartda0436e2009-05-22 14:51:39 -04006619 return port_error;
6620}
6621
6622/**
6623 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
6624 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05006625 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04006626 *
6627 * This routine is invoked to set up SLI4 BAR0 PCI config space register
6628 * memory map.
6629 **/
6630static void
James Smart2fcee4b2010-12-15 17:57:46 -05006631lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04006632{
James Smart2fcee4b2010-12-15 17:57:46 -05006633 switch (if_type) {
6634 case LPFC_SLI_INTF_IF_TYPE_0:
6635 phba->sli4_hba.u.if_type0.UERRLOregaddr =
6636 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
6637 phba->sli4_hba.u.if_type0.UERRHIregaddr =
6638 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
6639 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
6640 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
6641 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
6642 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
6643 phba->sli4_hba.SLIINTFregaddr =
6644 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6645 break;
6646 case LPFC_SLI_INTF_IF_TYPE_2:
6647 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006648 phba->sli4_hba.conf_regs_memmap_p +
6649 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006650 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006651 phba->sli4_hba.conf_regs_memmap_p +
6652 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006653 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006654 phba->sli4_hba.conf_regs_memmap_p +
6655 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006656 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006657 phba->sli4_hba.conf_regs_memmap_p +
6658 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006659 phba->sli4_hba.SLIINTFregaddr =
6660 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6661 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006662 phba->sli4_hba.conf_regs_memmap_p +
6663 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006664 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006665 phba->sli4_hba.conf_regs_memmap_p +
6666 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006667 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006668 phba->sli4_hba.conf_regs_memmap_p +
6669 LPFC_ULP0_WQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006670 phba->sli4_hba.EQCQDBregaddr =
6671 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
6672 phba->sli4_hba.MQDBregaddr =
6673 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
6674 phba->sli4_hba.BMBXregaddr =
6675 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
6676 break;
6677 case LPFC_SLI_INTF_IF_TYPE_1:
6678 default:
6679 dev_printk(KERN_ERR, &phba->pcidev->dev,
6680 "FATAL - unsupported SLI4 interface type - %d\n",
6681 if_type);
6682 break;
6683 }
James Smartda0436e2009-05-22 14:51:39 -04006684}
6685
6686/**
6687 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
6688 * @phba: pointer to lpfc hba data structure.
6689 *
6690 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
6691 * memory map.
6692 **/
6693static void
6694lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
6695{
James Smart2fcee4b2010-12-15 17:57:46 -05006696 phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
6697 LPFC_SLIPORT_IF0_SMPHR;
James Smartda0436e2009-05-22 14:51:39 -04006698 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006699 LPFC_HST_ISR0;
James Smartda0436e2009-05-22 14:51:39 -04006700 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006701 LPFC_HST_IMR0;
James Smartda0436e2009-05-22 14:51:39 -04006702 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006703 LPFC_HST_ISCR0;
James Smartda0436e2009-05-22 14:51:39 -04006704}
6705
6706/**
6707 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
6708 * @phba: pointer to lpfc hba data structure.
6709 * @vf: virtual function number
6710 *
6711 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
6712 * based on the given viftual function number, @vf.
6713 *
6714 * Return 0 if successful, otherwise -ENODEV.
6715 **/
6716static int
6717lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
6718{
6719 if (vf > LPFC_VIR_FUNC_MAX)
6720 return -ENODEV;
6721
6722 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05006723 vf * LPFC_VFR_PAGE_SIZE +
6724 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04006725 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05006726 vf * LPFC_VFR_PAGE_SIZE +
6727 LPFC_ULP0_WQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04006728 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6729 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
6730 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6731 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
6732 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6733 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
6734 return 0;
6735}
6736
6737/**
6738 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
6739 * @phba: pointer to lpfc hba data structure.
6740 *
6741 * This routine is invoked to create the bootstrap mailbox
6742 * region consistent with the SLI-4 interface spec. This
6743 * routine allocates all memory necessary to communicate
6744 * mailbox commands to the port and sets up all alignment
6745 * needs. No locks are expected to be held when calling
6746 * this routine.
6747 *
6748 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006749 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04006750 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04006751 **/
6752static int
6753lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
6754{
6755 uint32_t bmbx_size;
6756 struct lpfc_dmabuf *dmabuf;
6757 struct dma_address *dma_address;
6758 uint32_t pa_addr;
6759 uint64_t phys_addr;
6760
6761 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6762 if (!dmabuf)
6763 return -ENOMEM;
6764
6765 /*
6766 * The bootstrap mailbox region is comprised of 2 parts
6767 * plus an alignment restriction of 16 bytes.
6768 */
6769 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
Joe Perches1aee3832014-09-03 12:56:12 -04006770 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
6771 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04006772 if (!dmabuf->virt) {
6773 kfree(dmabuf);
6774 return -ENOMEM;
6775 }
James Smartda0436e2009-05-22 14:51:39 -04006776
6777 /*
6778 * Initialize the bootstrap mailbox pointers now so that the register
6779 * operations are simple later. The mailbox dma address is required
6780 * to be 16-byte aligned. Also align the virtual memory as each
6781 * maibox is copied into the bmbx mailbox region before issuing the
6782 * command to the port.
6783 */
6784 phba->sli4_hba.bmbx.dmabuf = dmabuf;
6785 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
6786
6787 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
6788 LPFC_ALIGN_16_BYTE);
6789 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
6790 LPFC_ALIGN_16_BYTE);
6791
6792 /*
6793 * Set the high and low physical addresses now. The SLI4 alignment
6794 * requirement is 16 bytes and the mailbox is posted to the port
6795 * as two 30-bit addresses. The other data is a bit marking whether
6796 * the 30-bit address is the high or low address.
6797 * Upcast bmbx aphys to 64bits so shift instruction compiles
6798 * clean on 32 bit machines.
6799 */
6800 dma_address = &phba->sli4_hba.bmbx.dma_address;
6801 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
6802 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
6803 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
6804 LPFC_BMBX_BIT1_ADDR_HI);
6805
6806 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
6807 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
6808 LPFC_BMBX_BIT1_ADDR_LO);
6809 return 0;
6810}
6811
6812/**
6813 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
6814 * @phba: pointer to lpfc hba data structure.
6815 *
6816 * This routine is invoked to teardown the bootstrap mailbox
6817 * region and release all host resources. This routine requires
6818 * the caller to ensure all mailbox commands recovered, no
6819 * additional mailbox comands are sent, and interrupts are disabled
6820 * before calling this routine.
6821 *
6822 **/
6823static void
6824lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
6825{
6826 dma_free_coherent(&phba->pcidev->dev,
6827 phba->sli4_hba.bmbx.bmbx_size,
6828 phba->sli4_hba.bmbx.dmabuf->virt,
6829 phba->sli4_hba.bmbx.dmabuf->phys);
6830
6831 kfree(phba->sli4_hba.bmbx.dmabuf);
6832 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
6833}
6834
6835/**
6836 * lpfc_sli4_read_config - Get the config parameters.
6837 * @phba: pointer to lpfc hba data structure.
6838 *
6839 * This routine is invoked to read the configuration parameters from the HBA.
6840 * The configuration parameters are used to set the base and maximum values
6841 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
6842 * allocation for the port.
6843 *
6844 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006845 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006846 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006847 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006848 **/
James Smartff78d8f2011-12-13 13:21:35 -05006849int
James Smartda0436e2009-05-22 14:51:39 -04006850lpfc_sli4_read_config(struct lpfc_hba *phba)
6851{
6852 LPFC_MBOXQ_t *pmb;
6853 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04006854 union lpfc_sli4_cfg_shdr *shdr;
6855 uint32_t shdr_status, shdr_add_status;
6856 struct lpfc_mbx_get_func_cfg *get_func_cfg;
6857 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04006858 char *pdesc_0;
James Smart8aa134a2012-08-14 14:25:29 -04006859 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04006860
6861 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6862 if (!pmb) {
6863 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6864 "2011 Unable to allocate memory for issuing "
6865 "SLI_CONFIG_SPECIAL mailbox command\n");
6866 return -ENOMEM;
6867 }
6868
6869 lpfc_read_config(phba, pmb);
6870
6871 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
6872 if (rc != MBX_SUCCESS) {
6873 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6874 "2012 Mailbox failed , mbxCmd x%x "
6875 "READ_CONFIG, mbxStatus x%x\n",
6876 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6877 bf_get(lpfc_mqe_status, &pmb->u.mqe));
6878 rc = -EIO;
6879 } else {
6880 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05006881 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
6882 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
6883 phba->sli4_hba.lnk_info.lnk_tp =
6884 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
6885 phba->sli4_hba.lnk_info.lnk_no =
6886 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
6887 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6888 "3081 lnk_type:%d, lnk_numb:%d\n",
6889 phba->sli4_hba.lnk_info.lnk_tp,
6890 phba->sli4_hba.lnk_info.lnk_no);
6891 } else
6892 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6893 "3082 Mailbox (x%x) returned ldv:x0\n",
6894 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart6d368e52011-05-24 11:44:12 -04006895 phba->sli4_hba.extents_in_use =
6896 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04006897 phba->sli4_hba.max_cfg_param.max_xri =
6898 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
6899 phba->sli4_hba.max_cfg_param.xri_base =
6900 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
6901 phba->sli4_hba.max_cfg_param.max_vpi =
6902 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
6903 phba->sli4_hba.max_cfg_param.vpi_base =
6904 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
6905 phba->sli4_hba.max_cfg_param.max_rpi =
6906 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
6907 phba->sli4_hba.max_cfg_param.rpi_base =
6908 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
6909 phba->sli4_hba.max_cfg_param.max_vfi =
6910 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
6911 phba->sli4_hba.max_cfg_param.vfi_base =
6912 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
6913 phba->sli4_hba.max_cfg_param.max_fcfi =
6914 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04006915 phba->sli4_hba.max_cfg_param.max_eq =
6916 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
6917 phba->sli4_hba.max_cfg_param.max_rq =
6918 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
6919 phba->sli4_hba.max_cfg_param.max_wq =
6920 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
6921 phba->sli4_hba.max_cfg_param.max_cq =
6922 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
6923 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
6924 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
6925 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
6926 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05006927 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
6928 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04006929 phba->max_vports = phba->max_vpi;
6930 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04006931 "2003 cfg params Extents? %d "
6932 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04006933 "VPI(B:%d M:%d) "
6934 "VFI(B:%d M:%d) "
6935 "RPI(B:%d M:%d) "
James Smart6d368e52011-05-24 11:44:12 -04006936 "FCFI(Count:%d)\n",
6937 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04006938 phba->sli4_hba.max_cfg_param.xri_base,
6939 phba->sli4_hba.max_cfg_param.max_xri,
6940 phba->sli4_hba.max_cfg_param.vpi_base,
6941 phba->sli4_hba.max_cfg_param.max_vpi,
6942 phba->sli4_hba.max_cfg_param.vfi_base,
6943 phba->sli4_hba.max_cfg_param.max_vfi,
6944 phba->sli4_hba.max_cfg_param.rpi_base,
6945 phba->sli4_hba.max_cfg_param.max_rpi,
James Smartda0436e2009-05-22 14:51:39 -04006946 phba->sli4_hba.max_cfg_param.max_fcfi);
6947 }
James Smart912e3ac2011-05-24 11:42:11 -04006948
6949 if (rc)
6950 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04006951
6952 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -04006953 length = phba->sli4_hba.max_cfg_param.max_xri -
6954 lpfc_sli4_get_els_iocb_cnt(phba);
6955 if (phba->cfg_hba_queue_depth > length) {
6956 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6957 "3361 HBA queue depth changed from %d to %d\n",
6958 phba->cfg_hba_queue_depth, length);
6959 phba->cfg_hba_queue_depth = length;
6960 }
James Smart912e3ac2011-05-24 11:42:11 -04006961
6962 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
6963 LPFC_SLI_INTF_IF_TYPE_2)
6964 goto read_cfg_out;
6965
6966 /* get the pf# and vf# for SLI4 if_type 2 port */
6967 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
6968 sizeof(struct lpfc_sli4_cfg_mhdr));
6969 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
6970 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
6971 length, LPFC_SLI4_MBX_EMBED);
6972
James Smart8aa134a2012-08-14 14:25:29 -04006973 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04006974 shdr = (union lpfc_sli4_cfg_shdr *)
6975 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
6976 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6977 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04006978 if (rc2 || shdr_status || shdr_add_status) {
James Smart912e3ac2011-05-24 11:42:11 -04006979 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6980 "3026 Mailbox failed , mbxCmd x%x "
6981 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
6982 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6983 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04006984 goto read_cfg_out;
6985 }
6986
6987 /* search for fc_fcoe resrouce descriptor */
6988 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
James Smart912e3ac2011-05-24 11:42:11 -04006989
James Smart8aa134a2012-08-14 14:25:29 -04006990 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
6991 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
6992 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
6993 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
6994 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
6995 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
6996 goto read_cfg_out;
6997
James Smart912e3ac2011-05-24 11:42:11 -04006998 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04006999 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04007000 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04007001 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04007002 phba->sli4_hba.iov.pf_number =
7003 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
7004 phba->sli4_hba.iov.vf_number =
7005 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
7006 break;
7007 }
7008 }
7009
7010 if (i < LPFC_RSRC_DESC_MAX_NUM)
7011 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7012 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
7013 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
7014 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04007015 else
James Smart912e3ac2011-05-24 11:42:11 -04007016 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7017 "3028 GET_FUNCTION_CONFIG: failed to find "
7018 "Resrouce Descriptor:x%x\n",
7019 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04007020
7021read_cfg_out:
7022 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04007023 return rc;
7024}
7025
7026/**
James Smart2fcee4b2010-12-15 17:57:46 -05007027 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04007028 * @phba: pointer to lpfc hba data structure.
7029 *
James Smart2fcee4b2010-12-15 17:57:46 -05007030 * This routine is invoked to setup the port-side endian order when
7031 * the port if_type is 0. This routine has no function for other
7032 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04007033 *
7034 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007035 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007036 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007037 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007038 **/
7039static int
7040lpfc_setup_endian_order(struct lpfc_hba *phba)
7041{
7042 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05007043 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04007044 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
7045 HOST_ENDIAN_HIGH_WORD1};
7046
James Smart2fcee4b2010-12-15 17:57:46 -05007047 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7048 switch (if_type) {
7049 case LPFC_SLI_INTF_IF_TYPE_0:
7050 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7051 GFP_KERNEL);
7052 if (!mboxq) {
7053 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7054 "0492 Unable to allocate memory for "
7055 "issuing SLI_CONFIG_SPECIAL mailbox "
7056 "command\n");
7057 return -ENOMEM;
7058 }
James Smartda0436e2009-05-22 14:51:39 -04007059
James Smart2fcee4b2010-12-15 17:57:46 -05007060 /*
7061 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
7062 * two words to contain special data values and no other data.
7063 */
7064 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
7065 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
7066 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7067 if (rc != MBX_SUCCESS) {
7068 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7069 "0493 SLI_CONFIG_SPECIAL mailbox "
7070 "failed with status x%x\n",
7071 rc);
7072 rc = -EIO;
7073 }
7074 mempool_free(mboxq, phba->mbox_mem_pool);
7075 break;
7076 case LPFC_SLI_INTF_IF_TYPE_2:
7077 case LPFC_SLI_INTF_IF_TYPE_1:
7078 default:
7079 break;
James Smartda0436e2009-05-22 14:51:39 -04007080 }
James Smartda0436e2009-05-22 14:51:39 -04007081 return rc;
7082}
7083
7084/**
James Smart5350d872011-10-10 21:33:49 -04007085 * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts
James Smartda0436e2009-05-22 14:51:39 -04007086 * @phba: pointer to lpfc hba data structure.
7087 *
James Smart5350d872011-10-10 21:33:49 -04007088 * This routine is invoked to check the user settable queue counts for EQs and
7089 * CQs. after this routine is called the counts will be set to valid values that
7090 * adhere to the constraints of the system's interrupt vectors and the port's
7091 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04007092 *
7093 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007094 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007095 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007096 **/
7097static int
James Smart5350d872011-10-10 21:33:49 -04007098lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04007099{
James Smart67d12732012-08-03 12:36:13 -04007100 int cfg_fcp_io_channel;
James Smart90695ee2012-08-14 14:25:36 -04007101 uint32_t cpu;
7102 uint32_t i = 0;
James Smart1ba981f2014-02-20 09:56:45 -05007103 int fof_vectors = phba->cfg_fof ? 1 : 0;
James Smartda0436e2009-05-22 14:51:39 -04007104
7105 /*
James Smart67d12732012-08-03 12:36:13 -04007106 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04007107 * device parameters
7108 */
7109
James Smart67d12732012-08-03 12:36:13 -04007110 /* Sanity check on HBA EQ parameters */
7111 cfg_fcp_io_channel = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04007112
James Smart7bb03bb2013-04-17 20:19:16 -04007113 /* It doesn't make sense to have more io channels then online CPUs */
7114 for_each_present_cpu(cpu) {
7115 if (cpu_online(cpu))
7116 i++;
James Smart90695ee2012-08-14 14:25:36 -04007117 }
James Smart7bb03bb2013-04-17 20:19:16 -04007118 phba->sli4_hba.num_online_cpu = i;
James Smartb246de12013-05-31 17:03:07 -04007119 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
James Smart76fd07a2014-02-20 09:57:18 -05007120 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04007121
James Smart90695ee2012-08-14 14:25:36 -04007122 if (i < cfg_fcp_io_channel) {
James Smart82c3e9b2012-09-29 11:29:50 -04007123 lpfc_printf_log(phba,
7124 KERN_ERR, LOG_INIT,
James Smart90695ee2012-08-14 14:25:36 -04007125 "3188 Reducing IO channels to match number of "
James Smart7bb03bb2013-04-17 20:19:16 -04007126 "online CPUs: from %d to %d\n",
7127 cfg_fcp_io_channel, i);
James Smart90695ee2012-08-14 14:25:36 -04007128 cfg_fcp_io_channel = i;
7129 }
7130
James Smart1ba981f2014-02-20 09:56:45 -05007131 if (cfg_fcp_io_channel + fof_vectors >
James Smart67d12732012-08-03 12:36:13 -04007132 phba->sli4_hba.max_cfg_param.max_eq) {
James Smart82c3e9b2012-09-29 11:29:50 -04007133 if (phba->sli4_hba.max_cfg_param.max_eq <
7134 LPFC_FCP_IO_CHAN_MIN) {
James Smartda0436e2009-05-22 14:51:39 -04007135 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7136 "2574 Not enough EQs (%d) from the "
7137 "pci function for supporting FCP "
7138 "EQs (%d)\n",
7139 phba->sli4_hba.max_cfg_param.max_eq,
James Smart67d12732012-08-03 12:36:13 -04007140 phba->cfg_fcp_io_channel);
James Smartda0436e2009-05-22 14:51:39 -04007141 goto out_error;
7142 }
James Smart82c3e9b2012-09-29 11:29:50 -04007143 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7144 "2575 Reducing IO channels to match number of "
7145 "available EQs: from %d to %d\n",
7146 cfg_fcp_io_channel,
7147 phba->sli4_hba.max_cfg_param.max_eq);
James Smart1ba981f2014-02-20 09:56:45 -05007148 cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq -
7149 fof_vectors;
James Smartda0436e2009-05-22 14:51:39 -04007150 }
James Smart67d12732012-08-03 12:36:13 -04007151
James Smartda0436e2009-05-22 14:51:39 -04007152 /* The actual number of FCP event queues adopted */
James Smart67d12732012-08-03 12:36:13 -04007153 phba->cfg_fcp_io_channel = cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04007154
James Smartda0436e2009-05-22 14:51:39 -04007155 /* Get EQ depth from module parameter, fake the default for now */
7156 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
7157 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
7158
James Smart5350d872011-10-10 21:33:49 -04007159 /* Get CQ depth from module parameter, fake the default for now */
7160 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
7161 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
7162
7163 return 0;
7164out_error:
7165 return -ENOMEM;
7166}
7167
7168/**
7169 * lpfc_sli4_queue_create - Create all the SLI4 queues
7170 * @phba: pointer to lpfc hba data structure.
7171 *
7172 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
7173 * operation. For each SLI4 queue type, the parameters such as queue entry
7174 * count (queue depth) shall be taken from the module parameter. For now,
7175 * we just use some constant number as place holder.
7176 *
7177 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07007178 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04007179 * -ENOMEM - No availble memory
7180 * -EIO - The mailbox failed to complete successfully.
7181 **/
7182int
7183lpfc_sli4_queue_create(struct lpfc_hba *phba)
7184{
7185 struct lpfc_queue *qdesc;
James Smart67d12732012-08-03 12:36:13 -04007186 int idx;
James Smart5350d872011-10-10 21:33:49 -04007187
7188 /*
James Smart67d12732012-08-03 12:36:13 -04007189 * Create HBA Record arrays.
James Smart5350d872011-10-10 21:33:49 -04007190 */
James Smart67d12732012-08-03 12:36:13 -04007191 if (!phba->cfg_fcp_io_channel)
7192 return -ERANGE;
James Smart5350d872011-10-10 21:33:49 -04007193
James Smart67d12732012-08-03 12:36:13 -04007194 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
7195 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
7196 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
7197 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
7198 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
7199 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
7200
7201 phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) *
7202 phba->cfg_fcp_io_channel), GFP_KERNEL);
7203 if (!phba->sli4_hba.hba_eq) {
James Smartda0436e2009-05-22 14:51:39 -04007204 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007205 "2576 Failed allocate memory for "
7206 "fast-path EQ record array\n");
James Smartda0436e2009-05-22 14:51:39 -04007207 goto out_error;
7208 }
James Smart67d12732012-08-03 12:36:13 -04007209
7210 phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
7211 phba->cfg_fcp_io_channel), GFP_KERNEL);
7212 if (!phba->sli4_hba.fcp_cq) {
7213 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7214 "2577 Failed allocate memory for fast-path "
7215 "CQ record array\n");
7216 goto out_error;
7217 }
7218
7219 phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
7220 phba->cfg_fcp_io_channel), GFP_KERNEL);
7221 if (!phba->sli4_hba.fcp_wq) {
7222 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7223 "2578 Failed allocate memory for fast-path "
7224 "WQ record array\n");
7225 goto out_error;
7226 }
James Smartda0436e2009-05-22 14:51:39 -04007227
James Smart5350d872011-10-10 21:33:49 -04007228 /*
James Smart67d12732012-08-03 12:36:13 -04007229 * Since the first EQ can have multiple CQs associated with it,
7230 * this array is used to quickly see if we have a FCP fast-path
7231 * CQ match.
James Smart5350d872011-10-10 21:33:49 -04007232 */
James Smart67d12732012-08-03 12:36:13 -04007233 phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) *
7234 phba->cfg_fcp_io_channel), GFP_KERNEL);
7235 if (!phba->sli4_hba.fcp_cq_map) {
7236 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7237 "2545 Failed allocate memory for fast-path "
7238 "CQ map\n");
7239 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007240 }
James Smart67d12732012-08-03 12:36:13 -04007241
7242 /*
7243 * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies
7244 * how many EQs to create.
7245 */
7246 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7247
7248 /* Create EQs */
James Smartda0436e2009-05-22 14:51:39 -04007249 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
7250 phba->sli4_hba.eq_ecount);
7251 if (!qdesc) {
7252 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007253 "0497 Failed allocate EQ (%d)\n", idx);
7254 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007255 }
James Smart67d12732012-08-03 12:36:13 -04007256 phba->sli4_hba.hba_eq[idx] = qdesc;
7257
7258 /* Create Fast Path FCP CQs */
7259 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7260 phba->sli4_hba.cq_ecount);
7261 if (!qdesc) {
7262 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7263 "0499 Failed allocate fast-path FCP "
7264 "CQ (%d)\n", idx);
7265 goto out_error;
7266 }
7267 phba->sli4_hba.fcp_cq[idx] = qdesc;
7268
7269 /* Create Fast Path FCP WQs */
James Smartb5c53952016-03-31 14:12:30 -07007270 if (phba->fcp_embed_io) {
7271 qdesc = lpfc_sli4_queue_alloc(phba,
7272 LPFC_WQE128_SIZE,
7273 LPFC_WQE128_DEF_COUNT);
7274 } else {
7275 qdesc = lpfc_sli4_queue_alloc(phba,
7276 phba->sli4_hba.wq_esize,
7277 phba->sli4_hba.wq_ecount);
7278 }
James Smart67d12732012-08-03 12:36:13 -04007279 if (!qdesc) {
7280 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7281 "0503 Failed allocate fast-path FCP "
7282 "WQ (%d)\n", idx);
7283 goto out_error;
7284 }
7285 phba->sli4_hba.fcp_wq[idx] = qdesc;
James Smartda0436e2009-05-22 14:51:39 -04007286 }
7287
James Smart67d12732012-08-03 12:36:13 -04007288
James Smartda0436e2009-05-22 14:51:39 -04007289 /*
James Smart67d12732012-08-03 12:36:13 -04007290 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04007291 */
7292
James Smartda0436e2009-05-22 14:51:39 -04007293 /* Create slow-path Mailbox Command Complete Queue */
7294 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7295 phba->sli4_hba.cq_ecount);
7296 if (!qdesc) {
7297 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7298 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04007299 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007300 }
7301 phba->sli4_hba.mbx_cq = qdesc;
7302
7303 /* Create slow-path ELS Complete Queue */
7304 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7305 phba->sli4_hba.cq_ecount);
7306 if (!qdesc) {
7307 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7308 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -04007309 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007310 }
7311 phba->sli4_hba.els_cq = qdesc;
7312
James Smartda0436e2009-05-22 14:51:39 -04007313
James Smart5350d872011-10-10 21:33:49 -04007314 /*
James Smart67d12732012-08-03 12:36:13 -04007315 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04007316 */
James Smartda0436e2009-05-22 14:51:39 -04007317
7318 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04007319
7320 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
7321 phba->sli4_hba.mq_ecount);
7322 if (!qdesc) {
7323 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7324 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04007325 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007326 }
7327 phba->sli4_hba.mbx_wq = qdesc;
7328
7329 /*
James Smart67d12732012-08-03 12:36:13 -04007330 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04007331 */
James Smartda0436e2009-05-22 14:51:39 -04007332
7333 /* Create slow-path ELS Work Queue */
7334 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
7335 phba->sli4_hba.wq_ecount);
7336 if (!qdesc) {
7337 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7338 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04007339 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007340 }
7341 phba->sli4_hba.els_wq = qdesc;
7342
James Smartda0436e2009-05-22 14:51:39 -04007343 /*
7344 * Create Receive Queue (RQ)
7345 */
James Smartda0436e2009-05-22 14:51:39 -04007346
7347 /* Create Receive Queue for header */
7348 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
7349 phba->sli4_hba.rq_ecount);
7350 if (!qdesc) {
7351 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7352 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04007353 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007354 }
7355 phba->sli4_hba.hdr_rq = qdesc;
7356
7357 /* Create Receive Queue for data */
7358 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
7359 phba->sli4_hba.rq_ecount);
7360 if (!qdesc) {
7361 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7362 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04007363 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007364 }
7365 phba->sli4_hba.dat_rq = qdesc;
7366
James Smart1ba981f2014-02-20 09:56:45 -05007367 /* Create the Queues needed for Flash Optimized Fabric operations */
7368 if (phba->cfg_fof)
7369 lpfc_fof_queue_create(phba);
James Smartda0436e2009-05-22 14:51:39 -04007370 return 0;
7371
James Smartda0436e2009-05-22 14:51:39 -04007372out_error:
James Smart67d12732012-08-03 12:36:13 -04007373 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04007374 return -ENOMEM;
7375}
7376
7377/**
7378 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
7379 * @phba: pointer to lpfc hba data structure.
7380 *
7381 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
7382 * operation.
7383 *
7384 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007385 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007386 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007387 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007388 **/
James Smart5350d872011-10-10 21:33:49 -04007389void
James Smartda0436e2009-05-22 14:51:39 -04007390lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
7391{
James Smart67d12732012-08-03 12:36:13 -04007392 int idx;
7393
James Smart1ba981f2014-02-20 09:56:45 -05007394 if (phba->cfg_fof)
7395 lpfc_fof_queue_destroy(phba);
7396
James Smart67d12732012-08-03 12:36:13 -04007397 if (phba->sli4_hba.hba_eq != NULL) {
7398 /* Release HBA event queue */
7399 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7400 if (phba->sli4_hba.hba_eq[idx] != NULL) {
7401 lpfc_sli4_queue_free(
7402 phba->sli4_hba.hba_eq[idx]);
7403 phba->sli4_hba.hba_eq[idx] = NULL;
7404 }
7405 }
7406 kfree(phba->sli4_hba.hba_eq);
7407 phba->sli4_hba.hba_eq = NULL;
7408 }
7409
7410 if (phba->sli4_hba.fcp_cq != NULL) {
7411 /* Release FCP completion queue */
7412 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7413 if (phba->sli4_hba.fcp_cq[idx] != NULL) {
7414 lpfc_sli4_queue_free(
7415 phba->sli4_hba.fcp_cq[idx]);
7416 phba->sli4_hba.fcp_cq[idx] = NULL;
7417 }
7418 }
7419 kfree(phba->sli4_hba.fcp_cq);
7420 phba->sli4_hba.fcp_cq = NULL;
7421 }
7422
7423 if (phba->sli4_hba.fcp_wq != NULL) {
7424 /* Release FCP work queue */
7425 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7426 if (phba->sli4_hba.fcp_wq[idx] != NULL) {
7427 lpfc_sli4_queue_free(
7428 phba->sli4_hba.fcp_wq[idx]);
7429 phba->sli4_hba.fcp_wq[idx] = NULL;
7430 }
7431 }
7432 kfree(phba->sli4_hba.fcp_wq);
7433 phba->sli4_hba.fcp_wq = NULL;
7434 }
7435
7436 /* Release FCP CQ mapping array */
7437 if (phba->sli4_hba.fcp_cq_map != NULL) {
7438 kfree(phba->sli4_hba.fcp_cq_map);
7439 phba->sli4_hba.fcp_cq_map = NULL;
7440 }
James Smartda0436e2009-05-22 14:51:39 -04007441
7442 /* Release mailbox command work queue */
James Smart67d12732012-08-03 12:36:13 -04007443 if (phba->sli4_hba.mbx_wq != NULL) {
7444 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
7445 phba->sli4_hba.mbx_wq = NULL;
7446 }
James Smartda0436e2009-05-22 14:51:39 -04007447
7448 /* Release ELS work queue */
James Smart67d12732012-08-03 12:36:13 -04007449 if (phba->sli4_hba.els_wq != NULL) {
7450 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
7451 phba->sli4_hba.els_wq = NULL;
7452 }
James Smartda0436e2009-05-22 14:51:39 -04007453
7454 /* Release unsolicited receive queue */
James Smart67d12732012-08-03 12:36:13 -04007455 if (phba->sli4_hba.hdr_rq != NULL) {
7456 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
7457 phba->sli4_hba.hdr_rq = NULL;
7458 }
7459 if (phba->sli4_hba.dat_rq != NULL) {
7460 lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
7461 phba->sli4_hba.dat_rq = NULL;
7462 }
James Smartda0436e2009-05-22 14:51:39 -04007463
James Smartda0436e2009-05-22 14:51:39 -04007464 /* Release ELS complete queue */
James Smart67d12732012-08-03 12:36:13 -04007465 if (phba->sli4_hba.els_cq != NULL) {
7466 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
7467 phba->sli4_hba.els_cq = NULL;
7468 }
James Smartda0436e2009-05-22 14:51:39 -04007469
7470 /* Release mailbox command complete queue */
James Smart67d12732012-08-03 12:36:13 -04007471 if (phba->sli4_hba.mbx_cq != NULL) {
7472 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
7473 phba->sli4_hba.mbx_cq = NULL;
7474 }
James Smartda0436e2009-05-22 14:51:39 -04007475
7476 return;
7477}
7478
7479/**
7480 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
7481 * @phba: pointer to lpfc hba data structure.
7482 *
7483 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
7484 * operation.
7485 *
7486 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007487 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007488 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007489 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007490 **/
7491int
7492lpfc_sli4_queue_setup(struct lpfc_hba *phba)
7493{
James Smart2a76a282012-08-03 12:35:54 -04007494 struct lpfc_sli *psli = &phba->sli;
7495 struct lpfc_sli_ring *pring;
James Smartda0436e2009-05-22 14:51:39 -04007496 int rc = -ENOMEM;
7497 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
7498 int fcp_cq_index = 0;
James Smart962bc512013-01-03 15:44:00 -05007499 uint32_t shdr_status, shdr_add_status;
7500 union lpfc_sli4_cfg_shdr *shdr;
7501 LPFC_MBOXQ_t *mboxq;
7502 uint32_t length;
7503
7504 /* Check for dual-ULP support */
7505 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7506 if (!mboxq) {
7507 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7508 "3249 Unable to allocate memory for "
7509 "QUERY_FW_CFG mailbox command\n");
7510 return -ENOMEM;
7511 }
7512 length = (sizeof(struct lpfc_mbx_query_fw_config) -
7513 sizeof(struct lpfc_sli4_cfg_mhdr));
7514 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
7515 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
7516 length, LPFC_SLI4_MBX_EMBED);
7517
7518 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7519
7520 shdr = (union lpfc_sli4_cfg_shdr *)
7521 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
7522 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7523 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7524 if (shdr_status || shdr_add_status || rc) {
7525 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7526 "3250 QUERY_FW_CFG mailbox failed with status "
7527 "x%x add_status x%x, mbx status x%x\n",
7528 shdr_status, shdr_add_status, rc);
7529 if (rc != MBX_TIMEOUT)
7530 mempool_free(mboxq, phba->mbox_mem_pool);
7531 rc = -ENXIO;
7532 goto out_error;
7533 }
7534
7535 phba->sli4_hba.fw_func_mode =
7536 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
7537 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
7538 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
James Smart8b017a32015-05-21 13:55:18 -04007539 phba->sli4_hba.physical_port =
7540 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
James Smart962bc512013-01-03 15:44:00 -05007541 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7542 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
7543 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
7544 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
7545
7546 if (rc != MBX_TIMEOUT)
7547 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04007548
7549 /*
James Smart67d12732012-08-03 12:36:13 -04007550 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04007551 */
7552
James Smart67d12732012-08-03 12:36:13 -04007553 /* Set up HBA event queue */
7554 if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) {
James Smart2e90f4b2011-12-13 13:22:37 -05007555 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7556 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007557 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007558 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05007559 }
James Smart67d12732012-08-03 12:36:13 -04007560 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
7561 if (!phba->sli4_hba.hba_eq[fcp_eqidx]) {
James Smartda0436e2009-05-22 14:51:39 -04007562 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7563 "0522 Fast-path EQ (%d) not "
7564 "allocated\n", fcp_eqidx);
James Smart1b511972011-12-13 13:23:09 -05007565 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007566 goto out_destroy_hba_eq;
James Smartda0436e2009-05-22 14:51:39 -04007567 }
James Smart67d12732012-08-03 12:36:13 -04007568 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx],
James Smartbf8dae82012-08-03 12:36:24 -04007569 (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel));
James Smartda0436e2009-05-22 14:51:39 -04007570 if (rc) {
7571 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7572 "0523 Failed setup of fast-path EQ "
James Smarta2fc4aef2014-09-03 12:57:55 -04007573 "(%d), rc = 0x%x\n", fcp_eqidx,
7574 (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007575 goto out_destroy_hba_eq;
James Smartda0436e2009-05-22 14:51:39 -04007576 }
7577 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007578 "2584 HBA EQ setup: "
James Smartda0436e2009-05-22 14:51:39 -04007579 "queue[%d]-id=%d\n", fcp_eqidx,
James Smart67d12732012-08-03 12:36:13 -04007580 phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007581 }
7582
James Smart67d12732012-08-03 12:36:13 -04007583 /* Set up fast-path FCP Response Complete Queue */
7584 if (!phba->sli4_hba.fcp_cq) {
7585 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7586 "3148 Fast-path FCP CQ array not "
7587 "allocated\n");
7588 rc = -ENOMEM;
7589 goto out_destroy_hba_eq;
7590 }
7591
7592 for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) {
7593 if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
7594 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7595 "0526 Fast-path FCP CQ (%d) not "
7596 "allocated\n", fcp_cqidx);
7597 rc = -ENOMEM;
7598 goto out_destroy_fcp_cq;
7599 }
7600 rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
7601 phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP);
7602 if (rc) {
7603 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7604 "0527 Failed setup of fast-path FCP "
James Smarta2fc4aef2014-09-03 12:57:55 -04007605 "CQ (%d), rc = 0x%x\n", fcp_cqidx,
7606 (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007607 goto out_destroy_fcp_cq;
7608 }
7609
7610 /* Setup fcp_cq_map for fast lookup */
7611 phba->sli4_hba.fcp_cq_map[fcp_cqidx] =
7612 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id;
7613
7614 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7615 "2588 FCP CQ setup: cq[%d]-id=%d, "
7616 "parent seq[%d]-id=%d\n",
7617 fcp_cqidx,
7618 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
7619 fcp_cqidx,
7620 phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id);
7621 }
7622
7623 /* Set up fast-path FCP Work Queue */
7624 if (!phba->sli4_hba.fcp_wq) {
7625 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7626 "3149 Fast-path FCP WQ array not "
7627 "allocated\n");
7628 rc = -ENOMEM;
7629 goto out_destroy_fcp_cq;
7630 }
7631
7632 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) {
7633 if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
7634 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7635 "0534 Fast-path FCP WQ (%d) not "
7636 "allocated\n", fcp_wqidx);
7637 rc = -ENOMEM;
7638 goto out_destroy_fcp_wq;
7639 }
7640 rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
7641 phba->sli4_hba.fcp_cq[fcp_wqidx],
7642 LPFC_FCP);
7643 if (rc) {
7644 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7645 "0535 Failed setup of fast-path FCP "
James Smarta2fc4aef2014-09-03 12:57:55 -04007646 "WQ (%d), rc = 0x%x\n", fcp_wqidx,
7647 (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007648 goto out_destroy_fcp_wq;
7649 }
7650
7651 /* Bind this WQ to the next FCP ring */
7652 pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx];
7653 pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx];
7654 phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring;
7655
7656 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7657 "2591 FCP WQ setup: wq[%d]-id=%d, "
7658 "parent cq[%d]-id=%d\n",
7659 fcp_wqidx,
7660 phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
7661 fcp_cq_index,
7662 phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id);
7663 }
James Smartda0436e2009-05-22 14:51:39 -04007664 /*
7665 * Set up Complete Queues (CQs)
7666 */
7667
7668 /* Set up slow-path MBOX Complete Queue as the first CQ */
7669 if (!phba->sli4_hba.mbx_cq) {
7670 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7671 "0528 Mailbox CQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007672 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007673 goto out_destroy_fcp_wq;
James Smartda0436e2009-05-22 14:51:39 -04007674 }
James Smart67d12732012-08-03 12:36:13 -04007675 rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq,
7676 phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04007677 if (rc) {
7678 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7679 "0529 Failed setup of slow-path mailbox CQ: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007680 "rc = 0x%x\n", (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007681 goto out_destroy_fcp_wq;
James Smartda0436e2009-05-22 14:51:39 -04007682 }
7683 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7684 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
7685 phba->sli4_hba.mbx_cq->queue_id,
James Smart67d12732012-08-03 12:36:13 -04007686 phba->sli4_hba.hba_eq[0]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007687
7688 /* Set up slow-path ELS Complete Queue */
7689 if (!phba->sli4_hba.els_cq) {
7690 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7691 "0530 ELS CQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007692 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007693 goto out_destroy_mbx_cq;
7694 }
James Smart67d12732012-08-03 12:36:13 -04007695 rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq,
7696 phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04007697 if (rc) {
7698 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7699 "0531 Failed setup of slow-path ELS CQ: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007700 "rc = 0x%x\n", (uint32_t)rc);
James Smartda0436e2009-05-22 14:51:39 -04007701 goto out_destroy_mbx_cq;
7702 }
7703 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7704 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
7705 phba->sli4_hba.els_cq->queue_id,
James Smart67d12732012-08-03 12:36:13 -04007706 phba->sli4_hba.hba_eq[0]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007707
7708 /*
7709 * Set up all the Work Queues (WQs)
7710 */
7711
7712 /* Set up Mailbox Command Queue */
7713 if (!phba->sli4_hba.mbx_wq) {
7714 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7715 "0538 Slow-path MQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007716 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007717 goto out_destroy_els_cq;
James Smartda0436e2009-05-22 14:51:39 -04007718 }
7719 rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
7720 phba->sli4_hba.mbx_cq, LPFC_MBOX);
7721 if (rc) {
7722 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7723 "0539 Failed setup of slow-path MQ: "
7724 "rc = 0x%x\n", rc);
James Smart67d12732012-08-03 12:36:13 -04007725 goto out_destroy_els_cq;
James Smartda0436e2009-05-22 14:51:39 -04007726 }
7727 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7728 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
7729 phba->sli4_hba.mbx_wq->queue_id,
7730 phba->sli4_hba.mbx_cq->queue_id);
7731
7732 /* Set up slow-path ELS Work Queue */
7733 if (!phba->sli4_hba.els_wq) {
7734 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7735 "0536 Slow-path ELS WQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007736 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007737 goto out_destroy_mbx_wq;
7738 }
7739 rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
7740 phba->sli4_hba.els_cq, LPFC_ELS);
7741 if (rc) {
7742 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7743 "0537 Failed setup of slow-path ELS WQ: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007744 "rc = 0x%x\n", (uint32_t)rc);
James Smartda0436e2009-05-22 14:51:39 -04007745 goto out_destroy_mbx_wq;
7746 }
James Smart2a76a282012-08-03 12:35:54 -04007747
7748 /* Bind this WQ to the ELS ring */
7749 pring = &psli->ring[LPFC_ELS_RING];
7750 pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq;
7751 phba->sli4_hba.els_cq->pring = pring;
7752
James Smartda0436e2009-05-22 14:51:39 -04007753 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7754 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
7755 phba->sli4_hba.els_wq->queue_id,
7756 phba->sli4_hba.els_cq->queue_id);
7757
James Smartda0436e2009-05-22 14:51:39 -04007758 /*
7759 * Create Receive Queue (RQ)
7760 */
7761 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
7762 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7763 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007764 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007765 goto out_destroy_els_wq;
James Smartda0436e2009-05-22 14:51:39 -04007766 }
James Smart73d91e52011-10-10 21:32:10 -04007767
7768 lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
7769 lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
7770
James Smartda0436e2009-05-22 14:51:39 -04007771 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04007772 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04007773 if (rc) {
7774 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7775 "0541 Failed setup of Receive Queue: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007776 "rc = 0x%x\n", (uint32_t)rc);
James Smartda0436e2009-05-22 14:51:39 -04007777 goto out_destroy_fcp_wq;
7778 }
James Smart73d91e52011-10-10 21:32:10 -04007779
James Smartda0436e2009-05-22 14:51:39 -04007780 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7781 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
7782 "parent cq-id=%d\n",
7783 phba->sli4_hba.hdr_rq->queue_id,
7784 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04007785 phba->sli4_hba.els_cq->queue_id);
James Smart1ba981f2014-02-20 09:56:45 -05007786
7787 if (phba->cfg_fof) {
7788 rc = lpfc_fof_queue_setup(phba);
7789 if (rc) {
7790 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7791 "0549 Failed setup of FOF Queues: "
7792 "rc = 0x%x\n", rc);
7793 goto out_destroy_els_rq;
7794 }
7795 }
James Smart2c9c5a02015-04-07 15:07:15 -04007796
7797 /*
7798 * Configure EQ delay multipier for interrupt coalescing using
7799 * MODIFY_EQ_DELAY for all EQs created, LPFC_MAX_EQ_DELAY at a time.
7800 */
7801 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel;
7802 fcp_eqidx += LPFC_MAX_EQ_DELAY)
7803 lpfc_modify_fcp_eq_delay(phba, fcp_eqidx);
James Smartda0436e2009-05-22 14:51:39 -04007804 return 0;
7805
James Smart1ba981f2014-02-20 09:56:45 -05007806out_destroy_els_rq:
7807 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
James Smart2e90f4b2011-12-13 13:22:37 -05007808out_destroy_els_wq:
James Smartda0436e2009-05-22 14:51:39 -04007809 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7810out_destroy_mbx_wq:
7811 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
James Smart2e90f4b2011-12-13 13:22:37 -05007812out_destroy_els_cq:
James Smartda0436e2009-05-22 14:51:39 -04007813 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
7814out_destroy_mbx_cq:
7815 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
James Smart67d12732012-08-03 12:36:13 -04007816out_destroy_fcp_wq:
7817 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
7818 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
7819out_destroy_fcp_cq:
7820 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
7821 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
7822out_destroy_hba_eq:
James Smartda0436e2009-05-22 14:51:39 -04007823 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
James Smart67d12732012-08-03 12:36:13 -04007824 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]);
James Smartda0436e2009-05-22 14:51:39 -04007825out_error:
7826 return rc;
7827}
7828
7829/**
7830 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
7831 * @phba: pointer to lpfc hba data structure.
7832 *
7833 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
7834 * operation.
7835 *
7836 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007837 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007838 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007839 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007840 **/
7841void
7842lpfc_sli4_queue_unset(struct lpfc_hba *phba)
7843{
7844 int fcp_qidx;
7845
James Smart1ba981f2014-02-20 09:56:45 -05007846 /* Unset the queues created for Flash Optimized Fabric operations */
7847 if (phba->cfg_fof)
7848 lpfc_fof_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04007849 /* Unset mailbox command work queue */
7850 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
7851 /* Unset ELS work queue */
7852 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7853 /* Unset unsolicited receive queue */
7854 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
7855 /* Unset FCP work queue */
James Smart67d12732012-08-03 12:36:13 -04007856 if (phba->sli4_hba.fcp_wq) {
7857 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
7858 fcp_qidx++)
7859 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
7860 }
James Smartda0436e2009-05-22 14:51:39 -04007861 /* Unset mailbox command complete queue */
7862 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
7863 /* Unset ELS complete queue */
7864 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
James Smartda0436e2009-05-22 14:51:39 -04007865 /* Unset FCP response complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05007866 if (phba->sli4_hba.fcp_cq) {
James Smart67d12732012-08-03 12:36:13 -04007867 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
7868 fcp_qidx++)
James Smart2e90f4b2011-12-13 13:22:37 -05007869 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
James Smart2e90f4b2011-12-13 13:22:37 -05007870 }
James Smartda0436e2009-05-22 14:51:39 -04007871 /* Unset fast-path event queue */
James Smart67d12732012-08-03 12:36:13 -04007872 if (phba->sli4_hba.hba_eq) {
7873 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
James Smart2e90f4b2011-12-13 13:22:37 -05007874 fcp_qidx++)
James Smart67d12732012-08-03 12:36:13 -04007875 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_qidx]);
James Smart2e90f4b2011-12-13 13:22:37 -05007876 }
James Smartda0436e2009-05-22 14:51:39 -04007877}
7878
7879/**
7880 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
7881 * @phba: pointer to lpfc hba data structure.
7882 *
7883 * This routine is invoked to allocate and set up a pool of completion queue
7884 * events. The body of the completion queue event is a completion queue entry
7885 * CQE. For now, this pool is used for the interrupt service routine to queue
7886 * the following HBA completion queue events for the worker thread to process:
7887 * - Mailbox asynchronous events
7888 * - Receive queue completion unsolicited events
7889 * Later, this can be used for all the slow-path events.
7890 *
7891 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007892 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007893 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007894 **/
7895static int
7896lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
7897{
7898 struct lpfc_cq_event *cq_event;
7899 int i;
7900
7901 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
7902 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
7903 if (!cq_event)
7904 goto out_pool_create_fail;
7905 list_add_tail(&cq_event->list,
7906 &phba->sli4_hba.sp_cqe_event_pool);
7907 }
7908 return 0;
7909
7910out_pool_create_fail:
7911 lpfc_sli4_cq_event_pool_destroy(phba);
7912 return -ENOMEM;
7913}
7914
7915/**
7916 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
7917 * @phba: pointer to lpfc hba data structure.
7918 *
7919 * This routine is invoked to free the pool of completion queue events at
7920 * driver unload time. Note that, it is the responsibility of the driver
7921 * cleanup routine to free all the outstanding completion-queue events
7922 * allocated from this pool back into the pool before invoking this routine
7923 * to destroy the pool.
7924 **/
7925static void
7926lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
7927{
7928 struct lpfc_cq_event *cq_event, *next_cq_event;
7929
7930 list_for_each_entry_safe(cq_event, next_cq_event,
7931 &phba->sli4_hba.sp_cqe_event_pool, list) {
7932 list_del(&cq_event->list);
7933 kfree(cq_event);
7934 }
7935}
7936
7937/**
7938 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7939 * @phba: pointer to lpfc hba data structure.
7940 *
7941 * This routine is the lock free version of the API invoked to allocate a
7942 * completion-queue event from the free pool.
7943 *
7944 * Return: Pointer to the newly allocated completion-queue event if successful
7945 * NULL otherwise.
7946 **/
7947struct lpfc_cq_event *
7948__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
7949{
7950 struct lpfc_cq_event *cq_event = NULL;
7951
7952 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
7953 struct lpfc_cq_event, list);
7954 return cq_event;
7955}
7956
7957/**
7958 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7959 * @phba: pointer to lpfc hba data structure.
7960 *
7961 * This routine is the lock version of the API invoked to allocate a
7962 * completion-queue event from the free pool.
7963 *
7964 * Return: Pointer to the newly allocated completion-queue event if successful
7965 * NULL otherwise.
7966 **/
7967struct lpfc_cq_event *
7968lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
7969{
7970 struct lpfc_cq_event *cq_event;
7971 unsigned long iflags;
7972
7973 spin_lock_irqsave(&phba->hbalock, iflags);
7974 cq_event = __lpfc_sli4_cq_event_alloc(phba);
7975 spin_unlock_irqrestore(&phba->hbalock, iflags);
7976 return cq_event;
7977}
7978
7979/**
7980 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7981 * @phba: pointer to lpfc hba data structure.
7982 * @cq_event: pointer to the completion queue event to be freed.
7983 *
7984 * This routine is the lock free version of the API invoked to release a
7985 * completion-queue event back into the free pool.
7986 **/
7987void
7988__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
7989 struct lpfc_cq_event *cq_event)
7990{
7991 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
7992}
7993
7994/**
7995 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7996 * @phba: pointer to lpfc hba data structure.
7997 * @cq_event: pointer to the completion queue event to be freed.
7998 *
7999 * This routine is the lock version of the API invoked to release a
8000 * completion-queue event back into the free pool.
8001 **/
8002void
8003lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
8004 struct lpfc_cq_event *cq_event)
8005{
8006 unsigned long iflags;
8007 spin_lock_irqsave(&phba->hbalock, iflags);
8008 __lpfc_sli4_cq_event_release(phba, cq_event);
8009 spin_unlock_irqrestore(&phba->hbalock, iflags);
8010}
8011
8012/**
8013 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
8014 * @phba: pointer to lpfc hba data structure.
8015 *
8016 * This routine is to free all the pending completion-queue events to the
8017 * back into the free pool for device reset.
8018 **/
8019static void
8020lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
8021{
8022 LIST_HEAD(cqelist);
8023 struct lpfc_cq_event *cqe;
8024 unsigned long iflags;
8025
8026 /* Retrieve all the pending WCQEs from pending WCQE lists */
8027 spin_lock_irqsave(&phba->hbalock, iflags);
8028 /* Pending FCP XRI abort events */
8029 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
8030 &cqelist);
8031 /* Pending ELS XRI abort events */
8032 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
8033 &cqelist);
8034 /* Pending asynnc events */
8035 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
8036 &cqelist);
8037 spin_unlock_irqrestore(&phba->hbalock, iflags);
8038
8039 while (!list_empty(&cqelist)) {
8040 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
8041 lpfc_sli4_cq_event_release(phba, cqe);
8042 }
8043}
8044
8045/**
8046 * lpfc_pci_function_reset - Reset pci function.
8047 * @phba: pointer to lpfc hba data structure.
8048 *
8049 * This routine is invoked to request a PCI function reset. It will destroys
8050 * all resources assigned to the PCI function which originates this request.
8051 *
8052 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008053 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008054 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008055 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008056 **/
8057int
8058lpfc_pci_function_reset(struct lpfc_hba *phba)
8059{
8060 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05008061 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04008062 uint32_t shdr_status, shdr_add_status;
James Smart2f6fa2c2014-09-03 12:57:08 -04008063 uint32_t rdy_chk;
8064 uint32_t port_reset = 0;
James Smartda0436e2009-05-22 14:51:39 -04008065 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05008066 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -05008067 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -04008068
James Smart2fcee4b2010-12-15 17:57:46 -05008069 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8070 switch (if_type) {
8071 case LPFC_SLI_INTF_IF_TYPE_0:
8072 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8073 GFP_KERNEL);
8074 if (!mboxq) {
8075 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8076 "0494 Unable to allocate memory for "
8077 "issuing SLI_FUNCTION_RESET mailbox "
8078 "command\n");
8079 return -ENOMEM;
8080 }
8081
8082 /* Setup PCI function reset mailbox-ioctl command */
8083 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8084 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
8085 LPFC_SLI4_MBX_EMBED);
8086 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8087 shdr = (union lpfc_sli4_cfg_shdr *)
8088 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
8089 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8090 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
8091 &shdr->response);
8092 if (rc != MBX_TIMEOUT)
8093 mempool_free(mboxq, phba->mbox_mem_pool);
8094 if (shdr_status || shdr_add_status || rc) {
8095 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8096 "0495 SLI_FUNCTION_RESET mailbox "
8097 "failed with status x%x add_status x%x,"
8098 " mbx status x%x\n",
8099 shdr_status, shdr_add_status, rc);
8100 rc = -ENXIO;
8101 }
8102 break;
8103 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2f6fa2c2014-09-03 12:57:08 -04008104wait:
8105 /*
8106 * Poll the Port Status Register and wait for RDY for
8107 * up to 30 seconds. If the port doesn't respond, treat
8108 * it as an error.
8109 */
James Smart77d093f2015-04-07 15:07:08 -04008110 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
James Smart2f6fa2c2014-09-03 12:57:08 -04008111 if (lpfc_readl(phba->sli4_hba.u.if_type2.
8112 STATUSregaddr, &reg_data.word0)) {
8113 rc = -ENODEV;
8114 goto out;
8115 }
8116 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
8117 break;
8118 msleep(20);
8119 }
8120
8121 if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
8122 phba->work_status[0] = readl(
8123 phba->sli4_hba.u.if_type2.ERR1regaddr);
8124 phba->work_status[1] = readl(
8125 phba->sli4_hba.u.if_type2.ERR2regaddr);
8126 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8127 "2890 Port not ready, port status reg "
8128 "0x%x error 1=0x%x, error 2=0x%x\n",
8129 reg_data.word0,
8130 phba->work_status[0],
8131 phba->work_status[1]);
8132 rc = -ENODEV;
8133 goto out;
8134 }
8135
8136 if (!port_reset) {
8137 /*
8138 * Reset the port now
8139 */
James Smart2fcee4b2010-12-15 17:57:46 -05008140 reg_data.word0 = 0;
8141 bf_set(lpfc_sliport_ctrl_end, &reg_data,
8142 LPFC_SLIPORT_LITTLE_ENDIAN);
8143 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
8144 LPFC_SLIPORT_INIT_PORT);
8145 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
8146 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -05008147 /* flush */
James Smart2b81f942012-03-01 22:37:18 -05008148 pci_read_config_word(phba->pcidev,
8149 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -05008150
James Smart2f6fa2c2014-09-03 12:57:08 -04008151 port_reset = 1;
8152 msleep(20);
8153 goto wait;
8154 } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
8155 rc = -ENODEV;
8156 goto out;
James Smart2fcee4b2010-12-15 17:57:46 -05008157 }
8158 break;
James Smart2f6fa2c2014-09-03 12:57:08 -04008159
James Smart2fcee4b2010-12-15 17:57:46 -05008160 case LPFC_SLI_INTF_IF_TYPE_1:
8161 default:
8162 break;
James Smartda0436e2009-05-22 14:51:39 -04008163 }
8164
James Smart73d91e52011-10-10 21:32:10 -04008165out:
James Smart2fcee4b2010-12-15 17:57:46 -05008166 /* Catch the not-ready port failure after a port reset. */
James Smart2f6fa2c2014-09-03 12:57:08 -04008167 if (rc) {
James Smart229adb02013-04-17 20:16:51 -04008168 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8169 "3317 HBA not functional: IP Reset Failed "
James Smart2f6fa2c2014-09-03 12:57:08 -04008170 "try: echo fw_reset > board_mode\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008171 rc = -ENODEV;
James Smart229adb02013-04-17 20:16:51 -04008172 }
James Smart2fcee4b2010-12-15 17:57:46 -05008173
James Smartda0436e2009-05-22 14:51:39 -04008174 return rc;
8175}
8176
8177/**
James Smartda0436e2009-05-22 14:51:39 -04008178 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
8179 * @phba: pointer to lpfc hba data structure.
8180 *
8181 * This routine is invoked to set up the PCI device memory space for device
8182 * with SLI-4 interface spec.
8183 *
8184 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008185 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008186 * other values - error
8187 **/
8188static int
8189lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
8190{
8191 struct pci_dev *pdev;
8192 unsigned long bar0map_len, bar1map_len, bar2map_len;
8193 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05008194 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04008195
8196 /* Obtain PCI device reference */
8197 if (!phba->pcidev)
8198 return error;
8199 else
8200 pdev = phba->pcidev;
8201
8202 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05008203 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
8204 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
8205 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
8206 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smartda0436e2009-05-22 14:51:39 -04008207 return error;
Michael Reed8e685972009-09-18 12:02:05 -05008208 }
8209 }
James Smartda0436e2009-05-22 14:51:39 -04008210
James Smart2fcee4b2010-12-15 17:57:46 -05008211 /*
8212 * The BARs and register set definitions and offset locations are
8213 * dependent on the if_type.
8214 */
8215 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
8216 &phba->sli4_hba.sli_intf.word0)) {
8217 return error;
8218 }
8219
8220 /* There is no SLI3 failback for SLI4 devices. */
8221 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
8222 LPFC_SLI_INTF_VALID) {
8223 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8224 "2894 SLI_INTF reg contents invalid "
8225 "sli_intf reg 0x%x\n",
8226 phba->sli4_hba.sli_intf.word0);
8227 return error;
8228 }
8229
8230 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8231 /*
8232 * Get the bus address of SLI4 device Bar regions and the
8233 * number of bytes required by each mapping. The mapping of the
8234 * particular PCI BARs regions is dependent on the type of
8235 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04008236 */
James Smartf5ca6f22013-09-06 12:21:09 -04008237 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
8238 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
8239 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
James Smart2fcee4b2010-12-15 17:57:46 -05008240
8241 /*
8242 * Map SLI4 PCI Config Space Register base to a kernel virtual
8243 * addr
8244 */
8245 phba->sli4_hba.conf_regs_memmap_p =
8246 ioremap(phba->pci_bar0_map, bar0map_len);
8247 if (!phba->sli4_hba.conf_regs_memmap_p) {
8248 dev_printk(KERN_ERR, &pdev->dev,
8249 "ioremap failed for SLI4 PCI config "
8250 "registers.\n");
8251 goto out;
8252 }
James Smartf5ca6f22013-09-06 12:21:09 -04008253 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008254 /* Set up BAR0 PCI config space register memory map */
8255 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05008256 } else {
8257 phba->pci_bar0_map = pci_resource_start(pdev, 1);
8258 bar0map_len = pci_resource_len(pdev, 1);
James Smart2fcee4b2010-12-15 17:57:46 -05008259 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
8260 dev_printk(KERN_ERR, &pdev->dev,
8261 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
8262 goto out;
8263 }
8264 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008265 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008266 if (!phba->sli4_hba.conf_regs_memmap_p) {
8267 dev_printk(KERN_ERR, &pdev->dev,
8268 "ioremap failed for SLI4 PCI config "
8269 "registers.\n");
8270 goto out;
8271 }
8272 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04008273 }
8274
James Smartc31098c2011-04-16 11:03:33 -04008275 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04008276 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
James Smart2fcee4b2010-12-15 17:57:46 -05008277 /*
8278 * Map SLI4 if type 0 HBA Control Register base to a kernel
8279 * virtual address and setup the registers.
8280 */
James Smartf5ca6f22013-09-06 12:21:09 -04008281 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
8282 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
James Smart2fcee4b2010-12-15 17:57:46 -05008283 phba->sli4_hba.ctrl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008284 ioremap(phba->pci_bar1_map, bar1map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008285 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
8286 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04008287 "ioremap failed for SLI4 HBA control registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008288 goto out_iounmap_conf;
8289 }
James Smartf5ca6f22013-09-06 12:21:09 -04008290 phba->pci_bar2_memmap_p = phba->sli4_hba.ctrl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008291 lpfc_sli4_bar1_register_memmap(phba);
James Smartda0436e2009-05-22 14:51:39 -04008292 }
8293
James Smartc31098c2011-04-16 11:03:33 -04008294 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04008295 (pci_resource_start(pdev, PCI_64BIT_BAR4))) {
James Smart2fcee4b2010-12-15 17:57:46 -05008296 /*
8297 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
8298 * virtual address and setup the registers.
8299 */
James Smartf5ca6f22013-09-06 12:21:09 -04008300 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
8301 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
James Smart2fcee4b2010-12-15 17:57:46 -05008302 phba->sli4_hba.drbl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008303 ioremap(phba->pci_bar2_map, bar2map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008304 if (!phba->sli4_hba.drbl_regs_memmap_p) {
8305 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04008306 "ioremap failed for SLI4 HBA doorbell registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008307 goto out_iounmap_ctrl;
8308 }
James Smartf5ca6f22013-09-06 12:21:09 -04008309 phba->pci_bar4_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008310 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
8311 if (error)
8312 goto out_iounmap_all;
James Smartda0436e2009-05-22 14:51:39 -04008313 }
8314
James Smartda0436e2009-05-22 14:51:39 -04008315 return 0;
8316
8317out_iounmap_all:
8318 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
8319out_iounmap_ctrl:
8320 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
8321out_iounmap_conf:
8322 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8323out:
8324 return error;
8325}
8326
8327/**
8328 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
8329 * @phba: pointer to lpfc hba data structure.
8330 *
8331 * This routine is invoked to unset the PCI device memory space for device
8332 * with SLI-4 interface spec.
8333 **/
8334static void
8335lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
8336{
James Smart2e90f4b2011-12-13 13:22:37 -05008337 uint32_t if_type;
8338 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -04008339
James Smart2e90f4b2011-12-13 13:22:37 -05008340 switch (if_type) {
8341 case LPFC_SLI_INTF_IF_TYPE_0:
8342 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
8343 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
8344 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8345 break;
8346 case LPFC_SLI_INTF_IF_TYPE_2:
8347 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8348 break;
8349 case LPFC_SLI_INTF_IF_TYPE_1:
8350 default:
8351 dev_printk(KERN_ERR, &phba->pcidev->dev,
8352 "FATAL - unsupported SLI4 interface type - %d\n",
8353 if_type);
8354 break;
8355 }
James Smartda0436e2009-05-22 14:51:39 -04008356}
8357
8358/**
James Smart3772a992009-05-22 14:50:54 -04008359 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
8360 * @phba: pointer to lpfc hba data structure.
8361 *
8362 * This routine is invoked to enable the MSI-X interrupt vectors to device
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008363 * with SLI-3 interface specs. The kernel function pci_enable_msix_exact()
8364 * is called to enable the MSI-X vectors. Note that pci_enable_msix_exact(),
8365 * once invoked, enables either all or nothing, depending on the current
James Smart3772a992009-05-22 14:50:54 -04008366 * availability of PCI vector resources. The device driver is responsible
8367 * for calling the individual request_irq() to register each MSI-X vector
8368 * with a interrupt handler, which is done in this function. Note that
8369 * later when device is unloading, the driver should always call free_irq()
8370 * on all MSI-X vectors it has done request_irq() on before calling
8371 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
8372 * will be left with MSI-X enabled and leaks its vectors.
8373 *
8374 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008375 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008376 * other values - error
8377 **/
8378static int
8379lpfc_sli_enable_msix(struct lpfc_hba *phba)
8380{
8381 int rc, i;
8382 LPFC_MBOXQ_t *pmb;
8383
8384 /* Set up MSI-X multi-message vectors */
8385 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8386 phba->msix_entries[i].entry = i;
8387
8388 /* Configure MSI-X capability structure */
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008389 rc = pci_enable_msix_exact(phba->pcidev, phba->msix_entries,
8390 LPFC_MSIX_VECTORS);
James Smart3772a992009-05-22 14:50:54 -04008391 if (rc) {
8392 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8393 "0420 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02008394 goto vec_fail_out;
James Smart3772a992009-05-22 14:50:54 -04008395 }
8396 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8397 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8398 "0477 MSI-X entry[%d]: vector=x%x "
8399 "message=%d\n", i,
8400 phba->msix_entries[i].vector,
8401 phba->msix_entries[i].entry);
8402 /*
8403 * Assign MSI-X vectors to interrupt handlers
8404 */
8405
8406 /* vector-0 is associated to slow-path handler */
8407 rc = request_irq(phba->msix_entries[0].vector,
James Smarted243d32015-05-21 13:55:25 -04008408 &lpfc_sli_sp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04008409 LPFC_SP_DRIVER_HANDLER_NAME, phba);
8410 if (rc) {
8411 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8412 "0421 MSI-X slow-path request_irq failed "
8413 "(%d)\n", rc);
8414 goto msi_fail_out;
8415 }
8416
8417 /* vector-1 is associated to fast-path handler */
8418 rc = request_irq(phba->msix_entries[1].vector,
James Smarted243d32015-05-21 13:55:25 -04008419 &lpfc_sli_fp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04008420 LPFC_FP_DRIVER_HANDLER_NAME, phba);
8421
8422 if (rc) {
8423 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8424 "0429 MSI-X fast-path request_irq failed "
8425 "(%d)\n", rc);
8426 goto irq_fail_out;
8427 }
8428
8429 /*
8430 * Configure HBA MSI-X attention conditions to messages
8431 */
8432 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8433
8434 if (!pmb) {
8435 rc = -ENOMEM;
8436 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8437 "0474 Unable to allocate memory for issuing "
8438 "MBOX_CONFIG_MSI command\n");
8439 goto mem_fail_out;
8440 }
8441 rc = lpfc_config_msi(phba, pmb);
8442 if (rc)
8443 goto mbx_fail_out;
8444 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
8445 if (rc != MBX_SUCCESS) {
8446 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
8447 "0351 Config MSI mailbox command failed, "
8448 "mbxCmd x%x, mbxStatus x%x\n",
8449 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
8450 goto mbx_fail_out;
8451 }
8452
8453 /* Free memory allocated for mailbox command */
8454 mempool_free(pmb, phba->mbox_mem_pool);
8455 return rc;
8456
8457mbx_fail_out:
8458 /* Free memory allocated for mailbox command */
8459 mempool_free(pmb, phba->mbox_mem_pool);
8460
8461mem_fail_out:
8462 /* free the irq already requested */
8463 free_irq(phba->msix_entries[1].vector, phba);
8464
8465irq_fail_out:
8466 /* free the irq already requested */
8467 free_irq(phba->msix_entries[0].vector, phba);
8468
8469msi_fail_out:
8470 /* Unconfigure MSI-X capability structure */
8471 pci_disable_msix(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02008472
8473vec_fail_out:
James Smart3772a992009-05-22 14:50:54 -04008474 return rc;
8475}
8476
8477/**
8478 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
8479 * @phba: pointer to lpfc hba data structure.
8480 *
8481 * This routine is invoked to release the MSI-X vectors and then disable the
8482 * MSI-X interrupt mode to device with SLI-3 interface spec.
8483 **/
8484static void
8485lpfc_sli_disable_msix(struct lpfc_hba *phba)
8486{
8487 int i;
8488
8489 /* Free up MSI-X multi-message vectors */
8490 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8491 free_irq(phba->msix_entries[i].vector, phba);
8492 /* Disable MSI-X */
8493 pci_disable_msix(phba->pcidev);
8494
8495 return;
8496}
8497
8498/**
8499 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
8500 * @phba: pointer to lpfc hba data structure.
8501 *
8502 * This routine is invoked to enable the MSI interrupt mode to device with
8503 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
8504 * enable the MSI vector. The device driver is responsible for calling the
8505 * request_irq() to register MSI vector with a interrupt the handler, which
8506 * is done in this function.
8507 *
8508 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008509 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008510 * other values - error
8511 */
8512static int
8513lpfc_sli_enable_msi(struct lpfc_hba *phba)
8514{
8515 int rc;
8516
8517 rc = pci_enable_msi(phba->pcidev);
8518 if (!rc)
8519 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8520 "0462 PCI enable MSI mode success.\n");
8521 else {
8522 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8523 "0471 PCI enable MSI mode failed (%d)\n", rc);
8524 return rc;
8525 }
8526
8527 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04008528 0, LPFC_DRIVER_NAME, phba);
James Smart3772a992009-05-22 14:50:54 -04008529 if (rc) {
8530 pci_disable_msi(phba->pcidev);
8531 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8532 "0478 MSI request_irq failed (%d)\n", rc);
8533 }
8534 return rc;
8535}
8536
8537/**
8538 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
8539 * @phba: pointer to lpfc hba data structure.
8540 *
8541 * This routine is invoked to disable the MSI interrupt mode to device with
8542 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
8543 * done request_irq() on before calling pci_disable_msi(). Failure to do so
8544 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
8545 * its vector.
8546 */
8547static void
8548lpfc_sli_disable_msi(struct lpfc_hba *phba)
8549{
8550 free_irq(phba->pcidev->irq, phba);
8551 pci_disable_msi(phba->pcidev);
8552 return;
8553}
8554
8555/**
8556 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
8557 * @phba: pointer to lpfc hba data structure.
8558 *
8559 * This routine is invoked to enable device interrupt and associate driver's
8560 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
8561 * spec. Depends on the interrupt mode configured to the driver, the driver
8562 * will try to fallback from the configured interrupt mode to an interrupt
8563 * mode which is supported by the platform, kernel, and device in the order
8564 * of:
8565 * MSI-X -> MSI -> IRQ.
8566 *
8567 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008568 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008569 * other values - error
8570 **/
8571static uint32_t
8572lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
8573{
8574 uint32_t intr_mode = LPFC_INTR_ERROR;
8575 int retval;
8576
8577 if (cfg_mode == 2) {
8578 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
8579 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
8580 if (!retval) {
8581 /* Now, try to enable MSI-X interrupt mode */
8582 retval = lpfc_sli_enable_msix(phba);
8583 if (!retval) {
8584 /* Indicate initialization to MSI-X mode */
8585 phba->intr_type = MSIX;
8586 intr_mode = 2;
8587 }
8588 }
8589 }
8590
8591 /* Fallback to MSI if MSI-X initialization failed */
8592 if (cfg_mode >= 1 && phba->intr_type == NONE) {
8593 retval = lpfc_sli_enable_msi(phba);
8594 if (!retval) {
8595 /* Indicate initialization to MSI mode */
8596 phba->intr_type = MSI;
8597 intr_mode = 1;
8598 }
8599 }
8600
8601 /* Fallback to INTx if both MSI-X/MSI initalization failed */
8602 if (phba->intr_type == NONE) {
8603 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
8604 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8605 if (!retval) {
8606 /* Indicate initialization to INTx mode */
8607 phba->intr_type = INTx;
8608 intr_mode = 0;
8609 }
8610 }
8611 return intr_mode;
8612}
8613
8614/**
8615 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
8616 * @phba: pointer to lpfc hba data structure.
8617 *
8618 * This routine is invoked to disable device interrupt and disassociate the
8619 * driver's interrupt handler(s) from interrupt vector(s) to device with
8620 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
8621 * release the interrupt vector(s) for the message signaled interrupt.
8622 **/
8623static void
8624lpfc_sli_disable_intr(struct lpfc_hba *phba)
8625{
8626 /* Disable the currently initialized interrupt mode */
8627 if (phba->intr_type == MSIX)
8628 lpfc_sli_disable_msix(phba);
8629 else if (phba->intr_type == MSI)
8630 lpfc_sli_disable_msi(phba);
8631 else if (phba->intr_type == INTx)
8632 free_irq(phba->pcidev->irq, phba);
8633
8634 /* Reset interrupt management states */
8635 phba->intr_type = NONE;
8636 phba->sli.slistat.sli_intr = 0;
8637
8638 return;
8639}
8640
8641/**
James Smart7bb03bb2013-04-17 20:19:16 -04008642 * lpfc_find_next_cpu - Find next available CPU that matches the phys_id
8643 * @phba: pointer to lpfc hba data structure.
8644 *
8645 * Find next available CPU to use for IRQ to CPU affinity.
8646 */
8647static int
8648lpfc_find_next_cpu(struct lpfc_hba *phba, uint32_t phys_id)
8649{
8650 struct lpfc_vector_map_info *cpup;
8651 int cpu;
8652
8653 cpup = phba->sli4_hba.cpu_map;
8654 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8655 /* CPU must be online */
8656 if (cpu_online(cpu)) {
8657 if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
8658 (lpfc_used_cpu[cpu] == LPFC_VECTOR_MAP_EMPTY) &&
8659 (cpup->phys_id == phys_id)) {
8660 return cpu;
8661 }
8662 }
8663 cpup++;
8664 }
8665
8666 /*
8667 * If we get here, we have used ALL CPUs for the specific
8668 * phys_id. Now we need to clear out lpfc_used_cpu and start
8669 * reusing CPUs.
8670 */
8671
8672 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8673 if (lpfc_used_cpu[cpu] == phys_id)
8674 lpfc_used_cpu[cpu] = LPFC_VECTOR_MAP_EMPTY;
8675 }
8676
8677 cpup = phba->sli4_hba.cpu_map;
8678 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8679 /* CPU must be online */
8680 if (cpu_online(cpu)) {
8681 if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
8682 (cpup->phys_id == phys_id)) {
8683 return cpu;
8684 }
8685 }
8686 cpup++;
8687 }
8688 return LPFC_VECTOR_MAP_EMPTY;
8689}
8690
8691/**
8692 * lpfc_sli4_set_affinity - Set affinity for HBA IRQ vectors
8693 * @phba: pointer to lpfc hba data structure.
8694 * @vectors: number of HBA vectors
8695 *
8696 * Affinitize MSIX IRQ vectors to CPUs. Try to equally spread vector
8697 * affinization across multple physical CPUs (numa nodes).
8698 * In addition, this routine will assign an IO channel for each CPU
8699 * to use when issuing I/Os.
8700 */
8701static int
8702lpfc_sli4_set_affinity(struct lpfc_hba *phba, int vectors)
8703{
8704 int i, idx, saved_chann, used_chann, cpu, phys_id;
James Smartec2087a2013-09-06 12:20:36 -04008705 int max_phys_id, min_phys_id;
8706 int num_io_channel, first_cpu, chan;
James Smart7bb03bb2013-04-17 20:19:16 -04008707 struct lpfc_vector_map_info *cpup;
8708#ifdef CONFIG_X86
8709 struct cpuinfo_x86 *cpuinfo;
8710#endif
James Smart7bb03bb2013-04-17 20:19:16 -04008711 uint8_t chann[LPFC_FCP_IO_CHAN_MAX+1];
8712
8713 /* If there is no mapping, just return */
8714 if (!phba->cfg_fcp_cpu_map)
8715 return 1;
8716
8717 /* Init cpu_map array */
8718 memset(phba->sli4_hba.cpu_map, 0xff,
8719 (sizeof(struct lpfc_vector_map_info) *
8720 phba->sli4_hba.num_present_cpu));
8721
8722 max_phys_id = 0;
James Smartec2087a2013-09-06 12:20:36 -04008723 min_phys_id = 0xff;
James Smart7bb03bb2013-04-17 20:19:16 -04008724 phys_id = 0;
8725 num_io_channel = 0;
8726 first_cpu = LPFC_VECTOR_MAP_EMPTY;
8727
8728 /* Update CPU map with physical id and core id of each CPU */
8729 cpup = phba->sli4_hba.cpu_map;
8730 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8731#ifdef CONFIG_X86
8732 cpuinfo = &cpu_data(cpu);
8733 cpup->phys_id = cpuinfo->phys_proc_id;
8734 cpup->core_id = cpuinfo->cpu_core_id;
8735#else
8736 /* No distinction between CPUs for other platforms */
8737 cpup->phys_id = 0;
8738 cpup->core_id = 0;
8739#endif
8740
8741 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8742 "3328 CPU physid %d coreid %d\n",
8743 cpup->phys_id, cpup->core_id);
8744
8745 if (cpup->phys_id > max_phys_id)
8746 max_phys_id = cpup->phys_id;
James Smartec2087a2013-09-06 12:20:36 -04008747 if (cpup->phys_id < min_phys_id)
8748 min_phys_id = cpup->phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008749 cpup++;
8750 }
8751
James Smartec2087a2013-09-06 12:20:36 -04008752 phys_id = min_phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008753 /* Now associate the HBA vectors with specific CPUs */
8754 for (idx = 0; idx < vectors; idx++) {
8755 cpup = phba->sli4_hba.cpu_map;
8756 cpu = lpfc_find_next_cpu(phba, phys_id);
8757 if (cpu == LPFC_VECTOR_MAP_EMPTY) {
8758
8759 /* Try for all phys_id's */
8760 for (i = 1; i < max_phys_id; i++) {
8761 phys_id++;
8762 if (phys_id > max_phys_id)
James Smartec2087a2013-09-06 12:20:36 -04008763 phys_id = min_phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008764 cpu = lpfc_find_next_cpu(phba, phys_id);
8765 if (cpu == LPFC_VECTOR_MAP_EMPTY)
8766 continue;
8767 goto found;
8768 }
8769
James Smartec2087a2013-09-06 12:20:36 -04008770 /* Use round robin for scheduling */
8771 phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_ROUND_ROBIN;
8772 chan = 0;
8773 cpup = phba->sli4_hba.cpu_map;
8774 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
8775 cpup->channel_id = chan;
8776 cpup++;
8777 chan++;
8778 if (chan >= phba->cfg_fcp_io_channel)
8779 chan = 0;
8780 }
8781
James Smart7bb03bb2013-04-17 20:19:16 -04008782 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8783 "3329 Cannot set affinity:"
8784 "Error mapping vector %d (%d)\n",
8785 idx, vectors);
8786 return 0;
8787 }
8788found:
8789 cpup += cpu;
8790 if (phba->cfg_fcp_cpu_map == LPFC_DRIVER_CPU_MAP)
8791 lpfc_used_cpu[cpu] = phys_id;
8792
8793 /* Associate vector with selected CPU */
8794 cpup->irq = phba->sli4_hba.msix_entries[idx].vector;
8795
8796 /* Associate IO channel with selected CPU */
8797 cpup->channel_id = idx;
8798 num_io_channel++;
8799
8800 if (first_cpu == LPFC_VECTOR_MAP_EMPTY)
8801 first_cpu = cpu;
8802
8803 /* Now affinitize to the selected CPU */
James Smart7bb03bb2013-04-17 20:19:16 -04008804 i = irq_set_affinity_hint(phba->sli4_hba.msix_entries[idx].
Ian Mitchellc0365c02015-08-31 16:48:12 -04008805 vector, get_cpu_mask(cpu));
James Smart7bb03bb2013-04-17 20:19:16 -04008806
8807 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8808 "3330 Set Affinity: CPU %d channel %d "
8809 "irq %d (%x)\n",
8810 cpu, cpup->channel_id,
8811 phba->sli4_hba.msix_entries[idx].vector, i);
8812
8813 /* Spread vector mapping across multple physical CPU nodes */
8814 phys_id++;
8815 if (phys_id > max_phys_id)
James Smartec2087a2013-09-06 12:20:36 -04008816 phys_id = min_phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008817 }
8818
8819 /*
8820 * Finally fill in the IO channel for any remaining CPUs.
8821 * At this point, all IO channels have been assigned to a specific
8822 * MSIx vector, mapped to a specific CPU.
8823 * Base the remaining IO channel assigned, to IO channels already
8824 * assigned to other CPUs on the same phys_id.
8825 */
James Smartec2087a2013-09-06 12:20:36 -04008826 for (i = min_phys_id; i <= max_phys_id; i++) {
James Smart7bb03bb2013-04-17 20:19:16 -04008827 /*
8828 * If there are no io channels already mapped to
8829 * this phys_id, just round robin thru the io_channels.
8830 * Setup chann[] for round robin.
8831 */
8832 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
8833 chann[idx] = idx;
8834
8835 saved_chann = 0;
8836 used_chann = 0;
8837
8838 /*
8839 * First build a list of IO channels already assigned
8840 * to this phys_id before reassigning the same IO
8841 * channels to the remaining CPUs.
8842 */
8843 cpup = phba->sli4_hba.cpu_map;
8844 cpu = first_cpu;
8845 cpup += cpu;
8846 for (idx = 0; idx < phba->sli4_hba.num_present_cpu;
8847 idx++) {
8848 if (cpup->phys_id == i) {
8849 /*
8850 * Save any IO channels that are
8851 * already mapped to this phys_id.
8852 */
8853 if (cpup->irq != LPFC_VECTOR_MAP_EMPTY) {
James Smart6690e0d2015-12-16 18:11:56 -05008854 if (saved_chann <=
8855 LPFC_FCP_IO_CHAN_MAX) {
8856 chann[saved_chann] =
8857 cpup->channel_id;
8858 saved_chann++;
8859 }
James Smart7bb03bb2013-04-17 20:19:16 -04008860 goto out;
8861 }
8862
8863 /* See if we are using round-robin */
8864 if (saved_chann == 0)
8865 saved_chann =
8866 phba->cfg_fcp_io_channel;
8867
8868 /* Associate next IO channel with CPU */
8869 cpup->channel_id = chann[used_chann];
8870 num_io_channel++;
8871 used_chann++;
8872 if (used_chann == saved_chann)
8873 used_chann = 0;
8874
8875 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8876 "3331 Set IO_CHANN "
8877 "CPU %d channel %d\n",
8878 idx, cpup->channel_id);
8879 }
8880out:
8881 cpu++;
8882 if (cpu >= phba->sli4_hba.num_present_cpu) {
8883 cpup = phba->sli4_hba.cpu_map;
8884 cpu = 0;
8885 } else {
8886 cpup++;
8887 }
8888 }
8889 }
8890
8891 if (phba->sli4_hba.num_online_cpu != phba->sli4_hba.num_present_cpu) {
8892 cpup = phba->sli4_hba.cpu_map;
8893 for (idx = 0; idx < phba->sli4_hba.num_present_cpu; idx++) {
8894 if (cpup->channel_id == LPFC_VECTOR_MAP_EMPTY) {
8895 cpup->channel_id = 0;
8896 num_io_channel++;
8897
8898 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8899 "3332 Assign IO_CHANN "
8900 "CPU %d channel %d\n",
8901 idx, cpup->channel_id);
8902 }
8903 cpup++;
8904 }
8905 }
8906
8907 /* Sanity check */
8908 if (num_io_channel != phba->sli4_hba.num_present_cpu)
8909 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8910 "3333 Set affinity mismatch:"
James Smartec2087a2013-09-06 12:20:36 -04008911 "%d chann != %d cpus: %d vectors\n",
James Smart7bb03bb2013-04-17 20:19:16 -04008912 num_io_channel, phba->sli4_hba.num_present_cpu,
8913 vectors);
8914
James Smartec2087a2013-09-06 12:20:36 -04008915 /* Enable using cpu affinity for scheduling */
James Smart7bb03bb2013-04-17 20:19:16 -04008916 phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_BY_CPU;
8917 return 1;
8918}
8919
8920
8921/**
James Smartda0436e2009-05-22 14:51:39 -04008922 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
8923 * @phba: pointer to lpfc hba data structure.
8924 *
8925 * This routine is invoked to enable the MSI-X interrupt vectors to device
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008926 * with SLI-4 interface spec. The kernel function pci_enable_msix_range()
8927 * is called to enable the MSI-X vectors. The device driver is responsible
8928 * for calling the individual request_irq() to register each MSI-X vector
8929 * with a interrupt handler, which is done in this function. Note that
8930 * later when device is unloading, the driver should always call free_irq()
8931 * on all MSI-X vectors it has done request_irq() on before calling
8932 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
8933 * will be left with MSI-X enabled and leaks its vectors.
James Smartda0436e2009-05-22 14:51:39 -04008934 *
8935 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008936 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008937 * other values - error
8938 **/
8939static int
8940lpfc_sli4_enable_msix(struct lpfc_hba *phba)
8941{
James Smart75baf692010-06-08 18:31:21 -04008942 int vectors, rc, index;
James Smartda0436e2009-05-22 14:51:39 -04008943
8944 /* Set up MSI-X multi-message vectors */
James Smart82c3e9b2012-09-29 11:29:50 -04008945 for (index = 0; index < phba->cfg_fcp_io_channel; index++)
James Smartda0436e2009-05-22 14:51:39 -04008946 phba->sli4_hba.msix_entries[index].entry = index;
8947
8948 /* Configure MSI-X capability structure */
James Smart82c3e9b2012-09-29 11:29:50 -04008949 vectors = phba->cfg_fcp_io_channel;
James Smart1ba981f2014-02-20 09:56:45 -05008950 if (phba->cfg_fof) {
8951 phba->sli4_hba.msix_entries[index].entry = index;
8952 vectors++;
8953 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008954 rc = pci_enable_msix_range(phba->pcidev, phba->sli4_hba.msix_entries,
8955 2, vectors);
8956 if (rc < 0) {
James Smartda0436e2009-05-22 14:51:39 -04008957 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8958 "0484 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02008959 goto vec_fail_out;
James Smartda0436e2009-05-22 14:51:39 -04008960 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008961 vectors = rc;
James Smart75baf692010-06-08 18:31:21 -04008962
James Smartda0436e2009-05-22 14:51:39 -04008963 /* Log MSI-X vector assignment */
James Smart75baf692010-06-08 18:31:21 -04008964 for (index = 0; index < vectors; index++)
James Smartda0436e2009-05-22 14:51:39 -04008965 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8966 "0489 MSI-X entry[%d]: vector=x%x "
8967 "message=%d\n", index,
8968 phba->sli4_hba.msix_entries[index].vector,
8969 phba->sli4_hba.msix_entries[index].entry);
James Smart67d12732012-08-03 12:36:13 -04008970
James Smart7bb03bb2013-04-17 20:19:16 -04008971 /* Assign MSI-X vectors to interrupt handlers */
James Smart67d12732012-08-03 12:36:13 -04008972 for (index = 0; index < vectors; index++) {
James Smart4305f182012-08-03 12:36:33 -04008973 memset(&phba->sli4_hba.handler_name[index], 0, 16);
James Smarta2fc4aef2014-09-03 12:57:55 -04008974 snprintf((char *)&phba->sli4_hba.handler_name[index],
8975 LPFC_SLI4_HANDLER_NAME_SZ,
James Smart4305f182012-08-03 12:36:33 -04008976 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -04008977
James Smart67d12732012-08-03 12:36:13 -04008978 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
8979 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
James Smartba20c852012-08-03 12:36:52 -04008980 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].fcp_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -05008981 if (phba->cfg_fof && (index == (vectors - 1)))
8982 rc = request_irq(
8983 phba->sli4_hba.msix_entries[index].vector,
James Smarted243d32015-05-21 13:55:25 -04008984 &lpfc_sli4_fof_intr_handler, 0,
James Smart1ba981f2014-02-20 09:56:45 -05008985 (char *)&phba->sli4_hba.handler_name[index],
8986 &phba->sli4_hba.fcp_eq_hdl[index]);
8987 else
8988 rc = request_irq(
8989 phba->sli4_hba.msix_entries[index].vector,
James Smarted243d32015-05-21 13:55:25 -04008990 &lpfc_sli4_hba_intr_handler, 0,
James Smart4305f182012-08-03 12:36:33 -04008991 (char *)&phba->sli4_hba.handler_name[index],
James Smart67d12732012-08-03 12:36:13 -04008992 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -04008993 if (rc) {
8994 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8995 "0486 MSI-X fast-path (%d) "
8996 "request_irq failed (%d)\n", index, rc);
8997 goto cfg_fail_out;
8998 }
8999 }
9000
James Smart1ba981f2014-02-20 09:56:45 -05009001 if (phba->cfg_fof)
9002 vectors--;
9003
James Smart82c3e9b2012-09-29 11:29:50 -04009004 if (vectors != phba->cfg_fcp_io_channel) {
9005 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9006 "3238 Reducing IO channels to match number of "
9007 "MSI-X vectors, requested %d got %d\n",
9008 phba->cfg_fcp_io_channel, vectors);
9009 phba->cfg_fcp_io_channel = vectors;
9010 }
James Smart7bb03bb2013-04-17 20:19:16 -04009011
James Smart8b0dff12015-05-22 10:42:38 -04009012 if (!shost_use_blk_mq(lpfc_shost_from_vport(phba->pport)))
9013 lpfc_sli4_set_affinity(phba, vectors);
James Smartda0436e2009-05-22 14:51:39 -04009014 return rc;
9015
9016cfg_fail_out:
9017 /* free the irq already requested */
James Smartacbd8612013-09-06 12:21:19 -04009018 for (--index; index >= 0; index--) {
9019 irq_set_affinity_hint(phba->sli4_hba.msix_entries[index].
9020 vector, NULL);
James Smart67d12732012-08-03 12:36:13 -04009021 free_irq(phba->sli4_hba.msix_entries[index].vector,
9022 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartacbd8612013-09-06 12:21:19 -04009023 }
James Smartda0436e2009-05-22 14:51:39 -04009024
James Smartda0436e2009-05-22 14:51:39 -04009025 /* Unconfigure MSI-X capability structure */
9026 pci_disable_msix(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009027
9028vec_fail_out:
James Smartda0436e2009-05-22 14:51:39 -04009029 return rc;
9030}
9031
9032/**
9033 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
9034 * @phba: pointer to lpfc hba data structure.
9035 *
9036 * This routine is invoked to release the MSI-X vectors and then disable the
9037 * MSI-X interrupt mode to device with SLI-4 interface spec.
9038 **/
9039static void
9040lpfc_sli4_disable_msix(struct lpfc_hba *phba)
9041{
9042 int index;
9043
9044 /* Free up MSI-X multi-message vectors */
James Smartacbd8612013-09-06 12:21:19 -04009045 for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
9046 irq_set_affinity_hint(phba->sli4_hba.msix_entries[index].
9047 vector, NULL);
James Smartda0436e2009-05-22 14:51:39 -04009048 free_irq(phba->sli4_hba.msix_entries[index].vector,
James Smart67d12732012-08-03 12:36:13 -04009049 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartacbd8612013-09-06 12:21:19 -04009050 }
James Smart1ba981f2014-02-20 09:56:45 -05009051 if (phba->cfg_fof) {
9052 free_irq(phba->sli4_hba.msix_entries[index].vector,
9053 &phba->sli4_hba.fcp_eq_hdl[index]);
9054 }
James Smartda0436e2009-05-22 14:51:39 -04009055 /* Disable MSI-X */
9056 pci_disable_msix(phba->pcidev);
9057
9058 return;
9059}
9060
9061/**
9062 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
9063 * @phba: pointer to lpfc hba data structure.
9064 *
9065 * This routine is invoked to enable the MSI interrupt mode to device with
9066 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
9067 * to enable the MSI vector. The device driver is responsible for calling
9068 * the request_irq() to register MSI vector with a interrupt the handler,
9069 * which is done in this function.
9070 *
9071 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009072 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009073 * other values - error
9074 **/
9075static int
9076lpfc_sli4_enable_msi(struct lpfc_hba *phba)
9077{
9078 int rc, index;
9079
9080 rc = pci_enable_msi(phba->pcidev);
9081 if (!rc)
9082 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9083 "0487 PCI enable MSI mode success.\n");
9084 else {
9085 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9086 "0488 PCI enable MSI mode failed (%d)\n", rc);
9087 return rc;
9088 }
9089
9090 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04009091 0, LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -04009092 if (rc) {
9093 pci_disable_msi(phba->pcidev);
9094 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9095 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -04009096 return rc;
James Smartda0436e2009-05-22 14:51:39 -04009097 }
9098
James Smart67d12732012-08-03 12:36:13 -04009099 for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
James Smartda0436e2009-05-22 14:51:39 -04009100 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9101 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9102 }
9103
James Smart1ba981f2014-02-20 09:56:45 -05009104 if (phba->cfg_fof) {
9105 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9106 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9107 }
James Smart75baf692010-06-08 18:31:21 -04009108 return 0;
James Smartda0436e2009-05-22 14:51:39 -04009109}
9110
9111/**
9112 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
9113 * @phba: pointer to lpfc hba data structure.
9114 *
9115 * This routine is invoked to disable the MSI interrupt mode to device with
9116 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
9117 * done request_irq() on before calling pci_disable_msi(). Failure to do so
9118 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
9119 * its vector.
9120 **/
9121static void
9122lpfc_sli4_disable_msi(struct lpfc_hba *phba)
9123{
9124 free_irq(phba->pcidev->irq, phba);
9125 pci_disable_msi(phba->pcidev);
9126 return;
9127}
9128
9129/**
9130 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
9131 * @phba: pointer to lpfc hba data structure.
9132 *
9133 * This routine is invoked to enable device interrupt and associate driver's
9134 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
9135 * interface spec. Depends on the interrupt mode configured to the driver,
9136 * the driver will try to fallback from the configured interrupt mode to an
9137 * interrupt mode which is supported by the platform, kernel, and device in
9138 * the order of:
9139 * MSI-X -> MSI -> IRQ.
9140 *
9141 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009142 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009143 * other values - error
9144 **/
9145static uint32_t
9146lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9147{
9148 uint32_t intr_mode = LPFC_INTR_ERROR;
9149 int retval, index;
9150
9151 if (cfg_mode == 2) {
9152 /* Preparation before conf_msi mbox cmd */
9153 retval = 0;
9154 if (!retval) {
9155 /* Now, try to enable MSI-X interrupt mode */
9156 retval = lpfc_sli4_enable_msix(phba);
9157 if (!retval) {
9158 /* Indicate initialization to MSI-X mode */
9159 phba->intr_type = MSIX;
9160 intr_mode = 2;
9161 }
9162 }
9163 }
9164
9165 /* Fallback to MSI if MSI-X initialization failed */
9166 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9167 retval = lpfc_sli4_enable_msi(phba);
9168 if (!retval) {
9169 /* Indicate initialization to MSI mode */
9170 phba->intr_type = MSI;
9171 intr_mode = 1;
9172 }
9173 }
9174
9175 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9176 if (phba->intr_type == NONE) {
9177 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
9178 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9179 if (!retval) {
9180 /* Indicate initialization to INTx mode */
9181 phba->intr_type = INTx;
9182 intr_mode = 0;
James Smart67d12732012-08-03 12:36:13 -04009183 for (index = 0; index < phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04009184 index++) {
9185 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9186 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
James Smartba20c852012-08-03 12:36:52 -04009187 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
9188 fcp_eq_in_use, 1);
James Smartda0436e2009-05-22 14:51:39 -04009189 }
James Smart1ba981f2014-02-20 09:56:45 -05009190 if (phba->cfg_fof) {
9191 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9192 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9193 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
9194 fcp_eq_in_use, 1);
9195 }
James Smartda0436e2009-05-22 14:51:39 -04009196 }
9197 }
9198 return intr_mode;
9199}
9200
9201/**
9202 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
9203 * @phba: pointer to lpfc hba data structure.
9204 *
9205 * This routine is invoked to disable device interrupt and disassociate
9206 * the driver's interrupt handler(s) from interrupt vector(s) to device
9207 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
9208 * will release the interrupt vector(s) for the message signaled interrupt.
9209 **/
9210static void
9211lpfc_sli4_disable_intr(struct lpfc_hba *phba)
9212{
9213 /* Disable the currently initialized interrupt mode */
9214 if (phba->intr_type == MSIX)
9215 lpfc_sli4_disable_msix(phba);
9216 else if (phba->intr_type == MSI)
9217 lpfc_sli4_disable_msi(phba);
9218 else if (phba->intr_type == INTx)
9219 free_irq(phba->pcidev->irq, phba);
9220
9221 /* Reset interrupt management states */
9222 phba->intr_type = NONE;
9223 phba->sli.slistat.sli_intr = 0;
9224
9225 return;
9226}
9227
9228/**
James Smart3772a992009-05-22 14:50:54 -04009229 * lpfc_unset_hba - Unset SLI3 hba device initialization
9230 * @phba: pointer to lpfc hba data structure.
9231 *
9232 * This routine is invoked to unset the HBA device initialization steps to
9233 * a device with SLI-3 interface spec.
9234 **/
9235static void
9236lpfc_unset_hba(struct lpfc_hba *phba)
9237{
9238 struct lpfc_vport *vport = phba->pport;
9239 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9240
9241 spin_lock_irq(shost->host_lock);
9242 vport->load_flag |= FC_UNLOADING;
9243 spin_unlock_irq(shost->host_lock);
9244
James Smart72859902012-01-18 16:25:38 -05009245 kfree(phba->vpi_bmask);
9246 kfree(phba->vpi_ids);
9247
James Smart3772a992009-05-22 14:50:54 -04009248 lpfc_stop_hba_timers(phba);
9249
9250 phba->pport->work_port_events = 0;
9251
9252 lpfc_sli_hba_down(phba);
9253
9254 lpfc_sli_brdrestart(phba);
9255
9256 lpfc_sli_disable_intr(phba);
9257
9258 return;
9259}
9260
9261/**
James Smart5af5eee2010-10-22 11:06:38 -04009262 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
9263 * @phba: Pointer to HBA context object.
9264 *
9265 * This function is called in the SLI4 code path to wait for completion
9266 * of device's XRIs exchange busy. It will check the XRI exchange busy
9267 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
9268 * that, it will check the XRI exchange busy on outstanding FCP and ELS
9269 * I/Os every 30 seconds, log error message, and wait forever. Only when
9270 * all XRI exchange busy complete, the driver unload shall proceed with
9271 * invoking the function reset ioctl mailbox command to the CNA and the
9272 * the rest of the driver unload resource release.
9273 **/
9274static void
9275lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
9276{
9277 int wait_time = 0;
9278 int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
9279 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9280
9281 while (!fcp_xri_cmpl || !els_xri_cmpl) {
9282 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
9283 if (!fcp_xri_cmpl)
9284 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9285 "2877 FCP XRI exchange busy "
9286 "wait time: %d seconds.\n",
9287 wait_time/1000);
9288 if (!els_xri_cmpl)
9289 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9290 "2878 ELS XRI exchange busy "
9291 "wait time: %d seconds.\n",
9292 wait_time/1000);
9293 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
9294 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
9295 } else {
9296 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
9297 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
9298 }
9299 fcp_xri_cmpl =
9300 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
9301 els_xri_cmpl =
9302 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9303 }
9304}
9305
9306/**
James Smartda0436e2009-05-22 14:51:39 -04009307 * lpfc_sli4_hba_unset - Unset the fcoe hba
9308 * @phba: Pointer to HBA context object.
9309 *
9310 * This function is called in the SLI4 code path to reset the HBA's FCoE
9311 * function. The caller is not required to hold any lock. This routine
9312 * issues PCI function reset mailbox command to reset the FCoE function.
9313 * At the end of the function, it calls lpfc_hba_down_post function to
9314 * free any pending commands.
9315 **/
9316static void
9317lpfc_sli4_hba_unset(struct lpfc_hba *phba)
9318{
9319 int wait_cnt = 0;
9320 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -04009321 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -04009322
9323 lpfc_stop_hba_timers(phba);
9324 phba->sli4_hba.intr_enable = 0;
9325
9326 /*
9327 * Gracefully wait out the potential current outstanding asynchronous
9328 * mailbox command.
9329 */
9330
9331 /* First, block any pending async mailbox command from posted */
9332 spin_lock_irq(&phba->hbalock);
9333 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
9334 spin_unlock_irq(&phba->hbalock);
9335 /* Now, trying to wait it out if we can */
9336 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9337 msleep(10);
9338 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
9339 break;
9340 }
9341 /* Forcefully release the outstanding mailbox command if timed out */
9342 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9343 spin_lock_irq(&phba->hbalock);
9344 mboxq = phba->sli.mbox_active;
9345 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
9346 __lpfc_mbox_cmpl_put(phba, mboxq);
9347 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9348 phba->sli.mbox_active = NULL;
9349 spin_unlock_irq(&phba->hbalock);
9350 }
9351
James Smart5af5eee2010-10-22 11:06:38 -04009352 /* Abort all iocbs associated with the hba */
9353 lpfc_sli_hba_iocb_abort(phba);
9354
9355 /* Wait for completion of device XRI exchange busy */
9356 lpfc_sli4_xri_exchange_busy_wait(phba);
9357
James Smartda0436e2009-05-22 14:51:39 -04009358 /* Disable PCI subsystem interrupt */
9359 lpfc_sli4_disable_intr(phba);
9360
James Smart912e3ac2011-05-24 11:42:11 -04009361 /* Disable SR-IOV if enabled */
9362 if (phba->cfg_sriov_nr_virtfn)
9363 pci_disable_sriov(pdev);
9364
James Smartda0436e2009-05-22 14:51:39 -04009365 /* Stop kthread signal shall trigger work_done one more time */
9366 kthread_stop(phba->worker_thread);
9367
James Smart3677a3a2010-09-29 11:19:14 -04009368 /* Reset SLI4 HBA FCoE function */
9369 lpfc_pci_function_reset(phba);
James Smart5350d872011-10-10 21:33:49 -04009370 lpfc_sli4_queue_destroy(phba);
James Smart3677a3a2010-09-29 11:19:14 -04009371
James Smartda0436e2009-05-22 14:51:39 -04009372 /* Stop the SLI4 device port */
9373 phba->pport->work_port_events = 0;
9374}
9375
James Smart28baac72010-02-12 14:42:03 -05009376 /**
9377 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
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_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9390{
9391 int rc;
9392 struct lpfc_mqe *mqe;
9393 struct lpfc_pc_sli4_params *sli4_params;
9394 uint32_t mbox_tmo;
9395
9396 rc = 0;
9397 mqe = &mboxq->u.mqe;
9398
9399 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -05009400 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -05009401 if (!phba->sli4_hba.intr_enable)
9402 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9403 else {
James Smarta183a152011-10-10 21:32:43 -04009404 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -05009405 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
9406 }
9407
9408 if (unlikely(rc))
9409 return 1;
9410
9411 sli4_params = &phba->sli4_hba.pc_sli4_params;
9412 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
9413 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
9414 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
9415 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
9416 &mqe->un.sli4_params);
9417 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
9418 &mqe->un.sli4_params);
9419 sli4_params->proto_types = mqe->un.sli4_params.word3;
9420 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
9421 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
9422 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
9423 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
9424 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
9425 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
9426 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
9427 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
9428 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
9429 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
9430 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
9431 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
9432 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
9433 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
9434 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
9435 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
9436 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
9437 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
9438 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
9439 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -04009440
9441 /* Make sure that sge_supp_len can be handled by the driver */
9442 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
9443 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
9444
James Smart28baac72010-02-12 14:42:03 -05009445 return rc;
9446}
9447
James Smartda0436e2009-05-22 14:51:39 -04009448/**
James Smartfedd3b72011-02-16 12:39:24 -05009449 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
9450 * @phba: Pointer to HBA context object.
9451 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9452 *
9453 * This function is called in the SLI4 code path to read the port's
9454 * sli4 capabilities.
9455 *
9456 * This function may be be called from any context that can block-wait
9457 * for the completion. The expectation is that this routine is called
9458 * typically from probe_one or from the online routine.
9459 **/
9460int
9461lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9462{
9463 int rc;
9464 struct lpfc_mqe *mqe = &mboxq->u.mqe;
9465 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -04009466 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -05009467 int length;
9468 struct lpfc_sli4_parameters *mbx_sli4_parameters;
9469
James Smart6d368e52011-05-24 11:44:12 -04009470 /*
9471 * By default, the driver assumes the SLI4 port requires RPI
9472 * header postings. The SLI4_PARAM response will correct this
9473 * assumption.
9474 */
9475 phba->sli4_hba.rpi_hdrs_in_use = 1;
9476
James Smartfedd3b72011-02-16 12:39:24 -05009477 /* Read the port's SLI4 Config Parameters */
9478 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
9479 sizeof(struct lpfc_sli4_cfg_mhdr));
9480 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9481 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
9482 length, LPFC_SLI4_MBX_EMBED);
9483 if (!phba->sli4_hba.intr_enable)
9484 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -04009485 else {
9486 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
9487 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
9488 }
James Smartfedd3b72011-02-16 12:39:24 -05009489 if (unlikely(rc))
9490 return rc;
9491 sli4_params = &phba->sli4_hba.pc_sli4_params;
9492 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
9493 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
9494 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
9495 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
9496 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
9497 mbx_sli4_parameters);
9498 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
9499 mbx_sli4_parameters);
9500 if (bf_get(cfg_phwq, mbx_sli4_parameters))
9501 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
9502 else
9503 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
9504 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
9505 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
James Smart1ba981f2014-02-20 09:56:45 -05009506 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -05009507 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
9508 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
9509 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
9510 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
James Smart0c651872013-07-15 18:33:23 -04009511 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -05009512 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
9513 mbx_sli4_parameters);
9514 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
9515 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -04009516 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
9517 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart05580562011-05-24 11:40:48 -04009518
9519 /* Make sure that sge_supp_len can be handled by the driver */
9520 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
9521 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
9522
James Smartb5c53952016-03-31 14:12:30 -07009523 /*
9524 * Issue IOs with CDB embedded in WQE to minimized the number
9525 * of DMAs the firmware has to do. Setting this to 1 also forces
9526 * the driver to use 128 bytes WQEs for FCP IOs.
9527 */
9528 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
9529 phba->fcp_embed_io = 1;
9530 else
9531 phba->fcp_embed_io = 0;
James Smartfedd3b72011-02-16 12:39:24 -05009532 return 0;
9533}
9534
9535/**
James Smart3772a992009-05-22 14:50:54 -04009536 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
9537 * @pdev: pointer to PCI device
9538 * @pid: pointer to PCI device identifier
9539 *
9540 * This routine is to be called to attach a device with SLI-3 interface spec
9541 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9542 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
9543 * information of the device and driver to see if the driver state that it can
9544 * support this kind of device. If the match is successful, the driver core
9545 * invokes this routine. If this routine determines it can claim the HBA, it
9546 * does all the initialization that it needs to do to handle the HBA properly.
9547 *
9548 * Return code
9549 * 0 - driver can claim the device
9550 * negative value - driver can not claim the device
9551 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009552static int
James Smart3772a992009-05-22 14:50:54 -04009553lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
9554{
9555 struct lpfc_hba *phba;
9556 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -04009557 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -04009558 int error;
9559 uint32_t cfg_mode, intr_mode;
9560
9561 /* Allocate memory for HBA structure */
9562 phba = lpfc_hba_alloc(pdev);
9563 if (!phba)
9564 return -ENOMEM;
9565
9566 /* Perform generic PCI device enabling operation */
9567 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -04009568 if (error)
James Smart3772a992009-05-22 14:50:54 -04009569 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -04009570
9571 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
9572 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
9573 if (error)
9574 goto out_disable_pci_dev;
9575
9576 /* Set up SLI-3 specific device PCI memory space */
9577 error = lpfc_sli_pci_mem_setup(phba);
9578 if (error) {
9579 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9580 "1402 Failed to set up pci memory space.\n");
9581 goto out_disable_pci_dev;
9582 }
9583
9584 /* Set up phase-1 common device driver resources */
9585 error = lpfc_setup_driver_resource_phase1(phba);
9586 if (error) {
9587 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9588 "1403 Failed to set up driver resource.\n");
9589 goto out_unset_pci_mem_s3;
9590 }
9591
9592 /* Set up SLI-3 specific device driver resources */
9593 error = lpfc_sli_driver_resource_setup(phba);
9594 if (error) {
9595 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9596 "1404 Failed to set up driver resource.\n");
9597 goto out_unset_pci_mem_s3;
9598 }
9599
9600 /* Initialize and populate the iocb list per host */
9601 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
9602 if (error) {
9603 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9604 "1405 Failed to initialize iocb list.\n");
9605 goto out_unset_driver_resource_s3;
9606 }
9607
9608 /* Set up common device driver resources */
9609 error = lpfc_setup_driver_resource_phase2(phba);
9610 if (error) {
9611 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9612 "1406 Failed to set up driver resource.\n");
9613 goto out_free_iocb_list;
9614 }
9615
James Smart079b5c92011-08-21 21:48:49 -04009616 /* Get the default values for Model Name and Description */
9617 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
9618
James Smart3772a992009-05-22 14:50:54 -04009619 /* Create SCSI host to the physical port */
9620 error = lpfc_create_shost(phba);
9621 if (error) {
9622 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9623 "1407 Failed to create scsi host.\n");
9624 goto out_unset_driver_resource;
9625 }
9626
9627 /* Configure sysfs attributes */
9628 vport = phba->pport;
9629 error = lpfc_alloc_sysfs_attr(vport);
9630 if (error) {
9631 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9632 "1476 Failed to allocate sysfs attr\n");
9633 goto out_destroy_shost;
9634 }
9635
James Smart6669f9b2009-10-02 15:16:45 -04009636 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -04009637 /* Now, trying to enable interrupt and bring up the device */
9638 cfg_mode = phba->cfg_use_msi;
9639 while (true) {
9640 /* Put device to a known state before enabling interrupt */
9641 lpfc_stop_port(phba);
9642 /* Configure and enable interrupt */
9643 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
9644 if (intr_mode == LPFC_INTR_ERROR) {
9645 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9646 "0431 Failed to enable interrupt.\n");
9647 error = -ENODEV;
9648 goto out_free_sysfs_attr;
9649 }
9650 /* SLI-3 HBA setup */
9651 if (lpfc_sli_hba_setup(phba)) {
9652 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9653 "1477 Failed to set up hba\n");
9654 error = -ENODEV;
9655 goto out_remove_device;
9656 }
9657
9658 /* Wait 50ms for the interrupts of previous mailbox commands */
9659 msleep(50);
9660 /* Check active interrupts on message signaled interrupts */
9661 if (intr_mode == 0 ||
9662 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
9663 /* Log the current active interrupt mode */
9664 phba->intr_mode = intr_mode;
9665 lpfc_log_intr_mode(phba, intr_mode);
9666 break;
9667 } else {
9668 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9669 "0447 Configure interrupt mode (%d) "
9670 "failed active interrupt test.\n",
9671 intr_mode);
9672 /* Disable the current interrupt mode */
9673 lpfc_sli_disable_intr(phba);
9674 /* Try next level of interrupt mode */
9675 cfg_mode = --intr_mode;
9676 }
9677 }
9678
9679 /* Perform post initialization setup */
9680 lpfc_post_init_setup(phba);
9681
9682 /* Check if there are static vports to be created. */
9683 lpfc_create_static_vport(phba);
9684
9685 return 0;
9686
9687out_remove_device:
9688 lpfc_unset_hba(phba);
9689out_free_sysfs_attr:
9690 lpfc_free_sysfs_attr(vport);
9691out_destroy_shost:
9692 lpfc_destroy_shost(phba);
9693out_unset_driver_resource:
9694 lpfc_unset_driver_resource_phase2(phba);
9695out_free_iocb_list:
9696 lpfc_free_iocb_list(phba);
9697out_unset_driver_resource_s3:
9698 lpfc_sli_driver_resource_unset(phba);
9699out_unset_pci_mem_s3:
9700 lpfc_sli_pci_mem_unset(phba);
9701out_disable_pci_dev:
9702 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -04009703 if (shost)
9704 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -04009705out_free_phba:
9706 lpfc_hba_free(phba);
9707 return error;
9708}
9709
9710/**
9711 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -04009712 * @pdev: pointer to PCI device
9713 *
James Smart3772a992009-05-22 14:50:54 -04009714 * This routine is to be called to disattach a device with SLI-3 interface
9715 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9716 * removed from PCI bus, it performs all the necessary cleanup for the HBA
9717 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -04009718 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009719static void
James Smart3772a992009-05-22 14:50:54 -04009720lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -05009721{
James Smart2e0fef82007-06-17 19:56:36 -05009722 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9723 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -05009724 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -05009725 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -05009726 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05009727 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
9728
James Smart549e55c2007-08-02 11:09:51 -04009729 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04009730 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04009731 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05009732
James Smart858c9f62007-06-17 19:56:39 -05009733 lpfc_free_sysfs_attr(vport);
9734
James Smarteada2722008-12-04 22:39:13 -05009735 /* Release all the vports against this physical port */
9736 vports = lpfc_create_vport_work_array(phba);
9737 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -04009738 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9739 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
9740 continue;
James Smarteada2722008-12-04 22:39:13 -05009741 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -04009742 }
James Smarteada2722008-12-04 22:39:13 -05009743 lpfc_destroy_vport_work_array(phba, vports);
9744
9745 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -05009746 fc_remove_host(shost);
9747 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04009748 lpfc_cleanup(vport);
9749
James Smart2e0fef82007-06-17 19:56:36 -05009750 /*
9751 * Bring down the SLI Layer. This step disable all interrupts,
9752 * clears the rings, discards all mailbox commands, and resets
9753 * the HBA.
9754 */
James Smarta257bf92009-04-06 18:48:10 -04009755
Justin P. Mattock48e34d02010-12-30 15:07:58 -08009756 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -05009757 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -04009758 /* Stop kthread signal shall trigger work_done one more time */
9759 kthread_stop(phba->worker_thread);
9760 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -05009761 lpfc_sli_brdrestart(phba);
9762
James Smart72859902012-01-18 16:25:38 -05009763 kfree(phba->vpi_bmask);
9764 kfree(phba->vpi_ids);
9765
James Smart3772a992009-05-22 14:50:54 -04009766 lpfc_stop_hba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05009767 spin_lock_irq(&phba->hbalock);
9768 list_del_init(&vport->listentry);
9769 spin_unlock_irq(&phba->hbalock);
9770
James Smart858c9f62007-06-17 19:56:39 -05009771 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05009772
James Smart912e3ac2011-05-24 11:42:11 -04009773 /* Disable SR-IOV if enabled */
9774 if (phba->cfg_sriov_nr_virtfn)
9775 pci_disable_sriov(pdev);
9776
James Smart5b75da22008-12-04 22:39:35 -05009777 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009778 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -05009779
James Smart858c9f62007-06-17 19:56:39 -05009780 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05009781
9782 /*
9783 * Call scsi_free before mem_free since scsi bufs are released to their
9784 * corresponding pools here.
9785 */
9786 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -04009787 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -05009788
James Smart34b02dc2008-08-24 21:49:55 -04009789 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
9790 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -05009791
James Smart2e0fef82007-06-17 19:56:36 -05009792 /* Free resources associated with SLI2 interface */
9793 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -04009794 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -05009795
9796 /* unmap adapter SLIM and Control Registers */
9797 iounmap(phba->ctrl_regs_memmap_p);
9798 iounmap(phba->slim_memmap_p);
9799
James Smart3772a992009-05-22 14:50:54 -04009800 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -05009801
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05009802 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05009803 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05009804}
9805
Linas Vepstas8d63f372007-02-14 14:28:36 -06009806/**
James Smart3772a992009-05-22 14:50:54 -04009807 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05009808 * @pdev: pointer to PCI device
9809 * @msg: power management message
9810 *
James Smart3772a992009-05-22 14:50:54 -04009811 * This routine is to be called from the kernel's PCI subsystem to support
9812 * system Power Management (PM) to device with SLI-3 interface spec. When
9813 * PM invokes this method, it quiesces the device by stopping the driver's
9814 * worker thread for the device, turning off device's interrupt and DMA,
9815 * and bring the device offline. Note that as the driver implements the
9816 * minimum PM requirements to a power-aware driver's PM support for the
9817 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
9818 * to the suspend() method call will be treated as SUSPEND and the driver will
9819 * fully reinitialize its device during resume() method call, the driver will
9820 * set device to PCI_D3hot state in PCI config space instead of setting it
9821 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -05009822 *
9823 * Return code
James Smart3772a992009-05-22 14:50:54 -04009824 * 0 - driver suspended the device
9825 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05009826 **/
9827static int
James Smart3772a992009-05-22 14:50:54 -04009828lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -05009829{
9830 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9831 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9832
9833 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9834 "0473 PCI device Power Management suspend.\n");
9835
9836 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -04009837 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -05009838 lpfc_offline(phba);
9839 kthread_stop(phba->worker_thread);
9840
9841 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -04009842 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -05009843
9844 /* Save device state to PCI config space */
9845 pci_save_state(pdev);
9846 pci_set_power_state(pdev, PCI_D3hot);
9847
9848 return 0;
9849}
9850
9851/**
James Smart3772a992009-05-22 14:50:54 -04009852 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05009853 * @pdev: pointer to PCI device
9854 *
James Smart3772a992009-05-22 14:50:54 -04009855 * This routine is to be called from the kernel's PCI subsystem to support
9856 * system Power Management (PM) to device with SLI-3 interface spec. When PM
9857 * invokes this method, it restores the device's PCI config space state and
9858 * fully reinitializes the device and brings it online. Note that as the
9859 * driver implements the minimum PM requirements to a power-aware driver's
9860 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
9861 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
9862 * driver will fully reinitialize its device during resume() method call,
9863 * the device will be set to PCI_D0 directly in PCI config space before
9864 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -05009865 *
9866 * Return code
James Smart3772a992009-05-22 14:50:54 -04009867 * 0 - driver suspended the device
9868 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05009869 **/
9870static int
James Smart3772a992009-05-22 14:50:54 -04009871lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -05009872{
9873 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9874 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -05009875 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05009876 int error;
9877
9878 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9879 "0452 PCI device Power Management resume.\n");
9880
9881 /* Restore device state from PCI config space */
9882 pci_set_power_state(pdev, PCI_D0);
9883 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -04009884
James Smart1dfb5a42010-02-12 14:40:50 -05009885 /*
9886 * As the new kernel behavior of pci_restore_state() API call clears
9887 * device saved_state flag, need to save the restored state again.
9888 */
9889 pci_save_state(pdev);
9890
James Smart3a55b532008-12-04 22:38:54 -05009891 if (pdev->is_busmaster)
9892 pci_set_master(pdev);
9893
9894 /* Startup the kernel thread for this host adapter. */
9895 phba->worker_thread = kthread_run(lpfc_do_work, phba,
9896 "lpfc_worker_%d", phba->brd_no);
9897 if (IS_ERR(phba->worker_thread)) {
9898 error = PTR_ERR(phba->worker_thread);
9899 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9900 "0434 PM resume failed to start worker "
9901 "thread: error=x%x.\n", error);
9902 return error;
9903 }
9904
James Smart5b75da22008-12-04 22:39:35 -05009905 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009906 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05009907 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -05009908 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -05009909 "0430 PM resume Failed to enable interrupt\n");
9910 return -EIO;
9911 } else
9912 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05009913
9914 /* Restart HBA and bring it online */
9915 lpfc_sli_brdrestart(phba);
9916 lpfc_online(phba);
9917
James Smart5b75da22008-12-04 22:39:35 -05009918 /* Log the current active interrupt mode */
9919 lpfc_log_intr_mode(phba, phba->intr_mode);
9920
James Smart3a55b532008-12-04 22:38:54 -05009921 return 0;
9922}
9923
9924/**
James Smart891478a2009-11-18 15:40:23 -05009925 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
9926 * @phba: pointer to lpfc hba data structure.
9927 *
9928 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -04009929 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -05009930 **/
9931static void
9932lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
9933{
9934 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9935 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -04009936
9937 /*
9938 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
9939 * and let the SCSI mid-layer to retry them to recover.
9940 */
James Smartdb55fba2014-04-04 13:52:02 -04009941 lpfc_sli_abort_fcp_rings(phba);
James Smart891478a2009-11-18 15:40:23 -05009942}
9943
9944/**
James Smart0d878412009-10-02 15:16:56 -04009945 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
9946 * @phba: pointer to lpfc hba data structure.
9947 *
9948 * This routine is called to prepare the SLI3 device for PCI slot reset. It
9949 * disables the device interrupt and pci device, and aborts the internal FCP
9950 * pending I/Os.
9951 **/
9952static void
9953lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
9954{
James Smart0d878412009-10-02 15:16:56 -04009955 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -05009956 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -04009957
James Smart75baf692010-06-08 18:31:21 -04009958 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -04009959 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -04009960
James Smarte2af0d22010-03-15 11:25:32 -04009961 /* Block all SCSI devices' I/Os on the host */
9962 lpfc_scsi_dev_block(phba);
9963
James Smartea714f32013-04-17 20:18:47 -04009964 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9965 lpfc_sli_flush_fcp_rings(phba);
9966
James Smarte2af0d22010-03-15 11:25:32 -04009967 /* stop all timers */
9968 lpfc_stop_hba_timers(phba);
9969
James Smart0d878412009-10-02 15:16:56 -04009970 /* Disable interrupt and pci device */
9971 lpfc_sli_disable_intr(phba);
9972 pci_disable_device(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -04009973}
9974
9975/**
9976 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
9977 * @phba: pointer to lpfc hba data structure.
9978 *
9979 * This routine is called to prepare the SLI3 device for PCI slot permanently
9980 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
9981 * pending I/Os.
9982 **/
9983static void
James Smart75baf692010-06-08 18:31:21 -04009984lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -04009985{
9986 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -05009987 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -04009988 /* Block all SCSI devices' I/Os on the host */
9989 lpfc_scsi_dev_block(phba);
9990
9991 /* stop all timers */
9992 lpfc_stop_hba_timers(phba);
9993
James Smart0d878412009-10-02 15:16:56 -04009994 /* Clean up all driver's outstanding SCSI I/Os */
9995 lpfc_sli_flush_fcp_rings(phba);
9996}
9997
9998/**
James Smart3772a992009-05-22 14:50:54 -04009999 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -040010000 * @pdev: pointer to PCI device.
10001 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010002 *
James Smart3772a992009-05-22 14:50:54 -040010003 * This routine is called from the PCI subsystem for I/O error handling to
10004 * device with SLI-3 interface spec. This function is called by the PCI
10005 * subsystem after a PCI bus error affecting this device has been detected.
10006 * When this function is invoked, it will need to stop all the I/Os and
10007 * interrupt(s) to the device. Once that is done, it will return
10008 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
10009 * as desired.
James Smarte59058c2008-08-24 21:49:00 -040010010 *
10011 * Return codes
James Smart0d878412009-10-02 15:16:56 -040010012 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -040010013 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10014 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -040010015 **/
James Smart3772a992009-05-22 14:50:54 -040010016static pci_ers_result_t
10017lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010018{
James Smart51ef4c22007-08-02 11:10:31 -040010019 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10020 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010021
James Smart0d878412009-10-02 15:16:56 -040010022 switch (state) {
10023 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -050010024 /* Non-fatal error, prepare for recovery */
10025 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -040010026 return PCI_ERS_RESULT_CAN_RECOVER;
10027 case pci_channel_io_frozen:
10028 /* Fatal error, prepare for slot reset */
10029 lpfc_sli_prep_dev_for_reset(phba);
10030 return PCI_ERS_RESULT_NEED_RESET;
10031 case pci_channel_io_perm_failure:
10032 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -040010033 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010034 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -040010035 default:
10036 /* Unknown state, prepare and request slot reset */
10037 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10038 "0472 Unknown PCI error state: x%x\n", state);
10039 lpfc_sli_prep_dev_for_reset(phba);
10040 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -040010041 }
Linas Vepstas8d63f372007-02-14 14:28:36 -060010042}
10043
10044/**
James Smart3772a992009-05-22 14:50:54 -040010045 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -040010046 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010047 *
James Smart3772a992009-05-22 14:50:54 -040010048 * This routine is called from the PCI subsystem for error handling to
10049 * device with SLI-3 interface spec. This is called after PCI bus has been
10050 * reset to restart the PCI card from scratch, as if from a cold-boot.
10051 * During the PCI subsystem error recovery, after driver returns
10052 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10053 * recovery and then call this routine before calling the .resume method
10054 * to recover the device. This function will initialize the HBA device,
10055 * enable the interrupt, but it will just put the HBA to offline state
10056 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -040010057 *
10058 * Return codes
James Smart3772a992009-05-22 14:50:54 -040010059 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10060 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -060010061 */
James Smart3772a992009-05-22 14:50:54 -040010062static pci_ers_result_t
10063lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010064{
James Smart51ef4c22007-08-02 11:10:31 -040010065 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10066 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010067 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -050010068 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010069
10070 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +110010071 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -060010072 printk(KERN_ERR "lpfc: Cannot re-enable "
10073 "PCI device after reset.\n");
10074 return PCI_ERS_RESULT_DISCONNECT;
10075 }
10076
James Smart97207482008-12-04 22:39:19 -050010077 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050010078
10079 /*
10080 * As the new kernel behavior of pci_restore_state() API call clears
10081 * device saved_state flag, need to save the restored state again.
10082 */
10083 pci_save_state(pdev);
10084
James Smart97207482008-12-04 22:39:19 -050010085 if (pdev->is_busmaster)
10086 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010087
James Smart92d7f7b2007-06-17 19:56:38 -050010088 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040010089 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -050010090 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010091
James Smart5b75da22008-12-04 22:39:35 -050010092 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040010093 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050010094 if (intr_mode == LPFC_INTR_ERROR) {
10095 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10096 "0427 Cannot re-enable interrupt after "
10097 "slot reset.\n");
10098 return PCI_ERS_RESULT_DISCONNECT;
10099 } else
10100 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010101
James Smart75baf692010-06-08 18:31:21 -040010102 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -040010103 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010104 lpfc_offline(phba);
10105 lpfc_sli_brdrestart(phba);
10106
James Smart5b75da22008-12-04 22:39:35 -050010107 /* Log the current active interrupt mode */
10108 lpfc_log_intr_mode(phba, phba->intr_mode);
10109
Linas Vepstas8d63f372007-02-14 14:28:36 -060010110 return PCI_ERS_RESULT_RECOVERED;
10111}
10112
10113/**
James Smart3772a992009-05-22 14:50:54 -040010114 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -040010115 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -060010116 *
James Smart3772a992009-05-22 14:50:54 -040010117 * This routine is called from the PCI subsystem for error handling to device
10118 * with SLI-3 interface spec. It is called when kernel error recovery tells
10119 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10120 * error recovery. After this call, traffic can start to flow from this device
10121 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010122 */
James Smart3772a992009-05-22 14:50:54 -040010123static void
10124lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010125{
James Smart51ef4c22007-08-02 11:10:31 -040010126 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10127 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010128
James Smarte2af0d22010-03-15 11:25:32 -040010129 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -040010130 lpfc_online(phba);
James Smart0d878412009-10-02 15:16:56 -040010131
10132 /* Clean up Advanced Error Reporting (AER) if needed */
10133 if (phba->hba_flag & HBA_AER_ENABLED)
10134 pci_cleanup_aer_uncorrect_error_status(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010135}
10136
James Smart3772a992009-05-22 14:50:54 -040010137/**
James Smartda0436e2009-05-22 14:51:39 -040010138 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
10139 * @phba: pointer to lpfc hba data structure.
10140 *
10141 * returns the number of ELS/CT IOCBs to reserve
10142 **/
10143int
10144lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
10145{
10146 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
10147
James Smartf1126682009-06-10 17:22:44 -040010148 if (phba->sli_rev == LPFC_SLI_REV4) {
10149 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -040010150 return 10;
James Smartf1126682009-06-10 17:22:44 -040010151 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -040010152 return 25;
James Smartf1126682009-06-10 17:22:44 -040010153 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -040010154 return 50;
James Smartf1126682009-06-10 17:22:44 -040010155 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -040010156 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -040010157 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -040010158 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -040010159 else if (max_xri <= 2048)
10160 return 200;
10161 else
10162 return 250;
James Smartf1126682009-06-10 17:22:44 -040010163 } else
10164 return 0;
James Smartda0436e2009-05-22 14:51:39 -040010165}
10166
10167/**
James Smart52d52442011-05-24 11:42:45 -040010168 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -040010169 * @fw: pointer to firmware image returned from request_firmware.
James Smartce396282012-09-29 11:30:56 -040010170 * @phba: pointer to lpfc hba data structure.
James Smart52d52442011-05-24 11:42:45 -040010171 *
James Smart52d52442011-05-24 11:42:45 -040010172 **/
James Smartce396282012-09-29 11:30:56 -040010173static void
10174lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -040010175{
James Smartce396282012-09-29 11:30:56 -040010176 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -050010177 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -040010178 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -040010179 struct list_head dma_buffer_list;
10180 int i, rc = 0;
10181 struct lpfc_dmabuf *dmabuf, *next;
10182 uint32_t offset = 0, temp_offset = 0;
10183
James Smartc71ab862012-10-31 14:44:33 -040010184 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -040010185 if (!fw) {
10186 rc = -ENXIO;
10187 goto out;
10188 }
10189 image = (struct lpfc_grp_hdr *)fw->data;
10190
James Smart52d52442011-05-24 11:42:45 -040010191 INIT_LIST_HEAD(&dma_buffer_list);
James Smart079b5c92011-08-21 21:48:49 -040010192 if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) ||
10193 (bf_get_be32(lpfc_grp_hdr_file_type, image) !=
10194 LPFC_FILE_TYPE_GROUP) ||
10195 (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) ||
10196 (be32_to_cpu(image->size) != fw->size)) {
James Smart52d52442011-05-24 11:42:45 -040010197 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10198 "3022 Invalid FW image found. "
James Smart079b5c92011-08-21 21:48:49 -040010199 "Magic:%x Type:%x ID:%x\n",
10200 be32_to_cpu(image->magic_number),
10201 bf_get_be32(lpfc_grp_hdr_file_type, image),
10202 bf_get_be32(lpfc_grp_hdr_id, image));
James Smartce396282012-09-29 11:30:56 -040010203 rc = -EINVAL;
10204 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010205 }
10206 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -040010207 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -040010208 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartce396282012-09-29 11:30:56 -040010209 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -040010210 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -040010211 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -040010212 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
10213 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
10214 GFP_KERNEL);
10215 if (!dmabuf) {
10216 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040010217 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010218 }
10219 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
10220 SLI4_PAGE_SIZE,
10221 &dmabuf->phys,
10222 GFP_KERNEL);
10223 if (!dmabuf->virt) {
10224 kfree(dmabuf);
10225 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040010226 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010227 }
10228 list_add_tail(&dmabuf->list, &dma_buffer_list);
10229 }
10230 while (offset < fw->size) {
10231 temp_offset = offset;
10232 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -040010233 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -040010234 memcpy(dmabuf->virt,
10235 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -040010236 fw->size - temp_offset);
10237 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -040010238 break;
10239 }
James Smart52d52442011-05-24 11:42:45 -040010240 memcpy(dmabuf->virt, fw->data + temp_offset,
10241 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -040010242 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -040010243 }
10244 rc = lpfc_wr_object(phba, &dma_buffer_list,
10245 (fw->size - offset), &offset);
James Smartce396282012-09-29 11:30:56 -040010246 if (rc)
10247 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010248 }
10249 rc = offset;
10250 }
James Smartce396282012-09-29 11:30:56 -040010251
10252release_out:
James Smart52d52442011-05-24 11:42:45 -040010253 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
10254 list_del(&dmabuf->list);
10255 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
10256 dmabuf->virt, dmabuf->phys);
10257 kfree(dmabuf);
10258 }
James Smartce396282012-09-29 11:30:56 -040010259 release_firmware(fw);
10260out:
10261 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc71ab862012-10-31 14:44:33 -040010262 "3024 Firmware update done: %d.\n", rc);
James Smartce396282012-09-29 11:30:56 -040010263 return;
James Smart52d52442011-05-24 11:42:45 -040010264}
10265
10266/**
James Smartc71ab862012-10-31 14:44:33 -040010267 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
10268 * @phba: pointer to lpfc hba data structure.
10269 *
10270 * This routine is called to perform Linux generic firmware upgrade on device
10271 * that supports such feature.
10272 **/
10273int
10274lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
10275{
10276 uint8_t file_name[ELX_MODEL_NAME_SIZE];
10277 int ret;
10278 const struct firmware *fw;
10279
10280 /* Only supported on SLI4 interface type 2 for now */
10281 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
10282 LPFC_SLI_INTF_IF_TYPE_2)
10283 return -EPERM;
10284
10285 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
10286
10287 if (fw_upgrade == INT_FW_UPGRADE) {
10288 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
10289 file_name, &phba->pcidev->dev,
10290 GFP_KERNEL, (void *)phba,
10291 lpfc_write_firmware);
10292 } else if (fw_upgrade == RUN_FW_UPGRADE) {
10293 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
10294 if (!ret)
10295 lpfc_write_firmware(fw, (void *)phba);
10296 } else {
10297 ret = -EINVAL;
10298 }
10299
10300 return ret;
10301}
10302
10303/**
James Smartda0436e2009-05-22 14:51:39 -040010304 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
10305 * @pdev: pointer to PCI device
10306 * @pid: pointer to PCI device identifier
10307 *
10308 * This routine is called from the kernel's PCI subsystem to device with
10309 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10310 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10311 * information of the device and driver to see if the driver state that it
10312 * can support this kind of device. If the match is successful, the driver
10313 * core invokes this routine. If this routine determines it can claim the HBA,
10314 * it does all the initialization that it needs to do to handle the HBA
10315 * properly.
10316 *
10317 * Return code
10318 * 0 - driver can claim the device
10319 * negative value - driver can not claim the device
10320 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010321static int
James Smartda0436e2009-05-22 14:51:39 -040010322lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
10323{
10324 struct lpfc_hba *phba;
10325 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040010326 struct Scsi_Host *shost = NULL;
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040010327 int error;
James Smartda0436e2009-05-22 14:51:39 -040010328 uint32_t cfg_mode, intr_mode;
James Smart67d12732012-08-03 12:36:13 -040010329 int adjusted_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -040010330
10331 /* Allocate memory for HBA structure */
10332 phba = lpfc_hba_alloc(pdev);
10333 if (!phba)
10334 return -ENOMEM;
10335
10336 /* Perform generic PCI device enabling operation */
10337 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040010338 if (error)
James Smartda0436e2009-05-22 14:51:39 -040010339 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -040010340
10341 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
10342 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
10343 if (error)
10344 goto out_disable_pci_dev;
10345
10346 /* Set up SLI-4 specific device PCI memory space */
10347 error = lpfc_sli4_pci_mem_setup(phba);
10348 if (error) {
10349 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10350 "1410 Failed to set up pci memory space.\n");
10351 goto out_disable_pci_dev;
10352 }
10353
10354 /* Set up phase-1 common device driver resources */
10355 error = lpfc_setup_driver_resource_phase1(phba);
10356 if (error) {
10357 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10358 "1411 Failed to set up driver resource.\n");
10359 goto out_unset_pci_mem_s4;
10360 }
10361
10362 /* Set up SLI-4 Specific device driver resources */
10363 error = lpfc_sli4_driver_resource_setup(phba);
10364 if (error) {
10365 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10366 "1412 Failed to set up driver resource.\n");
10367 goto out_unset_pci_mem_s4;
10368 }
10369
10370 /* Initialize and populate the iocb list per host */
James Smart2a9bf3d2010-06-07 15:24:45 -040010371
10372 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10373 "2821 initialize iocb list %d.\n",
10374 phba->cfg_iocb_cnt*1024);
10375 error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
10376
James Smartda0436e2009-05-22 14:51:39 -040010377 if (error) {
10378 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10379 "1413 Failed to initialize iocb list.\n");
10380 goto out_unset_driver_resource_s4;
10381 }
10382
James Smart19ca7602010-11-20 23:11:55 -050010383 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -040010384 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -050010385
James Smartda0436e2009-05-22 14:51:39 -040010386 /* Set up common device driver resources */
10387 error = lpfc_setup_driver_resource_phase2(phba);
10388 if (error) {
10389 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10390 "1414 Failed to set up driver resource.\n");
10391 goto out_free_iocb_list;
10392 }
10393
James Smart079b5c92011-08-21 21:48:49 -040010394 /* Get the default values for Model Name and Description */
10395 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
10396
James Smartda0436e2009-05-22 14:51:39 -040010397 /* Create SCSI host to the physical port */
10398 error = lpfc_create_shost(phba);
10399 if (error) {
10400 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10401 "1415 Failed to create scsi host.\n");
10402 goto out_unset_driver_resource;
10403 }
10404
10405 /* Configure sysfs attributes */
10406 vport = phba->pport;
10407 error = lpfc_alloc_sysfs_attr(vport);
10408 if (error) {
10409 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10410 "1416 Failed to allocate sysfs attr\n");
10411 goto out_destroy_shost;
10412 }
10413
James Smart6669f9b2009-10-02 15:16:45 -040010414 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -040010415 /* Now, trying to enable interrupt and bring up the device */
10416 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -040010417
James Smart7b15db32013-01-03 15:43:29 -050010418 /* Put device to a known state before enabling interrupt */
10419 lpfc_stop_port(phba);
10420 /* Configure and enable interrupt */
10421 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
10422 if (intr_mode == LPFC_INTR_ERROR) {
10423 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10424 "0426 Failed to enable interrupt.\n");
10425 error = -ENODEV;
10426 goto out_free_sysfs_attr;
James Smartda0436e2009-05-22 14:51:39 -040010427 }
James Smart7b15db32013-01-03 15:43:29 -050010428 /* Default to single EQ for non-MSI-X */
10429 if (phba->intr_type != MSIX)
10430 adjusted_fcp_io_channel = 1;
10431 else
10432 adjusted_fcp_io_channel = phba->cfg_fcp_io_channel;
10433 phba->cfg_fcp_io_channel = adjusted_fcp_io_channel;
10434 /* Set up SLI-4 HBA */
10435 if (lpfc_sli4_hba_setup(phba)) {
10436 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10437 "1421 Failed to set up hba\n");
10438 error = -ENODEV;
10439 goto out_disable_intr;
10440 }
10441
10442 /* Log the current active interrupt mode */
10443 phba->intr_mode = intr_mode;
10444 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -040010445
10446 /* Perform post initialization setup */
10447 lpfc_post_init_setup(phba);
10448
James Smartc71ab862012-10-31 14:44:33 -040010449 /* check for firmware upgrade or downgrade */
10450 if (phba->cfg_request_firmware_upgrade)
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040010451 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -040010452
James Smart1c6834a2009-07-19 10:01:26 -040010453 /* Check if there are static vports to be created. */
10454 lpfc_create_static_vport(phba);
James Smartda0436e2009-05-22 14:51:39 -040010455 return 0;
10456
10457out_disable_intr:
10458 lpfc_sli4_disable_intr(phba);
10459out_free_sysfs_attr:
10460 lpfc_free_sysfs_attr(vport);
10461out_destroy_shost:
10462 lpfc_destroy_shost(phba);
10463out_unset_driver_resource:
10464 lpfc_unset_driver_resource_phase2(phba);
10465out_free_iocb_list:
10466 lpfc_free_iocb_list(phba);
10467out_unset_driver_resource_s4:
10468 lpfc_sli4_driver_resource_unset(phba);
10469out_unset_pci_mem_s4:
10470 lpfc_sli4_pci_mem_unset(phba);
10471out_disable_pci_dev:
10472 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040010473 if (shost)
10474 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -040010475out_free_phba:
10476 lpfc_hba_free(phba);
10477 return error;
10478}
10479
10480/**
10481 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
10482 * @pdev: pointer to PCI device
10483 *
10484 * This routine is called from the kernel's PCI subsystem to device with
10485 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10486 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10487 * device to be removed from the PCI subsystem properly.
10488 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010489static void
James Smartda0436e2009-05-22 14:51:39 -040010490lpfc_pci_remove_one_s4(struct pci_dev *pdev)
10491{
10492 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10493 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
10494 struct lpfc_vport **vports;
10495 struct lpfc_hba *phba = vport->phba;
10496 int i;
10497
10498 /* Mark the device unloading flag */
10499 spin_lock_irq(&phba->hbalock);
10500 vport->load_flag |= FC_UNLOADING;
10501 spin_unlock_irq(&phba->hbalock);
10502
10503 /* Free the HBA sysfs attributes */
10504 lpfc_free_sysfs_attr(vport);
10505
10506 /* Release all the vports against this physical port */
10507 vports = lpfc_create_vport_work_array(phba);
10508 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040010509 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10510 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
10511 continue;
James Smartda0436e2009-05-22 14:51:39 -040010512 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040010513 }
James Smartda0436e2009-05-22 14:51:39 -040010514 lpfc_destroy_vport_work_array(phba, vports);
10515
10516 /* Remove FC host and then SCSI host with the physical port */
10517 fc_remove_host(shost);
10518 scsi_remove_host(shost);
10519
10520 /* Perform cleanup on the physical port */
10521 lpfc_cleanup(vport);
10522
10523 /*
10524 * Bring down the SLI Layer. This step disables all interrupts,
10525 * clears the rings, discards all mailbox commands, and resets
10526 * the HBA FCoE function.
10527 */
10528 lpfc_debugfs_terminate(vport);
10529 lpfc_sli4_hba_unset(phba);
10530
10531 spin_lock_irq(&phba->hbalock);
10532 list_del_init(&vport->listentry);
10533 spin_unlock_irq(&phba->hbalock);
10534
James Smart3677a3a2010-09-29 11:19:14 -040010535 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -040010536 * buffers are released to their corresponding pools here.
10537 */
10538 lpfc_scsi_free(phba);
James Smart67d12732012-08-03 12:36:13 -040010539
James Smartda0436e2009-05-22 14:51:39 -040010540 lpfc_sli4_driver_resource_unset(phba);
10541
10542 /* Unmap adapter Control and Doorbell registers */
10543 lpfc_sli4_pci_mem_unset(phba);
10544
10545 /* Release PCI resources and disable device's PCI function */
10546 scsi_host_put(shost);
10547 lpfc_disable_pci_dev(phba);
10548
10549 /* Finally, free the driver's device data structure */
10550 lpfc_hba_free(phba);
10551
10552 return;
10553}
10554
10555/**
10556 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
10557 * @pdev: pointer to PCI device
10558 * @msg: power management message
10559 *
10560 * This routine is called from the kernel's PCI subsystem to support system
10561 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
10562 * this method, it quiesces the device by stopping the driver's worker
10563 * thread for the device, turning off device's interrupt and DMA, and bring
10564 * the device offline. Note that as the driver implements the minimum PM
10565 * requirements to a power-aware driver's PM support for suspend/resume -- all
10566 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
10567 * method call will be treated as SUSPEND and the driver will fully
10568 * reinitialize its device during resume() method call, the driver will set
10569 * device to PCI_D3hot state in PCI config space instead of setting it
10570 * according to the @msg provided by the PM.
10571 *
10572 * Return code
10573 * 0 - driver suspended the device
10574 * Error otherwise
10575 **/
10576static int
10577lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
10578{
10579 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10580 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10581
10582 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -040010583 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -040010584
10585 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040010586 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -040010587 lpfc_offline(phba);
10588 kthread_stop(phba->worker_thread);
10589
10590 /* Disable interrupt from device */
10591 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040010592 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040010593
10594 /* Save device state to PCI config space */
10595 pci_save_state(pdev);
10596 pci_set_power_state(pdev, PCI_D3hot);
10597
10598 return 0;
10599}
10600
10601/**
10602 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
10603 * @pdev: pointer to PCI device
10604 *
10605 * This routine is called from the kernel's PCI subsystem to support system
10606 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
10607 * this method, it restores the device's PCI config space state and fully
10608 * reinitializes the device and brings it online. Note that as the driver
10609 * implements the minimum PM requirements to a power-aware driver's PM for
10610 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10611 * to the suspend() method call will be treated as SUSPEND and the driver
10612 * will fully reinitialize its device during resume() method call, the device
10613 * will be set to PCI_D0 directly in PCI config space before restoring the
10614 * state.
10615 *
10616 * Return code
10617 * 0 - driver suspended the device
10618 * Error otherwise
10619 **/
10620static int
10621lpfc_pci_resume_one_s4(struct pci_dev *pdev)
10622{
10623 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10624 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10625 uint32_t intr_mode;
10626 int error;
10627
10628 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10629 "0292 PCI device Power Management resume.\n");
10630
10631 /* Restore device state from PCI config space */
10632 pci_set_power_state(pdev, PCI_D0);
10633 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050010634
10635 /*
10636 * As the new kernel behavior of pci_restore_state() API call clears
10637 * device saved_state flag, need to save the restored state again.
10638 */
10639 pci_save_state(pdev);
10640
James Smartda0436e2009-05-22 14:51:39 -040010641 if (pdev->is_busmaster)
10642 pci_set_master(pdev);
10643
10644 /* Startup the kernel thread for this host adapter. */
10645 phba->worker_thread = kthread_run(lpfc_do_work, phba,
10646 "lpfc_worker_%d", phba->brd_no);
10647 if (IS_ERR(phba->worker_thread)) {
10648 error = PTR_ERR(phba->worker_thread);
10649 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10650 "0293 PM resume failed to start worker "
10651 "thread: error=x%x.\n", error);
10652 return error;
10653 }
10654
10655 /* Configure and enable interrupt */
10656 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
10657 if (intr_mode == LPFC_INTR_ERROR) {
10658 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10659 "0294 PM resume Failed to enable interrupt\n");
10660 return -EIO;
10661 } else
10662 phba->intr_mode = intr_mode;
10663
10664 /* Restart HBA and bring it online */
10665 lpfc_sli_brdrestart(phba);
10666 lpfc_online(phba);
10667
10668 /* Log the current active interrupt mode */
10669 lpfc_log_intr_mode(phba, phba->intr_mode);
10670
10671 return 0;
10672}
10673
10674/**
James Smart75baf692010-06-08 18:31:21 -040010675 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
10676 * @phba: pointer to lpfc hba data structure.
10677 *
10678 * This routine is called to prepare the SLI4 device for PCI slot recover. It
10679 * aborts all the outstanding SCSI I/Os to the pci device.
10680 **/
10681static void
10682lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
10683{
James Smart75baf692010-06-08 18:31:21 -040010684 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10685 "2828 PCI channel I/O abort preparing for recovery\n");
10686 /*
10687 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10688 * and let the SCSI mid-layer to retry them to recover.
10689 */
James Smartdb55fba2014-04-04 13:52:02 -040010690 lpfc_sli_abort_fcp_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040010691}
10692
10693/**
10694 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
10695 * @phba: pointer to lpfc hba data structure.
10696 *
10697 * This routine is called to prepare the SLI4 device for PCI slot reset. It
10698 * disables the device interrupt and pci device, and aborts the internal FCP
10699 * pending I/Os.
10700 **/
10701static void
10702lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
10703{
10704 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10705 "2826 PCI channel disable preparing for reset\n");
10706
10707 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040010708 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010709
10710 /* Block all SCSI devices' I/Os on the host */
10711 lpfc_scsi_dev_block(phba);
10712
James Smartea714f32013-04-17 20:18:47 -040010713 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10714 lpfc_sli_flush_fcp_rings(phba);
10715
James Smart75baf692010-06-08 18:31:21 -040010716 /* stop all timers */
10717 lpfc_stop_hba_timers(phba);
10718
10719 /* Disable interrupt and pci device */
10720 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040010721 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -040010722 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -040010723}
10724
10725/**
10726 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
10727 * @phba: pointer to lpfc hba data structure.
10728 *
10729 * This routine is called to prepare the SLI4 device for PCI slot permanently
10730 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10731 * pending I/Os.
10732 **/
10733static void
10734lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
10735{
10736 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10737 "2827 PCI channel permanent disable for failure\n");
10738
10739 /* Block all SCSI devices' I/Os on the host */
10740 lpfc_scsi_dev_block(phba);
10741
10742 /* stop all timers */
10743 lpfc_stop_hba_timers(phba);
10744
10745 /* Clean up all driver's outstanding SCSI I/Os */
10746 lpfc_sli_flush_fcp_rings(phba);
10747}
10748
10749/**
James Smartda0436e2009-05-22 14:51:39 -040010750 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
10751 * @pdev: pointer to PCI device.
10752 * @state: the current PCI connection state.
10753 *
10754 * This routine is called from the PCI subsystem for error handling to device
10755 * with SLI-4 interface spec. This function is called by the PCI subsystem
10756 * after a PCI bus error affecting this device has been detected. When this
10757 * function is invoked, it will need to stop all the I/Os and interrupt(s)
10758 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
10759 * for the PCI subsystem to perform proper recovery as desired.
10760 *
10761 * Return codes
10762 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10763 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10764 **/
10765static pci_ers_result_t
10766lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
10767{
James Smart75baf692010-06-08 18:31:21 -040010768 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10769 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10770
10771 switch (state) {
10772 case pci_channel_io_normal:
10773 /* Non-fatal error, prepare for recovery */
10774 lpfc_sli4_prep_dev_for_recover(phba);
10775 return PCI_ERS_RESULT_CAN_RECOVER;
10776 case pci_channel_io_frozen:
10777 /* Fatal error, prepare for slot reset */
10778 lpfc_sli4_prep_dev_for_reset(phba);
10779 return PCI_ERS_RESULT_NEED_RESET;
10780 case pci_channel_io_perm_failure:
10781 /* Permanent failure, prepare for device down */
10782 lpfc_sli4_prep_dev_for_perm_failure(phba);
10783 return PCI_ERS_RESULT_DISCONNECT;
10784 default:
10785 /* Unknown state, prepare and request slot reset */
10786 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10787 "2825 Unknown PCI error state: x%x\n", state);
10788 lpfc_sli4_prep_dev_for_reset(phba);
10789 return PCI_ERS_RESULT_NEED_RESET;
10790 }
James Smartda0436e2009-05-22 14:51:39 -040010791}
10792
10793/**
10794 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
10795 * @pdev: pointer to PCI device.
10796 *
10797 * This routine is called from the PCI subsystem for error handling to device
10798 * with SLI-4 interface spec. It is called after PCI bus has been reset to
10799 * restart the PCI card from scratch, as if from a cold-boot. During the
10800 * PCI subsystem error recovery, after the driver returns
10801 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10802 * recovery and then call this routine before calling the .resume method to
10803 * recover the device. This function will initialize the HBA device, enable
10804 * the interrupt, but it will just put the HBA to offline state without
10805 * passing any I/O traffic.
10806 *
10807 * Return codes
10808 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10809 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10810 */
10811static pci_ers_result_t
10812lpfc_io_slot_reset_s4(struct pci_dev *pdev)
10813{
James Smart75baf692010-06-08 18:31:21 -040010814 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10815 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10816 struct lpfc_sli *psli = &phba->sli;
10817 uint32_t intr_mode;
10818
10819 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
10820 if (pci_enable_device_mem(pdev)) {
10821 printk(KERN_ERR "lpfc: Cannot re-enable "
10822 "PCI device after reset.\n");
10823 return PCI_ERS_RESULT_DISCONNECT;
10824 }
10825
10826 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040010827
10828 /*
10829 * As the new kernel behavior of pci_restore_state() API call clears
10830 * device saved_state flag, need to save the restored state again.
10831 */
10832 pci_save_state(pdev);
10833
James Smart75baf692010-06-08 18:31:21 -040010834 if (pdev->is_busmaster)
10835 pci_set_master(pdev);
10836
10837 spin_lock_irq(&phba->hbalock);
10838 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
10839 spin_unlock_irq(&phba->hbalock);
10840
10841 /* Configure and enable interrupt */
10842 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
10843 if (intr_mode == LPFC_INTR_ERROR) {
10844 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10845 "2824 Cannot re-enable interrupt after "
10846 "slot reset.\n");
10847 return PCI_ERS_RESULT_DISCONNECT;
10848 } else
10849 phba->intr_mode = intr_mode;
10850
10851 /* Log the current active interrupt mode */
10852 lpfc_log_intr_mode(phba, phba->intr_mode);
10853
James Smartda0436e2009-05-22 14:51:39 -040010854 return PCI_ERS_RESULT_RECOVERED;
10855}
10856
10857/**
10858 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
10859 * @pdev: pointer to PCI device
10860 *
10861 * This routine is called from the PCI subsystem for error handling to device
10862 * with SLI-4 interface spec. It is called when kernel error recovery tells
10863 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10864 * error recovery. After this call, traffic can start to flow from this device
10865 * again.
10866 **/
10867static void
10868lpfc_io_resume_s4(struct pci_dev *pdev)
10869{
James Smart75baf692010-06-08 18:31:21 -040010870 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10871 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10872
10873 /*
10874 * In case of slot reset, as function reset is performed through
10875 * mailbox command which needs DMA to be enabled, this operation
10876 * has to be moved to the io resume phase. Taking device offline
10877 * will perform the necessary cleanup.
10878 */
10879 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
10880 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040010881 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010882 lpfc_offline(phba);
10883 lpfc_sli_brdrestart(phba);
10884 /* Bring the device back online */
10885 lpfc_online(phba);
10886 }
10887
10888 /* Clean up Advanced Error Reporting (AER) if needed */
10889 if (phba->hba_flag & HBA_AER_ENABLED)
10890 pci_cleanup_aer_uncorrect_error_status(pdev);
James Smartda0436e2009-05-22 14:51:39 -040010891}
10892
10893/**
James Smart3772a992009-05-22 14:50:54 -040010894 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
10895 * @pdev: pointer to PCI device
10896 * @pid: pointer to PCI device identifier
10897 *
10898 * This routine is to be registered to the kernel's PCI subsystem. When an
10899 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
10900 * at PCI device-specific information of the device and driver to see if the
10901 * driver state that it can support this kind of device. If the match is
10902 * successful, the driver core invokes this routine. This routine dispatches
10903 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
10904 * do all the initialization that it needs to do to handle the HBA device
10905 * properly.
10906 *
10907 * Return code
10908 * 0 - driver can claim the device
10909 * negative value - driver can not claim the device
10910 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010911static int
James Smart3772a992009-05-22 14:50:54 -040010912lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
10913{
10914 int rc;
James Smart8fa38512009-07-19 10:01:03 -040010915 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040010916
James Smart28baac72010-02-12 14:42:03 -050010917 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040010918 return -ENODEV;
10919
James Smart8fa38512009-07-19 10:01:03 -040010920 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050010921 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040010922 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040010923 else
James Smart3772a992009-05-22 14:50:54 -040010924 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040010925
James Smart3772a992009-05-22 14:50:54 -040010926 return rc;
10927}
10928
10929/**
10930 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
10931 * @pdev: pointer to PCI device
10932 *
10933 * This routine is to be registered to the kernel's PCI subsystem. When an
10934 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
10935 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
10936 * remove routine, which will perform all the necessary cleanup for the
10937 * device to be removed from the PCI subsystem properly.
10938 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010939static void
James Smart3772a992009-05-22 14:50:54 -040010940lpfc_pci_remove_one(struct pci_dev *pdev)
10941{
10942 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10943 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10944
10945 switch (phba->pci_dev_grp) {
10946 case LPFC_PCI_DEV_LP:
10947 lpfc_pci_remove_one_s3(pdev);
10948 break;
James Smartda0436e2009-05-22 14:51:39 -040010949 case LPFC_PCI_DEV_OC:
10950 lpfc_pci_remove_one_s4(pdev);
10951 break;
James Smart3772a992009-05-22 14:50:54 -040010952 default:
10953 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10954 "1424 Invalid PCI device group: 0x%x\n",
10955 phba->pci_dev_grp);
10956 break;
10957 }
10958 return;
10959}
10960
10961/**
10962 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
10963 * @pdev: pointer to PCI device
10964 * @msg: power management message
10965 *
10966 * This routine is to be registered to the kernel's PCI subsystem to support
10967 * system Power Management (PM). When PM invokes this method, it dispatches
10968 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
10969 * suspend the device.
10970 *
10971 * Return code
10972 * 0 - driver suspended the device
10973 * Error otherwise
10974 **/
10975static int
10976lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
10977{
10978 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10979 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10980 int rc = -ENODEV;
10981
10982 switch (phba->pci_dev_grp) {
10983 case LPFC_PCI_DEV_LP:
10984 rc = lpfc_pci_suspend_one_s3(pdev, msg);
10985 break;
James Smartda0436e2009-05-22 14:51:39 -040010986 case LPFC_PCI_DEV_OC:
10987 rc = lpfc_pci_suspend_one_s4(pdev, msg);
10988 break;
James Smart3772a992009-05-22 14:50:54 -040010989 default:
10990 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10991 "1425 Invalid PCI device group: 0x%x\n",
10992 phba->pci_dev_grp);
10993 break;
10994 }
10995 return rc;
10996}
10997
10998/**
10999 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
11000 * @pdev: pointer to PCI device
11001 *
11002 * This routine is to be registered to the kernel's PCI subsystem to support
11003 * system Power Management (PM). When PM invokes this method, it dispatches
11004 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
11005 * resume the device.
11006 *
11007 * Return code
11008 * 0 - driver suspended the device
11009 * Error otherwise
11010 **/
11011static int
11012lpfc_pci_resume_one(struct pci_dev *pdev)
11013{
11014 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11015 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11016 int rc = -ENODEV;
11017
11018 switch (phba->pci_dev_grp) {
11019 case LPFC_PCI_DEV_LP:
11020 rc = lpfc_pci_resume_one_s3(pdev);
11021 break;
James Smartda0436e2009-05-22 14:51:39 -040011022 case LPFC_PCI_DEV_OC:
11023 rc = lpfc_pci_resume_one_s4(pdev);
11024 break;
James Smart3772a992009-05-22 14:50:54 -040011025 default:
11026 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11027 "1426 Invalid PCI device group: 0x%x\n",
11028 phba->pci_dev_grp);
11029 break;
11030 }
11031 return rc;
11032}
11033
11034/**
11035 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
11036 * @pdev: pointer to PCI device.
11037 * @state: the current PCI connection state.
11038 *
11039 * This routine is registered to the PCI subsystem for error handling. This
11040 * function is called by the PCI subsystem after a PCI bus error affecting
11041 * this device has been detected. When this routine is invoked, it dispatches
11042 * the action to the proper SLI-3 or SLI-4 device error detected handling
11043 * routine, which will perform the proper error detected operation.
11044 *
11045 * Return codes
11046 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11047 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11048 **/
11049static pci_ers_result_t
11050lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
11051{
11052 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11053 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11054 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11055
11056 switch (phba->pci_dev_grp) {
11057 case LPFC_PCI_DEV_LP:
11058 rc = lpfc_io_error_detected_s3(pdev, state);
11059 break;
James Smartda0436e2009-05-22 14:51:39 -040011060 case LPFC_PCI_DEV_OC:
11061 rc = lpfc_io_error_detected_s4(pdev, state);
11062 break;
James Smart3772a992009-05-22 14:50:54 -040011063 default:
11064 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11065 "1427 Invalid PCI device group: 0x%x\n",
11066 phba->pci_dev_grp);
11067 break;
11068 }
11069 return rc;
11070}
11071
11072/**
11073 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
11074 * @pdev: pointer to PCI device.
11075 *
11076 * This routine is registered to the PCI subsystem for error handling. This
11077 * function is called after PCI bus has been reset to restart the PCI card
11078 * from scratch, as if from a cold-boot. When this routine is invoked, it
11079 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
11080 * routine, which will perform the proper device reset.
11081 *
11082 * Return codes
11083 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11084 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11085 **/
11086static pci_ers_result_t
11087lpfc_io_slot_reset(struct pci_dev *pdev)
11088{
11089 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11090 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11091 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11092
11093 switch (phba->pci_dev_grp) {
11094 case LPFC_PCI_DEV_LP:
11095 rc = lpfc_io_slot_reset_s3(pdev);
11096 break;
James Smartda0436e2009-05-22 14:51:39 -040011097 case LPFC_PCI_DEV_OC:
11098 rc = lpfc_io_slot_reset_s4(pdev);
11099 break;
James Smart3772a992009-05-22 14:50:54 -040011100 default:
11101 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11102 "1428 Invalid PCI device group: 0x%x\n",
11103 phba->pci_dev_grp);
11104 break;
11105 }
11106 return rc;
11107}
11108
11109/**
11110 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
11111 * @pdev: pointer to PCI device
11112 *
11113 * This routine is registered to the PCI subsystem for error handling. It
11114 * is called when kernel error recovery tells the lpfc driver that it is
11115 * OK to resume normal PCI operation after PCI bus error recovery. When
11116 * this routine is invoked, it dispatches the action to the proper SLI-3
11117 * or SLI-4 device io_resume routine, which will resume the device operation.
11118 **/
11119static void
11120lpfc_io_resume(struct pci_dev *pdev)
11121{
11122 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11123 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11124
11125 switch (phba->pci_dev_grp) {
11126 case LPFC_PCI_DEV_LP:
11127 lpfc_io_resume_s3(pdev);
11128 break;
James Smartda0436e2009-05-22 14:51:39 -040011129 case LPFC_PCI_DEV_OC:
11130 lpfc_io_resume_s4(pdev);
11131 break;
James Smart3772a992009-05-22 14:50:54 -040011132 default:
11133 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11134 "1429 Invalid PCI device group: 0x%x\n",
11135 phba->pci_dev_grp);
11136 break;
11137 }
11138 return;
11139}
11140
James Smart1ba981f2014-02-20 09:56:45 -050011141/**
11142 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
11143 * @phba: pointer to lpfc hba data structure.
11144 *
11145 * This routine checks to see if OAS is supported for this adapter. If
11146 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
11147 * the enable oas flag is cleared and the pool created for OAS device data
11148 * is destroyed.
11149 *
11150 **/
11151void
11152lpfc_sli4_oas_verify(struct lpfc_hba *phba)
11153{
11154
11155 if (!phba->cfg_EnableXLane)
11156 return;
11157
11158 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
11159 phba->cfg_fof = 1;
11160 } else {
James Smartf38fa0b2014-04-04 13:52:21 -040011161 phba->cfg_fof = 0;
James Smart1ba981f2014-02-20 09:56:45 -050011162 if (phba->device_data_mem_pool)
11163 mempool_destroy(phba->device_data_mem_pool);
11164 phba->device_data_mem_pool = NULL;
11165 }
11166
11167 return;
11168}
11169
11170/**
11171 * lpfc_fof_queue_setup - Set up all the fof queues
11172 * @phba: pointer to lpfc hba data structure.
11173 *
11174 * This routine is invoked to set up all the fof queues for the FC HBA
11175 * operation.
11176 *
11177 * Return codes
11178 * 0 - successful
11179 * -ENOMEM - No available memory
11180 **/
11181int
11182lpfc_fof_queue_setup(struct lpfc_hba *phba)
11183{
11184 struct lpfc_sli *psli = &phba->sli;
11185 int rc;
11186
11187 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
11188 if (rc)
11189 return -ENOMEM;
11190
James Smartf38fa0b2014-04-04 13:52:21 -040011191 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050011192
11193 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
11194 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
11195 if (rc)
11196 goto out_oas_cq;
11197
11198 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
11199 phba->sli4_hba.oas_cq, LPFC_FCP);
11200 if (rc)
11201 goto out_oas_wq;
11202
11203 phba->sli4_hba.oas_cq->pring = &psli->ring[LPFC_FCP_OAS_RING];
11204 phba->sli4_hba.oas_ring = &psli->ring[LPFC_FCP_OAS_RING];
11205 }
11206
11207 return 0;
11208
11209out_oas_wq:
James Smartf38fa0b2014-04-04 13:52:21 -040011210 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
James Smart1ba981f2014-02-20 09:56:45 -050011211out_oas_cq:
11212 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
11213 return rc;
11214
11215}
11216
11217/**
11218 * lpfc_fof_queue_create - Create all the fof queues
11219 * @phba: pointer to lpfc hba data structure.
11220 *
11221 * This routine is invoked to allocate all the fof queues for the FC HBA
11222 * operation. For each SLI4 queue type, the parameters such as queue entry
11223 * count (queue depth) shall be taken from the module parameter. For now,
11224 * we just use some constant number as place holder.
11225 *
11226 * Return codes
11227 * 0 - successful
11228 * -ENOMEM - No availble memory
11229 * -EIO - The mailbox failed to complete successfully.
11230 **/
11231int
11232lpfc_fof_queue_create(struct lpfc_hba *phba)
11233{
11234 struct lpfc_queue *qdesc;
11235
11236 /* Create FOF EQ */
11237 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
11238 phba->sli4_hba.eq_ecount);
11239 if (!qdesc)
11240 goto out_error;
11241
11242 phba->sli4_hba.fof_eq = qdesc;
11243
James Smartf38fa0b2014-04-04 13:52:21 -040011244 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050011245
11246 /* Create OAS CQ */
11247 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
11248 phba->sli4_hba.cq_ecount);
11249 if (!qdesc)
11250 goto out_error;
11251
11252 phba->sli4_hba.oas_cq = qdesc;
11253
11254 /* Create OAS WQ */
11255 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
11256 phba->sli4_hba.wq_ecount);
11257 if (!qdesc)
11258 goto out_error;
11259
11260 phba->sli4_hba.oas_wq = qdesc;
11261
11262 }
11263 return 0;
11264
11265out_error:
11266 lpfc_fof_queue_destroy(phba);
11267 return -ENOMEM;
11268}
11269
11270/**
11271 * lpfc_fof_queue_destroy - Destroy all the fof queues
11272 * @phba: pointer to lpfc hba data structure.
11273 *
11274 * This routine is invoked to release all the SLI4 queues with the FC HBA
11275 * operation.
11276 *
11277 * Return codes
11278 * 0 - successful
11279 **/
11280int
11281lpfc_fof_queue_destroy(struct lpfc_hba *phba)
11282{
11283 /* Release FOF Event queue */
11284 if (phba->sli4_hba.fof_eq != NULL) {
11285 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
11286 phba->sli4_hba.fof_eq = NULL;
11287 }
11288
11289 /* Release OAS Completion queue */
11290 if (phba->sli4_hba.oas_cq != NULL) {
11291 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
11292 phba->sli4_hba.oas_cq = NULL;
11293 }
11294
11295 /* Release OAS Work queue */
11296 if (phba->sli4_hba.oas_wq != NULL) {
11297 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
11298 phba->sli4_hba.oas_wq = NULL;
11299 }
11300 return 0;
11301}
11302
dea31012005-04-17 16:05:31 -050011303static struct pci_device_id lpfc_id_table[] = {
11304 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
11305 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -040011306 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
11307 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011308 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
11309 PCI_ANY_ID, PCI_ANY_ID, },
11310 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
11311 PCI_ANY_ID, PCI_ANY_ID, },
11312 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
11313 PCI_ANY_ID, PCI_ANY_ID, },
11314 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
11315 PCI_ANY_ID, PCI_ANY_ID, },
11316 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
11317 PCI_ANY_ID, PCI_ANY_ID, },
11318 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
11319 PCI_ANY_ID, PCI_ANY_ID, },
11320 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
11321 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011322 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
11323 PCI_ANY_ID, PCI_ANY_ID, },
11324 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
11325 PCI_ANY_ID, PCI_ANY_ID, },
11326 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
11327 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011328 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
11329 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011330 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
11331 PCI_ANY_ID, PCI_ANY_ID, },
11332 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
11333 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011334 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
11335 PCI_ANY_ID, PCI_ANY_ID, },
11336 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
11337 PCI_ANY_ID, PCI_ANY_ID, },
11338 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
11339 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -040011340 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
11341 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011342 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
11343 PCI_ANY_ID, PCI_ANY_ID, },
11344 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
11345 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011346 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
11347 PCI_ANY_ID, PCI_ANY_ID, },
11348 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
11349 PCI_ANY_ID, PCI_ANY_ID, },
11350 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
11351 PCI_ANY_ID, PCI_ANY_ID, },
11352 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
11353 PCI_ANY_ID, PCI_ANY_ID, },
11354 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
11355 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011356 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
11357 PCI_ANY_ID, PCI_ANY_ID, },
11358 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
11359 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -040011360 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
11361 PCI_ANY_ID, PCI_ANY_ID, },
11362 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
11363 PCI_ANY_ID, PCI_ANY_ID, },
11364 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
11365 PCI_ANY_ID, PCI_ANY_ID, },
11366 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
11367 PCI_ANY_ID, PCI_ANY_ID, },
11368 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
11369 PCI_ANY_ID, PCI_ANY_ID, },
11370 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
11371 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -040011372 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
11373 PCI_ANY_ID, PCI_ANY_ID, },
11374 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
11375 PCI_ANY_ID, PCI_ANY_ID, },
11376 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
11377 PCI_ANY_ID, PCI_ANY_ID, },
James Smart3772a992009-05-22 14:50:54 -040011378 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
11379 PCI_ANY_ID, PCI_ANY_ID, },
James Smarta747c9c2009-11-18 15:41:10 -050011380 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT,
11381 PCI_ANY_ID, PCI_ANY_ID, },
11382 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON,
James Smart6669f9b2009-10-02 15:16:45 -040011383 PCI_ANY_ID, PCI_ANY_ID, },
James Smart98fc5dd2010-06-07 15:24:29 -040011384 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS,
11385 PCI_ANY_ID, PCI_ANY_ID, },
James Smart085c6472010-11-20 23:11:37 -050011386 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC,
11387 PCI_ANY_ID, PCI_ANY_ID, },
11388 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE,
11389 PCI_ANY_ID, PCI_ANY_ID, },
James Smartc0c11512011-05-24 11:41:34 -040011390 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF,
11391 PCI_ANY_ID, PCI_ANY_ID, },
11392 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF,
11393 PCI_ANY_ID, PCI_ANY_ID, },
James Smartd38dd522015-08-31 16:48:17 -040011394 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_G6_FC,
11395 PCI_ANY_ID, PCI_ANY_ID, },
James Smartf8cafd32012-08-03 12:42:51 -040011396 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK,
11397 PCI_ANY_ID, PCI_ANY_ID, },
11398 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF,
11399 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011400 { 0 }
11401};
11402
11403MODULE_DEVICE_TABLE(pci, lpfc_id_table);
11404
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070011405static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060011406 .error_detected = lpfc_io_error_detected,
11407 .slot_reset = lpfc_io_slot_reset,
11408 .resume = lpfc_io_resume,
11409};
11410
dea31012005-04-17 16:05:31 -050011411static struct pci_driver lpfc_driver = {
11412 .name = LPFC_DRIVER_NAME,
11413 .id_table = lpfc_id_table,
11414 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011415 .remove = lpfc_pci_remove_one,
James Smart3a55b532008-12-04 22:38:54 -050011416 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040011417 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050011418 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050011419};
11420
James Smart3ef6d242012-01-18 16:23:48 -050011421static const struct file_operations lpfc_mgmt_fop = {
Al Viro858feac2013-04-14 22:39:37 -040011422 .owner = THIS_MODULE,
James Smart3ef6d242012-01-18 16:23:48 -050011423};
11424
11425static struct miscdevice lpfc_mgmt_dev = {
11426 .minor = MISC_DYNAMIC_MINOR,
11427 .name = "lpfcmgmt",
11428 .fops = &lpfc_mgmt_fop,
11429};
11430
James Smarte59058c2008-08-24 21:49:00 -040011431/**
James Smart3621a712009-04-06 18:47:14 -040011432 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040011433 *
11434 * This routine is to be invoked when the lpfc module is loaded into the
11435 * kernel. The special kernel macro module_init() is used to indicate the
11436 * role of this routine to the kernel as lpfc module entry point.
11437 *
11438 * Return codes
11439 * 0 - successful
11440 * -ENOMEM - FC attach transport failed
11441 * all others - failed
11442 */
dea31012005-04-17 16:05:31 -050011443static int __init
11444lpfc_init(void)
11445{
James Smart7bb03bb2013-04-17 20:19:16 -040011446 int cpu;
dea31012005-04-17 16:05:31 -050011447 int error = 0;
11448
11449 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040011450 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050011451
James Smart3ef6d242012-01-18 16:23:48 -050011452 error = misc_register(&lpfc_mgmt_dev);
11453 if (error)
11454 printk(KERN_ERR "Could not register lpfcmgmt device, "
11455 "misc_register returned with status %d", error);
11456
James Smart7ee5d432007-10-27 13:37:17 -040011457 if (lpfc_enable_npiv) {
11458 lpfc_transport_functions.vport_create = lpfc_vport_create;
11459 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
11460 }
dea31012005-04-17 16:05:31 -050011461 lpfc_transport_template =
11462 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040011463 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050011464 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040011465 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -040011466 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -040011467 fc_attach_transport(&lpfc_vport_transport_functions);
11468 if (lpfc_vport_transport_template == NULL) {
11469 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040011470 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -040011471 }
James Smart7ee5d432007-10-27 13:37:17 -040011472 }
James Smart7bb03bb2013-04-17 20:19:16 -040011473
11474 /* Initialize in case vector mapping is needed */
James Smartb246de12013-05-31 17:03:07 -040011475 lpfc_used_cpu = NULL;
11476 lpfc_present_cpu = 0;
11477 for_each_present_cpu(cpu)
11478 lpfc_present_cpu++;
James Smart7bb03bb2013-04-17 20:19:16 -040011479
dea31012005-04-17 16:05:31 -050011480 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050011481 if (error) {
dea31012005-04-17 16:05:31 -050011482 fc_release_transport(lpfc_transport_template);
James Smartd7c255b2008-08-24 21:50:00 -040011483 if (lpfc_enable_npiv)
11484 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050011485 }
dea31012005-04-17 16:05:31 -050011486
11487 return error;
11488}
11489
James Smarte59058c2008-08-24 21:49:00 -040011490/**
James Smart3621a712009-04-06 18:47:14 -040011491 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040011492 *
11493 * This routine is invoked when the lpfc module is removed from the kernel.
11494 * The special kernel macro module_exit() is used to indicate the role of
11495 * this routine to the kernel as lpfc module exit point.
11496 */
dea31012005-04-17 16:05:31 -050011497static void __exit
11498lpfc_exit(void)
11499{
James Smart3ef6d242012-01-18 16:23:48 -050011500 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050011501 pci_unregister_driver(&lpfc_driver);
11502 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040011503 if (lpfc_enable_npiv)
11504 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050011505 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040011506 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
11507 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050011508 (1L << _dump_buf_data_order), _dump_buf_data);
11509 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
11510 }
11511
11512 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040011513 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
11514 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050011515 (1L << _dump_buf_dif_order), _dump_buf_dif);
11516 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
11517 }
James Smartb246de12013-05-31 17:03:07 -040011518 kfree(lpfc_used_cpu);
Johannes Thumshirn79739672015-08-31 16:48:11 -040011519 idr_destroy(&lpfc_hba_index);
dea31012005-04-17 16:05:31 -050011520}
11521
11522module_init(lpfc_init);
11523module_exit(lpfc_exit);
11524MODULE_LICENSE("GPL");
11525MODULE_DESCRIPTION(LPFC_MODULE_DESC);
11526MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
11527MODULE_VERSION("0:" LPFC_DRIVER_VERSION);