blob: bb514d2262cfa69864b5cc61468a8effd62c3fff [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,
James Smart65791f12016-07-06 12:35:56 -0700571 jiffies + msecs_to_jiffies(1000 * phba->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
James Smart65791f12016-07-06 12:35:56 -07001590 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1591 LPFC_SLI_INTF_IF_TYPE_2) {
1592 /*
1593 * On error status condition, driver need to wait for port
1594 * ready before performing reset.
1595 */
1596 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1597 if (!rc)
1598 return rc;
James Smart618a5232012-06-12 13:54:36 -04001599 }
James Smart65791f12016-07-06 12:35:56 -07001600 /* need reset: attempt for port recovery */
1601 if (en_rn_msg)
1602 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1603 "2887 Reset Needed: Attempting Port "
1604 "Recovery...\n");
1605 lpfc_offline_prep(phba, mbx_action);
1606 lpfc_offline(phba);
1607 /* release interrupt for possible resource change */
1608 lpfc_sli4_disable_intr(phba);
1609 lpfc_sli_brdrestart(phba);
1610 /* request and enable interrupt */
1611 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1612 if (intr_mode == LPFC_INTR_ERROR) {
1613 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1614 "3175 Failed to enable interrupt\n");
1615 return -EIO;
1616 }
1617 phba->intr_mode = intr_mode;
1618 rc = lpfc_online(phba);
1619 if (rc == 0)
1620 lpfc_unblock_mgmt_io(phba);
1621
James Smart618a5232012-06-12 13:54:36 -04001622 return rc;
1623}
1624
1625/**
James Smartda0436e2009-05-22 14:51:39 -04001626 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1627 * @phba: pointer to lpfc hba data structure.
1628 *
1629 * This routine is invoked to handle the SLI4 HBA hardware error attention
1630 * conditions.
1631 **/
1632static void
1633lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1634{
1635 struct lpfc_vport *vport = phba->pport;
1636 uint32_t event_data;
1637 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001638 uint32_t if_type;
James Smart2e90f4b2011-12-13 13:22:37 -05001639 struct lpfc_register portstat_reg = {0};
1640 uint32_t reg_err1, reg_err2;
1641 uint32_t uerrlo_reg, uemasklo_reg;
James Smart65791f12016-07-06 12:35:56 -07001642 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
James Smarte10b2022014-02-20 09:57:43 -05001643 bool en_rn_msg = true;
James Smart946727d2015-04-07 15:07:09 -04001644 struct temp_event temp_event_data;
James Smart65791f12016-07-06 12:35:56 -07001645 struct lpfc_register portsmphr_reg;
1646 int rc, i;
James Smartda0436e2009-05-22 14:51:39 -04001647
1648 /* If the pci channel is offline, ignore possible errors, since
1649 * we cannot communicate with the pci card anyway.
1650 */
1651 if (pci_channel_offline(phba->pcidev))
1652 return;
James Smartda0436e2009-05-22 14:51:39 -04001653
James Smart65791f12016-07-06 12:35:56 -07001654 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
James Smart2fcee4b2010-12-15 17:57:46 -05001655 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1656 switch (if_type) {
1657 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart2e90f4b2011-12-13 13:22:37 -05001658 pci_rd_rc1 = lpfc_readl(
1659 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1660 &uerrlo_reg);
1661 pci_rd_rc2 = lpfc_readl(
1662 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1663 &uemasklo_reg);
1664 /* consider PCI bus read error as pci_channel_offline */
1665 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1666 return;
James Smart65791f12016-07-06 12:35:56 -07001667 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
1668 lpfc_sli4_offline_eratt(phba);
1669 return;
1670 }
1671 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1672 "7623 Checking UE recoverable");
1673
1674 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
1675 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1676 &portsmphr_reg.word0))
1677 continue;
1678
1679 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
1680 &portsmphr_reg);
1681 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1682 LPFC_PORT_SEM_UE_RECOVERABLE)
1683 break;
1684 /*Sleep for 1Sec, before checking SEMAPHORE */
1685 msleep(1000);
1686 }
1687
1688 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1689 "4827 smphr_port_status x%x : Waited %dSec",
1690 smphr_port_status, i);
1691
1692 /* Recoverable UE, reset the HBA device */
1693 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1694 LPFC_PORT_SEM_UE_RECOVERABLE) {
1695 for (i = 0; i < 20; i++) {
1696 msleep(1000);
1697 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1698 &portsmphr_reg.word0) &&
1699 (LPFC_POST_STAGE_PORT_READY ==
1700 bf_get(lpfc_port_smphr_port_status,
1701 &portsmphr_reg))) {
1702 rc = lpfc_sli4_port_sta_fn_reset(phba,
1703 LPFC_MBX_NO_WAIT, en_rn_msg);
1704 if (rc == 0)
1705 return;
1706 lpfc_printf_log(phba,
1707 KERN_ERR, LOG_INIT,
1708 "4215 Failed to recover UE");
1709 break;
1710 }
1711 }
1712 }
1713 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1714 "7624 Firmware not ready: Failing UE recovery,"
1715 " waited %dSec", i);
James Smart2fcee4b2010-12-15 17:57:46 -05001716 lpfc_sli4_offline_eratt(phba);
1717 break;
James Smart946727d2015-04-07 15:07:09 -04001718
James Smart2fcee4b2010-12-15 17:57:46 -05001719 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2e90f4b2011-12-13 13:22:37 -05001720 pci_rd_rc1 = lpfc_readl(
1721 phba->sli4_hba.u.if_type2.STATUSregaddr,
1722 &portstat_reg.word0);
1723 /* consider PCI bus read error as pci_channel_offline */
James Smart6b5151f2012-01-18 16:24:06 -05001724 if (pci_rd_rc1 == -EIO) {
1725 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1726 "3151 PCI bus read access failure: x%x\n",
1727 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
James Smart2e90f4b2011-12-13 13:22:37 -05001728 return;
James Smart6b5151f2012-01-18 16:24:06 -05001729 }
James Smart2e90f4b2011-12-13 13:22:37 -05001730 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1731 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
James Smart2fcee4b2010-12-15 17:57:46 -05001732 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
James Smart2fcee4b2010-12-15 17:57:46 -05001733 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1734 "2889 Port Overtemperature event, "
James Smart946727d2015-04-07 15:07:09 -04001735 "taking port offline Data: x%x x%x\n",
1736 reg_err1, reg_err2);
1737
James Smart310429e2016-07-06 12:35:54 -07001738 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04001739 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1740 temp_event_data.event_code = LPFC_CRIT_TEMP;
1741 temp_event_data.data = 0xFFFFFFFF;
1742
1743 shost = lpfc_shost_from_vport(phba->pport);
1744 fc_host_post_vendor_event(shost, fc_get_event_number(),
1745 sizeof(temp_event_data),
1746 (char *)&temp_event_data,
1747 SCSI_NL_VID_TYPE_PCI
1748 | PCI_VENDOR_ID_EMULEX);
1749
James Smart2fcee4b2010-12-15 17:57:46 -05001750 spin_lock_irq(&phba->hbalock);
1751 phba->over_temp_state = HBA_OVER_TEMP;
1752 spin_unlock_irq(&phba->hbalock);
1753 lpfc_sli4_offline_eratt(phba);
James Smart946727d2015-04-07 15:07:09 -04001754 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001755 }
James Smart2e90f4b2011-12-13 13:22:37 -05001756 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smarte10b2022014-02-20 09:57:43 -05001757 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
James Smart2e90f4b2011-12-13 13:22:37 -05001758 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte10b2022014-02-20 09:57:43 -05001759 "3143 Port Down: Firmware Update "
1760 "Detected\n");
1761 en_rn_msg = false;
1762 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smart2e90f4b2011-12-13 13:22:37 -05001763 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1764 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1765 "3144 Port Down: Debug Dump\n");
1766 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1767 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1768 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1769 "3145 Port Down: Provisioning\n");
James Smart618a5232012-06-12 13:54:36 -04001770
James Smart946727d2015-04-07 15:07:09 -04001771 /* If resets are disabled then leave the HBA alone and return */
1772 if (!phba->cfg_enable_hba_reset)
1773 return;
1774
James Smart618a5232012-06-12 13:54:36 -04001775 /* Check port status register for function reset */
James Smarte10b2022014-02-20 09:57:43 -05001776 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1777 en_rn_msg);
James Smart618a5232012-06-12 13:54:36 -04001778 if (rc == 0) {
1779 /* don't report event on forced debug dump */
1780 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1781 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1782 return;
1783 else
1784 break;
James Smart2fcee4b2010-12-15 17:57:46 -05001785 }
James Smart618a5232012-06-12 13:54:36 -04001786 /* fall through for not able to recover */
James Smart6b5151f2012-01-18 16:24:06 -05001787 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1788 "3152 Unrecoverable error, bring the port "
1789 "offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05001790 lpfc_sli4_offline_eratt(phba);
1791 break;
1792 case LPFC_SLI_INTF_IF_TYPE_1:
1793 default:
1794 break;
1795 }
James Smart2e90f4b2011-12-13 13:22:37 -05001796 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1797 "3123 Report dump event to upper layer\n");
1798 /* Send an internal error event to mgmt application */
1799 lpfc_board_errevt_to_mgmt(phba);
1800
1801 event_data = FC_REG_DUMP_EVENT;
1802 shost = lpfc_shost_from_vport(vport);
1803 fc_host_post_vendor_event(shost, fc_get_event_number(),
1804 sizeof(event_data), (char *) &event_data,
1805 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
James Smartda0436e2009-05-22 14:51:39 -04001806}
1807
1808/**
1809 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1810 * @phba: pointer to lpfc HBA data structure.
1811 *
1812 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1813 * routine from the API jump table function pointer from the lpfc_hba struct.
1814 *
1815 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001816 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001817 * Any other value - error.
1818 **/
1819void
1820lpfc_handle_eratt(struct lpfc_hba *phba)
1821{
1822 (*phba->lpfc_handle_eratt)(phba);
1823}
1824
1825/**
James Smart3621a712009-04-06 18:47:14 -04001826 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04001827 * @phba: pointer to lpfc hba data structure.
1828 *
1829 * This routine is invoked from the worker thread to handle a HBA host
1830 * attention link event.
1831 **/
dea31012005-04-17 16:05:31 -05001832void
James Smart2e0fef82007-06-17 19:56:36 -05001833lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001834{
James Smart2e0fef82007-06-17 19:56:36 -05001835 struct lpfc_vport *vport = phba->pport;
1836 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001837 LPFC_MBOXQ_t *pmb;
1838 volatile uint32_t control;
1839 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05001840 int rc = 0;
dea31012005-04-17 16:05:31 -05001841
1842 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001843 if (!pmb) {
1844 rc = 1;
dea31012005-04-17 16:05:31 -05001845 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05001846 }
dea31012005-04-17 16:05:31 -05001847
1848 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001849 if (!mp) {
1850 rc = 2;
dea31012005-04-17 16:05:31 -05001851 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05001852 }
dea31012005-04-17 16:05:31 -05001853
1854 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05001855 if (!mp->virt) {
1856 rc = 3;
dea31012005-04-17 16:05:31 -05001857 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05001858 }
dea31012005-04-17 16:05:31 -05001859
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001860 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04001861 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05001862
1863 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05001864 lpfc_read_topology(phba, pmb, mp);
1865 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05001866 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04001867 /* Block ELS IOCBs until we have processed this mbox command */
1868 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04001869 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05001870 if (rc == MBX_NOT_FINISHED) {
1871 rc = 4;
James Smart14691152006-12-02 13:34:28 -05001872 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05001873 }
dea31012005-04-17 16:05:31 -05001874
1875 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05001876 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001877 writel(HA_LATT, phba->HAregaddr);
1878 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001879 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001880
1881 return;
1882
James Smart14691152006-12-02 13:34:28 -05001883lpfc_handle_latt_free_mbuf:
James Smart0d2b6b82008-06-14 22:52:47 -04001884 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05001885 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05001886lpfc_handle_latt_free_mp:
1887 kfree(mp);
1888lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04001889 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001890lpfc_handle_latt_err_exit:
1891 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001892 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001893 psli->sli_flag |= LPFC_PROCESS_LA;
1894 control = readl(phba->HCregaddr);
1895 control |= HC_LAINT_ENA;
1896 writel(control, phba->HCregaddr);
1897 readl(phba->HCregaddr); /* flush */
1898
1899 /* Clear Link Attention in HA REG */
1900 writel(HA_LATT, phba->HAregaddr);
1901 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001902 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001903 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001904 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001905
James Smart09372822008-01-11 01:52:54 -05001906 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1907 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05001908
1909 return;
1910}
1911
James Smarte59058c2008-08-24 21:49:00 -04001912/**
James Smart3621a712009-04-06 18:47:14 -04001913 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04001914 * @phba: pointer to lpfc hba data structure.
1915 * @vpd: pointer to the vital product data.
1916 * @len: length of the vital product data in bytes.
1917 *
1918 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1919 * an array of characters. In this routine, the ModelName, ProgramType, and
1920 * ModelDesc, etc. fields of the phba data structure will be populated.
1921 *
1922 * Return codes
1923 * 0 - pointer to the VPD passed in is NULL
1924 * 1 - success
1925 **/
James Smart3772a992009-05-22 14:50:54 -04001926int
James Smart2e0fef82007-06-17 19:56:36 -05001927lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05001928{
1929 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05001930 int Length;
dea31012005-04-17 16:05:31 -05001931 int i, j;
1932 int finished = 0;
1933 int index = 0;
1934
1935 if (!vpd)
1936 return 0;
1937
1938 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05001939 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001940 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001941 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
1942 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001943 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05001944 switch (vpd[index]) {
1945 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001946 case 0x91:
dea31012005-04-17 16:05:31 -05001947 index += 1;
1948 lenlo = vpd[index];
1949 index += 1;
1950 lenhi = vpd[index];
1951 index += 1;
1952 i = ((((unsigned short)lenhi) << 8) + lenlo);
1953 index += i;
1954 break;
1955 case 0x90:
1956 index += 1;
1957 lenlo = vpd[index];
1958 index += 1;
1959 lenhi = vpd[index];
1960 index += 1;
1961 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001962 if (Length > len - index)
1963 Length = len - index;
dea31012005-04-17 16:05:31 -05001964 while (Length > 0) {
1965 /* Look for Serial Number */
1966 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
1967 index += 2;
1968 i = vpd[index];
1969 index += 1;
1970 j = 0;
1971 Length -= (3+i);
1972 while(i--) {
1973 phba->SerialNumber[j++] = vpd[index++];
1974 if (j == 31)
1975 break;
1976 }
1977 phba->SerialNumber[j] = 0;
1978 continue;
1979 }
1980 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
1981 phba->vpd_flag |= VPD_MODEL_DESC;
1982 index += 2;
1983 i = vpd[index];
1984 index += 1;
1985 j = 0;
1986 Length -= (3+i);
1987 while(i--) {
1988 phba->ModelDesc[j++] = vpd[index++];
1989 if (j == 255)
1990 break;
1991 }
1992 phba->ModelDesc[j] = 0;
1993 continue;
1994 }
1995 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
1996 phba->vpd_flag |= VPD_MODEL_NAME;
1997 index += 2;
1998 i = vpd[index];
1999 index += 1;
2000 j = 0;
2001 Length -= (3+i);
2002 while(i--) {
2003 phba->ModelName[j++] = vpd[index++];
2004 if (j == 79)
2005 break;
2006 }
2007 phba->ModelName[j] = 0;
2008 continue;
2009 }
2010 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2011 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2012 index += 2;
2013 i = vpd[index];
2014 index += 1;
2015 j = 0;
2016 Length -= (3+i);
2017 while(i--) {
2018 phba->ProgramType[j++] = vpd[index++];
2019 if (j == 255)
2020 break;
2021 }
2022 phba->ProgramType[j] = 0;
2023 continue;
2024 }
2025 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2026 phba->vpd_flag |= VPD_PORT;
2027 index += 2;
2028 i = vpd[index];
2029 index += 1;
2030 j = 0;
2031 Length -= (3+i);
2032 while(i--) {
James Smartcd1c8302011-10-10 21:33:25 -04002033 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2034 (phba->sli4_hba.pport_name_sta ==
2035 LPFC_SLI4_PPNAME_GET)) {
2036 j++;
2037 index++;
2038 } else
2039 phba->Port[j++] = vpd[index++];
2040 if (j == 19)
2041 break;
dea31012005-04-17 16:05:31 -05002042 }
James Smartcd1c8302011-10-10 21:33:25 -04002043 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2044 (phba->sli4_hba.pport_name_sta ==
2045 LPFC_SLI4_PPNAME_NON))
2046 phba->Port[j] = 0;
dea31012005-04-17 16:05:31 -05002047 continue;
2048 }
2049 else {
2050 index += 2;
2051 i = vpd[index];
2052 index += 1;
2053 index += i;
2054 Length -= (3 + i);
2055 }
2056 }
2057 finished = 0;
2058 break;
2059 case 0x78:
2060 finished = 1;
2061 break;
2062 default:
2063 index ++;
2064 break;
2065 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002066 }
dea31012005-04-17 16:05:31 -05002067
2068 return(1);
2069}
2070
James Smarte59058c2008-08-24 21:49:00 -04002071/**
James Smart3621a712009-04-06 18:47:14 -04002072 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04002073 * @phba: pointer to lpfc hba data structure.
2074 * @mdp: pointer to the data structure to hold the derived model name.
2075 * @descp: pointer to the data structure to hold the derived description.
2076 *
2077 * This routine retrieves HBA's description based on its registered PCI device
2078 * ID. The @descp passed into this function points to an array of 256 chars. It
2079 * shall be returned with the model name, maximum speed, and the host bus type.
2080 * The @mdp passed into this function points to an array of 80 chars. When the
2081 * function returns, the @mdp will be filled with the model name.
2082 **/
dea31012005-04-17 16:05:31 -05002083static void
James Smart2e0fef82007-06-17 19:56:36 -05002084lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05002085{
2086 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05002087 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002088 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04002089 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04002090 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002091 struct {
James Smarta747c9c2009-11-18 15:41:10 -05002092 char *name;
2093 char *bus;
2094 char *function;
2095 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002096
2097 if (mdp && mdp[0] != '\0'
2098 && descp && descp[0] != '\0')
2099 return;
2100
James Smartd38dd522015-08-31 16:48:17 -04002101 if (phba->lmt & LMT_32Gb)
2102 max_speed = 32;
2103 else if (phba->lmt & LMT_16Gb)
James Smartc0c11512011-05-24 11:41:34 -04002104 max_speed = 16;
2105 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002106 max_speed = 10;
2107 else if (phba->lmt & LMT_8Gb)
2108 max_speed = 8;
2109 else if (phba->lmt & LMT_4Gb)
2110 max_speed = 4;
2111 else if (phba->lmt & LMT_2Gb)
2112 max_speed = 2;
James Smart4169d862012-09-29 11:32:09 -04002113 else if (phba->lmt & LMT_1Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002114 max_speed = 1;
James Smart4169d862012-09-29 11:32:09 -04002115 else
2116 max_speed = 0;
dea31012005-04-17 16:05:31 -05002117
2118 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05002119
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002120 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002121 case PCI_DEVICE_ID_FIREFLY:
James Smart12222f42014-05-21 08:05:19 -04002122 m = (typeof(m)){"LP6000", "PCI",
2123 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002124 break;
dea31012005-04-17 16:05:31 -05002125 case PCI_DEVICE_ID_SUPERFLY:
2126 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart12222f42014-05-21 08:05:19 -04002127 m = (typeof(m)){"LP7000", "PCI", ""};
dea31012005-04-17 16:05:31 -05002128 else
James Smart12222f42014-05-21 08:05:19 -04002129 m = (typeof(m)){"LP7000E", "PCI", ""};
2130 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002131 break;
2132 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002133 m = (typeof(m)){"LP8000", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002134 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002135 break;
2136 case PCI_DEVICE_ID_CENTAUR:
2137 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart12222f42014-05-21 08:05:19 -04002138 m = (typeof(m)){"LP9002", "PCI", ""};
dea31012005-04-17 16:05:31 -05002139 else
James Smart12222f42014-05-21 08:05:19 -04002140 m = (typeof(m)){"LP9000", "PCI", ""};
2141 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002142 break;
2143 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002144 m = (typeof(m)){"LP952", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002145 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002146 break;
2147 case PCI_DEVICE_ID_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05002148 m = (typeof(m)){"LP9802", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002149 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002150 break;
2151 case PCI_DEVICE_ID_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05002152 m = (typeof(m)){"LP10000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002153 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002154 break;
2155 case PCI_DEVICE_ID_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05002156 m = (typeof(m)){"LPX1000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002157 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002158 break;
2159 case PCI_DEVICE_ID_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002160 m = (typeof(m)){"LP982", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002161 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002162 break;
2163 case PCI_DEVICE_ID_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002164 m = (typeof(m)){"LP1050", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002165 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002166 break;
2167 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05002168 m = (typeof(m)){"LP11000", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002169 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002170 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002171 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002172 m = (typeof(m)){"LP11000-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002173 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002174 break;
2175 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002176 m = (typeof(m)){"LP11002-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002177 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002178 break;
2179 case PCI_DEVICE_ID_NEPTUNE:
James Smart12222f42014-05-21 08:05:19 -04002180 m = (typeof(m)){"LPe1000", "PCIe",
2181 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002182 break;
2183 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart12222f42014-05-21 08:05:19 -04002184 m = (typeof(m)){"LPe1000-SP", "PCIe",
2185 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002186 break;
2187 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart12222f42014-05-21 08:05:19 -04002188 m = (typeof(m)){"LPe1002-SP", "PCIe",
2189 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002190 break;
dea31012005-04-17 16:05:31 -05002191 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05002192 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002193 break;
2194 case PCI_DEVICE_ID_BSMB:
James Smart12222f42014-05-21 08:05:19 -04002195 m = (typeof(m)){"LP111", "PCI-X2",
2196 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002197 break;
2198 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05002199 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002200 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002201 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002202 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002203 break;
2204 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002205 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04002206 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002207 break;
dea31012005-04-17 16:05:31 -05002208 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05002209 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002210 break;
2211 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05002212 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002213 break;
2214 case PCI_DEVICE_ID_LP101:
James Smart12222f42014-05-21 08:05:19 -04002215 m = (typeof(m)){"LP101", "PCI-X",
2216 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002217 break;
2218 case PCI_DEVICE_ID_LP10000S:
James Smart12222f42014-05-21 08:05:19 -04002219 m = (typeof(m)){"LP10000-S", "PCI",
2220 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002221 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002222 case PCI_DEVICE_ID_LP11000S:
James Smart12222f42014-05-21 08:05:19 -04002223 m = (typeof(m)){"LP11000-S", "PCI-X2",
2224 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05002225 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002226 case PCI_DEVICE_ID_LPE11000S:
James Smart12222f42014-05-21 08:05:19 -04002227 m = (typeof(m)){"LPe11000-S", "PCIe",
2228 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002229 break;
James Smartb87eab32007-04-25 09:53:28 -04002230 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05002231 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002232 break;
2233 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05002234 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002235 break;
2236 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05002237 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002238 break;
2239 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002240 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002241 break;
2242 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002243 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002244 break;
2245 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05002246 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002247 break;
James Smart84774a42008-08-24 21:50:06 -04002248 case PCI_DEVICE_ID_HORNET:
James Smart12222f42014-05-21 08:05:19 -04002249 m = (typeof(m)){"LP21000", "PCIe",
2250 "Obsolete, Unsupported FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002251 GE = 1;
2252 break;
2253 case PCI_DEVICE_ID_PROTEUS_VF:
James Smarta747c9c2009-11-18 15:41:10 -05002254 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002255 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002256 break;
2257 case PCI_DEVICE_ID_PROTEUS_PF:
James Smarta747c9c2009-11-18 15:41:10 -05002258 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002259 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002260 break;
2261 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05002262 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002263 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002264 break;
James Smartda0436e2009-05-22 14:51:39 -04002265 case PCI_DEVICE_ID_TIGERSHARK:
2266 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002267 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04002268 break;
James Smarta747c9c2009-11-18 15:41:10 -05002269 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04002270 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002271 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2272 break;
2273 case PCI_DEVICE_ID_FALCON:
2274 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2275 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04002276 break;
James Smart98fc5dd2010-06-07 15:24:29 -04002277 case PCI_DEVICE_ID_BALIUS:
2278 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
James Smart12222f42014-05-21 08:05:19 -04002279 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart98fc5dd2010-06-07 15:24:29 -04002280 break;
James Smart085c6472010-11-20 23:11:37 -05002281 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04002282 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05002283 break;
James Smart12222f42014-05-21 08:05:19 -04002284 case PCI_DEVICE_ID_LANCER_FC_VF:
2285 m = (typeof(m)){"LPe16000", "PCIe",
2286 "Obsolete, Unsupported Fibre Channel Adapter"};
2287 break;
James Smart085c6472010-11-20 23:11:37 -05002288 case PCI_DEVICE_ID_LANCER_FCOE:
2289 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04002290 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05002291 break;
James Smart12222f42014-05-21 08:05:19 -04002292 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2293 oneConnect = 1;
2294 m = (typeof(m)){"OCe15100", "PCIe",
2295 "Obsolete, Unsupported FCoE"};
2296 break;
James Smartd38dd522015-08-31 16:48:17 -04002297 case PCI_DEVICE_ID_LANCER_G6_FC:
2298 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2299 break;
James Smartf8cafd32012-08-03 12:42:51 -04002300 case PCI_DEVICE_ID_SKYHAWK:
2301 case PCI_DEVICE_ID_SKYHAWK_VF:
2302 oneConnect = 1;
2303 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2304 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002305 default:
James Smarta747c9c2009-11-18 15:41:10 -05002306 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002307 break;
dea31012005-04-17 16:05:31 -05002308 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002309
2310 if (mdp && mdp[0] == '\0')
2311 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04002312 /*
2313 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04002314 * and we put the port number on the end
2315 */
2316 if (descp && descp[0] == '\0') {
2317 if (oneConnect)
2318 snprintf(descp, 255,
James Smart4169d862012-09-29 11:32:09 -04002319 "Emulex OneConnect %s, %s Initiator %s",
James Smarta747c9c2009-11-18 15:41:10 -05002320 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04002321 phba->Port);
James Smart4169d862012-09-29 11:32:09 -04002322 else if (max_speed == 0)
2323 snprintf(descp, 255,
Sebastian Herbszt290237d2015-08-31 16:48:08 -04002324 "Emulex %s %s %s",
James Smart4169d862012-09-29 11:32:09 -04002325 m.name, m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002326 else
2327 snprintf(descp, 255,
2328 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05002329 m.name, max_speed, (GE) ? "GE" : "Gb",
2330 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002331 }
dea31012005-04-17 16:05:31 -05002332}
2333
James Smarte59058c2008-08-24 21:49:00 -04002334/**
James Smart3621a712009-04-06 18:47:14 -04002335 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04002336 * @phba: pointer to lpfc hba data structure.
2337 * @pring: pointer to a IOCB ring.
2338 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2339 *
2340 * This routine posts a given number of IOCBs with the associated DMA buffer
2341 * descriptors specified by the cnt argument to the given IOCB ring.
2342 *
2343 * Return codes
2344 * The number of IOCBs NOT able to be posted to the IOCB ring.
2345 **/
dea31012005-04-17 16:05:31 -05002346int
James Smart495a7142008-06-14 22:52:59 -04002347lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002348{
2349 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002350 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002351 struct lpfc_dmabuf *mp1, *mp2;
2352
2353 cnt += pring->missbufcnt;
2354
2355 /* While there are buffers to post */
2356 while (cnt > 0) {
2357 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002358 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002359 if (iocb == NULL) {
2360 pring->missbufcnt = cnt;
2361 return cnt;
2362 }
dea31012005-04-17 16:05:31 -05002363 icmd = &iocb->iocb;
2364
2365 /* 2 buffers can be posted per command */
2366 /* Allocate buffer to post */
2367 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2368 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002369 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2370 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002371 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002372 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002373 pring->missbufcnt = cnt;
2374 return cnt;
2375 }
2376
2377 INIT_LIST_HEAD(&mp1->list);
2378 /* Allocate buffer to post */
2379 if (cnt > 1) {
2380 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2381 if (mp2)
2382 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2383 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002384 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002385 kfree(mp2);
dea31012005-04-17 16:05:31 -05002386 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2387 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002388 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002389 pring->missbufcnt = cnt;
2390 return cnt;
2391 }
2392
2393 INIT_LIST_HEAD(&mp2->list);
2394 } else {
2395 mp2 = NULL;
2396 }
2397
2398 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2399 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2400 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2401 icmd->ulpBdeCount = 1;
2402 cnt--;
2403 if (mp2) {
2404 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2405 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2406 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2407 cnt--;
2408 icmd->ulpBdeCount = 2;
2409 }
2410
2411 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2412 icmd->ulpLe = 1;
2413
James Smart3772a992009-05-22 14:50:54 -04002414 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2415 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002416 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2417 kfree(mp1);
2418 cnt++;
2419 if (mp2) {
2420 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2421 kfree(mp2);
2422 cnt++;
2423 }
James Bottomley604a3e32005-10-29 10:28:33 -05002424 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002425 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002426 return cnt;
2427 }
dea31012005-04-17 16:05:31 -05002428 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002429 if (mp2)
dea31012005-04-17 16:05:31 -05002430 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002431 }
2432 pring->missbufcnt = 0;
2433 return 0;
2434}
2435
James Smarte59058c2008-08-24 21:49:00 -04002436/**
James Smart3621a712009-04-06 18:47:14 -04002437 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002438 * @phba: pointer to lpfc hba data structure.
2439 *
2440 * This routine posts initial receive IOCB buffers to the ELS ring. The
2441 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2442 * set to 64 IOCBs.
2443 *
2444 * Return codes
2445 * 0 - success (currently always success)
2446 **/
dea31012005-04-17 16:05:31 -05002447static int
James Smart2e0fef82007-06-17 19:56:36 -05002448lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002449{
2450 struct lpfc_sli *psli = &phba->sli;
2451
2452 /* Ring 0, ELS / CT buffers */
James Smart495a7142008-06-14 22:52:59 -04002453 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002454 /* Ring 2 - FCP no buffers needed */
2455
2456 return 0;
2457}
2458
2459#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2460
James Smarte59058c2008-08-24 21:49:00 -04002461/**
James Smart3621a712009-04-06 18:47:14 -04002462 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002463 * @HashResultPointer: pointer to an array as hash table.
2464 *
2465 * This routine sets up the initial values to the array of hash table entries
2466 * for the LC HBAs.
2467 **/
dea31012005-04-17 16:05:31 -05002468static void
2469lpfc_sha_init(uint32_t * HashResultPointer)
2470{
2471 HashResultPointer[0] = 0x67452301;
2472 HashResultPointer[1] = 0xEFCDAB89;
2473 HashResultPointer[2] = 0x98BADCFE;
2474 HashResultPointer[3] = 0x10325476;
2475 HashResultPointer[4] = 0xC3D2E1F0;
2476}
2477
James Smarte59058c2008-08-24 21:49:00 -04002478/**
James Smart3621a712009-04-06 18:47:14 -04002479 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002480 * @HashResultPointer: pointer to an initial/result hash table.
2481 * @HashWorkingPointer: pointer to an working hash table.
2482 *
2483 * This routine iterates an initial hash table pointed by @HashResultPointer
2484 * with the values from the working hash table pointeed by @HashWorkingPointer.
2485 * The results are putting back to the initial hash table, returned through
2486 * the @HashResultPointer as the result hash table.
2487 **/
dea31012005-04-17 16:05:31 -05002488static void
2489lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2490{
2491 int t;
2492 uint32_t TEMP;
2493 uint32_t A, B, C, D, E;
2494 t = 16;
2495 do {
2496 HashWorkingPointer[t] =
2497 S(1,
2498 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2499 8] ^
2500 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2501 } while (++t <= 79);
2502 t = 0;
2503 A = HashResultPointer[0];
2504 B = HashResultPointer[1];
2505 C = HashResultPointer[2];
2506 D = HashResultPointer[3];
2507 E = HashResultPointer[4];
2508
2509 do {
2510 if (t < 20) {
2511 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2512 } else if (t < 40) {
2513 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2514 } else if (t < 60) {
2515 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2516 } else {
2517 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2518 }
2519 TEMP += S(5, A) + E + HashWorkingPointer[t];
2520 E = D;
2521 D = C;
2522 C = S(30, B);
2523 B = A;
2524 A = TEMP;
2525 } while (++t <= 79);
2526
2527 HashResultPointer[0] += A;
2528 HashResultPointer[1] += B;
2529 HashResultPointer[2] += C;
2530 HashResultPointer[3] += D;
2531 HashResultPointer[4] += E;
2532
2533}
2534
James Smarte59058c2008-08-24 21:49:00 -04002535/**
James Smart3621a712009-04-06 18:47:14 -04002536 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002537 * @RandomChallenge: pointer to the entry of host challenge random number array.
2538 * @HashWorking: pointer to the entry of the working hash array.
2539 *
2540 * This routine calculates the working hash array referred by @HashWorking
2541 * from the challenge random numbers associated with the host, referred by
2542 * @RandomChallenge. The result is put into the entry of the working hash
2543 * array and returned by reference through @HashWorking.
2544 **/
dea31012005-04-17 16:05:31 -05002545static void
2546lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2547{
2548 *HashWorking = (*RandomChallenge ^ *HashWorking);
2549}
2550
James Smarte59058c2008-08-24 21:49:00 -04002551/**
James Smart3621a712009-04-06 18:47:14 -04002552 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002553 * @phba: pointer to lpfc hba data structure.
2554 * @hbainit: pointer to an array of unsigned 32-bit integers.
2555 *
2556 * This routine performs the special handling for LC HBA initialization.
2557 **/
dea31012005-04-17 16:05:31 -05002558void
2559lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2560{
2561 int t;
2562 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002563 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002564
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002565 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002566 if (!HashWorking)
2567 return;
2568
dea31012005-04-17 16:05:31 -05002569 HashWorking[0] = HashWorking[78] = *pwwnn++;
2570 HashWorking[1] = HashWorking[79] = *pwwnn;
2571
2572 for (t = 0; t < 7; t++)
2573 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2574
2575 lpfc_sha_init(hbainit);
2576 lpfc_sha_iterate(hbainit, HashWorking);
2577 kfree(HashWorking);
2578}
2579
James Smarte59058c2008-08-24 21:49:00 -04002580/**
James Smart3621a712009-04-06 18:47:14 -04002581 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002582 * @vport: pointer to a virtual N_Port data structure.
2583 *
2584 * This routine performs the necessary cleanups before deleting the @vport.
2585 * It invokes the discovery state machine to perform necessary state
2586 * transitions and to release the ndlps associated with the @vport. Note,
2587 * the physical port is treated as @vport 0.
2588 **/
James Smart87af33f2007-10-27 13:37:43 -04002589void
James Smart2e0fef82007-06-17 19:56:36 -05002590lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002591{
James Smart87af33f2007-10-27 13:37:43 -04002592 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002593 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002594 int i = 0;
dea31012005-04-17 16:05:31 -05002595
James Smart87af33f2007-10-27 13:37:43 -04002596 if (phba->link_state > LPFC_LINK_DOWN)
2597 lpfc_port_link_failure(vport);
2598
2599 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002600 if (!NLP_CHK_NODE_ACT(ndlp)) {
2601 ndlp = lpfc_enable_node(vport, ndlp,
2602 NLP_STE_UNUSED_NODE);
2603 if (!ndlp)
2604 continue;
2605 spin_lock_irq(&phba->ndlp_lock);
2606 NLP_SET_FREE_REQ(ndlp);
2607 spin_unlock_irq(&phba->ndlp_lock);
2608 /* Trigger the release of the ndlp memory */
2609 lpfc_nlp_put(ndlp);
2610 continue;
2611 }
2612 spin_lock_irq(&phba->ndlp_lock);
2613 if (NLP_CHK_FREE_REQ(ndlp)) {
2614 /* The ndlp should not be in memory free mode already */
2615 spin_unlock_irq(&phba->ndlp_lock);
2616 continue;
2617 } else
2618 /* Indicate request for freeing ndlp memory */
2619 NLP_SET_FREE_REQ(ndlp);
2620 spin_unlock_irq(&phba->ndlp_lock);
2621
James Smart58da1ff2008-04-07 10:15:56 -04002622 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2623 ndlp->nlp_DID == Fabric_DID) {
2624 /* Just free up ndlp with Fabric_DID for vports */
2625 lpfc_nlp_put(ndlp);
2626 continue;
2627 }
2628
James Smarteff4a012012-01-18 16:25:25 -05002629 /* take care of nodes in unused state before the state
2630 * machine taking action.
2631 */
2632 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2633 lpfc_nlp_put(ndlp);
2634 continue;
2635 }
2636
James Smart87af33f2007-10-27 13:37:43 -04002637 if (ndlp->nlp_type & NLP_FABRIC)
2638 lpfc_disc_state_machine(vport, ndlp, NULL,
2639 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002640
James Smart87af33f2007-10-27 13:37:43 -04002641 lpfc_disc_state_machine(vport, ndlp, NULL,
2642 NLP_EVT_DEVICE_RM);
2643 }
2644
James Smarta8adb832007-10-27 13:37:53 -04002645 /* At this point, ALL ndlp's should be gone
2646 * because of the previous NLP_EVT_DEVICE_RM.
2647 * Lets wait for this to happen, if needed.
2648 */
James Smart87af33f2007-10-27 13:37:43 -04002649 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002650 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04002651 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04002652 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002653 list_for_each_entry_safe(ndlp, next_ndlp,
2654 &vport->fc_nodes, nlp_listp) {
2655 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2656 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04002657 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05002658 "usgmap:x%x refcnt:%d\n",
2659 ndlp->nlp_DID, (void *)ndlp,
2660 ndlp->nlp_usg_map,
2661 atomic_read(
2662 &ndlp->kref.refcount));
2663 }
James Smarta8adb832007-10-27 13:37:53 -04002664 break;
James Smart87af33f2007-10-27 13:37:43 -04002665 }
James Smarta8adb832007-10-27 13:37:53 -04002666
2667 /* Wait for any activity on ndlps to settle */
2668 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002669 }
James Smart1151e3e2011-02-16 12:39:35 -05002670 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002671}
2672
James Smarte59058c2008-08-24 21:49:00 -04002673/**
James Smart3621a712009-04-06 18:47:14 -04002674 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002675 * @vport: pointer to a virtual N_Port data structure.
2676 *
2677 * This routine stops all the timers associated with a @vport. This function
2678 * is invoked before disabling or deleting a @vport. Note that the physical
2679 * port is treated as @vport 0.
2680 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002681void
2682lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002683{
James Smart92d7f7b2007-06-17 19:56:38 -05002684 del_timer_sync(&vport->els_tmofunc);
James Smart92494142011-02-16 12:39:44 -05002685 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002686 lpfc_can_disctmo(vport);
2687 return;
dea31012005-04-17 16:05:31 -05002688}
2689
James Smarte59058c2008-08-24 21:49:00 -04002690/**
James Smartecfd03c2010-02-12 14:41:27 -05002691 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2692 * @phba: pointer to lpfc hba data structure.
2693 *
2694 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2695 * caller of this routine should already hold the host lock.
2696 **/
2697void
2698__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2699{
James Smart5ac6b302010-10-22 11:05:36 -04002700 /* Clear pending FCF rediscovery wait flag */
2701 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2702
James Smartecfd03c2010-02-12 14:41:27 -05002703 /* Now, try to stop the timer */
2704 del_timer(&phba->fcf.redisc_wait);
2705}
2706
2707/**
2708 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2709 * @phba: pointer to lpfc hba data structure.
2710 *
2711 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2712 * checks whether the FCF rediscovery wait timer is pending with the host
2713 * lock held before proceeding with disabling the timer and clearing the
2714 * wait timer pendig flag.
2715 **/
2716void
2717lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2718{
2719 spin_lock_irq(&phba->hbalock);
2720 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2721 /* FCF rediscovery timer already fired or stopped */
2722 spin_unlock_irq(&phba->hbalock);
2723 return;
2724 }
2725 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002726 /* Clear failover in progress flags */
2727 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002728 spin_unlock_irq(&phba->hbalock);
2729}
2730
2731/**
James Smart3772a992009-05-22 14:50:54 -04002732 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002733 * @phba: pointer to lpfc hba data structure.
2734 *
2735 * This routine stops all the timers associated with a HBA. This function is
2736 * invoked before either putting a HBA offline or unloading the driver.
2737 **/
James Smart3772a992009-05-22 14:50:54 -04002738void
2739lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002740{
James Smart51ef4c22007-08-02 11:10:31 -04002741 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05002742 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002743 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002744 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002745 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002746 if (phba->sli_rev == LPFC_SLI_REV4) {
2747 del_timer_sync(&phba->rrq_tmr);
2748 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2749 }
James Smart3772a992009-05-22 14:50:54 -04002750 phba->hb_outstanding = 0;
2751
2752 switch (phba->pci_dev_grp) {
2753 case LPFC_PCI_DEV_LP:
2754 /* Stop any LightPulse device specific driver timers */
2755 del_timer_sync(&phba->fcp_poll_timer);
2756 break;
2757 case LPFC_PCI_DEV_OC:
2758 /* Stop any OneConnect device sepcific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002759 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002760 break;
2761 default:
2762 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2763 "0297 Invalid device group (x%x)\n",
2764 phba->pci_dev_grp);
2765 break;
2766 }
James Smart2e0fef82007-06-17 19:56:36 -05002767 return;
dea31012005-04-17 16:05:31 -05002768}
2769
James Smarte59058c2008-08-24 21:49:00 -04002770/**
James Smart3621a712009-04-06 18:47:14 -04002771 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002772 * @phba: pointer to lpfc hba data structure.
2773 *
2774 * This routine marks a HBA's management interface as blocked. Once the HBA's
2775 * management interface is marked as blocked, all the user space access to
2776 * the HBA, whether they are from sysfs interface or libdfc interface will
2777 * all be blocked. The HBA is set to block the management interface when the
2778 * driver prepares the HBA interface for online or offline.
2779 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01002780static void
James Smart618a5232012-06-12 13:54:36 -04002781lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
Adrian Bunka6ababd2007-11-05 18:07:33 +01002782{
2783 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04002784 uint8_t actcmd = MBX_HEARTBEAT;
2785 unsigned long timeout;
2786
Adrian Bunka6ababd2007-11-05 18:07:33 +01002787 spin_lock_irqsave(&phba->hbalock, iflag);
2788 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart618a5232012-06-12 13:54:36 -04002789 spin_unlock_irqrestore(&phba->hbalock, iflag);
2790 if (mbx_action == LPFC_MBX_NO_WAIT)
2791 return;
2792 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2793 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002794 if (phba->sli.mbox_active) {
James Smart6e7288d2010-06-07 15:23:35 -04002795 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
James Smarta183a152011-10-10 21:32:43 -04002796 /* Determine how long we might wait for the active mailbox
2797 * command to be gracefully completed by firmware.
2798 */
2799 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
2800 phba->sli.mbox_active) * 1000) + jiffies;
2801 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002802 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002803
James Smart6e7288d2010-06-07 15:23:35 -04002804 /* Wait for the outstnading mailbox command to complete */
2805 while (phba->sli.mbox_active) {
2806 /* Check active mailbox complete status every 2ms */
2807 msleep(2);
2808 if (time_after(jiffies, timeout)) {
2809 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2810 "2813 Mgmt IO is Blocked %x "
2811 "- mbox cmd %x still active\n",
2812 phba->sli.sli_flag, actcmd);
2813 break;
2814 }
2815 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002816}
2817
James Smarte59058c2008-08-24 21:49:00 -04002818/**
James Smart6b5151f2012-01-18 16:24:06 -05002819 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
2820 * @phba: pointer to lpfc hba data structure.
2821 *
2822 * Allocate RPIs for all active remote nodes. This is needed whenever
2823 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
2824 * is to fixup the temporary rpi assignments.
2825 **/
2826void
2827lpfc_sli4_node_prep(struct lpfc_hba *phba)
2828{
2829 struct lpfc_nodelist *ndlp, *next_ndlp;
2830 struct lpfc_vport **vports;
2831 int i;
2832
2833 if (phba->sli_rev != LPFC_SLI_REV4)
2834 return;
2835
2836 vports = lpfc_create_vport_work_array(phba);
2837 if (vports != NULL) {
2838 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2839 if (vports[i]->load_flag & FC_UNLOADING)
2840 continue;
2841
2842 list_for_each_entry_safe(ndlp, next_ndlp,
2843 &vports[i]->fc_nodes,
2844 nlp_listp) {
James Smartbe6bb942015-04-07 15:07:22 -04002845 if (NLP_CHK_NODE_ACT(ndlp)) {
James Smart6b5151f2012-01-18 16:24:06 -05002846 ndlp->nlp_rpi =
2847 lpfc_sli4_alloc_rpi(phba);
James Smartbe6bb942015-04-07 15:07:22 -04002848 lpfc_printf_vlog(ndlp->vport, KERN_INFO,
2849 LOG_NODE,
2850 "0009 rpi:%x DID:%x "
2851 "flg:%x map:%x %p\n",
2852 ndlp->nlp_rpi,
2853 ndlp->nlp_DID,
2854 ndlp->nlp_flag,
2855 ndlp->nlp_usg_map,
2856 ndlp);
2857 }
James Smart6b5151f2012-01-18 16:24:06 -05002858 }
2859 }
2860 }
2861 lpfc_destroy_vport_work_array(phba, vports);
2862}
2863
2864/**
James Smart3621a712009-04-06 18:47:14 -04002865 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04002866 * @phba: pointer to lpfc hba data structure.
2867 *
2868 * This routine initializes the HBA and brings a HBA online. During this
2869 * process, the management interface is blocked to prevent user space access
2870 * to the HBA interfering with the driver initialization.
2871 *
2872 * Return codes
2873 * 0 - successful
2874 * 1 - failed
2875 **/
dea31012005-04-17 16:05:31 -05002876int
James Smart2e0fef82007-06-17 19:56:36 -05002877lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002878{
Julia Lawall372bd282008-12-16 16:15:08 +01002879 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04002880 struct lpfc_vport **vports;
2881 int i;
James Smart16a3a202013-04-17 20:14:38 -04002882 bool vpis_cleared = false;
James Smart2e0fef82007-06-17 19:56:36 -05002883
dea31012005-04-17 16:05:31 -05002884 if (!phba)
2885 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01002886 vport = phba->pport;
dea31012005-04-17 16:05:31 -05002887
James Smart2e0fef82007-06-17 19:56:36 -05002888 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05002889 return 0;
2890
James Smarted957682007-06-17 19:56:37 -05002891 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002892 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05002893
James Smart618a5232012-06-12 13:54:36 -04002894 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05002895
James Smart46fa3112007-04-25 09:51:45 -04002896 if (!lpfc_sli_queue_setup(phba)) {
2897 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002898 return 1;
James Smart46fa3112007-04-25 09:51:45 -04002899 }
2900
James Smartda0436e2009-05-22 14:51:39 -04002901 if (phba->sli_rev == LPFC_SLI_REV4) {
2902 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
2903 lpfc_unblock_mgmt_io(phba);
2904 return 1;
2905 }
James Smart16a3a202013-04-17 20:14:38 -04002906 spin_lock_irq(&phba->hbalock);
2907 if (!phba->sli4_hba.max_cfg_param.vpi_used)
2908 vpis_cleared = true;
2909 spin_unlock_irq(&phba->hbalock);
James Smartda0436e2009-05-22 14:51:39 -04002910 } else {
2911 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
2912 lpfc_unblock_mgmt_io(phba);
2913 return 1;
2914 }
James Smart46fa3112007-04-25 09:51:45 -04002915 }
dea31012005-04-17 16:05:31 -05002916
James Smart549e55c2007-08-02 11:09:51 -04002917 vports = lpfc_create_vport_work_array(phba);
Arnd Bergmannaeb66412016-03-14 15:29:44 +01002918 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04002919 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002920 struct Scsi_Host *shost;
2921 shost = lpfc_shost_from_vport(vports[i]);
2922 spin_lock_irq(shost->host_lock);
2923 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
2924 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2925 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart16a3a202013-04-17 20:14:38 -04002926 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart1c6834a2009-07-19 10:01:26 -04002927 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart16a3a202013-04-17 20:14:38 -04002928 if ((vpis_cleared) &&
2929 (vports[i]->port_type !=
2930 LPFC_PHYSICAL_PORT))
2931 vports[i]->vpi = 0;
2932 }
James Smart549e55c2007-08-02 11:09:51 -04002933 spin_unlock_irq(shost->host_lock);
2934 }
Arnd Bergmannaeb66412016-03-14 15:29:44 +01002935 }
2936 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002937
James Smart46fa3112007-04-25 09:51:45 -04002938 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002939 return 0;
2940}
2941
James Smarte59058c2008-08-24 21:49:00 -04002942/**
James Smart3621a712009-04-06 18:47:14 -04002943 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04002944 * @phba: pointer to lpfc hba data structure.
2945 *
2946 * This routine marks a HBA's management interface as not blocked. Once the
2947 * HBA's management interface is marked as not blocked, all the user space
2948 * access to the HBA, whether they are from sysfs interface or libdfc
2949 * interface will be allowed. The HBA is set to block the management interface
2950 * when the driver prepares the HBA interface for online or offline and then
2951 * set to unblock the management interface afterwards.
2952 **/
James Smart46fa3112007-04-25 09:51:45 -04002953void
James Smart46fa3112007-04-25 09:51:45 -04002954lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
2955{
2956 unsigned long iflag;
2957
James Smart2e0fef82007-06-17 19:56:36 -05002958 spin_lock_irqsave(&phba->hbalock, iflag);
2959 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
2960 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04002961}
2962
James Smarte59058c2008-08-24 21:49:00 -04002963/**
James Smart3621a712009-04-06 18:47:14 -04002964 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04002965 * @phba: pointer to lpfc hba data structure.
2966 *
2967 * This routine is invoked to prepare a HBA to be brought offline. It performs
2968 * unregistration login to all the nodes on all vports and flushes the mailbox
2969 * queue to make it ready to be brought offline.
2970 **/
James Smart46fa3112007-04-25 09:51:45 -04002971void
James Smart618a5232012-06-12 13:54:36 -04002972lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04002973{
James Smart2e0fef82007-06-17 19:56:36 -05002974 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04002975 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04002976 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05002977 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04002978 int i;
dea31012005-04-17 16:05:31 -05002979
James Smart2e0fef82007-06-17 19:56:36 -05002980 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002981 return;
dea31012005-04-17 16:05:31 -05002982
James Smart618a5232012-06-12 13:54:36 -04002983 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05002984
2985 lpfc_linkdown(phba);
2986
James Smart87af33f2007-10-27 13:37:43 -04002987 /* Issue an unreg_login to all nodes on all vports */
2988 vports = lpfc_create_vport_work_array(phba);
2989 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04002990 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04002991 if (vports[i]->load_flag & FC_UNLOADING)
2992 continue;
James Smart72100cc2010-02-12 14:43:01 -05002993 shost = lpfc_shost_from_vport(vports[i]);
2994 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05002995 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002996 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2997 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05002998 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05002999
James Smart87af33f2007-10-27 13:37:43 -04003000 shost = lpfc_shost_from_vport(vports[i]);
3001 list_for_each_entry_safe(ndlp, next_ndlp,
3002 &vports[i]->fc_nodes,
3003 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003004 if (!NLP_CHK_NODE_ACT(ndlp))
3005 continue;
James Smart87af33f2007-10-27 13:37:43 -04003006 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3007 continue;
3008 if (ndlp->nlp_type & NLP_FABRIC) {
3009 lpfc_disc_state_machine(vports[i], ndlp,
3010 NULL, NLP_EVT_DEVICE_RECOVERY);
3011 lpfc_disc_state_machine(vports[i], ndlp,
3012 NULL, NLP_EVT_DEVICE_RM);
3013 }
3014 spin_lock_irq(shost->host_lock);
3015 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart401ee0c2012-03-01 22:35:34 -05003016 spin_unlock_irq(shost->host_lock);
James Smart6b5151f2012-01-18 16:24:06 -05003017 /*
3018 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05003019 * RPI. Get a new RPI when the adapter port
3020 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05003021 */
James Smartbe6bb942015-04-07 15:07:22 -04003022 if (phba->sli_rev == LPFC_SLI_REV4) {
3023 lpfc_printf_vlog(ndlp->vport,
3024 KERN_INFO, LOG_NODE,
3025 "0011 lpfc_offline: "
3026 "ndlp:x%p did %x "
3027 "usgmap:x%x rpi:%x\n",
3028 ndlp, ndlp->nlp_DID,
3029 ndlp->nlp_usg_map,
3030 ndlp->nlp_rpi);
3031
James Smart6b5151f2012-01-18 16:24:06 -05003032 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smartbe6bb942015-04-07 15:07:22 -04003033 }
James Smart87af33f2007-10-27 13:37:43 -04003034 lpfc_unreg_rpi(vports[i], ndlp);
3035 }
3036 }
3037 }
James Smart09372822008-01-11 01:52:54 -05003038 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003039
James Smart618a5232012-06-12 13:54:36 -04003040 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
James Smart46fa3112007-04-25 09:51:45 -04003041}
3042
James Smarte59058c2008-08-24 21:49:00 -04003043/**
James Smart3621a712009-04-06 18:47:14 -04003044 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04003045 * @phba: pointer to lpfc hba data structure.
3046 *
3047 * This routine actually brings a HBA offline. It stops all the timers
3048 * associated with the HBA, brings down the SLI layer, and eventually
3049 * marks the HBA as in offline state for the upper layer protocol.
3050 **/
James Smart46fa3112007-04-25 09:51:45 -04003051void
James Smart2e0fef82007-06-17 19:56:36 -05003052lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04003053{
James Smart549e55c2007-08-02 11:09:51 -04003054 struct Scsi_Host *shost;
3055 struct lpfc_vport **vports;
3056 int i;
James Smart46fa3112007-04-25 09:51:45 -04003057
James Smart549e55c2007-08-02 11:09:51 -04003058 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003059 return;
James Smart688a8862006-07-06 15:49:56 -04003060
James Smartda0436e2009-05-22 14:51:39 -04003061 /* stop port and all timers associated with this hba */
3062 lpfc_stop_port(phba);
James Smart51ef4c22007-08-02 11:10:31 -04003063 vports = lpfc_create_vport_work_array(phba);
3064 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003065 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04003066 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05003067 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05003068 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003069 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05003070 /* Bring down the SLI Layer and cleanup. The HBA is offline
3071 now. */
3072 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003073 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04003074 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003075 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04003076 vports = lpfc_create_vport_work_array(phba);
3077 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003078 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003079 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04003080 spin_lock_irq(shost->host_lock);
3081 vports[i]->work_port_events = 0;
3082 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3083 spin_unlock_irq(shost->host_lock);
3084 }
James Smart09372822008-01-11 01:52:54 -05003085 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003086}
3087
James Smarte59058c2008-08-24 21:49:00 -04003088/**
James Smart3621a712009-04-06 18:47:14 -04003089 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04003090 * @phba: pointer to lpfc hba data structure.
3091 *
3092 * This routine is to free all the SCSI buffers and IOCBs from the driver
3093 * list back to kernel. It is called from lpfc_pci_remove_one to free
3094 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04003095 **/
James Smart8a9d2e82012-05-09 21:16:12 -04003096static void
James Smart2e0fef82007-06-17 19:56:36 -05003097lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003098{
3099 struct lpfc_scsi_buf *sb, *sb_next;
3100 struct lpfc_iocbq *io, *io_next;
3101
James Smart2e0fef82007-06-17 19:56:36 -05003102 spin_lock_irq(&phba->hbalock);
James Smarta40fc5f2013-04-17 20:17:40 -04003103
dea31012005-04-17 16:05:31 -05003104 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smarta40fc5f2013-04-17 20:17:40 -04003105
3106 spin_lock(&phba->scsi_buf_list_put_lock);
3107 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3108 list) {
dea31012005-04-17 16:05:31 -05003109 list_del(&sb->list);
3110 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05003111 sb->dma_handle);
dea31012005-04-17 16:05:31 -05003112 kfree(sb);
3113 phba->total_scsi_bufs--;
3114 }
James Smarta40fc5f2013-04-17 20:17:40 -04003115 spin_unlock(&phba->scsi_buf_list_put_lock);
3116
3117 spin_lock(&phba->scsi_buf_list_get_lock);
3118 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3119 list) {
3120 list_del(&sb->list);
3121 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
3122 sb->dma_handle);
3123 kfree(sb);
3124 phba->total_scsi_bufs--;
3125 }
3126 spin_unlock(&phba->scsi_buf_list_get_lock);
dea31012005-04-17 16:05:31 -05003127
3128 /* Release all the lpfc_iocbq entries maintained by this host. */
3129 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
3130 list_del(&io->list);
3131 kfree(io);
3132 phba->total_iocbq_bufs--;
3133 }
James Smart6d368e52011-05-24 11:44:12 -04003134
James Smart2e0fef82007-06-17 19:56:36 -05003135 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003136}
3137
3138/**
3139 * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping
3140 * @phba: pointer to lpfc hba data structure.
3141 *
3142 * This routine first calculates the sizes of the current els and allocated
3143 * scsi sgl lists, and then goes through all sgls to updates the physical
3144 * XRIs assigned due to port function reset. During port initialization, the
3145 * current els and allocated scsi sgl lists are 0s.
3146 *
3147 * Return codes
3148 * 0 - successful (for now, it always returns 0)
3149 **/
3150int
3151lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba)
3152{
3153 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3154 struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL;
3155 uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt;
3156 LIST_HEAD(els_sgl_list);
3157 LIST_HEAD(scsi_sgl_list);
3158 int rc;
James Smartdafe8ce2014-09-03 12:56:40 -04003159 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart8a9d2e82012-05-09 21:16:12 -04003160
3161 /*
3162 * update on pci function's els xri-sgl list
3163 */
3164 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3165 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3166 /* els xri-sgl expanded */
3167 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3168 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3169 "3157 ELS xri-sgl count increased from "
3170 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3171 els_xri_cnt);
3172 /* allocate the additional els sgls */
3173 for (i = 0; i < xri_cnt; i++) {
3174 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3175 GFP_KERNEL);
3176 if (sglq_entry == NULL) {
3177 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3178 "2562 Failure to allocate an "
3179 "ELS sgl entry:%d\n", i);
3180 rc = -ENOMEM;
3181 goto out_free_mem;
3182 }
3183 sglq_entry->buff_type = GEN_BUFF_TYPE;
3184 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3185 &sglq_entry->phys);
3186 if (sglq_entry->virt == NULL) {
3187 kfree(sglq_entry);
3188 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3189 "2563 Failure to allocate an "
3190 "ELS mbuf:%d\n", i);
3191 rc = -ENOMEM;
3192 goto out_free_mem;
3193 }
3194 sglq_entry->sgl = sglq_entry->virt;
3195 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3196 sglq_entry->state = SGL_FREED;
3197 list_add_tail(&sglq_entry->list, &els_sgl_list);
3198 }
James Smart38c20672013-03-01 16:37:44 -05003199 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04003200 spin_lock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003201 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04003202 spin_unlock(&pring->ring_lock);
James Smart38c20672013-03-01 16:37:44 -05003203 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003204 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3205 /* els xri-sgl shrinked */
3206 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3207 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3208 "3158 ELS xri-sgl count decreased from "
3209 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3210 els_xri_cnt);
3211 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04003212 spin_lock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003213 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04003214 spin_unlock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003215 spin_unlock_irq(&phba->hbalock);
3216 /* release extra els sgls from list */
3217 for (i = 0; i < xri_cnt; i++) {
3218 list_remove_head(&els_sgl_list,
3219 sglq_entry, struct lpfc_sglq, list);
3220 if (sglq_entry) {
3221 lpfc_mbuf_free(phba, sglq_entry->virt,
3222 sglq_entry->phys);
3223 kfree(sglq_entry);
3224 }
3225 }
3226 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04003227 spin_lock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003228 list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list);
James Smartdafe8ce2014-09-03 12:56:40 -04003229 spin_unlock(&pring->ring_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003230 spin_unlock_irq(&phba->hbalock);
3231 } else
3232 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3233 "3163 ELS xri-sgl count unchanged: %d\n",
3234 els_xri_cnt);
3235 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3236
3237 /* update xris to els sgls on the list */
3238 sglq_entry = NULL;
3239 sglq_entry_next = NULL;
3240 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3241 &phba->sli4_hba.lpfc_sgl_list, list) {
3242 lxri = lpfc_sli4_next_xritag(phba);
3243 if (lxri == NO_XRI) {
3244 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3245 "2400 Failed to allocate xri for "
3246 "ELS sgl\n");
3247 rc = -ENOMEM;
3248 goto out_free_mem;
3249 }
3250 sglq_entry->sli4_lxritag = lxri;
3251 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3252 }
3253
3254 /*
3255 * update on pci function's allocated scsi xri-sgl list
3256 */
3257 phba->total_scsi_bufs = 0;
3258
3259 /* maximum number of xris available for scsi buffers */
3260 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3261 els_xri_cnt;
3262
3263 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3264 "2401 Current allocated SCSI xri-sgl count:%d, "
3265 "maximum SCSI xri count:%d\n",
3266 phba->sli4_hba.scsi_xri_cnt,
3267 phba->sli4_hba.scsi_xri_max);
3268
James Smarta40fc5f2013-04-17 20:17:40 -04003269 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003270 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003271 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3272 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
James Smart164cecd2013-09-06 12:22:38 -04003273 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003274 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003275
3276 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3277 /* max scsi xri shrinked below the allocated scsi buffers */
3278 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3279 phba->sli4_hba.scsi_xri_max;
3280 /* release the extra allocated scsi buffers */
3281 for (i = 0; i < scsi_xri_cnt; i++) {
3282 list_remove_head(&scsi_sgl_list, psb,
3283 struct lpfc_scsi_buf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04003284 if (psb) {
3285 pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
3286 psb->data, psb->dma_handle);
3287 kfree(psb);
3288 }
James Smart8a9d2e82012-05-09 21:16:12 -04003289 }
James Smarta40fc5f2013-04-17 20:17:40 -04003290 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003291 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
James Smarta40fc5f2013-04-17 20:17:40 -04003292 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003293 }
3294
3295 /* update xris associated to remaining allocated scsi buffers */
3296 psb = NULL;
3297 psb_next = NULL;
3298 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3299 lxri = lpfc_sli4_next_xritag(phba);
3300 if (lxri == NO_XRI) {
3301 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3302 "2560 Failed to allocate xri for "
3303 "scsi buffer\n");
3304 rc = -ENOMEM;
3305 goto out_free_mem;
3306 }
3307 psb->cur_iocbq.sli4_lxritag = lxri;
3308 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3309 }
James Smarta40fc5f2013-04-17 20:17:40 -04003310 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003311 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003312 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3313 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
James Smart164cecd2013-09-06 12:22:38 -04003314 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003315 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003316
dea31012005-04-17 16:05:31 -05003317 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003318
3319out_free_mem:
3320 lpfc_free_els_sgl_list(phba);
3321 lpfc_scsi_free(phba);
3322 return rc;
dea31012005-04-17 16:05:31 -05003323}
3324
James Smarte59058c2008-08-24 21:49:00 -04003325/**
James Smart3621a712009-04-06 18:47:14 -04003326 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04003327 * @phba: pointer to lpfc hba data structure.
3328 * @instance: a unique integer ID to this FC port.
3329 * @dev: pointer to the device data structure.
3330 *
3331 * This routine creates a FC port for the upper layer protocol. The FC port
3332 * can be created on top of either a physical port or a virtual port provided
3333 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3334 * and associates the FC port created before adding the shost into the SCSI
3335 * layer.
3336 *
3337 * Return codes
3338 * @vport - pointer to the virtual N_Port data structure.
3339 * NULL - port create failed.
3340 **/
James Smart2e0fef82007-06-17 19:56:36 -05003341struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04003342lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04003343{
James Smart2e0fef82007-06-17 19:56:36 -05003344 struct lpfc_vport *vport;
3345 struct Scsi_Host *shost;
3346 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04003347
James Smartea4142f2015-04-07 15:07:13 -04003348 if (dev != &phba->pcidev->dev) {
James Smart3de2a652007-08-02 11:09:59 -04003349 shost = scsi_host_alloc(&lpfc_vport_template,
3350 sizeof(struct lpfc_vport));
James Smartea4142f2015-04-07 15:07:13 -04003351 } else {
3352 if (phba->sli_rev == LPFC_SLI_REV4)
3353 shost = scsi_host_alloc(&lpfc_template,
James Smart3de2a652007-08-02 11:09:59 -04003354 sizeof(struct lpfc_vport));
James Smartea4142f2015-04-07 15:07:13 -04003355 else
3356 shost = scsi_host_alloc(&lpfc_template_s3,
3357 sizeof(struct lpfc_vport));
3358 }
James Smart2e0fef82007-06-17 19:56:36 -05003359 if (!shost)
3360 goto out;
James Smart47a86172007-04-25 09:53:22 -04003361
James Smart2e0fef82007-06-17 19:56:36 -05003362 vport = (struct lpfc_vport *) shost->hostdata;
3363 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05003364 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05003365 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05003366 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04003367
James Smart3de2a652007-08-02 11:09:59 -04003368 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05003369 shost->unique_id = instance;
3370 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04003371 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05003372 shost->this_id = -1;
3373 shost->max_cmd_len = 16;
James Smart8b0dff12015-05-22 10:42:38 -04003374 shost->nr_hw_queues = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04003375 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05003376 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04003377 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smartda0436e2009-05-22 14:51:39 -04003378 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
3379 }
James Smart81301a92008-12-04 22:39:46 -05003380
James Smart47a86172007-04-25 09:53:22 -04003381 /*
James Smart2e0fef82007-06-17 19:56:36 -05003382 * Set initial can_queue value since 0 is no longer supported and
3383 * scsi_add_host will fail. This will be adjusted later based on the
3384 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04003385 */
James Smart2e0fef82007-06-17 19:56:36 -05003386 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04003387 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05003388 shost->transportt = lpfc_vport_transport_template;
3389 vport->port_type = LPFC_NPIV_PORT;
3390 } else {
3391 shost->transportt = lpfc_transport_template;
3392 vport->port_type = LPFC_PHYSICAL_PORT;
3393 }
James Smart47a86172007-04-25 09:53:22 -04003394
James Smart2e0fef82007-06-17 19:56:36 -05003395 /* Initialize all internally managed lists. */
3396 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04003397 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05003398 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04003399
James Smart2e0fef82007-06-17 19:56:36 -05003400 init_timer(&vport->fc_disctmo);
3401 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003402 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04003403
James Smart2e0fef82007-06-17 19:56:36 -05003404 init_timer(&vport->els_tmofunc);
3405 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003406 vport->els_tmofunc.data = (unsigned long)vport;
James Smart92494142011-02-16 12:39:44 -05003407
3408 init_timer(&vport->delayed_disc_tmo);
3409 vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
3410 vport->delayed_disc_tmo.data = (unsigned long)vport;
3411
James Bottomleyd139b9b2009-11-05 13:33:12 -06003412 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05003413 if (error)
3414 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04003415
James Smart549e55c2007-08-02 11:09:51 -04003416 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003417 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04003418 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003419 return vport;
James Smart47a86172007-04-25 09:53:22 -04003420
James Smart2e0fef82007-06-17 19:56:36 -05003421out_put_shost:
3422 scsi_host_put(shost);
3423out:
3424 return NULL;
James Smart47a86172007-04-25 09:53:22 -04003425}
3426
James Smarte59058c2008-08-24 21:49:00 -04003427/**
James Smart3621a712009-04-06 18:47:14 -04003428 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04003429 * @vport: pointer to an lpfc virtual N_Port data structure.
3430 *
3431 * This routine destroys a FC port from the upper layer protocol. All the
3432 * resources associated with the port are released.
3433 **/
James Smart2e0fef82007-06-17 19:56:36 -05003434void
3435destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04003436{
James Smart92d7f7b2007-06-17 19:56:38 -05003437 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3438 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003439
James Smart858c9f62007-06-17 19:56:39 -05003440 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05003441 fc_remove_host(shost);
3442 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04003443
James Smart92d7f7b2007-06-17 19:56:38 -05003444 spin_lock_irq(&phba->hbalock);
3445 list_del_init(&vport->listentry);
3446 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04003447
James Smart92d7f7b2007-06-17 19:56:38 -05003448 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04003449 return;
James Smart47a86172007-04-25 09:53:22 -04003450}
3451
James Smarte59058c2008-08-24 21:49:00 -04003452/**
James Smart3621a712009-04-06 18:47:14 -04003453 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04003454 *
3455 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3456 * uses the kernel idr facility to perform the task.
3457 *
3458 * Return codes:
3459 * instance - a unique integer ID allocated as the new instance.
3460 * -1 - lpfc get instance failed.
3461 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003462int
3463lpfc_get_instance(void)
3464{
Tejun Heoab516032013-02-27 17:04:44 -08003465 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003466
Tejun Heoab516032013-02-27 17:04:44 -08003467 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
3468 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003469}
3470
James Smarte59058c2008-08-24 21:49:00 -04003471/**
James Smart3621a712009-04-06 18:47:14 -04003472 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04003473 * @shost: pointer to SCSI host data structure.
3474 * @time: elapsed time of the scan in jiffies.
3475 *
3476 * This routine is called by the SCSI layer with a SCSI host to determine
3477 * whether the scan host is finished.
3478 *
3479 * Note: there is no scan_start function as adapter initialization will have
3480 * asynchronously kicked off the link initialization.
3481 *
3482 * Return codes
3483 * 0 - SCSI host scan is not over yet.
3484 * 1 - SCSI host scan is over.
3485 **/
James Smart47a86172007-04-25 09:53:22 -04003486int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
3487{
James Smart2e0fef82007-06-17 19:56:36 -05003488 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3489 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05003490 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04003491
James Smart858c9f62007-06-17 19:56:39 -05003492 spin_lock_irq(shost->host_lock);
3493
James Smart51ef4c22007-08-02 11:10:31 -04003494 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05003495 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003496 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05003497 }
James Smart256ec0d2013-04-17 20:14:58 -04003498 if (time >= msecs_to_jiffies(30 * 1000)) {
James Smart2e0fef82007-06-17 19:56:36 -05003499 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003500 "0461 Scanning longer than 30 "
3501 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003502 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003503 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003504 }
James Smart256ec0d2013-04-17 20:14:58 -04003505 if (time >= msecs_to_jiffies(15 * 1000) &&
3506 phba->link_state <= LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05003507 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003508 "0465 Link down longer than 15 "
3509 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003510 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05003511 goto finished;
James Smart47a86172007-04-25 09:53:22 -04003512 }
3513
James Smart2e0fef82007-06-17 19:56:36 -05003514 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05003515 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003516 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05003517 goto finished;
James Smart256ec0d2013-04-17 20:14:58 -04003518 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
James Smart858c9f62007-06-17 19:56:39 -05003519 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003520 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05003521 goto finished;
3522
3523 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003524
3525finished:
James Smart858c9f62007-06-17 19:56:39 -05003526 spin_unlock_irq(shost->host_lock);
3527 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003528}
3529
James Smarte59058c2008-08-24 21:49:00 -04003530/**
James Smart3621a712009-04-06 18:47:14 -04003531 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04003532 * @shost: pointer to SCSI host data structure.
3533 *
3534 * This routine initializes a given SCSI host attributes on a FC port. The
3535 * SCSI host can be either on top of a physical port or a virtual port.
3536 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003537void lpfc_host_attrib_init(struct Scsi_Host *shost)
3538{
3539 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3540 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003541 /*
James Smart2e0fef82007-06-17 19:56:36 -05003542 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04003543 */
3544
James Smart2e0fef82007-06-17 19:56:36 -05003545 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
3546 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04003547 fc_host_supported_classes(shost) = FC_COS_CLASS3;
3548
3549 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003550 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003551 fc_host_supported_fc4s(shost)[2] = 1;
3552 fc_host_supported_fc4s(shost)[7] = 1;
3553
James Smart92d7f7b2007-06-17 19:56:38 -05003554 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
3555 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04003556
3557 fc_host_supported_speeds(shost) = 0;
James Smartd38dd522015-08-31 16:48:17 -04003558 if (phba->lmt & LMT_32Gb)
3559 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
James Smart88a2cfb2011-07-22 18:36:33 -04003560 if (phba->lmt & LMT_16Gb)
3561 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
James Smart47a86172007-04-25 09:53:22 -04003562 if (phba->lmt & LMT_10Gb)
3563 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04003564 if (phba->lmt & LMT_8Gb)
3565 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04003566 if (phba->lmt & LMT_4Gb)
3567 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
3568 if (phba->lmt & LMT_2Gb)
3569 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
3570 if (phba->lmt & LMT_1Gb)
3571 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
3572
3573 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05003574 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
3575 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04003576
Mike Christie0af5d702010-09-15 16:52:31 -05003577 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
3578
James Smart47a86172007-04-25 09:53:22 -04003579 /* This value is also unchanging */
3580 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003581 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003582 fc_host_active_fc4s(shost)[2] = 1;
3583 fc_host_active_fc4s(shost)[7] = 1;
3584
James Smart92d7f7b2007-06-17 19:56:38 -05003585 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04003586 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04003587 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04003588 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04003589}
dea31012005-04-17 16:05:31 -05003590
James Smarte59058c2008-08-24 21:49:00 -04003591/**
James Smartda0436e2009-05-22 14:51:39 -04003592 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04003593 * @phba: pointer to lpfc hba data structure.
3594 *
James Smartda0436e2009-05-22 14:51:39 -04003595 * This routine is invoked to stop an SLI3 device port, it stops the device
3596 * from generating interrupts and stops the device driver's timers for the
3597 * device.
James Smarte59058c2008-08-24 21:49:00 -04003598 **/
James Smartdb2378e2008-02-08 18:49:51 -05003599static void
James Smartda0436e2009-05-22 14:51:39 -04003600lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05003601{
James Smartda0436e2009-05-22 14:51:39 -04003602 /* Clear all interrupt enable conditions */
3603 writel(0, phba->HCregaddr);
3604 readl(phba->HCregaddr); /* flush */
3605 /* Clear all pending interrupts */
3606 writel(0xffffffff, phba->HAregaddr);
3607 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04003608
James Smartda0436e2009-05-22 14:51:39 -04003609 /* Reset some HBA SLI setup states */
3610 lpfc_stop_hba_timers(phba);
3611 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05003612}
3613
James Smarte59058c2008-08-24 21:49:00 -04003614/**
James Smartda0436e2009-05-22 14:51:39 -04003615 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05003616 * @phba: pointer to lpfc hba data structure.
3617 *
James Smartda0436e2009-05-22 14:51:39 -04003618 * This routine is invoked to stop an SLI4 device port, it stops the device
3619 * from generating interrupts and stops the device driver's timers for the
3620 * device.
3621 **/
3622static void
3623lpfc_stop_port_s4(struct lpfc_hba *phba)
3624{
3625 /* Reset some HBA SLI4 setup states */
3626 lpfc_stop_hba_timers(phba);
3627 phba->pport->work_port_events = 0;
3628 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04003629}
3630
3631/**
3632 * lpfc_stop_port - Wrapper function for stopping hba port
3633 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05003634 *
James Smartda0436e2009-05-22 14:51:39 -04003635 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3636 * the API jump table function pointer from the lpfc_hba struct.
3637 **/
3638void
3639lpfc_stop_port(struct lpfc_hba *phba)
3640{
3641 phba->lpfc_stop_port(phba);
3642}
3643
3644/**
James Smartecfd03c2010-02-12 14:41:27 -05003645 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3646 * @phba: Pointer to hba for which this call is being executed.
3647 *
3648 * This routine starts the timer waiting for the FCF rediscovery to complete.
3649 **/
3650void
3651lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
3652{
3653 unsigned long fcf_redisc_wait_tmo =
3654 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
3655 /* Start fcf rediscovery wait period timer */
3656 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
3657 spin_lock_irq(&phba->hbalock);
3658 /* Allow action to new fcf asynchronous event */
3659 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
3660 /* Mark the FCF rediscovery pending state */
3661 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
3662 spin_unlock_irq(&phba->hbalock);
3663}
3664
3665/**
3666 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
3667 * @ptr: Map to lpfc_hba data structure pointer.
3668 *
3669 * This routine is invoked when waiting for FCF table rediscover has been
3670 * timed out. If new FCF record(s) has (have) been discovered during the
3671 * wait period, a new FCF event shall be added to the FCOE async event
3672 * list, and then worker thread shall be waked up for processing from the
3673 * worker thread context.
3674 **/
Rashika Kheriae399b222014-09-03 12:55:28 -04003675static void
James Smartecfd03c2010-02-12 14:41:27 -05003676lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
3677{
3678 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
3679
3680 /* Don't send FCF rediscovery event if timer cancelled */
3681 spin_lock_irq(&phba->hbalock);
3682 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
3683 spin_unlock_irq(&phba->hbalock);
3684 return;
3685 }
3686 /* Clear FCF rediscovery timer pending flag */
3687 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
3688 /* FCF rediscovery event to worker thread */
3689 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
3690 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003691 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04003692 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05003693 /* wake up worker thread */
3694 lpfc_worker_wake_up(phba);
3695}
3696
3697/**
James Smartda0436e2009-05-22 14:51:39 -04003698 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
3699 * @phba: pointer to lpfc hba data structure.
3700 * @acqe_link: pointer to the async link completion queue entry.
3701 *
3702 * This routine is to parse the SLI4 link-attention link fault code and
3703 * translate it into the base driver's read link attention mailbox command
3704 * status.
3705 *
3706 * Return: Link-attention status in terms of base driver's coding.
3707 **/
3708static uint16_t
3709lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
3710 struct lpfc_acqe_link *acqe_link)
3711{
3712 uint16_t latt_fault;
3713
3714 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
3715 case LPFC_ASYNC_LINK_FAULT_NONE:
3716 case LPFC_ASYNC_LINK_FAULT_LOCAL:
3717 case LPFC_ASYNC_LINK_FAULT_REMOTE:
3718 latt_fault = 0;
3719 break;
3720 default:
3721 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3722 "0398 Invalid link fault code: x%x\n",
3723 bf_get(lpfc_acqe_link_fault, acqe_link));
3724 latt_fault = MBXERR_ERROR;
3725 break;
3726 }
3727 return latt_fault;
3728}
3729
3730/**
3731 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
3732 * @phba: pointer to lpfc hba data structure.
3733 * @acqe_link: pointer to the async link completion queue entry.
3734 *
3735 * This routine is to parse the SLI4 link attention type and translate it
3736 * into the base driver's link attention type coding.
3737 *
3738 * Return: Link attention type in terms of base driver's coding.
3739 **/
3740static uint8_t
3741lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
3742 struct lpfc_acqe_link *acqe_link)
3743{
3744 uint8_t att_type;
3745
3746 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
3747 case LPFC_ASYNC_LINK_STATUS_DOWN:
3748 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05003749 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04003750 break;
3751 case LPFC_ASYNC_LINK_STATUS_UP:
3752 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05003753 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003754 break;
3755 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05003756 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04003757 break;
3758 default:
3759 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3760 "0399 Invalid link attention type: x%x\n",
3761 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003762 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003763 break;
3764 }
3765 return att_type;
3766}
3767
3768/**
James Smart8b68cd52012-09-29 11:32:37 -04003769 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
3770 * @phba: pointer to lpfc hba data structure.
3771 *
3772 * This routine is to get an SLI3 FC port's link speed in Mbps.
3773 *
3774 * Return: link speed in terms of Mbps.
3775 **/
3776uint32_t
3777lpfc_sli_port_speed_get(struct lpfc_hba *phba)
3778{
3779 uint32_t link_speed;
3780
3781 if (!lpfc_is_link_up(phba))
3782 return 0;
3783
James Smarta085e872015-12-16 18:12:02 -05003784 if (phba->sli_rev <= LPFC_SLI_REV3) {
3785 switch (phba->fc_linkspeed) {
3786 case LPFC_LINK_SPEED_1GHZ:
3787 link_speed = 1000;
3788 break;
3789 case LPFC_LINK_SPEED_2GHZ:
3790 link_speed = 2000;
3791 break;
3792 case LPFC_LINK_SPEED_4GHZ:
3793 link_speed = 4000;
3794 break;
3795 case LPFC_LINK_SPEED_8GHZ:
3796 link_speed = 8000;
3797 break;
3798 case LPFC_LINK_SPEED_10GHZ:
3799 link_speed = 10000;
3800 break;
3801 case LPFC_LINK_SPEED_16GHZ:
3802 link_speed = 16000;
3803 break;
3804 default:
3805 link_speed = 0;
3806 }
3807 } else {
3808 if (phba->sli4_hba.link_state.logical_speed)
3809 link_speed =
3810 phba->sli4_hba.link_state.logical_speed;
3811 else
3812 link_speed = phba->sli4_hba.link_state.speed;
James Smart8b68cd52012-09-29 11:32:37 -04003813 }
3814 return link_speed;
3815}
3816
3817/**
3818 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
3819 * @phba: pointer to lpfc hba data structure.
3820 * @evt_code: asynchronous event code.
3821 * @speed_code: asynchronous event link speed code.
3822 *
3823 * This routine is to parse the giving SLI4 async event link speed code into
3824 * value of Mbps for the link speed.
3825 *
3826 * Return: link speed in terms of Mbps.
3827 **/
3828static uint32_t
3829lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
3830 uint8_t speed_code)
3831{
3832 uint32_t port_speed;
3833
3834 switch (evt_code) {
3835 case LPFC_TRAILER_CODE_LINK:
3836 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04003837 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smart8b68cd52012-09-29 11:32:37 -04003838 port_speed = 0;
3839 break;
James Smart26d830e2015-04-07 15:07:17 -04003840 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04003841 port_speed = 10;
3842 break;
James Smart26d830e2015-04-07 15:07:17 -04003843 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04003844 port_speed = 100;
3845 break;
James Smart26d830e2015-04-07 15:07:17 -04003846 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04003847 port_speed = 1000;
3848 break;
James Smart26d830e2015-04-07 15:07:17 -04003849 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04003850 port_speed = 10000;
3851 break;
James Smart26d830e2015-04-07 15:07:17 -04003852 case LPFC_ASYNC_LINK_SPEED_20GBPS:
3853 port_speed = 20000;
3854 break;
3855 case LPFC_ASYNC_LINK_SPEED_25GBPS:
3856 port_speed = 25000;
3857 break;
3858 case LPFC_ASYNC_LINK_SPEED_40GBPS:
3859 port_speed = 40000;
3860 break;
James Smart8b68cd52012-09-29 11:32:37 -04003861 default:
3862 port_speed = 0;
3863 }
3864 break;
3865 case LPFC_TRAILER_CODE_FC:
3866 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04003867 case LPFC_FC_LA_SPEED_UNKNOWN:
James Smart8b68cd52012-09-29 11:32:37 -04003868 port_speed = 0;
3869 break;
James Smart26d830e2015-04-07 15:07:17 -04003870 case LPFC_FC_LA_SPEED_1G:
James Smart8b68cd52012-09-29 11:32:37 -04003871 port_speed = 1000;
3872 break;
James Smart26d830e2015-04-07 15:07:17 -04003873 case LPFC_FC_LA_SPEED_2G:
James Smart8b68cd52012-09-29 11:32:37 -04003874 port_speed = 2000;
3875 break;
James Smart26d830e2015-04-07 15:07:17 -04003876 case LPFC_FC_LA_SPEED_4G:
James Smart8b68cd52012-09-29 11:32:37 -04003877 port_speed = 4000;
3878 break;
James Smart26d830e2015-04-07 15:07:17 -04003879 case LPFC_FC_LA_SPEED_8G:
James Smart8b68cd52012-09-29 11:32:37 -04003880 port_speed = 8000;
3881 break;
James Smart26d830e2015-04-07 15:07:17 -04003882 case LPFC_FC_LA_SPEED_10G:
James Smart8b68cd52012-09-29 11:32:37 -04003883 port_speed = 10000;
3884 break;
James Smart26d830e2015-04-07 15:07:17 -04003885 case LPFC_FC_LA_SPEED_16G:
James Smart8b68cd52012-09-29 11:32:37 -04003886 port_speed = 16000;
3887 break;
James Smartd38dd522015-08-31 16:48:17 -04003888 case LPFC_FC_LA_SPEED_32G:
3889 port_speed = 32000;
3890 break;
James Smart8b68cd52012-09-29 11:32:37 -04003891 default:
3892 port_speed = 0;
3893 }
3894 break;
3895 default:
3896 port_speed = 0;
3897 }
3898 return port_speed;
3899}
3900
3901/**
James Smart70f3c072010-12-15 17:57:33 -05003902 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04003903 * @phba: pointer to lpfc hba data structure.
3904 * @acqe_link: pointer to the async link completion queue entry.
3905 *
James Smart70f3c072010-12-15 17:57:33 -05003906 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04003907 **/
3908static void
3909lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
3910 struct lpfc_acqe_link *acqe_link)
3911{
3912 struct lpfc_dmabuf *mp;
3913 LPFC_MBOXQ_t *pmb;
3914 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05003915 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04003916 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05003917 int rc;
James Smartda0436e2009-05-22 14:51:39 -04003918
3919 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05003920 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04003921 return;
James Smart32b97932009-07-19 10:01:21 -04003922 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04003923 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3924 if (!pmb) {
3925 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3926 "0395 The mboxq allocation failed\n");
3927 return;
3928 }
3929 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3930 if (!mp) {
3931 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3932 "0396 The lpfc_dmabuf allocation failed\n");
3933 goto out_free_pmb;
3934 }
3935 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
3936 if (!mp->virt) {
3937 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3938 "0397 The mbuf allocation failed\n");
3939 goto out_free_dmabuf;
3940 }
3941
3942 /* Cleanup any outstanding ELS commands */
3943 lpfc_els_flush_all_cmd(phba);
3944
3945 /* Block ELS IOCBs until we have done process link event */
3946 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
3947
3948 /* Update link event statistics */
3949 phba->sli.slistat.link_event++;
3950
James Smart76a95d72010-11-20 23:11:48 -05003951 /* Create lpfc_handle_latt mailbox command from link ACQE */
3952 lpfc_read_topology(phba, pmb, mp);
3953 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04003954 pmb->vport = phba->pport;
3955
James Smartda0436e2009-05-22 14:51:39 -04003956 /* Keep the link status for extra SLI4 state machine reference */
3957 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04003958 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
3959 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04003960 phba->sli4_hba.link_state.duplex =
3961 bf_get(lpfc_acqe_link_duplex, acqe_link);
3962 phba->sli4_hba.link_state.status =
3963 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05003964 phba->sli4_hba.link_state.type =
3965 bf_get(lpfc_acqe_link_type, acqe_link);
3966 phba->sli4_hba.link_state.number =
3967 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04003968 phba->sli4_hba.link_state.fault =
3969 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05003970 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04003971 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
3972
James Smart70f3c072010-12-15 17:57:33 -05003973 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04003974 "2900 Async FC/FCoE Link event - Speed:%dGBit "
3975 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
3976 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05003977 phba->sli4_hba.link_state.speed,
3978 phba->sli4_hba.link_state.topology,
3979 phba->sli4_hba.link_state.status,
3980 phba->sli4_hba.link_state.type,
3981 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04003982 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05003983 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05003984 /*
3985 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
3986 * topology info. Note: Optional for non FC-AL ports.
3987 */
3988 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3989 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3990 if (rc == MBX_NOT_FINISHED)
3991 goto out_free_dmabuf;
3992 return;
3993 }
3994 /*
3995 * For FCoE Mode: fill in all the topology information we need and call
3996 * the READ_TOPOLOGY completion routine to continue without actually
3997 * sending the READ_TOPOLOGY mailbox command to the port.
3998 */
3999 /* Parse and translate status field */
4000 mb = &pmb->u.mb;
4001 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
4002
4003 /* Parse and translate link attention fields */
4004 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
4005 la->eventTag = acqe_link->event_tag;
4006 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
4007 bf_set(lpfc_mbx_read_top_link_spd, la,
James Smarta085e872015-12-16 18:12:02 -05004008 (bf_get(lpfc_acqe_link_speed, acqe_link)));
James Smart76a95d72010-11-20 23:11:48 -05004009
4010 /* Fake the the following irrelvant fields */
4011 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
4012 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
4013 bf_set(lpfc_mbx_read_top_il, la, 0);
4014 bf_set(lpfc_mbx_read_top_pb, la, 0);
4015 bf_set(lpfc_mbx_read_top_fa, la, 0);
4016 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04004017
4018 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05004019 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04004020
4021 return;
4022
4023out_free_dmabuf:
4024 kfree(mp);
4025out_free_pmb:
4026 mempool_free(pmb, phba->mbox_mem_pool);
4027}
4028
4029/**
James Smart70f3c072010-12-15 17:57:33 -05004030 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
4031 * @phba: pointer to lpfc hba data structure.
4032 * @acqe_fc: pointer to the async fc completion queue entry.
4033 *
4034 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
4035 * that the event was received and then issue a read_topology mailbox command so
4036 * that the rest of the driver will treat it the same as SLI3.
4037 **/
4038static void
4039lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
4040{
4041 struct lpfc_dmabuf *mp;
4042 LPFC_MBOXQ_t *pmb;
James Smart7bdedb32016-07-06 12:36:00 -07004043 MAILBOX_t *mb;
4044 struct lpfc_mbx_read_top *la;
James Smart70f3c072010-12-15 17:57:33 -05004045 int rc;
4046
4047 if (bf_get(lpfc_trailer_type, acqe_fc) !=
4048 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
4049 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4050 "2895 Non FC link Event detected.(%d)\n",
4051 bf_get(lpfc_trailer_type, acqe_fc));
4052 return;
4053 }
4054 /* Keep the link status for extra SLI4 state machine reference */
4055 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004056 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
4057 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05004058 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
4059 phba->sli4_hba.link_state.topology =
4060 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
4061 phba->sli4_hba.link_state.status =
4062 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
4063 phba->sli4_hba.link_state.type =
4064 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
4065 phba->sli4_hba.link_state.number =
4066 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
4067 phba->sli4_hba.link_state.fault =
4068 bf_get(lpfc_acqe_link_fault, acqe_fc);
4069 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004070 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart70f3c072010-12-15 17:57:33 -05004071 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4072 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4073 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4074 "%dMbps Fault:%d\n",
4075 phba->sli4_hba.link_state.speed,
4076 phba->sli4_hba.link_state.topology,
4077 phba->sli4_hba.link_state.status,
4078 phba->sli4_hba.link_state.type,
4079 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004080 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004081 phba->sli4_hba.link_state.fault);
4082 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4083 if (!pmb) {
4084 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4085 "2897 The mboxq allocation failed\n");
4086 return;
4087 }
4088 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4089 if (!mp) {
4090 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4091 "2898 The lpfc_dmabuf allocation failed\n");
4092 goto out_free_pmb;
4093 }
4094 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4095 if (!mp->virt) {
4096 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4097 "2899 The mbuf allocation failed\n");
4098 goto out_free_dmabuf;
4099 }
4100
4101 /* Cleanup any outstanding ELS commands */
4102 lpfc_els_flush_all_cmd(phba);
4103
4104 /* Block ELS IOCBs until we have done process link event */
4105 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
4106
4107 /* Update link event statistics */
4108 phba->sli.slistat.link_event++;
4109
4110 /* Create lpfc_handle_latt mailbox command from link ACQE */
4111 lpfc_read_topology(phba, pmb, mp);
4112 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4113 pmb->vport = phba->pport;
4114
James Smart7bdedb32016-07-06 12:36:00 -07004115 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
4116 /* Parse and translate status field */
4117 mb = &pmb->u.mb;
4118 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba,
4119 (void *)acqe_fc);
4120
4121 /* Parse and translate link attention fields */
4122 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
4123 la->eventTag = acqe_fc->event_tag;
4124 bf_set(lpfc_mbx_read_top_att_type, la,
4125 LPFC_FC_LA_TYPE_LINK_DOWN);
4126
4127 /* Invoke the mailbox command callback function */
4128 lpfc_mbx_cmpl_read_topology(phba, pmb);
4129
4130 return;
4131 }
4132
James Smart70f3c072010-12-15 17:57:33 -05004133 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4134 if (rc == MBX_NOT_FINISHED)
4135 goto out_free_dmabuf;
4136 return;
4137
4138out_free_dmabuf:
4139 kfree(mp);
4140out_free_pmb:
4141 mempool_free(pmb, phba->mbox_mem_pool);
4142}
4143
4144/**
4145 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4146 * @phba: pointer to lpfc hba data structure.
4147 * @acqe_fc: pointer to the async SLI completion queue entry.
4148 *
4149 * This routine is to handle the SLI4 asynchronous SLI events.
4150 **/
4151static void
4152lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
4153{
James Smart4b8bae02012-06-12 13:55:07 -04004154 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04004155 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04004156 uint8_t status;
James Smart946727d2015-04-07 15:07:09 -04004157 uint8_t evt_type;
James Smart448193b2015-12-16 18:12:05 -05004158 uint8_t operational = 0;
James Smart946727d2015-04-07 15:07:09 -04004159 struct temp_event temp_event_data;
James Smart4b8bae02012-06-12 13:55:07 -04004160 struct lpfc_acqe_misconfigured_event *misconfigured;
James Smart946727d2015-04-07 15:07:09 -04004161 struct Scsi_Host *shost;
James Smart4b8bae02012-06-12 13:55:07 -04004162
James Smart946727d2015-04-07 15:07:09 -04004163 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
4164
James Smart448193b2015-12-16 18:12:05 -05004165 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4166 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4167 "x%08x SLI Event Type:%d\n",
4168 acqe_sli->event_data1, acqe_sli->event_data2,
4169 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004170
4171 port_name = phba->Port[0];
4172 if (port_name == 0x00)
4173 port_name = '?'; /* get port name is empty */
4174
James Smart946727d2015-04-07 15:07:09 -04004175 switch (evt_type) {
4176 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
4177 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4178 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
4179 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4180
4181 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4182 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4183 acqe_sli->event_data1, port_name);
4184
James Smart310429e2016-07-06 12:35:54 -07004185 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04004186 shost = lpfc_shost_from_vport(phba->pport);
4187 fc_host_post_vendor_event(shost, fc_get_event_number(),
4188 sizeof(temp_event_data),
4189 (char *)&temp_event_data,
4190 SCSI_NL_VID_TYPE_PCI
4191 | PCI_VENDOR_ID_EMULEX);
4192 break;
4193 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
4194 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4195 temp_event_data.event_code = LPFC_NORMAL_TEMP;
4196 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4197
4198 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4199 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4200 acqe_sli->event_data1, port_name);
4201
4202 shost = lpfc_shost_from_vport(phba->pport);
4203 fc_host_post_vendor_event(shost, fc_get_event_number(),
4204 sizeof(temp_event_data),
4205 (char *)&temp_event_data,
4206 SCSI_NL_VID_TYPE_PCI
4207 | PCI_VENDOR_ID_EMULEX);
4208 break;
4209 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
4210 misconfigured = (struct lpfc_acqe_misconfigured_event *)
James Smart4b8bae02012-06-12 13:55:07 -04004211 &acqe_sli->event_data1;
4212
James Smart946727d2015-04-07 15:07:09 -04004213 /* fetch the status for this port */
4214 switch (phba->sli4_hba.lnk_info.lnk_no) {
4215 case LPFC_LINK_NUMBER_0:
James Smart448193b2015-12-16 18:12:05 -05004216 status = bf_get(lpfc_sli_misconfigured_port0_state,
4217 &misconfigured->theEvent);
4218 operational = bf_get(lpfc_sli_misconfigured_port0_op,
James Smart4b8bae02012-06-12 13:55:07 -04004219 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004220 break;
4221 case LPFC_LINK_NUMBER_1:
James Smart448193b2015-12-16 18:12:05 -05004222 status = bf_get(lpfc_sli_misconfigured_port1_state,
4223 &misconfigured->theEvent);
4224 operational = bf_get(lpfc_sli_misconfigured_port1_op,
James Smart4b8bae02012-06-12 13:55:07 -04004225 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004226 break;
4227 case LPFC_LINK_NUMBER_2:
James Smart448193b2015-12-16 18:12:05 -05004228 status = bf_get(lpfc_sli_misconfigured_port2_state,
4229 &misconfigured->theEvent);
4230 operational = bf_get(lpfc_sli_misconfigured_port2_op,
James Smart4b8bae02012-06-12 13:55:07 -04004231 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004232 break;
4233 case LPFC_LINK_NUMBER_3:
James Smart448193b2015-12-16 18:12:05 -05004234 status = bf_get(lpfc_sli_misconfigured_port3_state,
4235 &misconfigured->theEvent);
4236 operational = bf_get(lpfc_sli_misconfigured_port3_op,
James Smart4b8bae02012-06-12 13:55:07 -04004237 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004238 break;
4239 default:
James Smart448193b2015-12-16 18:12:05 -05004240 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4241 "3296 "
4242 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
4243 "event: Invalid link %d",
4244 phba->sli4_hba.lnk_info.lnk_no);
4245 return;
James Smart946727d2015-04-07 15:07:09 -04004246 }
James Smart4b8bae02012-06-12 13:55:07 -04004247
James Smart448193b2015-12-16 18:12:05 -05004248 /* Skip if optic state unchanged */
4249 if (phba->sli4_hba.lnk_info.optic_state == status)
4250 return;
4251
James Smart946727d2015-04-07 15:07:09 -04004252 switch (status) {
4253 case LPFC_SLI_EVENT_STATUS_VALID:
James Smart448193b2015-12-16 18:12:05 -05004254 sprintf(message, "Physical Link is functional");
4255 break;
James Smart946727d2015-04-07 15:07:09 -04004256 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
4257 sprintf(message, "Optics faulted/incorrectly "
4258 "installed/not installed - Reseat optics, "
4259 "if issue not resolved, replace.");
4260 break;
4261 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
4262 sprintf(message,
4263 "Optics of two types installed - Remove one "
4264 "optic or install matching pair of optics.");
4265 break;
4266 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
4267 sprintf(message, "Incompatible optics - Replace with "
James Smart292098b2012-09-29 11:31:41 -04004268 "compatible optics for card to function.");
James Smart946727d2015-04-07 15:07:09 -04004269 break;
James Smart448193b2015-12-16 18:12:05 -05004270 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
4271 sprintf(message, "Unqualified optics - Replace with "
4272 "Avago optics for Warranty and Technical "
4273 "Support - Link is%s operational",
4274 (operational) ? "" : " not");
4275 break;
4276 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
4277 sprintf(message, "Uncertified optics - Replace with "
4278 "Avago-certified optics to enable link "
4279 "operation - Link is%s operational",
4280 (operational) ? "" : " not");
4281 break;
James Smart946727d2015-04-07 15:07:09 -04004282 default:
4283 /* firmware is reporting a status we don't know about */
4284 sprintf(message, "Unknown event status x%02x", status);
4285 break;
4286 }
James Smart448193b2015-12-16 18:12:05 -05004287 phba->sli4_hba.lnk_info.optic_state = status;
James Smart946727d2015-04-07 15:07:09 -04004288 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart448193b2015-12-16 18:12:05 -05004289 "3176 Port Name %c %s\n", port_name, message);
James Smart946727d2015-04-07 15:07:09 -04004290 break;
4291 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
4292 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4293 "3192 Remote DPort Test Initiated - "
4294 "Event Data1:x%08x Event Data2: x%08x\n",
4295 acqe_sli->event_data1, acqe_sli->event_data2);
James Smart4b8bae02012-06-12 13:55:07 -04004296 break;
4297 default:
James Smart946727d2015-04-07 15:07:09 -04004298 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4299 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
4300 "x%08x SLI Event Type:%d\n",
4301 acqe_sli->event_data1, acqe_sli->event_data2,
4302 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004303 break;
4304 }
James Smart70f3c072010-12-15 17:57:33 -05004305}
4306
4307/**
James Smartfc2b9892010-02-26 14:15:29 -05004308 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
4309 * @vport: pointer to vport data structure.
4310 *
4311 * This routine is to perform Clear Virtual Link (CVL) on a vport in
4312 * response to a CVL event.
4313 *
4314 * Return the pointer to the ndlp with the vport if successful, otherwise
4315 * return NULL.
4316 **/
4317static struct lpfc_nodelist *
4318lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
4319{
4320 struct lpfc_nodelist *ndlp;
4321 struct Scsi_Host *shost;
4322 struct lpfc_hba *phba;
4323
4324 if (!vport)
4325 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05004326 phba = vport->phba;
4327 if (!phba)
4328 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04004329 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4330 if (!ndlp) {
4331 /* Cannot find existing Fabric ndlp, so allocate a new one */
4332 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4333 if (!ndlp)
4334 return 0;
4335 lpfc_nlp_init(vport, ndlp, Fabric_DID);
4336 /* Set the node type */
4337 ndlp->nlp_type |= NLP_FABRIC;
4338 /* Put ndlp onto node list */
4339 lpfc_enqueue_node(vport, ndlp);
4340 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4341 /* re-setup ndlp without removing from node list */
4342 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4343 if (!ndlp)
4344 return 0;
4345 }
James Smart63e801c2010-11-20 23:14:19 -05004346 if ((phba->pport->port_state < LPFC_FLOGI) &&
4347 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004348 return NULL;
4349 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05004350 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
4351 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004352 return NULL;
4353 shost = lpfc_shost_from_vport(vport);
4354 if (!shost)
4355 return NULL;
4356 lpfc_linkdown_port(vport);
4357 lpfc_cleanup_pending_mbox(vport);
4358 spin_lock_irq(shost->host_lock);
4359 vport->fc_flag |= FC_VPORT_CVL_RCVD;
4360 spin_unlock_irq(shost->host_lock);
4361
4362 return ndlp;
4363}
4364
4365/**
4366 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4367 * @vport: pointer to lpfc hba data structure.
4368 *
4369 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4370 * response to a FCF dead event.
4371 **/
4372static void
4373lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
4374{
4375 struct lpfc_vport **vports;
4376 int i;
4377
4378 vports = lpfc_create_vport_work_array(phba);
4379 if (vports)
4380 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4381 lpfc_sli4_perform_vport_cvl(vports[i]);
4382 lpfc_destroy_vport_work_array(phba, vports);
4383}
4384
4385/**
James Smart76a95d72010-11-20 23:11:48 -05004386 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04004387 * @phba: pointer to lpfc hba data structure.
4388 * @acqe_link: pointer to the async fcoe completion queue entry.
4389 *
4390 * This routine is to handle the SLI4 asynchronous fcoe event.
4391 **/
4392static void
James Smart76a95d72010-11-20 23:11:48 -05004393lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05004394 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04004395{
James Smart70f3c072010-12-15 17:57:33 -05004396 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004397 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04004398 struct lpfc_vport *vport;
4399 struct lpfc_nodelist *ndlp;
4400 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05004401 int active_vlink_present;
4402 struct lpfc_vport **vports;
4403 int i;
James Smartda0436e2009-05-22 14:51:39 -04004404
James Smart70f3c072010-12-15 17:57:33 -05004405 phba->fc_eventTag = acqe_fip->event_tag;
4406 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004407 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05004408 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
4409 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
4410 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04004411 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4412 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004413 "2546 New FCF event, evt_tag:x%x, "
4414 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004415 acqe_fip->event_tag,
4416 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04004417 else
4418 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
4419 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004420 "2788 FCF param modified event, "
4421 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004422 acqe_fip->event_tag,
4423 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04004424 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004425 /*
4426 * During period of FCF discovery, read the FCF
4427 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04004428 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05004429 */
4430 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4431 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004432 "2779 Read FCF (x%x) for updating "
4433 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05004434 acqe_fip->index);
4435 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004436 }
James Smart38b92ef2010-08-04 16:11:39 -04004437
4438 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04004439 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04004440 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04004441 spin_unlock_irq(&phba->hbalock);
4442 break;
4443 }
4444 /* If fast FCF failover rescan event is pending, do nothing */
4445 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
4446 spin_unlock_irq(&phba->hbalock);
4447 break;
4448 }
4449
James Smartc2b97122013-05-31 17:05:36 -04004450 /* If the FCF has been in discovered state, do nothing. */
4451 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
James Smart3804dc82010-07-14 15:31:37 -04004452 spin_unlock_irq(&phba->hbalock);
4453 break;
4454 }
4455 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04004456
James Smart0c9ab6f2010-02-26 14:15:57 -05004457 /* Otherwise, scan the entire FCF table and re-discover SAN */
4458 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004459 "2770 Start FCF table scan per async FCF "
4460 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004461 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004462 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
4463 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04004464 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004465 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4466 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04004467 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04004468 break;
4469
James Smart70f3c072010-12-15 17:57:33 -05004470 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04004471 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04004472 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004473 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
4474 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004475 break;
4476
James Smart70f3c072010-12-15 17:57:33 -05004477 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05004478 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004479 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004480 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05004481 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04004482 /*
4483 * If we are in the middle of FCF failover process, clear
4484 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04004485 */
James Smartfc2b9892010-02-26 14:15:29 -05004486 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004487 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05004488 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004489 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05004490 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004491 break;
4492 }
James Smart38b92ef2010-08-04 16:11:39 -04004493 spin_unlock_irq(&phba->hbalock);
4494
4495 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05004496 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04004497 break;
4498
4499 /*
4500 * Otherwise, request the port to rediscover the entire FCF
4501 * table for a fast recovery from case that the current FCF
4502 * is no longer valid as we are not in the middle of FCF
4503 * failover process already.
4504 */
James Smartc2b97122013-05-31 17:05:36 -04004505 spin_lock_irq(&phba->hbalock);
4506 /* Mark the fast failover process in progress */
4507 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
4508 spin_unlock_irq(&phba->hbalock);
4509
4510 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
4511 "2771 Start FCF fast failover process due to "
4512 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
4513 "\n", acqe_fip->event_tag, acqe_fip->index);
4514 rc = lpfc_sli4_redisc_fcf_table(phba);
4515 if (rc) {
4516 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4517 LOG_DISCOVERY,
4518 "2772 Issue FCF rediscover mabilbox "
4519 "command failed, fail through to FCF "
4520 "dead event\n");
4521 spin_lock_irq(&phba->hbalock);
4522 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
4523 spin_unlock_irq(&phba->hbalock);
4524 /*
4525 * Last resort will fail over by treating this
4526 * as a link down to FCF registration.
4527 */
4528 lpfc_sli4_fcf_dead_failthrough(phba);
4529 } else {
4530 /* Reset FCF roundrobin bmask for new discovery */
4531 lpfc_sli4_clear_fcf_rr_bmask(phba);
4532 /*
4533 * Handling fast FCF failover to a DEAD FCF event is
4534 * considered equalivant to receiving CVL to all vports.
4535 */
4536 lpfc_sli4_perform_all_vport_cvl(phba);
4537 }
James Smartda0436e2009-05-22 14:51:39 -04004538 break;
James Smart70f3c072010-12-15 17:57:33 -05004539 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05004540 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004541 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04004542 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05004543 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04004544
James Smart6669f9b2009-10-02 15:16:45 -04004545 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04004546 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004547 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004548 if (!ndlp)
4549 break;
James Smart695a8142010-01-26 23:08:03 -05004550 active_vlink_present = 0;
4551
4552 vports = lpfc_create_vport_work_array(phba);
4553 if (vports) {
4554 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
4555 i++) {
4556 if ((!(vports[i]->fc_flag &
4557 FC_VPORT_CVL_RCVD)) &&
4558 (vports[i]->port_state > LPFC_FDISC)) {
4559 active_vlink_present = 1;
4560 break;
4561 }
4562 }
4563 lpfc_destroy_vport_work_array(phba, vports);
4564 }
4565
James Smartcc823552015-05-21 13:55:26 -04004566 /*
4567 * Don't re-instantiate if vport is marked for deletion.
4568 * If we are here first then vport_delete is going to wait
4569 * for discovery to complete.
4570 */
4571 if (!(vport->load_flag & FC_UNLOADING) &&
4572 active_vlink_present) {
James Smart695a8142010-01-26 23:08:03 -05004573 /*
4574 * If there are other active VLinks present,
4575 * re-instantiate the Vlink using FDISC.
4576 */
James Smart256ec0d2013-04-17 20:14:58 -04004577 mod_timer(&ndlp->nlp_delayfunc,
4578 jiffies + msecs_to_jiffies(1000));
James Smartfc2b9892010-02-26 14:15:29 -05004579 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004580 spin_lock_irq(shost->host_lock);
4581 ndlp->nlp_flag |= NLP_DELAY_TMO;
4582 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05004583 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
4584 vport->port_state = LPFC_FDISC;
4585 } else {
James Smartecfd03c2010-02-12 14:41:27 -05004586 /*
4587 * Otherwise, we request port to rediscover
4588 * the entire FCF table for a fast recovery
4589 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05004590 * is no longer valid if we are not already
4591 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05004592 */
James Smartfc2b9892010-02-26 14:15:29 -05004593 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004594 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05004595 spin_unlock_irq(&phba->hbalock);
4596 break;
4597 }
4598 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05004599 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004600 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004601 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4602 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004603 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05004604 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05004605 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05004606 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004607 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4608 LOG_DISCOVERY,
4609 "2774 Issue FCF rediscover "
4610 "mabilbox command failed, "
4611 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05004612 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004613 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004614 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05004615 /*
4616 * Last resort will be re-try on the
4617 * the current registered FCF entry.
4618 */
4619 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04004620 } else
4621 /*
4622 * Reset FCF roundrobin bmask for new
4623 * discovery.
4624 */
James Smart7d791df2011-07-22 18:37:52 -04004625 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04004626 }
4627 break;
James Smartda0436e2009-05-22 14:51:39 -04004628 default:
4629 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4630 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05004631 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004632 break;
4633 }
4634}
4635
4636/**
4637 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
4638 * @phba: pointer to lpfc hba data structure.
4639 * @acqe_link: pointer to the async dcbx completion queue entry.
4640 *
4641 * This routine is to handle the SLI4 asynchronous dcbx event.
4642 **/
4643static void
4644lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
4645 struct lpfc_acqe_dcbx *acqe_dcbx)
4646{
James Smart4d9ab992009-10-02 15:16:39 -04004647 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004648 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4649 "0290 The SLI4 DCBX asynchronous event is not "
4650 "handled yet\n");
4651}
4652
4653/**
James Smartb19a0612010-04-06 14:48:51 -04004654 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
4655 * @phba: pointer to lpfc hba data structure.
4656 * @acqe_link: pointer to the async grp5 completion queue entry.
4657 *
4658 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
4659 * is an asynchronous notified of a logical link speed change. The Port
4660 * reports the logical link speed in units of 10Mbps.
4661 **/
4662static void
4663lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
4664 struct lpfc_acqe_grp5 *acqe_grp5)
4665{
4666 uint16_t prev_ll_spd;
4667
4668 phba->fc_eventTag = acqe_grp5->event_tag;
4669 phba->fcoe_eventtag = acqe_grp5->event_tag;
4670 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
4671 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004672 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04004673 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4674 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04004675 "from %dMbps to %dMbps\n", prev_ll_spd,
4676 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04004677}
4678
4679/**
James Smartda0436e2009-05-22 14:51:39 -04004680 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
4681 * @phba: pointer to lpfc hba data structure.
4682 *
4683 * This routine is invoked by the worker thread to process all the pending
4684 * SLI4 asynchronous events.
4685 **/
4686void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
4687{
4688 struct lpfc_cq_event *cq_event;
4689
4690 /* First, declare the async event has been handled */
4691 spin_lock_irq(&phba->hbalock);
4692 phba->hba_flag &= ~ASYNC_EVENT;
4693 spin_unlock_irq(&phba->hbalock);
4694 /* Now, handle all the async events */
4695 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
4696 /* Get the first event from the head of the event queue */
4697 spin_lock_irq(&phba->hbalock);
4698 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
4699 cq_event, struct lpfc_cq_event, list);
4700 spin_unlock_irq(&phba->hbalock);
4701 /* Process the asynchronous event */
4702 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
4703 case LPFC_TRAILER_CODE_LINK:
4704 lpfc_sli4_async_link_evt(phba,
4705 &cq_event->cqe.acqe_link);
4706 break;
4707 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05004708 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004709 break;
4710 case LPFC_TRAILER_CODE_DCBX:
4711 lpfc_sli4_async_dcbx_evt(phba,
4712 &cq_event->cqe.acqe_dcbx);
4713 break;
James Smartb19a0612010-04-06 14:48:51 -04004714 case LPFC_TRAILER_CODE_GRP5:
4715 lpfc_sli4_async_grp5_evt(phba,
4716 &cq_event->cqe.acqe_grp5);
4717 break;
James Smart70f3c072010-12-15 17:57:33 -05004718 case LPFC_TRAILER_CODE_FC:
4719 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
4720 break;
4721 case LPFC_TRAILER_CODE_SLI:
4722 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
4723 break;
James Smartda0436e2009-05-22 14:51:39 -04004724 default:
4725 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4726 "1804 Invalid asynchrous event code: "
4727 "x%x\n", bf_get(lpfc_trailer_code,
4728 &cq_event->cqe.mcqe_cmpl));
4729 break;
4730 }
4731 /* Free the completion event processed to the free pool */
4732 lpfc_sli4_cq_event_release(phba, cq_event);
4733 }
4734}
4735
4736/**
James Smartecfd03c2010-02-12 14:41:27 -05004737 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
4738 * @phba: pointer to lpfc hba data structure.
4739 *
4740 * This routine is invoked by the worker thread to process FCF table
4741 * rediscovery pending completion event.
4742 **/
4743void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
4744{
4745 int rc;
4746
4747 spin_lock_irq(&phba->hbalock);
4748 /* Clear FCF rediscovery timeout event */
4749 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
4750 /* Clear driver fast failover FCF record flag */
4751 phba->fcf.failover_rec.flag = 0;
4752 /* Set state for FCF fast failover */
4753 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
4754 spin_unlock_irq(&phba->hbalock);
4755
4756 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05004757 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004758 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05004759 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05004760 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004761 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4762 "2747 Issue FCF scan read FCF mailbox "
4763 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05004764}
4765
4766/**
James Smartda0436e2009-05-22 14:51:39 -04004767 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
4768 * @phba: pointer to lpfc hba data structure.
4769 * @dev_grp: The HBA PCI-Device group number.
4770 *
4771 * This routine is invoked to set up the per HBA PCI-Device group function
4772 * API jump table entries.
4773 *
4774 * Return: 0 if success, otherwise -ENODEV
4775 **/
4776int
4777lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05004778{
4779 int rc;
4780
James Smartda0436e2009-05-22 14:51:39 -04004781 /* Set up lpfc PCI-device group */
4782 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05004783
James Smartda0436e2009-05-22 14:51:39 -04004784 /* The LPFC_PCI_DEV_OC uses SLI4 */
4785 if (dev_grp == LPFC_PCI_DEV_OC)
4786 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05004787
James Smartda0436e2009-05-22 14:51:39 -04004788 /* Set up device INIT API function jump table */
4789 rc = lpfc_init_api_table_setup(phba, dev_grp);
4790 if (rc)
4791 return -ENODEV;
4792 /* Set up SCSI API function jump table */
4793 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
4794 if (rc)
4795 return -ENODEV;
4796 /* Set up SLI API function jump table */
4797 rc = lpfc_sli_api_table_setup(phba, dev_grp);
4798 if (rc)
4799 return -ENODEV;
4800 /* Set up MBOX API function jump table */
4801 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
4802 if (rc)
4803 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05004804
James Smartda0436e2009-05-22 14:51:39 -04004805 return 0;
James Smart5b75da22008-12-04 22:39:35 -05004806}
4807
4808/**
James Smart3621a712009-04-06 18:47:14 -04004809 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05004810 * @phba: pointer to lpfc hba data structure.
4811 * @intr_mode: active interrupt mode adopted.
4812 *
4813 * This routine it invoked to log the currently used active interrupt mode
4814 * to the device.
James Smart3772a992009-05-22 14:50:54 -04004815 **/
4816static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05004817{
4818 switch (intr_mode) {
4819 case 0:
4820 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4821 "0470 Enable INTx interrupt mode.\n");
4822 break;
4823 case 1:
4824 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4825 "0481 Enabled MSI interrupt mode.\n");
4826 break;
4827 case 2:
4828 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4829 "0480 Enabled MSI-X interrupt mode.\n");
4830 break;
4831 default:
4832 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4833 "0482 Illegal interrupt mode.\n");
4834 break;
4835 }
4836 return;
4837}
4838
James Smart5b75da22008-12-04 22:39:35 -05004839/**
James Smart3772a992009-05-22 14:50:54 -04004840 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05004841 * @phba: pointer to lpfc hba data structure.
4842 *
James Smart3772a992009-05-22 14:50:54 -04004843 * This routine is invoked to enable the PCI device that is common to all
4844 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05004845 *
4846 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004847 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004848 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05004849 **/
James Smart3772a992009-05-22 14:50:54 -04004850static int
4851lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05004852{
James Smart3772a992009-05-22 14:50:54 -04004853 struct pci_dev *pdev;
James Smart079b5c92011-08-21 21:48:49 -04004854 int bars = 0;
James Smart5b75da22008-12-04 22:39:35 -05004855
James Smart3772a992009-05-22 14:50:54 -04004856 /* Obtain PCI device reference */
4857 if (!phba->pcidev)
4858 goto out_error;
4859 else
4860 pdev = phba->pcidev;
4861 /* Select PCI BARs */
4862 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4863 /* Enable PCI device */
4864 if (pci_enable_device_mem(pdev))
4865 goto out_error;
4866 /* Request PCI resource for the device */
4867 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
4868 goto out_disable_device;
4869 /* Set up device as PCI master and save state for EEH */
4870 pci_set_master(pdev);
4871 pci_try_set_mwi(pdev);
4872 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05004873
James Smart05580562011-05-24 11:40:48 -04004874 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
Jon Mason453193e2013-09-11 15:38:13 -07004875 if (pci_is_pcie(pdev))
James Smart05580562011-05-24 11:40:48 -04004876 pdev->needs_freset = 1;
4877
James Smart3772a992009-05-22 14:50:54 -04004878 return 0;
James Smart5b75da22008-12-04 22:39:35 -05004879
James Smart3772a992009-05-22 14:50:54 -04004880out_disable_device:
4881 pci_disable_device(pdev);
4882out_error:
James Smart079b5c92011-08-21 21:48:49 -04004883 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4884 "1401 Failed to enable pci device, bars:x%x\n", bars);
James Smart3772a992009-05-22 14:50:54 -04004885 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05004886}
4887
4888/**
James Smart3772a992009-05-22 14:50:54 -04004889 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05004890 * @phba: pointer to lpfc hba data structure.
4891 *
James Smart3772a992009-05-22 14:50:54 -04004892 * This routine is invoked to disable the PCI device that is common to all
4893 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05004894 **/
4895static void
James Smart3772a992009-05-22 14:50:54 -04004896lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05004897{
James Smart3772a992009-05-22 14:50:54 -04004898 struct pci_dev *pdev;
4899 int bars;
James Smart5b75da22008-12-04 22:39:35 -05004900
James Smart3772a992009-05-22 14:50:54 -04004901 /* Obtain PCI device reference */
4902 if (!phba->pcidev)
4903 return;
4904 else
4905 pdev = phba->pcidev;
4906 /* Select PCI BARs */
4907 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4908 /* Release PCI resource and disable PCI device */
4909 pci_release_selected_regions(pdev, bars);
4910 pci_disable_device(pdev);
James Smart5b75da22008-12-04 22:39:35 -05004911
4912 return;
4913}
4914
4915/**
James Smart3772a992009-05-22 14:50:54 -04004916 * lpfc_reset_hba - Reset a hba
4917 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04004918 *
James Smart3772a992009-05-22 14:50:54 -04004919 * This routine is invoked to reset a hba device. It brings the HBA
4920 * offline, performs a board restart, and then brings the board back
4921 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
4922 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04004923 **/
James Smart3772a992009-05-22 14:50:54 -04004924void
4925lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05004926{
James Smart3772a992009-05-22 14:50:54 -04004927 /* If resets are disabled then set error state and return. */
4928 if (!phba->cfg_enable_hba_reset) {
4929 phba->link_state = LPFC_HBA_ERROR;
4930 return;
4931 }
James Smartee620212014-04-04 13:51:53 -04004932 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
4933 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
4934 else
4935 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart3772a992009-05-22 14:50:54 -04004936 lpfc_offline(phba);
4937 lpfc_sli_brdrestart(phba);
4938 lpfc_online(phba);
4939 lpfc_unblock_mgmt_io(phba);
4940}
dea31012005-04-17 16:05:31 -05004941
James Smart3772a992009-05-22 14:50:54 -04004942/**
James Smart0a96e972011-07-22 18:37:28 -04004943 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
4944 * @phba: pointer to lpfc hba data structure.
4945 *
4946 * This function enables the PCI SR-IOV virtual functions to a physical
4947 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4948 * enable the number of virtual functions to the physical function. As
4949 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4950 * API call does not considered as an error condition for most of the device.
4951 **/
4952uint16_t
4953lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
4954{
4955 struct pci_dev *pdev = phba->pcidev;
4956 uint16_t nr_virtfn;
4957 int pos;
4958
James Smart0a96e972011-07-22 18:37:28 -04004959 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4960 if (pos == 0)
4961 return 0;
4962
4963 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
4964 return nr_virtfn;
4965}
4966
4967/**
James Smart912e3ac2011-05-24 11:42:11 -04004968 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
4969 * @phba: pointer to lpfc hba data structure.
4970 * @nr_vfn: number of virtual functions to be enabled.
4971 *
4972 * This function enables the PCI SR-IOV virtual functions to a physical
4973 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4974 * enable the number of virtual functions to the physical function. As
4975 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4976 * API call does not considered as an error condition for most of the device.
4977 **/
4978int
4979lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
4980{
4981 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04004982 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04004983 int rc;
4984
James Smart0a96e972011-07-22 18:37:28 -04004985 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
4986 if (nr_vfn > max_nr_vfn) {
4987 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4988 "3057 Requested vfs (%d) greater than "
4989 "supported vfs (%d)", nr_vfn, max_nr_vfn);
4990 return -EINVAL;
4991 }
4992
James Smart912e3ac2011-05-24 11:42:11 -04004993 rc = pci_enable_sriov(pdev, nr_vfn);
4994 if (rc) {
4995 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4996 "2806 Failed to enable sriov on this device "
4997 "with vfn number nr_vf:%d, rc:%d\n",
4998 nr_vfn, rc);
4999 } else
5000 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5001 "2807 Successful enable sriov on this device "
5002 "with vfn number nr_vf:%d\n", nr_vfn);
5003 return rc;
5004}
5005
5006/**
James Smart3772a992009-05-22 14:50:54 -04005007 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
5008 * @phba: pointer to lpfc hba data structure.
5009 *
5010 * This routine is invoked to set up the driver internal resources specific to
5011 * support the SLI-3 HBA device it attached to.
5012 *
5013 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005014 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005015 * other values - error
5016 **/
5017static int
5018lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
5019{
5020 struct lpfc_sli *psli;
James Smart912e3ac2011-05-24 11:42:11 -04005021 int rc;
dea31012005-04-17 16:05:31 -05005022
James Smart3772a992009-05-22 14:50:54 -04005023 /*
5024 * Initialize timers used by driver
5025 */
dea31012005-04-17 16:05:31 -05005026
James Smart3772a992009-05-22 14:50:54 -04005027 /* Heartbeat timer */
5028 init_timer(&phba->hb_tmofunc);
5029 phba->hb_tmofunc.function = lpfc_hb_timeout;
5030 phba->hb_tmofunc.data = (unsigned long)phba;
5031
5032 psli = &phba->sli;
5033 /* MBOX heartbeat timer */
5034 init_timer(&psli->mbox_tmo);
5035 psli->mbox_tmo.function = lpfc_mbox_timeout;
5036 psli->mbox_tmo.data = (unsigned long) phba;
5037 /* FCP polling mode timer */
5038 init_timer(&phba->fcp_poll_timer);
5039 phba->fcp_poll_timer.function = lpfc_poll_timeout;
5040 phba->fcp_poll_timer.data = (unsigned long) phba;
5041 /* Fabric block timer */
5042 init_timer(&phba->fabric_block_timer);
5043 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
5044 phba->fabric_block_timer.data = (unsigned long) phba;
5045 /* EA polling mode timer */
5046 init_timer(&phba->eratt_poll);
5047 phba->eratt_poll.function = lpfc_poll_eratt;
5048 phba->eratt_poll.data = (unsigned long) phba;
5049
5050 /* Host attention work mask setup */
5051 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
5052 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
5053
5054 /* Get all the module params for configuring this host */
5055 lpfc_get_cfgparam(phba);
James Smart49198b32010-04-06 15:04:33 -04005056 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
5057 phba->menlo_flag |= HBA_MENLO_SUPPORT;
5058 /* check for menlo minimum sg count */
5059 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
5060 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
5061 }
5062
James Smart2a76a282012-08-03 12:35:54 -04005063 if (!phba->sli.ring)
Firo Yangc6cb9b42015-08-31 16:48:09 -04005064 phba->sli.ring = kzalloc(LPFC_SLI3_MAX_RING *
James Smart2a76a282012-08-03 12:35:54 -04005065 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
5066 if (!phba->sli.ring)
5067 return -ENOMEM;
5068
James Smart3772a992009-05-22 14:50:54 -04005069 /*
James Smart96f70772013-04-17 20:16:15 -04005070 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smart3772a992009-05-22 14:50:54 -04005071 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart3772a992009-05-22 14:50:54 -04005072 */
James Smart3772a992009-05-22 14:50:54 -04005073
James Smart96f70772013-04-17 20:16:15 -04005074 /* Initialize the host templates the configured values. */
James Smart3772a992009-05-22 14:50:54 -04005075 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
Bodo Stroesser5f406fa2015-08-31 16:48:10 -04005076 lpfc_template_s3.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart3772a992009-05-22 14:50:54 -04005077
James Smart96f70772013-04-17 20:16:15 -04005078 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
5079 if (phba->cfg_enable_bg) {
5080 /*
5081 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5082 * the FCP rsp, and a BDE for each. Sice we have no control
5083 * over how many protection data segments the SCSI Layer
5084 * will hand us (ie: there could be one for every block
5085 * in the IO), we just allocate enough BDEs to accomidate
5086 * our max amount and we need to limit lpfc_sg_seg_cnt to
5087 * minimize the risk of running out.
5088 */
5089 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5090 sizeof(struct fcp_rsp) +
5091 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
5092
5093 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
5094 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
5095
5096 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
5097 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
5098 } else {
5099 /*
5100 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5101 * the FCP rsp, a BDE for each, and a BDE for up to
5102 * cfg_sg_seg_cnt data segments.
5103 */
5104 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5105 sizeof(struct fcp_rsp) +
5106 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
5107
5108 /* Total BDEs in BPL for scsi_sg_list */
5109 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5110 }
5111
5112 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5113 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
5114 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5115 phba->cfg_total_seg_cnt);
5116
James Smart3772a992009-05-22 14:50:54 -04005117 phba->max_vpi = LPFC_MAX_VPI;
5118 /* This will be set to correct value after config_port mbox */
5119 phba->max_vports = 0;
5120
5121 /*
5122 * Initialize the SLI Layer to run with lpfc HBAs.
5123 */
5124 lpfc_sli_setup(phba);
5125 lpfc_sli_queue_setup(phba);
5126
5127 /* Allocate device driver memory */
5128 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
5129 return -ENOMEM;
5130
James Smart912e3ac2011-05-24 11:42:11 -04005131 /*
5132 * Enable sr-iov virtual functions if supported and configured
5133 * through the module parameter.
5134 */
5135 if (phba->cfg_sriov_nr_virtfn > 0) {
5136 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5137 phba->cfg_sriov_nr_virtfn);
5138 if (rc) {
5139 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5140 "2808 Requested number of SR-IOV "
5141 "virtual functions (%d) is not "
5142 "supported\n",
5143 phba->cfg_sriov_nr_virtfn);
5144 phba->cfg_sriov_nr_virtfn = 0;
5145 }
5146 }
5147
James Smart3772a992009-05-22 14:50:54 -04005148 return 0;
5149}
5150
5151/**
5152 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
5153 * @phba: pointer to lpfc hba data structure.
5154 *
5155 * This routine is invoked to unset the driver internal resources set up
5156 * specific for supporting the SLI-3 HBA device it attached to.
5157 **/
5158static void
5159lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
5160{
5161 /* Free device driver memory allocated */
5162 lpfc_mem_free_all(phba);
5163
5164 return;
5165}
5166
5167/**
James Smartda0436e2009-05-22 14:51:39 -04005168 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
5169 * @phba: pointer to lpfc hba data structure.
5170 *
5171 * This routine is invoked to set up the driver internal resources specific to
5172 * support the SLI-4 HBA device it attached to.
5173 *
5174 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005175 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04005176 * other values - error
5177 **/
5178static int
5179lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5180{
James Smart7bb03bb2013-04-17 20:19:16 -04005181 struct lpfc_vector_map_info *cpup;
James Smartda0436e2009-05-22 14:51:39 -04005182 struct lpfc_sli *psli;
James Smart28baac72010-02-12 14:42:03 -05005183 LPFC_MBOXQ_t *mboxq;
James Smart96f70772013-04-17 20:16:15 -04005184 int rc, i, hbq_count, max_buf_size;
James Smart28baac72010-02-12 14:42:03 -05005185 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
5186 struct lpfc_mqe *mqe;
James Smart09294d42013-04-17 20:16:05 -04005187 int longs;
James Smart1ba981f2014-02-20 09:56:45 -05005188 int fof_vectors = 0;
James Smartda0436e2009-05-22 14:51:39 -04005189
James Smart716d3bc2013-09-06 12:18:28 -04005190 /* Get all the module params for configuring this host */
5191 lpfc_get_cfgparam(phba);
5192
James Smartda0436e2009-05-22 14:51:39 -04005193 /* Before proceed, wait for POST done and device ready */
5194 rc = lpfc_sli4_post_status_check(phba);
5195 if (rc)
5196 return -ENODEV;
5197
5198 /*
5199 * Initialize timers used by driver
5200 */
5201
5202 /* Heartbeat timer */
5203 init_timer(&phba->hb_tmofunc);
5204 phba->hb_tmofunc.function = lpfc_hb_timeout;
5205 phba->hb_tmofunc.data = (unsigned long)phba;
James Smart19ca7602010-11-20 23:11:55 -05005206 init_timer(&phba->rrq_tmr);
5207 phba->rrq_tmr.function = lpfc_rrq_timeout;
5208 phba->rrq_tmr.data = (unsigned long)phba;
James Smartda0436e2009-05-22 14:51:39 -04005209
5210 psli = &phba->sli;
5211 /* MBOX heartbeat timer */
5212 init_timer(&psli->mbox_tmo);
5213 psli->mbox_tmo.function = lpfc_mbox_timeout;
5214 psli->mbox_tmo.data = (unsigned long) phba;
5215 /* Fabric block timer */
5216 init_timer(&phba->fabric_block_timer);
5217 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
5218 phba->fabric_block_timer.data = (unsigned long) phba;
5219 /* EA polling mode timer */
5220 init_timer(&phba->eratt_poll);
5221 phba->eratt_poll.function = lpfc_poll_eratt;
5222 phba->eratt_poll.data = (unsigned long) phba;
James Smartecfd03c2010-02-12 14:41:27 -05005223 /* FCF rediscover timer */
5224 init_timer(&phba->fcf.redisc_wait);
5225 phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
5226 phba->fcf.redisc_wait.data = (unsigned long)phba;
5227
James Smartda0436e2009-05-22 14:51:39 -04005228 /*
James Smart7ad20aa2011-05-24 11:44:28 -04005229 * Control structure for handling external multi-buffer mailbox
5230 * command pass-through.
5231 */
5232 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
5233 sizeof(struct lpfc_mbox_ext_buf_ctx));
5234 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
5235
James Smartda0436e2009-05-22 14:51:39 -04005236 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04005237
James Smartda0436e2009-05-22 14:51:39 -04005238 /* This will be set to correct value after the read_config mbox */
5239 phba->max_vports = 0;
5240
5241 /* Program the default value of vlan_id and fc_map */
5242 phba->valid_vlan = 0;
5243 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5244 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5245 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5246
5247 /*
James Smart2a76a282012-08-03 12:35:54 -04005248 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
5249 * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple.
5250 */
5251 if (!phba->sli.ring)
5252 phba->sli.ring = kzalloc(
James Smart67d12732012-08-03 12:36:13 -04005253 (LPFC_SLI3_MAX_RING + phba->cfg_fcp_io_channel) *
James Smart2a76a282012-08-03 12:35:54 -04005254 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
5255 if (!phba->sli.ring)
5256 return -ENOMEM;
James Smart085c6472010-11-20 23:11:37 -05005257
James Smart09294d42013-04-17 20:16:05 -04005258 /*
5259 * It doesn't matter what family our adapter is in, we are
5260 * limited to 2 Pages, 512 SGEs, for our SGL.
5261 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
5262 */
5263 max_buf_size = (2 * SLI4_PAGE_SIZE);
5264 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2)
5265 phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2;
James Smart09294d42013-04-17 20:16:05 -04005266
James Smartda0436e2009-05-22 14:51:39 -04005267 /*
James Smart96f70772013-04-17 20:16:15 -04005268 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smartda0436e2009-05-22 14:51:39 -04005269 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart28baac72010-02-12 14:42:03 -05005270 */
James Smart085c6472010-11-20 23:11:37 -05005271
James Smart96f70772013-04-17 20:16:15 -04005272 if (phba->cfg_enable_bg) {
5273 /*
5274 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5275 * the FCP rsp, and a SGE for each. Sice we have no control
5276 * over how many protection data segments the SCSI Layer
5277 * will hand us (ie: there could be one for every block
5278 * in the IO), we just allocate enough SGEs to accomidate
5279 * our max amount and we need to limit lpfc_sg_seg_cnt to
5280 * minimize the risk of running out.
5281 */
5282 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5283 sizeof(struct fcp_rsp) + max_buf_size;
5284
5285 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
5286 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
5287
5288 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
5289 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
5290 } else {
5291 /*
5292 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5293 * the FCP rsp, a SGE for each, and a SGE for up to
5294 * cfg_sg_seg_cnt data segments.
5295 */
5296 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5297 sizeof(struct fcp_rsp) +
5298 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge));
5299
5300 /* Total SGEs for scsi_sg_list */
5301 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5302 /*
5303 * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only need
5304 * to post 1 page for the SGL.
5305 */
James Smart085c6472010-11-20 23:11:37 -05005306 }
James Smartacd68592012-01-18 16:25:09 -05005307
James Smart96f70772013-04-17 20:16:15 -04005308 /* Initialize the host templates with the updated values. */
5309 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5310 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5311
5312 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
5313 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
5314 else
5315 phba->cfg_sg_dma_buf_size =
5316 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
5317
5318 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5319 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
5320 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5321 phba->cfg_total_seg_cnt);
James Smartda0436e2009-05-22 14:51:39 -04005322
5323 /* Initialize buffer queue management fields */
5324 hbq_count = lpfc_sli_hbq_count();
5325 for (i = 0; i < hbq_count; ++i)
5326 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
5327 INIT_LIST_HEAD(&phba->rb_pend_list);
5328 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
5329 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
5330
5331 /*
5332 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
5333 */
5334 /* Initialize the Abort scsi buffer list used by driver */
5335 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
5336 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
5337 /* This abort list used by worker thread */
5338 spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
5339
5340 /*
James Smart6d368e52011-05-24 11:44:12 -04005341 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04005342 */
5343
5344 /* Driver internel slow-path CQ Event pool */
5345 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
5346 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04005347 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04005348 /* Asynchronous event CQ Event work queue list */
5349 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
5350 /* Fast-path XRI aborted CQ Event work queue list */
5351 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
5352 /* Slow-path XRI aborted CQ Event work queue list */
5353 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
5354 /* Receive queue CQ Event work queue list */
5355 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
5356
James Smart6d368e52011-05-24 11:44:12 -04005357 /* Initialize extent block lists. */
5358 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
5359 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
5360 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
5361 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
5362
James Smart448193b2015-12-16 18:12:05 -05005363 /* initialize optic_state to 0xFF */
5364 phba->sli4_hba.lnk_info.optic_state = 0xff;
5365
James Smartda0436e2009-05-22 14:51:39 -04005366 /* Initialize the driver internal SLI layer lists. */
5367 lpfc_sli_setup(phba);
5368 lpfc_sli_queue_setup(phba);
5369
5370 /* Allocate device driver memory */
5371 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
5372 if (rc)
5373 return -ENOMEM;
5374
James Smart2fcee4b2010-12-15 17:57:46 -05005375 /* IF Type 2 ports get initialized now. */
5376 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5377 LPFC_SLI_INTF_IF_TYPE_2) {
5378 rc = lpfc_pci_function_reset(phba);
5379 if (unlikely(rc))
5380 return -ENODEV;
James Smart946727d2015-04-07 15:07:09 -04005381 phba->temp_sensor_support = 1;
James Smart2fcee4b2010-12-15 17:57:46 -05005382 }
5383
James Smartda0436e2009-05-22 14:51:39 -04005384 /* Create the bootstrap mailbox command */
5385 rc = lpfc_create_bootstrap_mbox(phba);
5386 if (unlikely(rc))
5387 goto out_free_mem;
5388
5389 /* Set up the host's endian order with the device. */
5390 rc = lpfc_setup_endian_order(phba);
5391 if (unlikely(rc))
5392 goto out_free_bsmbx;
5393
5394 /* Set up the hba's configuration parameters. */
5395 rc = lpfc_sli4_read_config(phba);
5396 if (unlikely(rc))
5397 goto out_free_bsmbx;
James Smartcff261f2013-12-17 20:29:47 -05005398 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
5399 if (unlikely(rc))
5400 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005401
James Smart2fcee4b2010-12-15 17:57:46 -05005402 /* IF Type 0 ports get initialized now. */
5403 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5404 LPFC_SLI_INTF_IF_TYPE_0) {
5405 rc = lpfc_pci_function_reset(phba);
5406 if (unlikely(rc))
5407 goto out_free_bsmbx;
5408 }
James Smartda0436e2009-05-22 14:51:39 -04005409
James Smartcb5172e2010-03-15 11:25:07 -04005410 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
5411 GFP_KERNEL);
5412 if (!mboxq) {
5413 rc = -ENOMEM;
5414 goto out_free_bsmbx;
5415 }
5416
James Smartfedd3b72011-02-16 12:39:24 -05005417 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04005418 lpfc_supported_pages(mboxq);
5419 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05005420 if (!rc) {
5421 mqe = &mboxq->u.mqe;
5422 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
5423 LPFC_MAX_SUPPORTED_PAGES);
5424 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
5425 switch (pn_page[i]) {
5426 case LPFC_SLI4_PARAMETERS:
5427 phba->sli4_hba.pc_sli4_params.supported = 1;
5428 break;
5429 default:
5430 break;
5431 }
5432 }
5433 /* Read the port's SLI4 Parameters capabilities if supported. */
5434 if (phba->sli4_hba.pc_sli4_params.supported)
5435 rc = lpfc_pc_sli4_params_get(phba, mboxq);
5436 if (rc) {
5437 mempool_free(mboxq, phba->mbox_mem_pool);
5438 rc = -EIO;
5439 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04005440 }
5441 }
James Smart65791f12016-07-06 12:35:56 -07005442
James Smartfedd3b72011-02-16 12:39:24 -05005443 /*
5444 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04005445 * If this call fails, it isn't critical unless the SLI4 parameters come
5446 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05005447 */
James Smart6d368e52011-05-24 11:44:12 -04005448 rc = lpfc_get_sli4_parameters(phba, mboxq);
5449 if (rc) {
5450 if (phba->sli4_hba.extents_in_use &&
5451 phba->sli4_hba.rpi_hdrs_in_use) {
5452 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5453 "2999 Unsupported SLI4 Parameters "
5454 "Extents and RPI headers enabled.\n");
5455 goto out_free_bsmbx;
5456 }
5457 }
James Smartcb5172e2010-03-15 11:25:07 -04005458 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -05005459
5460 /* Verify OAS is supported */
5461 lpfc_sli4_oas_verify(phba);
5462 if (phba->cfg_fof)
5463 fof_vectors = 1;
5464
James Smart5350d872011-10-10 21:33:49 -04005465 /* Verify all the SLI4 queues */
5466 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04005467 if (rc)
5468 goto out_free_bsmbx;
5469
5470 /* Create driver internal CQE event pool */
5471 rc = lpfc_sli4_cq_event_pool_create(phba);
5472 if (rc)
James Smart5350d872011-10-10 21:33:49 -04005473 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005474
James Smart8a9d2e82012-05-09 21:16:12 -04005475 /* Initialize sgl lists per host */
5476 lpfc_init_sgl_list(phba);
5477
5478 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04005479 rc = lpfc_init_active_sgl_array(phba);
5480 if (rc) {
5481 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5482 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04005483 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04005484 }
James Smartda0436e2009-05-22 14:51:39 -04005485 rc = lpfc_sli4_init_rpi_hdrs(phba);
5486 if (rc) {
5487 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5488 "1432 Failed to initialize rpi headers.\n");
5489 goto out_free_active_sgl;
5490 }
5491
James Smarta93ff372010-10-22 11:06:08 -04005492 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05005493 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
5494 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
5495 GFP_KERNEL);
5496 if (!phba->fcf.fcf_rr_bmask) {
5497 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5498 "2759 Failed allocate memory for FCF round "
5499 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04005500 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05005501 goto out_remove_rpi_hdrs;
5502 }
5503
James Smart67d12732012-08-03 12:36:13 -04005504 phba->sli4_hba.fcp_eq_hdl =
5505 kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
James Smart1ba981f2014-02-20 09:56:45 -05005506 (fof_vectors + phba->cfg_fcp_io_channel)),
5507 GFP_KERNEL);
James Smart67d12732012-08-03 12:36:13 -04005508 if (!phba->sli4_hba.fcp_eq_hdl) {
5509 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5510 "2572 Failed allocate memory for "
5511 "fast-path per-EQ handle array\n");
5512 rc = -ENOMEM;
5513 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04005514 }
5515
5516 phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
James Smart1ba981f2014-02-20 09:56:45 -05005517 (fof_vectors +
5518 phba->cfg_fcp_io_channel)), GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04005519 if (!phba->sli4_hba.msix_entries) {
5520 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5521 "2573 Failed allocate memory for msi-x "
5522 "interrupt vector entries\n");
James Smart05580562011-05-24 11:40:48 -04005523 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04005524 goto out_free_fcp_eq_hdl;
5525 }
5526
James Smart7bb03bb2013-04-17 20:19:16 -04005527 phba->sli4_hba.cpu_map = kzalloc((sizeof(struct lpfc_vector_map_info) *
5528 phba->sli4_hba.num_present_cpu),
5529 GFP_KERNEL);
5530 if (!phba->sli4_hba.cpu_map) {
5531 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5532 "3327 Failed allocate memory for msi-x "
5533 "interrupt vector mapping\n");
5534 rc = -ENOMEM;
5535 goto out_free_msix;
5536 }
James Smartb246de12013-05-31 17:03:07 -04005537 if (lpfc_used_cpu == NULL) {
5538 lpfc_used_cpu = kzalloc((sizeof(uint16_t) * lpfc_present_cpu),
5539 GFP_KERNEL);
5540 if (!lpfc_used_cpu) {
5541 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5542 "3335 Failed allocate memory for msi-x "
5543 "interrupt vector mapping\n");
5544 kfree(phba->sli4_hba.cpu_map);
5545 rc = -ENOMEM;
5546 goto out_free_msix;
5547 }
5548 for (i = 0; i < lpfc_present_cpu; i++)
5549 lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
5550 }
5551
James Smart7bb03bb2013-04-17 20:19:16 -04005552 /* Initialize io channels for round robin */
5553 cpup = phba->sli4_hba.cpu_map;
5554 rc = 0;
5555 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
5556 cpup->channel_id = rc;
5557 rc++;
5558 if (rc >= phba->cfg_fcp_io_channel)
5559 rc = 0;
5560 }
5561
James Smart912e3ac2011-05-24 11:42:11 -04005562 /*
5563 * Enable sr-iov virtual functions if supported and configured
5564 * through the module parameter.
5565 */
5566 if (phba->cfg_sriov_nr_virtfn > 0) {
5567 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5568 phba->cfg_sriov_nr_virtfn);
5569 if (rc) {
5570 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5571 "3020 Requested number of SR-IOV "
5572 "virtual functions (%d) is not "
5573 "supported\n",
5574 phba->cfg_sriov_nr_virtfn);
5575 phba->cfg_sriov_nr_virtfn = 0;
5576 }
5577 }
5578
James Smart5248a742011-07-22 18:37:06 -04005579 return 0;
James Smartda0436e2009-05-22 14:51:39 -04005580
James Smart7bb03bb2013-04-17 20:19:16 -04005581out_free_msix:
5582 kfree(phba->sli4_hba.msix_entries);
James Smartda0436e2009-05-22 14:51:39 -04005583out_free_fcp_eq_hdl:
5584 kfree(phba->sli4_hba.fcp_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05005585out_free_fcf_rr_bmask:
5586 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04005587out_remove_rpi_hdrs:
5588 lpfc_sli4_remove_rpi_hdrs(phba);
5589out_free_active_sgl:
5590 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04005591out_destroy_cq_event_pool:
5592 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04005593out_free_bsmbx:
5594 lpfc_destroy_bootstrap_mbox(phba);
5595out_free_mem:
5596 lpfc_mem_free(phba);
5597 return rc;
5598}
5599
5600/**
5601 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
5602 * @phba: pointer to lpfc hba data structure.
5603 *
5604 * This routine is invoked to unset the driver internal resources set up
5605 * specific for supporting the SLI-4 HBA device it attached to.
5606 **/
5607static void
5608lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
5609{
5610 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
5611
James Smart7bb03bb2013-04-17 20:19:16 -04005612 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
5613 kfree(phba->sli4_hba.cpu_map);
5614 phba->sli4_hba.num_present_cpu = 0;
5615 phba->sli4_hba.num_online_cpu = 0;
James Smart76fd07a2014-02-20 09:57:18 -05005616 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04005617
James Smartda0436e2009-05-22 14:51:39 -04005618 /* Free memory allocated for msi-x interrupt vector entries */
5619 kfree(phba->sli4_hba.msix_entries);
5620
5621 /* Free memory allocated for fast-path work queue handles */
5622 kfree(phba->sli4_hba.fcp_eq_hdl);
5623
5624 /* Free the allocated rpi headers. */
5625 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04005626 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04005627
James Smart0c9ab6f2010-02-26 14:15:57 -05005628 /* Free eligible FCF index bmask */
5629 kfree(phba->fcf.fcf_rr_bmask);
5630
James Smartda0436e2009-05-22 14:51:39 -04005631 /* Free the ELS sgl list */
5632 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04005633 lpfc_free_els_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04005634
James Smartda0436e2009-05-22 14:51:39 -04005635 /* Free the completion queue EQ event pool */
5636 lpfc_sli4_cq_event_release_all(phba);
5637 lpfc_sli4_cq_event_pool_destroy(phba);
5638
James Smart6d368e52011-05-24 11:44:12 -04005639 /* Release resource identifiers. */
5640 lpfc_sli4_dealloc_resource_identifiers(phba);
5641
James Smartda0436e2009-05-22 14:51:39 -04005642 /* Free the bsmbx region. */
5643 lpfc_destroy_bootstrap_mbox(phba);
5644
5645 /* Free the SLI Layer memory with SLI4 HBAs */
5646 lpfc_mem_free_all(phba);
5647
5648 /* Free the current connect table */
5649 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04005650 &phba->fcf_conn_rec_list, list) {
5651 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04005652 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04005653 }
James Smartda0436e2009-05-22 14:51:39 -04005654
5655 return;
5656}
5657
5658/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005659 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04005660 * @phba: The hba struct for which this call is being executed.
5661 * @dev_grp: The HBA PCI-Device group number.
5662 *
5663 * This routine sets up the device INIT interface API function jump table
5664 * in @phba struct.
5665 *
5666 * Returns: 0 - success, -ENODEV - failure.
5667 **/
5668int
5669lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5670{
James Smart84d1b002010-02-12 14:42:33 -05005671 phba->lpfc_hba_init_link = lpfc_hba_init_link;
5672 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05005673 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04005674 switch (dev_grp) {
5675 case LPFC_PCI_DEV_LP:
5676 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
5677 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
5678 phba->lpfc_stop_port = lpfc_stop_port_s3;
5679 break;
James Smartda0436e2009-05-22 14:51:39 -04005680 case LPFC_PCI_DEV_OC:
5681 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
5682 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
5683 phba->lpfc_stop_port = lpfc_stop_port_s4;
5684 break;
James Smart3772a992009-05-22 14:50:54 -04005685 default:
5686 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5687 "1431 Invalid HBA PCI-device group: 0x%x\n",
5688 dev_grp);
5689 return -ENODEV;
5690 break;
5691 }
5692 return 0;
5693}
5694
5695/**
5696 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
5697 * @phba: pointer to lpfc hba data structure.
5698 *
5699 * This routine is invoked to set up the driver internal resources before the
5700 * device specific resource setup to support the HBA device it attached to.
5701 *
5702 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005703 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005704 * other values - error
5705 **/
5706static int
5707lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
5708{
5709 /*
5710 * Driver resources common to all SLI revisions
5711 */
James Smartea2151b2008-09-07 11:52:10 -04005712 atomic_set(&phba->fast_event_count, 0);
James Smart2e0fef82007-06-17 19:56:36 -05005713 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005714
James Smarte47c9092008-02-08 18:49:26 -05005715 /* Initialize ndlp management spinlock */
5716 spin_lock_init(&phba->ndlp_lock);
5717
James Smart2e0fef82007-06-17 19:56:36 -05005718 INIT_LIST_HEAD(&phba->port_list);
James Smart3772a992009-05-22 14:50:54 -04005719 INIT_LIST_HEAD(&phba->work_list);
James Smart84774a42008-08-24 21:50:06 -04005720 init_waitqueue_head(&phba->wait_4_mlo_m_q);
dea31012005-04-17 16:05:31 -05005721
James Smart3772a992009-05-22 14:50:54 -04005722 /* Initialize the wait queue head for the kernel thread */
5723 init_waitqueue_head(&phba->work_waitq);
James Smart858c9f62007-06-17 19:56:39 -05005724
James Smart3772a992009-05-22 14:50:54 -04005725 /* Initialize the scsi buffer list used by driver for scsi IO */
James Smarta40fc5f2013-04-17 20:17:40 -04005726 spin_lock_init(&phba->scsi_buf_list_get_lock);
5727 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5728 spin_lock_init(&phba->scsi_buf_list_put_lock);
5729 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
dea31012005-04-17 16:05:31 -05005730
James Smart3772a992009-05-22 14:50:54 -04005731 /* Initialize the fabric iocb list */
5732 INIT_LIST_HEAD(&phba->fabric_iocb_list);
dea31012005-04-17 16:05:31 -05005733
James Smart3772a992009-05-22 14:50:54 -04005734 /* Initialize list to save ELS buffers */
5735 INIT_LIST_HEAD(&phba->elsbuf);
dea31012005-04-17 16:05:31 -05005736
James Smart3772a992009-05-22 14:50:54 -04005737 /* Initialize FCF connection rec list */
5738 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
dea31012005-04-17 16:05:31 -05005739
James Smart1ba981f2014-02-20 09:56:45 -05005740 /* Initialize OAS configuration list */
5741 spin_lock_init(&phba->devicelock);
5742 INIT_LIST_HEAD(&phba->luns);
5743
James Smart3772a992009-05-22 14:50:54 -04005744 return 0;
5745}
dea31012005-04-17 16:05:31 -05005746
James Smart3772a992009-05-22 14:50:54 -04005747/**
5748 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
5749 * @phba: pointer to lpfc hba data structure.
5750 *
5751 * This routine is invoked to set up the driver internal resources after the
5752 * device specific resource setup to support the HBA device it attached to.
5753 *
5754 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005755 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005756 * other values - error
5757 **/
5758static int
5759lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
5760{
5761 int error;
5762
5763 /* Startup the kernel thread for this host adapter. */
5764 phba->worker_thread = kthread_run(lpfc_do_work, phba,
5765 "lpfc_worker_%d", phba->brd_no);
5766 if (IS_ERR(phba->worker_thread)) {
5767 error = PTR_ERR(phba->worker_thread);
5768 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005769 }
5770
James Smart3772a992009-05-22 14:50:54 -04005771 return 0;
5772}
5773
5774/**
5775 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
5776 * @phba: pointer to lpfc hba data structure.
5777 *
5778 * This routine is invoked to unset the driver internal resources set up after
5779 * the device specific resource setup for supporting the HBA device it
5780 * attached to.
5781 **/
5782static void
5783lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
5784{
5785 /* Stop kernel worker thread */
5786 kthread_stop(phba->worker_thread);
5787}
5788
5789/**
5790 * lpfc_free_iocb_list - Free iocb list.
5791 * @phba: pointer to lpfc hba data structure.
5792 *
5793 * This routine is invoked to free the driver's IOCB list and memory.
5794 **/
5795static void
5796lpfc_free_iocb_list(struct lpfc_hba *phba)
5797{
5798 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
5799
5800 spin_lock_irq(&phba->hbalock);
5801 list_for_each_entry_safe(iocbq_entry, iocbq_next,
5802 &phba->lpfc_iocb_list, list) {
5803 list_del(&iocbq_entry->list);
5804 kfree(iocbq_entry);
5805 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005806 }
James Smart3772a992009-05-22 14:50:54 -04005807 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005808
James Smart3772a992009-05-22 14:50:54 -04005809 return;
5810}
dea31012005-04-17 16:05:31 -05005811
James Smart3772a992009-05-22 14:50:54 -04005812/**
5813 * lpfc_init_iocb_list - Allocate and initialize iocb list.
5814 * @phba: pointer to lpfc hba data structure.
5815 *
5816 * This routine is invoked to allocate and initizlize the driver's IOCB
5817 * list and set up the IOCB tag array accordingly.
5818 *
5819 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005820 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005821 * other values - error
5822 **/
5823static int
5824lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
5825{
5826 struct lpfc_iocbq *iocbq_entry = NULL;
5827 uint16_t iotag;
5828 int i;
dea31012005-04-17 16:05:31 -05005829
5830 /* Initialize and populate the iocb list per host. */
5831 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04005832 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07005833 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05005834 if (iocbq_entry == NULL) {
5835 printk(KERN_ERR "%s: only allocated %d iocbs of "
5836 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07005837 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05005838 goto out_free_iocbq;
5839 }
5840
James Bottomley604a3e32005-10-29 10:28:33 -05005841 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
5842 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04005843 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05005844 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04005845 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05005846 goto out_free_iocbq;
5847 }
James Smart6d368e52011-05-24 11:44:12 -04005848 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04005849 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05005850
5851 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005852 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
5853 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05005854 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005855 }
5856
James Smart3772a992009-05-22 14:50:54 -04005857 return 0;
5858
5859out_free_iocbq:
5860 lpfc_free_iocb_list(phba);
5861
5862 return -ENOMEM;
5863}
5864
5865/**
James Smart8a9d2e82012-05-09 21:16:12 -04005866 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04005867 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04005868 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04005869 *
James Smart8a9d2e82012-05-09 21:16:12 -04005870 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04005871 **/
James Smart8a9d2e82012-05-09 21:16:12 -04005872void
5873lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04005874{
5875 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04005876
5877 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
5878 list_del(&sglq_entry->list);
5879 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
5880 kfree(sglq_entry);
5881 }
5882}
5883
5884/**
5885 * lpfc_free_els_sgl_list - Free els sgl list.
5886 * @phba: pointer to lpfc hba data structure.
5887 *
5888 * This routine is invoked to free the driver's els sgl list and memory.
5889 **/
5890static void
5891lpfc_free_els_sgl_list(struct lpfc_hba *phba)
5892{
James Smartda0436e2009-05-22 14:51:39 -04005893 LIST_HEAD(sglq_list);
James Smartdafe8ce2014-09-03 12:56:40 -04005894 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smartda0436e2009-05-22 14:51:39 -04005895
James Smart8a9d2e82012-05-09 21:16:12 -04005896 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04005897 spin_lock_irq(&phba->hbalock);
James Smartdafe8ce2014-09-03 12:56:40 -04005898 spin_lock(&pring->ring_lock);
James Smartda0436e2009-05-22 14:51:39 -04005899 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
James Smartdafe8ce2014-09-03 12:56:40 -04005900 spin_unlock(&pring->ring_lock);
James Smartda0436e2009-05-22 14:51:39 -04005901 spin_unlock_irq(&phba->hbalock);
5902
James Smart8a9d2e82012-05-09 21:16:12 -04005903 /* Now free the sgl list */
5904 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04005905}
5906
5907/**
5908 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
5909 * @phba: pointer to lpfc hba data structure.
5910 *
5911 * This routine is invoked to allocate the driver's active sgl memory.
5912 * This array will hold the sglq_entry's for active IOs.
5913 **/
5914static int
5915lpfc_init_active_sgl_array(struct lpfc_hba *phba)
5916{
5917 int size;
5918 size = sizeof(struct lpfc_sglq *);
5919 size *= phba->sli4_hba.max_cfg_param.max_xri;
5920
5921 phba->sli4_hba.lpfc_sglq_active_list =
5922 kzalloc(size, GFP_KERNEL);
5923 if (!phba->sli4_hba.lpfc_sglq_active_list)
5924 return -ENOMEM;
5925 return 0;
5926}
5927
5928/**
5929 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
5930 * @phba: pointer to lpfc hba data structure.
5931 *
5932 * This routine is invoked to walk through the array of active sglq entries
5933 * and free all of the resources.
5934 * This is just a place holder for now.
5935 **/
5936static void
5937lpfc_free_active_sgl(struct lpfc_hba *phba)
5938{
5939 kfree(phba->sli4_hba.lpfc_sglq_active_list);
5940}
5941
5942/**
5943 * lpfc_init_sgl_list - Allocate and initialize sgl list.
5944 * @phba: pointer to lpfc hba data structure.
5945 *
5946 * This routine is invoked to allocate and initizlize the driver's sgl
5947 * list and set up the sgl xritag tag array accordingly.
5948 *
James Smartda0436e2009-05-22 14:51:39 -04005949 **/
James Smart8a9d2e82012-05-09 21:16:12 -04005950static void
James Smartda0436e2009-05-22 14:51:39 -04005951lpfc_init_sgl_list(struct lpfc_hba *phba)
5952{
James Smartda0436e2009-05-22 14:51:39 -04005953 /* Initialize and populate the sglq list per host/VF. */
5954 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
5955 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
5956
James Smart8a9d2e82012-05-09 21:16:12 -04005957 /* els xri-sgl book keeping */
5958 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04005959
James Smart8a9d2e82012-05-09 21:16:12 -04005960 /* scsi xri-buffer book keeping */
James Smartda0436e2009-05-22 14:51:39 -04005961 phba->sli4_hba.scsi_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04005962}
5963
5964/**
5965 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
5966 * @phba: pointer to lpfc hba data structure.
5967 *
5968 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04005969 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04005970 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04005971 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
5972 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04005973 *
5974 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005975 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04005976 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04005977 **/
5978int
5979lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
5980{
5981 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04005982 struct lpfc_rpi_hdr *rpi_hdr;
5983
5984 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05005985 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04005986 return rc;
James Smart6d368e52011-05-24 11:44:12 -04005987 if (phba->sli4_hba.extents_in_use)
5988 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04005989
5990 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
5991 if (!rpi_hdr) {
5992 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5993 "0391 Error during rpi post operation\n");
5994 lpfc_sli4_remove_rpis(phba);
5995 rc = -ENODEV;
5996 }
5997
5998 return rc;
5999}
6000
6001/**
6002 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
6003 * @phba: pointer to lpfc hba data structure.
6004 *
6005 * This routine is invoked to allocate a single 4KB memory region to
6006 * support rpis and stores them in the phba. This single region
6007 * provides support for up to 64 rpis. The region is used globally
6008 * by the device.
6009 *
6010 * Returns:
6011 * A valid rpi hdr on success.
6012 * A NULL pointer on any failure.
6013 **/
6014struct lpfc_rpi_hdr *
6015lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
6016{
6017 uint16_t rpi_limit, curr_rpi_range;
6018 struct lpfc_dmabuf *dmabuf;
6019 struct lpfc_rpi_hdr *rpi_hdr;
James Smart9589b0622011-04-16 11:03:17 -04006020 uint32_t rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04006021
James Smart6d368e52011-05-24 11:44:12 -04006022 /*
6023 * If the SLI4 port supports extents, posting the rpi header isn't
6024 * required. Set the expected maximum count and let the actual value
6025 * get set when extents are fully allocated.
6026 */
6027 if (!phba->sli4_hba.rpi_hdrs_in_use)
6028 return NULL;
6029 if (phba->sli4_hba.extents_in_use)
6030 return NULL;
6031
6032 /* The limit on the logical index is just the max_rpi count. */
James Smartda0436e2009-05-22 14:51:39 -04006033 rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
James Smart6d368e52011-05-24 11:44:12 -04006034 phba->sli4_hba.max_cfg_param.max_rpi - 1;
James Smartda0436e2009-05-22 14:51:39 -04006035
6036 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006037 /*
6038 * Establish the starting RPI in this header block. The starting
6039 * rpi is normalized to a zero base because the physical rpi is
6040 * port based.
6041 */
James Smart97f2ecf2012-03-01 22:35:23 -05006042 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04006043 spin_unlock_irq(&phba->hbalock);
6044
6045 /*
6046 * The port has a limited number of rpis. The increment here
6047 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
6048 * and to allow the full max_rpi range per port.
6049 */
6050 if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
James Smart9589b0622011-04-16 11:03:17 -04006051 rpi_count = rpi_limit - curr_rpi_range;
6052 else
6053 rpi_count = LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04006054
James Smart6d368e52011-05-24 11:44:12 -04006055 if (!rpi_count)
6056 return NULL;
James Smartda0436e2009-05-22 14:51:39 -04006057 /*
6058 * First allocate the protocol header region for the port. The
6059 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
6060 */
6061 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6062 if (!dmabuf)
6063 return NULL;
6064
Joe Perches1aee3832014-09-03 12:56:12 -04006065 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
6066 LPFC_HDR_TEMPLATE_SIZE,
6067 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04006068 if (!dmabuf->virt) {
6069 rpi_hdr = NULL;
6070 goto err_free_dmabuf;
6071 }
6072
James Smartda0436e2009-05-22 14:51:39 -04006073 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
6074 rpi_hdr = NULL;
6075 goto err_free_coherent;
6076 }
6077
6078 /* Save the rpi header data for cleanup later. */
6079 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
6080 if (!rpi_hdr)
6081 goto err_free_coherent;
6082
6083 rpi_hdr->dmabuf = dmabuf;
6084 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
6085 rpi_hdr->page_count = 1;
6086 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006087
6088 /* The rpi_hdr stores the logical index only. */
6089 rpi_hdr->start_rpi = curr_rpi_range;
James Smartda0436e2009-05-22 14:51:39 -04006090 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
6091
6092 /*
James Smart6d368e52011-05-24 11:44:12 -04006093 * The next_rpi stores the next logical module-64 rpi value used
6094 * to post physical rpis in subsequent rpi postings.
James Smartda0436e2009-05-22 14:51:39 -04006095 */
James Smart9589b0622011-04-16 11:03:17 -04006096 phba->sli4_hba.next_rpi += rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04006097 spin_unlock_irq(&phba->hbalock);
6098 return rpi_hdr;
6099
6100 err_free_coherent:
6101 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
6102 dmabuf->virt, dmabuf->phys);
6103 err_free_dmabuf:
6104 kfree(dmabuf);
6105 return NULL;
6106}
6107
6108/**
6109 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
6110 * @phba: pointer to lpfc hba data structure.
6111 *
6112 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04006113 * to support rpis for SLI4 ports not supporting extents. This routine
6114 * presumes the caller has released all rpis consumed by fabric or port
6115 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04006116 **/
6117void
6118lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
6119{
6120 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
6121
James Smart6d368e52011-05-24 11:44:12 -04006122 if (!phba->sli4_hba.rpi_hdrs_in_use)
6123 goto exit;
6124
James Smartda0436e2009-05-22 14:51:39 -04006125 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
6126 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
6127 list_del(&rpi_hdr->list);
6128 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
6129 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
6130 kfree(rpi_hdr->dmabuf);
6131 kfree(rpi_hdr);
6132 }
James Smart6d368e52011-05-24 11:44:12 -04006133 exit:
6134 /* There are no rpis available to the port now. */
6135 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04006136}
6137
6138/**
James Smart3772a992009-05-22 14:50:54 -04006139 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
6140 * @pdev: pointer to pci device data structure.
6141 *
6142 * This routine is invoked to allocate the driver hba data structure for an
6143 * HBA device. If the allocation is successful, the phba reference to the
6144 * PCI device data structure is set.
6145 *
6146 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006147 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04006148 * NULL - error
6149 **/
6150static struct lpfc_hba *
6151lpfc_hba_alloc(struct pci_dev *pdev)
6152{
6153 struct lpfc_hba *phba;
6154
6155 /* Allocate memory for HBA structure */
6156 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
6157 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02006158 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04006159 return NULL;
6160 }
6161
6162 /* Set reference to PCI device in HBA structure */
6163 phba->pcidev = pdev;
6164
6165 /* Assign an unused board number */
6166 phba->brd_no = lpfc_get_instance();
6167 if (phba->brd_no < 0) {
6168 kfree(phba);
6169 return NULL;
6170 }
James Smart65791f12016-07-06 12:35:56 -07006171 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
James Smart3772a992009-05-22 14:50:54 -04006172
James Smart4fede782010-01-26 23:08:55 -05006173 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04006174 INIT_LIST_HEAD(&phba->ct_ev_waiters);
6175
James Smart3772a992009-05-22 14:50:54 -04006176 return phba;
6177}
6178
6179/**
6180 * lpfc_hba_free - Free driver hba data structure with a device.
6181 * @phba: pointer to lpfc hba data structure.
6182 *
6183 * This routine is invoked to free the driver hba data structure with an
6184 * HBA device.
6185 **/
6186static void
6187lpfc_hba_free(struct lpfc_hba *phba)
6188{
6189 /* Release the driver assigned board number */
6190 idr_remove(&lpfc_hba_index, phba->brd_no);
6191
James Smart2a76a282012-08-03 12:35:54 -04006192 /* Free memory allocated with sli rings */
6193 kfree(phba->sli.ring);
6194 phba->sli.ring = NULL;
6195
James Smart3772a992009-05-22 14:50:54 -04006196 kfree(phba);
6197 return;
6198}
6199
6200/**
6201 * lpfc_create_shost - Create hba physical port with associated scsi host.
6202 * @phba: pointer to lpfc hba data structure.
6203 *
6204 * This routine is invoked to create HBA physical port and associate a SCSI
6205 * host with it.
6206 *
6207 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006208 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006209 * other values - error
6210 **/
6211static int
6212lpfc_create_shost(struct lpfc_hba *phba)
6213{
6214 struct lpfc_vport *vport;
6215 struct Scsi_Host *shost;
6216
6217 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05006218 phba->fc_edtov = FF_DEF_EDTOV;
6219 phba->fc_ratov = FF_DEF_RATOV;
6220 phba->fc_altov = FF_DEF_ALTOV;
6221 phba->fc_arbtov = FF_DEF_ARBTOV;
6222
James Smartd7c47992010-06-08 18:31:54 -04006223 atomic_set(&phba->sdev_cnt, 0);
James Smart3de2a652007-08-02 11:09:59 -04006224 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05006225 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04006226 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05006227
6228 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05006229 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05006230 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04006231 /* Put reference to SCSI host to driver's device private data */
6232 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05006233
James Smart4258e982015-12-16 18:11:58 -05006234 /*
6235 * At this point we are fully registered with PSA. In addition,
6236 * any initial discovery should be completed.
6237 */
6238 vport->load_flag |= FC_ALLOW_FDMI;
James Smart8663cbb2016-03-31 14:12:33 -07006239 if (phba->cfg_enable_SmartSAN ||
6240 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -05006241
6242 /* Setup appropriate attribute masks */
6243 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -07006244 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -05006245 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
6246 else
6247 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
6248 }
James Smart3772a992009-05-22 14:50:54 -04006249 return 0;
6250}
dea31012005-04-17 16:05:31 -05006251
James Smart3772a992009-05-22 14:50:54 -04006252/**
6253 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
6254 * @phba: pointer to lpfc hba data structure.
6255 *
6256 * This routine is invoked to destroy HBA physical port and the associated
6257 * SCSI host.
6258 **/
6259static void
6260lpfc_destroy_shost(struct lpfc_hba *phba)
6261{
6262 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04006263
James Smart3772a992009-05-22 14:50:54 -04006264 /* Destroy physical port that associated with the SCSI host */
6265 destroy_port(vport);
6266
6267 return;
6268}
6269
6270/**
6271 * lpfc_setup_bg - Setup Block guard structures and debug areas.
6272 * @phba: pointer to lpfc hba data structure.
6273 * @shost: the shost to be used to detect Block guard settings.
6274 *
6275 * This routine sets up the local Block guard protocol settings for @shost.
6276 * This routine also allocates memory for debugging bg buffers.
6277 **/
6278static void
6279lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
6280{
James Smartbbeb79b2012-06-12 13:54:27 -04006281 uint32_t old_mask;
6282 uint32_t old_guard;
6283
James Smart3772a992009-05-22 14:50:54 -04006284 int pagecnt = 10;
6285 if (lpfc_prot_mask && lpfc_prot_guard) {
6286 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6287 "1478 Registering BlockGuard with the "
6288 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04006289
6290 old_mask = lpfc_prot_mask;
6291 old_guard = lpfc_prot_guard;
6292
6293 /* Only allow supported values */
6294 lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
6295 SHOST_DIX_TYPE0_PROTECTION |
6296 SHOST_DIX_TYPE1_PROTECTION);
6297 lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC);
6298
6299 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
6300 if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
6301 lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
6302
6303 if (lpfc_prot_mask && lpfc_prot_guard) {
6304 if ((old_mask != lpfc_prot_mask) ||
6305 (old_guard != lpfc_prot_guard))
6306 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6307 "1475 Registering BlockGuard with the "
6308 "SCSI layer: mask %d guard %d\n",
6309 lpfc_prot_mask, lpfc_prot_guard);
6310
6311 scsi_host_set_prot(shost, lpfc_prot_mask);
6312 scsi_host_set_guard(shost, lpfc_prot_guard);
6313 } else
6314 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6315 "1479 Not Registering BlockGuard with the SCSI "
6316 "layer, Bad protection parameters: %d %d\n",
6317 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04006318 }
James Smartbbeb79b2012-06-12 13:54:27 -04006319
James Smart81301a92008-12-04 22:39:46 -05006320 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05006321 while (pagecnt) {
6322 spin_lock_init(&_dump_buf_lock);
6323 _dump_buf_data =
6324 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6325 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04006326 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6327 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04006328 "_dump_buf_data at 0x%p\n",
6329 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05006330 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04006331 memset(_dump_buf_data, 0,
6332 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05006333 break;
James Smart3772a992009-05-22 14:50:54 -04006334 } else
James Smart81301a92008-12-04 22:39:46 -05006335 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05006336 }
James Smart81301a92008-12-04 22:39:46 -05006337 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04006338 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6339 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04006340 "memory for hexdump\n");
6341 } else
James Smart6a9c52c2009-10-02 15:16:51 -04006342 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6343 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05006344 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05006345 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05006346 while (pagecnt) {
6347 _dump_buf_dif =
6348 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6349 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04006350 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6351 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04006352 "_dump_buf_dif at 0x%p\n",
6353 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05006354 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04006355 memset(_dump_buf_dif, 0,
6356 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05006357 break;
James Smart3772a992009-05-22 14:50:54 -04006358 } else
James Smart81301a92008-12-04 22:39:46 -05006359 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05006360 }
James Smart81301a92008-12-04 22:39:46 -05006361 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04006362 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6363 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04006364 "memory for hexdump\n");
6365 } else
James Smart6a9c52c2009-10-02 15:16:51 -04006366 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6367 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04006368 _dump_buf_dif);
6369}
6370
6371/**
6372 * lpfc_post_init_setup - Perform necessary device post initialization setup.
6373 * @phba: pointer to lpfc hba data structure.
6374 *
6375 * This routine is invoked to perform all the necessary post initialization
6376 * setup for the device.
6377 **/
6378static void
6379lpfc_post_init_setup(struct lpfc_hba *phba)
6380{
6381 struct Scsi_Host *shost;
6382 struct lpfc_adapter_event_header adapter_event;
6383
6384 /* Get the default values for Model Name and Description */
6385 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
6386
6387 /*
6388 * hba setup may have changed the hba_queue_depth so we need to
6389 * adjust the value of can_queue.
6390 */
6391 shost = pci_get_drvdata(phba->pcidev);
6392 shost->can_queue = phba->cfg_hba_queue_depth - 10;
6393 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
6394 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05006395
6396 lpfc_host_attrib_init(shost);
6397
James Smart2e0fef82007-06-17 19:56:36 -05006398 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
6399 spin_lock_irq(shost->host_lock);
6400 lpfc_poll_start_timer(phba);
6401 spin_unlock_irq(shost->host_lock);
6402 }
James Smart8f6d98d2006-08-01 07:34:00 -04006403
James Smart93996272008-08-24 21:50:30 -04006404 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6405 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04006406 /* Send board arrival event to upper layer */
6407 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
6408 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
6409 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04006410 sizeof(adapter_event),
6411 (char *) &adapter_event,
6412 LPFC_NL_VENDOR_ID);
6413 return;
6414}
6415
6416/**
6417 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
6418 * @phba: pointer to lpfc hba data structure.
6419 *
6420 * This routine is invoked to set up the PCI device memory space for device
6421 * with SLI-3 interface spec.
6422 *
6423 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006424 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006425 * other values - error
6426 **/
6427static int
6428lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
6429{
6430 struct pci_dev *pdev;
6431 unsigned long bar0map_len, bar2map_len;
6432 int i, hbq_count;
6433 void *ptr;
6434 int error = -ENODEV;
6435
6436 /* Obtain PCI device reference */
6437 if (!phba->pcidev)
6438 return error;
6439 else
6440 pdev = phba->pcidev;
6441
6442 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05006443 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
6444 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
6445 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
6446 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smart3772a992009-05-22 14:50:54 -04006447 return error;
Michael Reed8e685972009-09-18 12:02:05 -05006448 }
6449 }
James Smart3772a992009-05-22 14:50:54 -04006450
6451 /* Get the bus address of Bar0 and Bar2 and the number of bytes
6452 * required by each mapping.
6453 */
6454 phba->pci_bar0_map = pci_resource_start(pdev, 0);
6455 bar0map_len = pci_resource_len(pdev, 0);
6456
6457 phba->pci_bar2_map = pci_resource_start(pdev, 2);
6458 bar2map_len = pci_resource_len(pdev, 2);
6459
6460 /* Map HBA SLIM to a kernel virtual address. */
6461 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
6462 if (!phba->slim_memmap_p) {
6463 dev_printk(KERN_ERR, &pdev->dev,
6464 "ioremap failed for SLIM memory.\n");
6465 goto out;
6466 }
6467
6468 /* Map HBA Control Registers to a kernel virtual address. */
6469 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
6470 if (!phba->ctrl_regs_memmap_p) {
6471 dev_printk(KERN_ERR, &pdev->dev,
6472 "ioremap failed for HBA control registers.\n");
6473 goto out_iounmap_slim;
6474 }
6475
6476 /* Allocate memory for SLI-2 structures */
Joe Perches1aee3832014-09-03 12:56:12 -04006477 phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6478 &phba->slim2p.phys, GFP_KERNEL);
James Smart3772a992009-05-22 14:50:54 -04006479 if (!phba->slim2p.virt)
6480 goto out_iounmap;
6481
James Smart3772a992009-05-22 14:50:54 -04006482 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04006483 phba->mbox_ext = (phba->slim2p.virt +
6484 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04006485 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
6486 phba->IOCBs = (phba->slim2p.virt +
6487 offsetof(struct lpfc_sli2_slim, IOCBs));
6488
6489 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
6490 lpfc_sli_hbq_size(),
6491 &phba->hbqslimp.phys,
6492 GFP_KERNEL);
6493 if (!phba->hbqslimp.virt)
6494 goto out_free_slim;
6495
6496 hbq_count = lpfc_sli_hbq_count();
6497 ptr = phba->hbqslimp.virt;
6498 for (i = 0; i < hbq_count; ++i) {
6499 phba->hbqs[i].hbq_virt = ptr;
6500 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
6501 ptr += (lpfc_hbq_defs[i]->entry_count *
6502 sizeof(struct lpfc_hbq_entry));
6503 }
6504 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
6505 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
6506
6507 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
6508
6509 INIT_LIST_HEAD(&phba->rb_pend_list);
6510
6511 phba->MBslimaddr = phba->slim_memmap_p;
6512 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
6513 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
6514 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
6515 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04006516
dea31012005-04-17 16:05:31 -05006517 return 0;
6518
dea31012005-04-17 16:05:31 -05006519out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04006520 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6521 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05006522out_iounmap:
6523 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006524out_iounmap_slim:
dea31012005-04-17 16:05:31 -05006525 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05006526out:
6527 return error;
6528}
6529
James Smarte59058c2008-08-24 21:49:00 -04006530/**
James Smart3772a992009-05-22 14:50:54 -04006531 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
6532 * @phba: pointer to lpfc hba data structure.
6533 *
6534 * This routine is invoked to unset the PCI device memory space for device
6535 * with SLI-3 interface spec.
6536 **/
6537static void
6538lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
6539{
6540 struct pci_dev *pdev;
6541
6542 /* Obtain PCI device reference */
6543 if (!phba->pcidev)
6544 return;
6545 else
6546 pdev = phba->pcidev;
6547
6548 /* Free coherent DMA memory allocated */
6549 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
6550 phba->hbqslimp.virt, phba->hbqslimp.phys);
6551 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6552 phba->slim2p.virt, phba->slim2p.phys);
6553
6554 /* I/O memory unmap */
6555 iounmap(phba->ctrl_regs_memmap_p);
6556 iounmap(phba->slim_memmap_p);
6557
6558 return;
6559}
6560
6561/**
James Smartda0436e2009-05-22 14:51:39 -04006562 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
6563 * @phba: pointer to lpfc hba data structure.
6564 *
6565 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
6566 * done and check status.
6567 *
6568 * Return 0 if successful, otherwise -ENODEV.
6569 **/
6570int
6571lpfc_sli4_post_status_check(struct lpfc_hba *phba)
6572{
James Smart2fcee4b2010-12-15 17:57:46 -05006573 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
6574 struct lpfc_register reg_data;
6575 int i, port_error = 0;
6576 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04006577
James Smart9940b972011-03-11 16:06:12 -05006578 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
6579 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05006580 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04006581 return -ENODEV;
6582
James Smartda0436e2009-05-22 14:51:39 -04006583 /* Wait up to 30 seconds for the SLI Port POST done and ready */
6584 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05006585 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
6586 &portsmphr_reg.word0) ||
6587 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006588 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04006589 port_error = -ENODEV;
6590 break;
6591 }
James Smart2fcee4b2010-12-15 17:57:46 -05006592 if (LPFC_POST_STAGE_PORT_READY ==
6593 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04006594 break;
James Smartda0436e2009-05-22 14:51:39 -04006595 msleep(10);
6596 }
6597
James Smart2fcee4b2010-12-15 17:57:46 -05006598 /*
6599 * If there was a port error during POST, then don't proceed with
6600 * other register reads as the data may not be valid. Just exit.
6601 */
6602 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04006603 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006604 "1408 Port Failed POST - portsmphr=0x%x, "
6605 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
6606 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
6607 portsmphr_reg.word0,
6608 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
6609 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
6610 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
6611 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
6612 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
6613 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
6614 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
6615 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
6616 } else {
James Smart28baac72010-02-12 14:42:03 -05006617 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006618 "2534 Device Info: SLIFamily=0x%x, "
6619 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
6620 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05006621 bf_get(lpfc_sli_intf_sli_family,
6622 &phba->sli4_hba.sli_intf),
6623 bf_get(lpfc_sli_intf_slirev,
6624 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006625 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05006626 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006627 bf_get(lpfc_sli_intf_sli_hint1,
6628 &phba->sli4_hba.sli_intf),
6629 bf_get(lpfc_sli_intf_sli_hint2,
6630 &phba->sli4_hba.sli_intf),
6631 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05006632 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05006633 /*
6634 * Check for other Port errors during the initialization
6635 * process. Fail the load if the port did not come up
6636 * correctly.
6637 */
6638 if_type = bf_get(lpfc_sli_intf_if_type,
6639 &phba->sli4_hba.sli_intf);
6640 switch (if_type) {
6641 case LPFC_SLI_INTF_IF_TYPE_0:
6642 phba->sli4_hba.ue_mask_lo =
6643 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
6644 phba->sli4_hba.ue_mask_hi =
6645 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
6646 uerrlo_reg.word0 =
6647 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
6648 uerrhi_reg.word0 =
6649 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
6650 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
6651 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
6652 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6653 "1422 Unrecoverable Error "
6654 "Detected during POST "
6655 "uerr_lo_reg=0x%x, "
6656 "uerr_hi_reg=0x%x, "
6657 "ue_mask_lo_reg=0x%x, "
6658 "ue_mask_hi_reg=0x%x\n",
6659 uerrlo_reg.word0,
6660 uerrhi_reg.word0,
6661 phba->sli4_hba.ue_mask_lo,
6662 phba->sli4_hba.ue_mask_hi);
6663 port_error = -ENODEV;
6664 }
6665 break;
6666 case LPFC_SLI_INTF_IF_TYPE_2:
6667 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05006668 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
6669 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04006670 (bf_get(lpfc_sliport_status_err, &reg_data) &&
6671 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006672 phba->work_status[0] =
6673 readl(phba->sli4_hba.u.if_type2.
6674 ERR1regaddr);
6675 phba->work_status[1] =
6676 readl(phba->sli4_hba.u.if_type2.
6677 ERR2regaddr);
6678 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05006679 "2888 Unrecoverable port error "
6680 "following POST: port status reg "
6681 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05006682 "error 1=0x%x, error 2=0x%x\n",
6683 reg_data.word0,
6684 portsmphr_reg.word0,
6685 phba->work_status[0],
6686 phba->work_status[1]);
6687 port_error = -ENODEV;
6688 }
6689 break;
6690 case LPFC_SLI_INTF_IF_TYPE_1:
6691 default:
6692 break;
6693 }
James Smart28baac72010-02-12 14:42:03 -05006694 }
James Smartda0436e2009-05-22 14:51:39 -04006695 return port_error;
6696}
6697
6698/**
6699 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
6700 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05006701 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04006702 *
6703 * This routine is invoked to set up SLI4 BAR0 PCI config space register
6704 * memory map.
6705 **/
6706static void
James Smart2fcee4b2010-12-15 17:57:46 -05006707lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04006708{
James Smart2fcee4b2010-12-15 17:57:46 -05006709 switch (if_type) {
6710 case LPFC_SLI_INTF_IF_TYPE_0:
6711 phba->sli4_hba.u.if_type0.UERRLOregaddr =
6712 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
6713 phba->sli4_hba.u.if_type0.UERRHIregaddr =
6714 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
6715 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
6716 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
6717 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
6718 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
6719 phba->sli4_hba.SLIINTFregaddr =
6720 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6721 break;
6722 case LPFC_SLI_INTF_IF_TYPE_2:
6723 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006724 phba->sli4_hba.conf_regs_memmap_p +
6725 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006726 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006727 phba->sli4_hba.conf_regs_memmap_p +
6728 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006729 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006730 phba->sli4_hba.conf_regs_memmap_p +
6731 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006732 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006733 phba->sli4_hba.conf_regs_memmap_p +
6734 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006735 phba->sli4_hba.SLIINTFregaddr =
6736 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6737 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006738 phba->sli4_hba.conf_regs_memmap_p +
6739 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006740 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006741 phba->sli4_hba.conf_regs_memmap_p +
6742 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006743 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006744 phba->sli4_hba.conf_regs_memmap_p +
6745 LPFC_ULP0_WQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006746 phba->sli4_hba.EQCQDBregaddr =
6747 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
6748 phba->sli4_hba.MQDBregaddr =
6749 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
6750 phba->sli4_hba.BMBXregaddr =
6751 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
6752 break;
6753 case LPFC_SLI_INTF_IF_TYPE_1:
6754 default:
6755 dev_printk(KERN_ERR, &phba->pcidev->dev,
6756 "FATAL - unsupported SLI4 interface type - %d\n",
6757 if_type);
6758 break;
6759 }
James Smartda0436e2009-05-22 14:51:39 -04006760}
6761
6762/**
6763 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
6764 * @phba: pointer to lpfc hba data structure.
6765 *
6766 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
6767 * memory map.
6768 **/
6769static void
6770lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
6771{
James Smart2fcee4b2010-12-15 17:57:46 -05006772 phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
6773 LPFC_SLIPORT_IF0_SMPHR;
James Smartda0436e2009-05-22 14:51:39 -04006774 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006775 LPFC_HST_ISR0;
James Smartda0436e2009-05-22 14:51:39 -04006776 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006777 LPFC_HST_IMR0;
James Smartda0436e2009-05-22 14:51:39 -04006778 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006779 LPFC_HST_ISCR0;
James Smartda0436e2009-05-22 14:51:39 -04006780}
6781
6782/**
6783 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
6784 * @phba: pointer to lpfc hba data structure.
6785 * @vf: virtual function number
6786 *
6787 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
6788 * based on the given viftual function number, @vf.
6789 *
6790 * Return 0 if successful, otherwise -ENODEV.
6791 **/
6792static int
6793lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
6794{
6795 if (vf > LPFC_VIR_FUNC_MAX)
6796 return -ENODEV;
6797
6798 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05006799 vf * LPFC_VFR_PAGE_SIZE +
6800 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04006801 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05006802 vf * LPFC_VFR_PAGE_SIZE +
6803 LPFC_ULP0_WQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04006804 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6805 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
6806 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6807 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
6808 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6809 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
6810 return 0;
6811}
6812
6813/**
6814 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
6815 * @phba: pointer to lpfc hba data structure.
6816 *
6817 * This routine is invoked to create the bootstrap mailbox
6818 * region consistent with the SLI-4 interface spec. This
6819 * routine allocates all memory necessary to communicate
6820 * mailbox commands to the port and sets up all alignment
6821 * needs. No locks are expected to be held when calling
6822 * this routine.
6823 *
6824 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006825 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04006826 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04006827 **/
6828static int
6829lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
6830{
6831 uint32_t bmbx_size;
6832 struct lpfc_dmabuf *dmabuf;
6833 struct dma_address *dma_address;
6834 uint32_t pa_addr;
6835 uint64_t phys_addr;
6836
6837 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6838 if (!dmabuf)
6839 return -ENOMEM;
6840
6841 /*
6842 * The bootstrap mailbox region is comprised of 2 parts
6843 * plus an alignment restriction of 16 bytes.
6844 */
6845 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
Joe Perches1aee3832014-09-03 12:56:12 -04006846 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
6847 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04006848 if (!dmabuf->virt) {
6849 kfree(dmabuf);
6850 return -ENOMEM;
6851 }
James Smartda0436e2009-05-22 14:51:39 -04006852
6853 /*
6854 * Initialize the bootstrap mailbox pointers now so that the register
6855 * operations are simple later. The mailbox dma address is required
6856 * to be 16-byte aligned. Also align the virtual memory as each
6857 * maibox is copied into the bmbx mailbox region before issuing the
6858 * command to the port.
6859 */
6860 phba->sli4_hba.bmbx.dmabuf = dmabuf;
6861 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
6862
6863 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
6864 LPFC_ALIGN_16_BYTE);
6865 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
6866 LPFC_ALIGN_16_BYTE);
6867
6868 /*
6869 * Set the high and low physical addresses now. The SLI4 alignment
6870 * requirement is 16 bytes and the mailbox is posted to the port
6871 * as two 30-bit addresses. The other data is a bit marking whether
6872 * the 30-bit address is the high or low address.
6873 * Upcast bmbx aphys to 64bits so shift instruction compiles
6874 * clean on 32 bit machines.
6875 */
6876 dma_address = &phba->sli4_hba.bmbx.dma_address;
6877 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
6878 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
6879 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
6880 LPFC_BMBX_BIT1_ADDR_HI);
6881
6882 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
6883 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
6884 LPFC_BMBX_BIT1_ADDR_LO);
6885 return 0;
6886}
6887
6888/**
6889 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
6890 * @phba: pointer to lpfc hba data structure.
6891 *
6892 * This routine is invoked to teardown the bootstrap mailbox
6893 * region and release all host resources. This routine requires
6894 * the caller to ensure all mailbox commands recovered, no
6895 * additional mailbox comands are sent, and interrupts are disabled
6896 * before calling this routine.
6897 *
6898 **/
6899static void
6900lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
6901{
6902 dma_free_coherent(&phba->pcidev->dev,
6903 phba->sli4_hba.bmbx.bmbx_size,
6904 phba->sli4_hba.bmbx.dmabuf->virt,
6905 phba->sli4_hba.bmbx.dmabuf->phys);
6906
6907 kfree(phba->sli4_hba.bmbx.dmabuf);
6908 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
6909}
6910
6911/**
6912 * lpfc_sli4_read_config - Get the config parameters.
6913 * @phba: pointer to lpfc hba data structure.
6914 *
6915 * This routine is invoked to read the configuration parameters from the HBA.
6916 * The configuration parameters are used to set the base and maximum values
6917 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
6918 * allocation for the port.
6919 *
6920 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006921 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006922 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006923 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006924 **/
James Smartff78d8f2011-12-13 13:21:35 -05006925int
James Smartda0436e2009-05-22 14:51:39 -04006926lpfc_sli4_read_config(struct lpfc_hba *phba)
6927{
6928 LPFC_MBOXQ_t *pmb;
6929 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04006930 union lpfc_sli4_cfg_shdr *shdr;
6931 uint32_t shdr_status, shdr_add_status;
6932 struct lpfc_mbx_get_func_cfg *get_func_cfg;
6933 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04006934 char *pdesc_0;
James Smart8aa134a2012-08-14 14:25:29 -04006935 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04006936
6937 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6938 if (!pmb) {
6939 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6940 "2011 Unable to allocate memory for issuing "
6941 "SLI_CONFIG_SPECIAL mailbox command\n");
6942 return -ENOMEM;
6943 }
6944
6945 lpfc_read_config(phba, pmb);
6946
6947 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
6948 if (rc != MBX_SUCCESS) {
6949 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6950 "2012 Mailbox failed , mbxCmd x%x "
6951 "READ_CONFIG, mbxStatus x%x\n",
6952 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6953 bf_get(lpfc_mqe_status, &pmb->u.mqe));
6954 rc = -EIO;
6955 } else {
6956 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05006957 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
6958 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
6959 phba->sli4_hba.lnk_info.lnk_tp =
6960 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
6961 phba->sli4_hba.lnk_info.lnk_no =
6962 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
6963 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6964 "3081 lnk_type:%d, lnk_numb:%d\n",
6965 phba->sli4_hba.lnk_info.lnk_tp,
6966 phba->sli4_hba.lnk_info.lnk_no);
6967 } else
6968 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6969 "3082 Mailbox (x%x) returned ldv:x0\n",
6970 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart6d368e52011-05-24 11:44:12 -04006971 phba->sli4_hba.extents_in_use =
6972 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04006973 phba->sli4_hba.max_cfg_param.max_xri =
6974 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
6975 phba->sli4_hba.max_cfg_param.xri_base =
6976 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
6977 phba->sli4_hba.max_cfg_param.max_vpi =
6978 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
6979 phba->sli4_hba.max_cfg_param.vpi_base =
6980 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
6981 phba->sli4_hba.max_cfg_param.max_rpi =
6982 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
6983 phba->sli4_hba.max_cfg_param.rpi_base =
6984 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
6985 phba->sli4_hba.max_cfg_param.max_vfi =
6986 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
6987 phba->sli4_hba.max_cfg_param.vfi_base =
6988 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
6989 phba->sli4_hba.max_cfg_param.max_fcfi =
6990 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04006991 phba->sli4_hba.max_cfg_param.max_eq =
6992 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
6993 phba->sli4_hba.max_cfg_param.max_rq =
6994 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
6995 phba->sli4_hba.max_cfg_param.max_wq =
6996 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
6997 phba->sli4_hba.max_cfg_param.max_cq =
6998 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
6999 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
7000 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
7001 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
7002 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05007003 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
7004 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04007005 phba->max_vports = phba->max_vpi;
7006 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04007007 "2003 cfg params Extents? %d "
7008 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04007009 "VPI(B:%d M:%d) "
7010 "VFI(B:%d M:%d) "
7011 "RPI(B:%d M:%d) "
James Smart6d368e52011-05-24 11:44:12 -04007012 "FCFI(Count:%d)\n",
7013 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04007014 phba->sli4_hba.max_cfg_param.xri_base,
7015 phba->sli4_hba.max_cfg_param.max_xri,
7016 phba->sli4_hba.max_cfg_param.vpi_base,
7017 phba->sli4_hba.max_cfg_param.max_vpi,
7018 phba->sli4_hba.max_cfg_param.vfi_base,
7019 phba->sli4_hba.max_cfg_param.max_vfi,
7020 phba->sli4_hba.max_cfg_param.rpi_base,
7021 phba->sli4_hba.max_cfg_param.max_rpi,
James Smartda0436e2009-05-22 14:51:39 -04007022 phba->sli4_hba.max_cfg_param.max_fcfi);
7023 }
James Smart912e3ac2011-05-24 11:42:11 -04007024
7025 if (rc)
7026 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04007027
7028 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -04007029 length = phba->sli4_hba.max_cfg_param.max_xri -
7030 lpfc_sli4_get_els_iocb_cnt(phba);
7031 if (phba->cfg_hba_queue_depth > length) {
7032 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7033 "3361 HBA queue depth changed from %d to %d\n",
7034 phba->cfg_hba_queue_depth, length);
7035 phba->cfg_hba_queue_depth = length;
7036 }
James Smart912e3ac2011-05-24 11:42:11 -04007037
7038 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
7039 LPFC_SLI_INTF_IF_TYPE_2)
7040 goto read_cfg_out;
7041
7042 /* get the pf# and vf# for SLI4 if_type 2 port */
7043 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
7044 sizeof(struct lpfc_sli4_cfg_mhdr));
7045 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
7046 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
7047 length, LPFC_SLI4_MBX_EMBED);
7048
James Smart8aa134a2012-08-14 14:25:29 -04007049 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04007050 shdr = (union lpfc_sli4_cfg_shdr *)
7051 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
7052 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7053 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04007054 if (rc2 || shdr_status || shdr_add_status) {
James Smart912e3ac2011-05-24 11:42:11 -04007055 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7056 "3026 Mailbox failed , mbxCmd x%x "
7057 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
7058 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7059 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04007060 goto read_cfg_out;
7061 }
7062
7063 /* search for fc_fcoe resrouce descriptor */
7064 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
James Smart912e3ac2011-05-24 11:42:11 -04007065
James Smart8aa134a2012-08-14 14:25:29 -04007066 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
7067 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
7068 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
7069 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
7070 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
7071 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
7072 goto read_cfg_out;
7073
James Smart912e3ac2011-05-24 11:42:11 -04007074 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04007075 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04007076 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04007077 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04007078 phba->sli4_hba.iov.pf_number =
7079 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
7080 phba->sli4_hba.iov.vf_number =
7081 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
7082 break;
7083 }
7084 }
7085
7086 if (i < LPFC_RSRC_DESC_MAX_NUM)
7087 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7088 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
7089 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
7090 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04007091 else
James Smart912e3ac2011-05-24 11:42:11 -04007092 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7093 "3028 GET_FUNCTION_CONFIG: failed to find "
7094 "Resrouce Descriptor:x%x\n",
7095 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04007096
7097read_cfg_out:
7098 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04007099 return rc;
7100}
7101
7102/**
James Smart2fcee4b2010-12-15 17:57:46 -05007103 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04007104 * @phba: pointer to lpfc hba data structure.
7105 *
James Smart2fcee4b2010-12-15 17:57:46 -05007106 * This routine is invoked to setup the port-side endian order when
7107 * the port if_type is 0. This routine has no function for other
7108 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04007109 *
7110 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007111 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007112 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007113 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007114 **/
7115static int
7116lpfc_setup_endian_order(struct lpfc_hba *phba)
7117{
7118 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05007119 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04007120 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
7121 HOST_ENDIAN_HIGH_WORD1};
7122
James Smart2fcee4b2010-12-15 17:57:46 -05007123 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7124 switch (if_type) {
7125 case LPFC_SLI_INTF_IF_TYPE_0:
7126 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7127 GFP_KERNEL);
7128 if (!mboxq) {
7129 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7130 "0492 Unable to allocate memory for "
7131 "issuing SLI_CONFIG_SPECIAL mailbox "
7132 "command\n");
7133 return -ENOMEM;
7134 }
James Smartda0436e2009-05-22 14:51:39 -04007135
James Smart2fcee4b2010-12-15 17:57:46 -05007136 /*
7137 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
7138 * two words to contain special data values and no other data.
7139 */
7140 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
7141 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
7142 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7143 if (rc != MBX_SUCCESS) {
7144 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7145 "0493 SLI_CONFIG_SPECIAL mailbox "
7146 "failed with status x%x\n",
7147 rc);
7148 rc = -EIO;
7149 }
7150 mempool_free(mboxq, phba->mbox_mem_pool);
7151 break;
7152 case LPFC_SLI_INTF_IF_TYPE_2:
7153 case LPFC_SLI_INTF_IF_TYPE_1:
7154 default:
7155 break;
James Smartda0436e2009-05-22 14:51:39 -04007156 }
James Smartda0436e2009-05-22 14:51:39 -04007157 return rc;
7158}
7159
7160/**
James Smart5350d872011-10-10 21:33:49 -04007161 * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts
James Smartda0436e2009-05-22 14:51:39 -04007162 * @phba: pointer to lpfc hba data structure.
7163 *
James Smart5350d872011-10-10 21:33:49 -04007164 * This routine is invoked to check the user settable queue counts for EQs and
7165 * CQs. after this routine is called the counts will be set to valid values that
7166 * adhere to the constraints of the system's interrupt vectors and the port's
7167 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04007168 *
7169 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007170 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007171 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007172 **/
7173static int
James Smart5350d872011-10-10 21:33:49 -04007174lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04007175{
James Smart67d12732012-08-03 12:36:13 -04007176 int cfg_fcp_io_channel;
James Smart90695ee2012-08-14 14:25:36 -04007177 uint32_t cpu;
7178 uint32_t i = 0;
James Smart1ba981f2014-02-20 09:56:45 -05007179 int fof_vectors = phba->cfg_fof ? 1 : 0;
James Smartda0436e2009-05-22 14:51:39 -04007180
7181 /*
James Smart67d12732012-08-03 12:36:13 -04007182 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04007183 * device parameters
7184 */
7185
James Smart67d12732012-08-03 12:36:13 -04007186 /* Sanity check on HBA EQ parameters */
7187 cfg_fcp_io_channel = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04007188
James Smart7bb03bb2013-04-17 20:19:16 -04007189 /* It doesn't make sense to have more io channels then online CPUs */
7190 for_each_present_cpu(cpu) {
7191 if (cpu_online(cpu))
7192 i++;
James Smart90695ee2012-08-14 14:25:36 -04007193 }
James Smart7bb03bb2013-04-17 20:19:16 -04007194 phba->sli4_hba.num_online_cpu = i;
James Smartb246de12013-05-31 17:03:07 -04007195 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
James Smart76fd07a2014-02-20 09:57:18 -05007196 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04007197
James Smart90695ee2012-08-14 14:25:36 -04007198 if (i < cfg_fcp_io_channel) {
James Smart82c3e9b2012-09-29 11:29:50 -04007199 lpfc_printf_log(phba,
7200 KERN_ERR, LOG_INIT,
James Smart90695ee2012-08-14 14:25:36 -04007201 "3188 Reducing IO channels to match number of "
James Smart7bb03bb2013-04-17 20:19:16 -04007202 "online CPUs: from %d to %d\n",
7203 cfg_fcp_io_channel, i);
James Smart90695ee2012-08-14 14:25:36 -04007204 cfg_fcp_io_channel = i;
7205 }
7206
James Smart1ba981f2014-02-20 09:56:45 -05007207 if (cfg_fcp_io_channel + fof_vectors >
James Smart67d12732012-08-03 12:36:13 -04007208 phba->sli4_hba.max_cfg_param.max_eq) {
James Smart82c3e9b2012-09-29 11:29:50 -04007209 if (phba->sli4_hba.max_cfg_param.max_eq <
7210 LPFC_FCP_IO_CHAN_MIN) {
James Smartda0436e2009-05-22 14:51:39 -04007211 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7212 "2574 Not enough EQs (%d) from the "
7213 "pci function for supporting FCP "
7214 "EQs (%d)\n",
7215 phba->sli4_hba.max_cfg_param.max_eq,
James Smart67d12732012-08-03 12:36:13 -04007216 phba->cfg_fcp_io_channel);
James Smartda0436e2009-05-22 14:51:39 -04007217 goto out_error;
7218 }
James Smart82c3e9b2012-09-29 11:29:50 -04007219 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7220 "2575 Reducing IO channels to match number of "
7221 "available EQs: from %d to %d\n",
7222 cfg_fcp_io_channel,
7223 phba->sli4_hba.max_cfg_param.max_eq);
James Smart1ba981f2014-02-20 09:56:45 -05007224 cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq -
7225 fof_vectors;
James Smartda0436e2009-05-22 14:51:39 -04007226 }
James Smart67d12732012-08-03 12:36:13 -04007227
James Smartda0436e2009-05-22 14:51:39 -04007228 /* The actual number of FCP event queues adopted */
James Smart67d12732012-08-03 12:36:13 -04007229 phba->cfg_fcp_io_channel = cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04007230
James Smartda0436e2009-05-22 14:51:39 -04007231 /* Get EQ depth from module parameter, fake the default for now */
7232 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
7233 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
7234
James Smart5350d872011-10-10 21:33:49 -04007235 /* Get CQ depth from module parameter, fake the default for now */
7236 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
7237 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
7238
7239 return 0;
7240out_error:
7241 return -ENOMEM;
7242}
7243
7244/**
7245 * lpfc_sli4_queue_create - Create all the SLI4 queues
7246 * @phba: pointer to lpfc hba data structure.
7247 *
7248 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
7249 * operation. For each SLI4 queue type, the parameters such as queue entry
7250 * count (queue depth) shall be taken from the module parameter. For now,
7251 * we just use some constant number as place holder.
7252 *
7253 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07007254 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04007255 * -ENOMEM - No availble memory
7256 * -EIO - The mailbox failed to complete successfully.
7257 **/
7258int
7259lpfc_sli4_queue_create(struct lpfc_hba *phba)
7260{
7261 struct lpfc_queue *qdesc;
James Smart67d12732012-08-03 12:36:13 -04007262 int idx;
James Smart5350d872011-10-10 21:33:49 -04007263
7264 /*
James Smart67d12732012-08-03 12:36:13 -04007265 * Create HBA Record arrays.
James Smart5350d872011-10-10 21:33:49 -04007266 */
James Smart67d12732012-08-03 12:36:13 -04007267 if (!phba->cfg_fcp_io_channel)
7268 return -ERANGE;
James Smart5350d872011-10-10 21:33:49 -04007269
James Smart67d12732012-08-03 12:36:13 -04007270 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
7271 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
7272 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
7273 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
7274 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
7275 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
7276
7277 phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) *
7278 phba->cfg_fcp_io_channel), GFP_KERNEL);
7279 if (!phba->sli4_hba.hba_eq) {
James Smartda0436e2009-05-22 14:51:39 -04007280 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007281 "2576 Failed allocate memory for "
7282 "fast-path EQ record array\n");
James Smartda0436e2009-05-22 14:51:39 -04007283 goto out_error;
7284 }
James Smart67d12732012-08-03 12:36:13 -04007285
7286 phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
7287 phba->cfg_fcp_io_channel), GFP_KERNEL);
7288 if (!phba->sli4_hba.fcp_cq) {
7289 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7290 "2577 Failed allocate memory for fast-path "
7291 "CQ record array\n");
7292 goto out_error;
7293 }
7294
7295 phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
7296 phba->cfg_fcp_io_channel), GFP_KERNEL);
7297 if (!phba->sli4_hba.fcp_wq) {
7298 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7299 "2578 Failed allocate memory for fast-path "
7300 "WQ record array\n");
7301 goto out_error;
7302 }
James Smartda0436e2009-05-22 14:51:39 -04007303
James Smart5350d872011-10-10 21:33:49 -04007304 /*
James Smart67d12732012-08-03 12:36:13 -04007305 * Since the first EQ can have multiple CQs associated with it,
7306 * this array is used to quickly see if we have a FCP fast-path
7307 * CQ match.
James Smart5350d872011-10-10 21:33:49 -04007308 */
James Smart67d12732012-08-03 12:36:13 -04007309 phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) *
7310 phba->cfg_fcp_io_channel), GFP_KERNEL);
7311 if (!phba->sli4_hba.fcp_cq_map) {
7312 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7313 "2545 Failed allocate memory for fast-path "
7314 "CQ map\n");
7315 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007316 }
James Smart67d12732012-08-03 12:36:13 -04007317
7318 /*
7319 * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies
7320 * how many EQs to create.
7321 */
7322 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7323
7324 /* Create EQs */
James Smartda0436e2009-05-22 14:51:39 -04007325 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
7326 phba->sli4_hba.eq_ecount);
7327 if (!qdesc) {
7328 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007329 "0497 Failed allocate EQ (%d)\n", idx);
7330 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007331 }
James Smart67d12732012-08-03 12:36:13 -04007332 phba->sli4_hba.hba_eq[idx] = qdesc;
7333
7334 /* Create Fast Path FCP CQs */
7335 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7336 phba->sli4_hba.cq_ecount);
7337 if (!qdesc) {
7338 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7339 "0499 Failed allocate fast-path FCP "
7340 "CQ (%d)\n", idx);
7341 goto out_error;
7342 }
7343 phba->sli4_hba.fcp_cq[idx] = qdesc;
7344
7345 /* Create Fast Path FCP WQs */
James Smartb5c53952016-03-31 14:12:30 -07007346 if (phba->fcp_embed_io) {
7347 qdesc = lpfc_sli4_queue_alloc(phba,
7348 LPFC_WQE128_SIZE,
7349 LPFC_WQE128_DEF_COUNT);
7350 } else {
7351 qdesc = lpfc_sli4_queue_alloc(phba,
7352 phba->sli4_hba.wq_esize,
7353 phba->sli4_hba.wq_ecount);
7354 }
James Smart67d12732012-08-03 12:36:13 -04007355 if (!qdesc) {
7356 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7357 "0503 Failed allocate fast-path FCP "
7358 "WQ (%d)\n", idx);
7359 goto out_error;
7360 }
7361 phba->sli4_hba.fcp_wq[idx] = qdesc;
James Smartda0436e2009-05-22 14:51:39 -04007362 }
7363
James Smart67d12732012-08-03 12:36:13 -04007364
James Smartda0436e2009-05-22 14:51:39 -04007365 /*
James Smart67d12732012-08-03 12:36:13 -04007366 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04007367 */
7368
James Smartda0436e2009-05-22 14:51:39 -04007369 /* Create slow-path Mailbox Command Complete Queue */
7370 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7371 phba->sli4_hba.cq_ecount);
7372 if (!qdesc) {
7373 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7374 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04007375 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007376 }
7377 phba->sli4_hba.mbx_cq = qdesc;
7378
7379 /* Create slow-path ELS Complete Queue */
7380 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7381 phba->sli4_hba.cq_ecount);
7382 if (!qdesc) {
7383 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7384 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -04007385 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007386 }
7387 phba->sli4_hba.els_cq = qdesc;
7388
James Smartda0436e2009-05-22 14:51:39 -04007389
James Smart5350d872011-10-10 21:33:49 -04007390 /*
James Smart67d12732012-08-03 12:36:13 -04007391 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04007392 */
James Smartda0436e2009-05-22 14:51:39 -04007393
7394 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04007395
7396 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
7397 phba->sli4_hba.mq_ecount);
7398 if (!qdesc) {
7399 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7400 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04007401 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007402 }
7403 phba->sli4_hba.mbx_wq = qdesc;
7404
7405 /*
James Smart67d12732012-08-03 12:36:13 -04007406 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04007407 */
James Smartda0436e2009-05-22 14:51:39 -04007408
7409 /* Create slow-path ELS Work Queue */
7410 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
7411 phba->sli4_hba.wq_ecount);
7412 if (!qdesc) {
7413 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7414 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04007415 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007416 }
7417 phba->sli4_hba.els_wq = qdesc;
7418
James Smartda0436e2009-05-22 14:51:39 -04007419 /*
7420 * Create Receive Queue (RQ)
7421 */
James Smartda0436e2009-05-22 14:51:39 -04007422
7423 /* Create Receive Queue for header */
7424 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
7425 phba->sli4_hba.rq_ecount);
7426 if (!qdesc) {
7427 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7428 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04007429 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007430 }
7431 phba->sli4_hba.hdr_rq = qdesc;
7432
7433 /* Create Receive Queue for data */
7434 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
7435 phba->sli4_hba.rq_ecount);
7436 if (!qdesc) {
7437 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7438 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04007439 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007440 }
7441 phba->sli4_hba.dat_rq = qdesc;
7442
James Smart1ba981f2014-02-20 09:56:45 -05007443 /* Create the Queues needed for Flash Optimized Fabric operations */
7444 if (phba->cfg_fof)
7445 lpfc_fof_queue_create(phba);
James Smartda0436e2009-05-22 14:51:39 -04007446 return 0;
7447
James Smartda0436e2009-05-22 14:51:39 -04007448out_error:
James Smart67d12732012-08-03 12:36:13 -04007449 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04007450 return -ENOMEM;
7451}
7452
7453/**
7454 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
7455 * @phba: pointer to lpfc hba data structure.
7456 *
7457 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
7458 * operation.
7459 *
7460 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007461 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007462 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007463 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007464 **/
James Smart5350d872011-10-10 21:33:49 -04007465void
James Smartda0436e2009-05-22 14:51:39 -04007466lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
7467{
James Smart67d12732012-08-03 12:36:13 -04007468 int idx;
7469
James Smart1ba981f2014-02-20 09:56:45 -05007470 if (phba->cfg_fof)
7471 lpfc_fof_queue_destroy(phba);
7472
James Smart67d12732012-08-03 12:36:13 -04007473 if (phba->sli4_hba.hba_eq != NULL) {
7474 /* Release HBA event queue */
7475 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7476 if (phba->sli4_hba.hba_eq[idx] != NULL) {
7477 lpfc_sli4_queue_free(
7478 phba->sli4_hba.hba_eq[idx]);
7479 phba->sli4_hba.hba_eq[idx] = NULL;
7480 }
7481 }
7482 kfree(phba->sli4_hba.hba_eq);
7483 phba->sli4_hba.hba_eq = NULL;
7484 }
7485
7486 if (phba->sli4_hba.fcp_cq != NULL) {
7487 /* Release FCP completion queue */
7488 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7489 if (phba->sli4_hba.fcp_cq[idx] != NULL) {
7490 lpfc_sli4_queue_free(
7491 phba->sli4_hba.fcp_cq[idx]);
7492 phba->sli4_hba.fcp_cq[idx] = NULL;
7493 }
7494 }
7495 kfree(phba->sli4_hba.fcp_cq);
7496 phba->sli4_hba.fcp_cq = NULL;
7497 }
7498
7499 if (phba->sli4_hba.fcp_wq != NULL) {
7500 /* Release FCP work queue */
7501 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) {
7502 if (phba->sli4_hba.fcp_wq[idx] != NULL) {
7503 lpfc_sli4_queue_free(
7504 phba->sli4_hba.fcp_wq[idx]);
7505 phba->sli4_hba.fcp_wq[idx] = NULL;
7506 }
7507 }
7508 kfree(phba->sli4_hba.fcp_wq);
7509 phba->sli4_hba.fcp_wq = NULL;
7510 }
7511
7512 /* Release FCP CQ mapping array */
7513 if (phba->sli4_hba.fcp_cq_map != NULL) {
7514 kfree(phba->sli4_hba.fcp_cq_map);
7515 phba->sli4_hba.fcp_cq_map = NULL;
7516 }
James Smartda0436e2009-05-22 14:51:39 -04007517
7518 /* Release mailbox command work queue */
James Smart67d12732012-08-03 12:36:13 -04007519 if (phba->sli4_hba.mbx_wq != NULL) {
7520 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
7521 phba->sli4_hba.mbx_wq = NULL;
7522 }
James Smartda0436e2009-05-22 14:51:39 -04007523
7524 /* Release ELS work queue */
James Smart67d12732012-08-03 12:36:13 -04007525 if (phba->sli4_hba.els_wq != NULL) {
7526 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
7527 phba->sli4_hba.els_wq = NULL;
7528 }
James Smartda0436e2009-05-22 14:51:39 -04007529
7530 /* Release unsolicited receive queue */
James Smart67d12732012-08-03 12:36:13 -04007531 if (phba->sli4_hba.hdr_rq != NULL) {
7532 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
7533 phba->sli4_hba.hdr_rq = NULL;
7534 }
7535 if (phba->sli4_hba.dat_rq != NULL) {
7536 lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
7537 phba->sli4_hba.dat_rq = NULL;
7538 }
James Smartda0436e2009-05-22 14:51:39 -04007539
James Smartda0436e2009-05-22 14:51:39 -04007540 /* Release ELS complete queue */
James Smart67d12732012-08-03 12:36:13 -04007541 if (phba->sli4_hba.els_cq != NULL) {
7542 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
7543 phba->sli4_hba.els_cq = NULL;
7544 }
James Smartda0436e2009-05-22 14:51:39 -04007545
7546 /* Release mailbox command complete queue */
James Smart67d12732012-08-03 12:36:13 -04007547 if (phba->sli4_hba.mbx_cq != NULL) {
7548 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
7549 phba->sli4_hba.mbx_cq = NULL;
7550 }
James Smartda0436e2009-05-22 14:51:39 -04007551
7552 return;
7553}
7554
7555/**
7556 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
7557 * @phba: pointer to lpfc hba data structure.
7558 *
7559 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
7560 * operation.
7561 *
7562 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007563 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007564 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007565 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007566 **/
7567int
7568lpfc_sli4_queue_setup(struct lpfc_hba *phba)
7569{
James Smart2a76a282012-08-03 12:35:54 -04007570 struct lpfc_sli *psli = &phba->sli;
7571 struct lpfc_sli_ring *pring;
James Smartda0436e2009-05-22 14:51:39 -04007572 int rc = -ENOMEM;
7573 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
7574 int fcp_cq_index = 0;
James Smart962bc512013-01-03 15:44:00 -05007575 uint32_t shdr_status, shdr_add_status;
7576 union lpfc_sli4_cfg_shdr *shdr;
7577 LPFC_MBOXQ_t *mboxq;
7578 uint32_t length;
7579
7580 /* Check for dual-ULP support */
7581 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7582 if (!mboxq) {
7583 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7584 "3249 Unable to allocate memory for "
7585 "QUERY_FW_CFG mailbox command\n");
7586 return -ENOMEM;
7587 }
7588 length = (sizeof(struct lpfc_mbx_query_fw_config) -
7589 sizeof(struct lpfc_sli4_cfg_mhdr));
7590 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
7591 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
7592 length, LPFC_SLI4_MBX_EMBED);
7593
7594 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7595
7596 shdr = (union lpfc_sli4_cfg_shdr *)
7597 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
7598 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7599 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7600 if (shdr_status || shdr_add_status || rc) {
7601 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7602 "3250 QUERY_FW_CFG mailbox failed with status "
7603 "x%x add_status x%x, mbx status x%x\n",
7604 shdr_status, shdr_add_status, rc);
7605 if (rc != MBX_TIMEOUT)
7606 mempool_free(mboxq, phba->mbox_mem_pool);
7607 rc = -ENXIO;
7608 goto out_error;
7609 }
7610
7611 phba->sli4_hba.fw_func_mode =
7612 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
7613 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
7614 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
James Smart8b017a32015-05-21 13:55:18 -04007615 phba->sli4_hba.physical_port =
7616 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
James Smart962bc512013-01-03 15:44:00 -05007617 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7618 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
7619 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
7620 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
7621
7622 if (rc != MBX_TIMEOUT)
7623 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04007624
7625 /*
James Smart67d12732012-08-03 12:36:13 -04007626 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04007627 */
7628
James Smart67d12732012-08-03 12:36:13 -04007629 /* Set up HBA event queue */
7630 if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) {
James Smart2e90f4b2011-12-13 13:22:37 -05007631 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7632 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007633 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007634 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05007635 }
James Smart67d12732012-08-03 12:36:13 -04007636 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
7637 if (!phba->sli4_hba.hba_eq[fcp_eqidx]) {
James Smartda0436e2009-05-22 14:51:39 -04007638 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7639 "0522 Fast-path EQ (%d) not "
7640 "allocated\n", fcp_eqidx);
James Smart1b511972011-12-13 13:23:09 -05007641 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007642 goto out_destroy_hba_eq;
James Smartda0436e2009-05-22 14:51:39 -04007643 }
James Smart67d12732012-08-03 12:36:13 -04007644 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx],
James Smartbf8dae82012-08-03 12:36:24 -04007645 (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel));
James Smartda0436e2009-05-22 14:51:39 -04007646 if (rc) {
7647 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7648 "0523 Failed setup of fast-path EQ "
James Smarta2fc4aef2014-09-03 12:57:55 -04007649 "(%d), rc = 0x%x\n", fcp_eqidx,
7650 (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007651 goto out_destroy_hba_eq;
James Smartda0436e2009-05-22 14:51:39 -04007652 }
7653 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007654 "2584 HBA EQ setup: "
James Smartda0436e2009-05-22 14:51:39 -04007655 "queue[%d]-id=%d\n", fcp_eqidx,
James Smart67d12732012-08-03 12:36:13 -04007656 phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007657 }
7658
James Smart67d12732012-08-03 12:36:13 -04007659 /* Set up fast-path FCP Response Complete Queue */
7660 if (!phba->sli4_hba.fcp_cq) {
7661 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7662 "3148 Fast-path FCP CQ array not "
7663 "allocated\n");
7664 rc = -ENOMEM;
7665 goto out_destroy_hba_eq;
7666 }
7667
7668 for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) {
7669 if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
7670 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7671 "0526 Fast-path FCP CQ (%d) not "
7672 "allocated\n", fcp_cqidx);
7673 rc = -ENOMEM;
7674 goto out_destroy_fcp_cq;
7675 }
7676 rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
7677 phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP);
7678 if (rc) {
7679 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7680 "0527 Failed setup of fast-path FCP "
James Smarta2fc4aef2014-09-03 12:57:55 -04007681 "CQ (%d), rc = 0x%x\n", fcp_cqidx,
7682 (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007683 goto out_destroy_fcp_cq;
7684 }
7685
7686 /* Setup fcp_cq_map for fast lookup */
7687 phba->sli4_hba.fcp_cq_map[fcp_cqidx] =
7688 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id;
7689
7690 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7691 "2588 FCP CQ setup: cq[%d]-id=%d, "
7692 "parent seq[%d]-id=%d\n",
7693 fcp_cqidx,
7694 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
7695 fcp_cqidx,
7696 phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id);
7697 }
7698
7699 /* Set up fast-path FCP Work Queue */
7700 if (!phba->sli4_hba.fcp_wq) {
7701 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7702 "3149 Fast-path FCP WQ array not "
7703 "allocated\n");
7704 rc = -ENOMEM;
7705 goto out_destroy_fcp_cq;
7706 }
7707
7708 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) {
7709 if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
7710 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7711 "0534 Fast-path FCP WQ (%d) not "
7712 "allocated\n", fcp_wqidx);
7713 rc = -ENOMEM;
7714 goto out_destroy_fcp_wq;
7715 }
7716 rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
7717 phba->sli4_hba.fcp_cq[fcp_wqidx],
7718 LPFC_FCP);
7719 if (rc) {
7720 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7721 "0535 Failed setup of fast-path FCP "
James Smarta2fc4aef2014-09-03 12:57:55 -04007722 "WQ (%d), rc = 0x%x\n", fcp_wqidx,
7723 (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007724 goto out_destroy_fcp_wq;
7725 }
7726
7727 /* Bind this WQ to the next FCP ring */
7728 pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx];
7729 pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx];
7730 phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring;
7731
7732 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7733 "2591 FCP WQ setup: wq[%d]-id=%d, "
7734 "parent cq[%d]-id=%d\n",
7735 fcp_wqidx,
7736 phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
7737 fcp_cq_index,
7738 phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id);
7739 }
James Smartda0436e2009-05-22 14:51:39 -04007740 /*
7741 * Set up Complete Queues (CQs)
7742 */
7743
7744 /* Set up slow-path MBOX Complete Queue as the first CQ */
7745 if (!phba->sli4_hba.mbx_cq) {
7746 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7747 "0528 Mailbox CQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007748 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007749 goto out_destroy_fcp_wq;
James Smartda0436e2009-05-22 14:51:39 -04007750 }
James Smart67d12732012-08-03 12:36:13 -04007751 rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq,
7752 phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04007753 if (rc) {
7754 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7755 "0529 Failed setup of slow-path mailbox CQ: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007756 "rc = 0x%x\n", (uint32_t)rc);
James Smart67d12732012-08-03 12:36:13 -04007757 goto out_destroy_fcp_wq;
James Smartda0436e2009-05-22 14:51:39 -04007758 }
7759 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7760 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
7761 phba->sli4_hba.mbx_cq->queue_id,
James Smart67d12732012-08-03 12:36:13 -04007762 phba->sli4_hba.hba_eq[0]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007763
7764 /* Set up slow-path ELS Complete Queue */
7765 if (!phba->sli4_hba.els_cq) {
7766 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7767 "0530 ELS CQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007768 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007769 goto out_destroy_mbx_cq;
7770 }
James Smart67d12732012-08-03 12:36:13 -04007771 rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq,
7772 phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04007773 if (rc) {
7774 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7775 "0531 Failed setup of slow-path ELS CQ: "
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_mbx_cq;
7778 }
7779 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7780 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
7781 phba->sli4_hba.els_cq->queue_id,
James Smart67d12732012-08-03 12:36:13 -04007782 phba->sli4_hba.hba_eq[0]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04007783
7784 /*
7785 * Set up all the Work Queues (WQs)
7786 */
7787
7788 /* Set up Mailbox Command Queue */
7789 if (!phba->sli4_hba.mbx_wq) {
7790 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7791 "0538 Slow-path MQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007792 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007793 goto out_destroy_els_cq;
James Smartda0436e2009-05-22 14:51:39 -04007794 }
7795 rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
7796 phba->sli4_hba.mbx_cq, LPFC_MBOX);
7797 if (rc) {
7798 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7799 "0539 Failed setup of slow-path MQ: "
7800 "rc = 0x%x\n", rc);
James Smart67d12732012-08-03 12:36:13 -04007801 goto out_destroy_els_cq;
James Smartda0436e2009-05-22 14:51:39 -04007802 }
7803 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7804 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
7805 phba->sli4_hba.mbx_wq->queue_id,
7806 phba->sli4_hba.mbx_cq->queue_id);
7807
7808 /* Set up slow-path ELS Work Queue */
7809 if (!phba->sli4_hba.els_wq) {
7810 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7811 "0536 Slow-path ELS WQ not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007812 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04007813 goto out_destroy_mbx_wq;
7814 }
7815 rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
7816 phba->sli4_hba.els_cq, LPFC_ELS);
7817 if (rc) {
7818 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7819 "0537 Failed setup of slow-path ELS WQ: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007820 "rc = 0x%x\n", (uint32_t)rc);
James Smartda0436e2009-05-22 14:51:39 -04007821 goto out_destroy_mbx_wq;
7822 }
James Smart2a76a282012-08-03 12:35:54 -04007823
7824 /* Bind this WQ to the ELS ring */
7825 pring = &psli->ring[LPFC_ELS_RING];
7826 pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq;
7827 phba->sli4_hba.els_cq->pring = pring;
7828
James Smartda0436e2009-05-22 14:51:39 -04007829 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7830 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
7831 phba->sli4_hba.els_wq->queue_id,
7832 phba->sli4_hba.els_cq->queue_id);
7833
James Smartda0436e2009-05-22 14:51:39 -04007834 /*
7835 * Create Receive Queue (RQ)
7836 */
7837 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
7838 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7839 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05007840 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007841 goto out_destroy_els_wq;
James Smartda0436e2009-05-22 14:51:39 -04007842 }
James Smart73d91e52011-10-10 21:32:10 -04007843
7844 lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
7845 lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
7846
James Smartda0436e2009-05-22 14:51:39 -04007847 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04007848 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04007849 if (rc) {
7850 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7851 "0541 Failed setup of Receive Queue: "
James Smarta2fc4aef2014-09-03 12:57:55 -04007852 "rc = 0x%x\n", (uint32_t)rc);
James Smartda0436e2009-05-22 14:51:39 -04007853 goto out_destroy_fcp_wq;
7854 }
James Smart73d91e52011-10-10 21:32:10 -04007855
James Smartda0436e2009-05-22 14:51:39 -04007856 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7857 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
7858 "parent cq-id=%d\n",
7859 phba->sli4_hba.hdr_rq->queue_id,
7860 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04007861 phba->sli4_hba.els_cq->queue_id);
James Smart1ba981f2014-02-20 09:56:45 -05007862
7863 if (phba->cfg_fof) {
7864 rc = lpfc_fof_queue_setup(phba);
7865 if (rc) {
7866 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7867 "0549 Failed setup of FOF Queues: "
7868 "rc = 0x%x\n", rc);
7869 goto out_destroy_els_rq;
7870 }
7871 }
James Smart2c9c5a02015-04-07 15:07:15 -04007872
7873 /*
7874 * Configure EQ delay multipier for interrupt coalescing using
7875 * MODIFY_EQ_DELAY for all EQs created, LPFC_MAX_EQ_DELAY at a time.
7876 */
7877 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel;
7878 fcp_eqidx += LPFC_MAX_EQ_DELAY)
7879 lpfc_modify_fcp_eq_delay(phba, fcp_eqidx);
James Smartda0436e2009-05-22 14:51:39 -04007880 return 0;
7881
James Smart1ba981f2014-02-20 09:56:45 -05007882out_destroy_els_rq:
7883 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
James Smart2e90f4b2011-12-13 13:22:37 -05007884out_destroy_els_wq:
James Smartda0436e2009-05-22 14:51:39 -04007885 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7886out_destroy_mbx_wq:
7887 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
James Smart2e90f4b2011-12-13 13:22:37 -05007888out_destroy_els_cq:
James Smartda0436e2009-05-22 14:51:39 -04007889 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
7890out_destroy_mbx_cq:
7891 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
James Smart67d12732012-08-03 12:36:13 -04007892out_destroy_fcp_wq:
7893 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
7894 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
7895out_destroy_fcp_cq:
7896 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
7897 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
7898out_destroy_hba_eq:
James Smartda0436e2009-05-22 14:51:39 -04007899 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
James Smart67d12732012-08-03 12:36:13 -04007900 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]);
James Smartda0436e2009-05-22 14:51:39 -04007901out_error:
7902 return rc;
7903}
7904
7905/**
7906 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
7907 * @phba: pointer to lpfc hba data structure.
7908 *
7909 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
7910 * operation.
7911 *
7912 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007913 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007914 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007915 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007916 **/
7917void
7918lpfc_sli4_queue_unset(struct lpfc_hba *phba)
7919{
7920 int fcp_qidx;
7921
James Smart1ba981f2014-02-20 09:56:45 -05007922 /* Unset the queues created for Flash Optimized Fabric operations */
7923 if (phba->cfg_fof)
7924 lpfc_fof_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04007925 /* Unset mailbox command work queue */
7926 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
7927 /* Unset ELS work queue */
7928 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
7929 /* Unset unsolicited receive queue */
7930 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
7931 /* Unset FCP work queue */
James Smart67d12732012-08-03 12:36:13 -04007932 if (phba->sli4_hba.fcp_wq) {
7933 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
7934 fcp_qidx++)
7935 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
7936 }
James Smartda0436e2009-05-22 14:51:39 -04007937 /* Unset mailbox command complete queue */
7938 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
7939 /* Unset ELS complete queue */
7940 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
James Smartda0436e2009-05-22 14:51:39 -04007941 /* Unset FCP response complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05007942 if (phba->sli4_hba.fcp_cq) {
James Smart67d12732012-08-03 12:36:13 -04007943 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
7944 fcp_qidx++)
James Smart2e90f4b2011-12-13 13:22:37 -05007945 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
James Smart2e90f4b2011-12-13 13:22:37 -05007946 }
James Smartda0436e2009-05-22 14:51:39 -04007947 /* Unset fast-path event queue */
James Smart67d12732012-08-03 12:36:13 -04007948 if (phba->sli4_hba.hba_eq) {
7949 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel;
James Smart2e90f4b2011-12-13 13:22:37 -05007950 fcp_qidx++)
James Smart67d12732012-08-03 12:36:13 -04007951 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_qidx]);
James Smart2e90f4b2011-12-13 13:22:37 -05007952 }
James Smartda0436e2009-05-22 14:51:39 -04007953}
7954
7955/**
7956 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
7957 * @phba: pointer to lpfc hba data structure.
7958 *
7959 * This routine is invoked to allocate and set up a pool of completion queue
7960 * events. The body of the completion queue event is a completion queue entry
7961 * CQE. For now, this pool is used for the interrupt service routine to queue
7962 * the following HBA completion queue events for the worker thread to process:
7963 * - Mailbox asynchronous events
7964 * - Receive queue completion unsolicited events
7965 * Later, this can be used for all the slow-path events.
7966 *
7967 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007968 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007969 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007970 **/
7971static int
7972lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
7973{
7974 struct lpfc_cq_event *cq_event;
7975 int i;
7976
7977 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
7978 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
7979 if (!cq_event)
7980 goto out_pool_create_fail;
7981 list_add_tail(&cq_event->list,
7982 &phba->sli4_hba.sp_cqe_event_pool);
7983 }
7984 return 0;
7985
7986out_pool_create_fail:
7987 lpfc_sli4_cq_event_pool_destroy(phba);
7988 return -ENOMEM;
7989}
7990
7991/**
7992 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
7993 * @phba: pointer to lpfc hba data structure.
7994 *
7995 * This routine is invoked to free the pool of completion queue events at
7996 * driver unload time. Note that, it is the responsibility of the driver
7997 * cleanup routine to free all the outstanding completion-queue events
7998 * allocated from this pool back into the pool before invoking this routine
7999 * to destroy the pool.
8000 **/
8001static void
8002lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
8003{
8004 struct lpfc_cq_event *cq_event, *next_cq_event;
8005
8006 list_for_each_entry_safe(cq_event, next_cq_event,
8007 &phba->sli4_hba.sp_cqe_event_pool, list) {
8008 list_del(&cq_event->list);
8009 kfree(cq_event);
8010 }
8011}
8012
8013/**
8014 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
8015 * @phba: pointer to lpfc hba data structure.
8016 *
8017 * This routine is the lock free version of the API invoked to allocate a
8018 * completion-queue event from the free pool.
8019 *
8020 * Return: Pointer to the newly allocated completion-queue event if successful
8021 * NULL otherwise.
8022 **/
8023struct lpfc_cq_event *
8024__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
8025{
8026 struct lpfc_cq_event *cq_event = NULL;
8027
8028 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
8029 struct lpfc_cq_event, list);
8030 return cq_event;
8031}
8032
8033/**
8034 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
8035 * @phba: pointer to lpfc hba data structure.
8036 *
8037 * This routine is the lock version of the API invoked to allocate a
8038 * completion-queue event from the free pool.
8039 *
8040 * Return: Pointer to the newly allocated completion-queue event if successful
8041 * NULL otherwise.
8042 **/
8043struct lpfc_cq_event *
8044lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
8045{
8046 struct lpfc_cq_event *cq_event;
8047 unsigned long iflags;
8048
8049 spin_lock_irqsave(&phba->hbalock, iflags);
8050 cq_event = __lpfc_sli4_cq_event_alloc(phba);
8051 spin_unlock_irqrestore(&phba->hbalock, iflags);
8052 return cq_event;
8053}
8054
8055/**
8056 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
8057 * @phba: pointer to lpfc hba data structure.
8058 * @cq_event: pointer to the completion queue event to be freed.
8059 *
8060 * This routine is the lock free version of the API invoked to release a
8061 * completion-queue event back into the free pool.
8062 **/
8063void
8064__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
8065 struct lpfc_cq_event *cq_event)
8066{
8067 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
8068}
8069
8070/**
8071 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
8072 * @phba: pointer to lpfc hba data structure.
8073 * @cq_event: pointer to the completion queue event to be freed.
8074 *
8075 * This routine is the lock version of the API invoked to release a
8076 * completion-queue event back into the free pool.
8077 **/
8078void
8079lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
8080 struct lpfc_cq_event *cq_event)
8081{
8082 unsigned long iflags;
8083 spin_lock_irqsave(&phba->hbalock, iflags);
8084 __lpfc_sli4_cq_event_release(phba, cq_event);
8085 spin_unlock_irqrestore(&phba->hbalock, iflags);
8086}
8087
8088/**
8089 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
8090 * @phba: pointer to lpfc hba data structure.
8091 *
8092 * This routine is to free all the pending completion-queue events to the
8093 * back into the free pool for device reset.
8094 **/
8095static void
8096lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
8097{
8098 LIST_HEAD(cqelist);
8099 struct lpfc_cq_event *cqe;
8100 unsigned long iflags;
8101
8102 /* Retrieve all the pending WCQEs from pending WCQE lists */
8103 spin_lock_irqsave(&phba->hbalock, iflags);
8104 /* Pending FCP XRI abort events */
8105 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
8106 &cqelist);
8107 /* Pending ELS XRI abort events */
8108 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
8109 &cqelist);
8110 /* Pending asynnc events */
8111 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
8112 &cqelist);
8113 spin_unlock_irqrestore(&phba->hbalock, iflags);
8114
8115 while (!list_empty(&cqelist)) {
8116 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
8117 lpfc_sli4_cq_event_release(phba, cqe);
8118 }
8119}
8120
8121/**
8122 * lpfc_pci_function_reset - Reset pci function.
8123 * @phba: pointer to lpfc hba data structure.
8124 *
8125 * This routine is invoked to request a PCI function reset. It will destroys
8126 * all resources assigned to the PCI function which originates this request.
8127 *
8128 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008129 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008130 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008131 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008132 **/
8133int
8134lpfc_pci_function_reset(struct lpfc_hba *phba)
8135{
8136 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05008137 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04008138 uint32_t shdr_status, shdr_add_status;
James Smart2f6fa2c2014-09-03 12:57:08 -04008139 uint32_t rdy_chk;
8140 uint32_t port_reset = 0;
James Smartda0436e2009-05-22 14:51:39 -04008141 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05008142 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -05008143 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -04008144
James Smart2fcee4b2010-12-15 17:57:46 -05008145 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8146 switch (if_type) {
8147 case LPFC_SLI_INTF_IF_TYPE_0:
8148 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8149 GFP_KERNEL);
8150 if (!mboxq) {
8151 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8152 "0494 Unable to allocate memory for "
8153 "issuing SLI_FUNCTION_RESET mailbox "
8154 "command\n");
8155 return -ENOMEM;
8156 }
8157
8158 /* Setup PCI function reset mailbox-ioctl command */
8159 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8160 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
8161 LPFC_SLI4_MBX_EMBED);
8162 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8163 shdr = (union lpfc_sli4_cfg_shdr *)
8164 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
8165 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8166 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
8167 &shdr->response);
8168 if (rc != MBX_TIMEOUT)
8169 mempool_free(mboxq, phba->mbox_mem_pool);
8170 if (shdr_status || shdr_add_status || rc) {
8171 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8172 "0495 SLI_FUNCTION_RESET mailbox "
8173 "failed with status x%x add_status x%x,"
8174 " mbx status x%x\n",
8175 shdr_status, shdr_add_status, rc);
8176 rc = -ENXIO;
8177 }
8178 break;
8179 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2f6fa2c2014-09-03 12:57:08 -04008180wait:
8181 /*
8182 * Poll the Port Status Register and wait for RDY for
8183 * up to 30 seconds. If the port doesn't respond, treat
8184 * it as an error.
8185 */
James Smart77d093f2015-04-07 15:07:08 -04008186 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
James Smart2f6fa2c2014-09-03 12:57:08 -04008187 if (lpfc_readl(phba->sli4_hba.u.if_type2.
8188 STATUSregaddr, &reg_data.word0)) {
8189 rc = -ENODEV;
8190 goto out;
8191 }
8192 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
8193 break;
8194 msleep(20);
8195 }
8196
8197 if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
8198 phba->work_status[0] = readl(
8199 phba->sli4_hba.u.if_type2.ERR1regaddr);
8200 phba->work_status[1] = readl(
8201 phba->sli4_hba.u.if_type2.ERR2regaddr);
8202 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8203 "2890 Port not ready, port status reg "
8204 "0x%x error 1=0x%x, error 2=0x%x\n",
8205 reg_data.word0,
8206 phba->work_status[0],
8207 phba->work_status[1]);
8208 rc = -ENODEV;
8209 goto out;
8210 }
8211
8212 if (!port_reset) {
8213 /*
8214 * Reset the port now
8215 */
James Smart2fcee4b2010-12-15 17:57:46 -05008216 reg_data.word0 = 0;
8217 bf_set(lpfc_sliport_ctrl_end, &reg_data,
8218 LPFC_SLIPORT_LITTLE_ENDIAN);
8219 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
8220 LPFC_SLIPORT_INIT_PORT);
8221 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
8222 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -05008223 /* flush */
James Smart2b81f942012-03-01 22:37:18 -05008224 pci_read_config_word(phba->pcidev,
8225 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -05008226
James Smart2f6fa2c2014-09-03 12:57:08 -04008227 port_reset = 1;
8228 msleep(20);
8229 goto wait;
8230 } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
8231 rc = -ENODEV;
8232 goto out;
James Smart2fcee4b2010-12-15 17:57:46 -05008233 }
8234 break;
James Smart2f6fa2c2014-09-03 12:57:08 -04008235
James Smart2fcee4b2010-12-15 17:57:46 -05008236 case LPFC_SLI_INTF_IF_TYPE_1:
8237 default:
8238 break;
James Smartda0436e2009-05-22 14:51:39 -04008239 }
8240
James Smart73d91e52011-10-10 21:32:10 -04008241out:
James Smart2fcee4b2010-12-15 17:57:46 -05008242 /* Catch the not-ready port failure after a port reset. */
James Smart2f6fa2c2014-09-03 12:57:08 -04008243 if (rc) {
James Smart229adb02013-04-17 20:16:51 -04008244 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8245 "3317 HBA not functional: IP Reset Failed "
James Smart2f6fa2c2014-09-03 12:57:08 -04008246 "try: echo fw_reset > board_mode\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008247 rc = -ENODEV;
James Smart229adb02013-04-17 20:16:51 -04008248 }
James Smart2fcee4b2010-12-15 17:57:46 -05008249
James Smartda0436e2009-05-22 14:51:39 -04008250 return rc;
8251}
8252
8253/**
James Smartda0436e2009-05-22 14:51:39 -04008254 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
8255 * @phba: pointer to lpfc hba data structure.
8256 *
8257 * This routine is invoked to set up the PCI device memory space for device
8258 * with SLI-4 interface spec.
8259 *
8260 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008261 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008262 * other values - error
8263 **/
8264static int
8265lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
8266{
8267 struct pci_dev *pdev;
8268 unsigned long bar0map_len, bar1map_len, bar2map_len;
8269 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05008270 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04008271
8272 /* Obtain PCI device reference */
8273 if (!phba->pcidev)
8274 return error;
8275 else
8276 pdev = phba->pcidev;
8277
8278 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05008279 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
8280 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
8281 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
8282 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smartda0436e2009-05-22 14:51:39 -04008283 return error;
Michael Reed8e685972009-09-18 12:02:05 -05008284 }
8285 }
James Smartda0436e2009-05-22 14:51:39 -04008286
James Smart2fcee4b2010-12-15 17:57:46 -05008287 /*
8288 * The BARs and register set definitions and offset locations are
8289 * dependent on the if_type.
8290 */
8291 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
8292 &phba->sli4_hba.sli_intf.word0)) {
8293 return error;
8294 }
8295
8296 /* There is no SLI3 failback for SLI4 devices. */
8297 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
8298 LPFC_SLI_INTF_VALID) {
8299 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8300 "2894 SLI_INTF reg contents invalid "
8301 "sli_intf reg 0x%x\n",
8302 phba->sli4_hba.sli_intf.word0);
8303 return error;
8304 }
8305
8306 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8307 /*
8308 * Get the bus address of SLI4 device Bar regions and the
8309 * number of bytes required by each mapping. The mapping of the
8310 * particular PCI BARs regions is dependent on the type of
8311 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04008312 */
James Smartf5ca6f22013-09-06 12:21:09 -04008313 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
8314 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
8315 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
James Smart2fcee4b2010-12-15 17:57:46 -05008316
8317 /*
8318 * Map SLI4 PCI Config Space Register base to a kernel virtual
8319 * addr
8320 */
8321 phba->sli4_hba.conf_regs_memmap_p =
8322 ioremap(phba->pci_bar0_map, bar0map_len);
8323 if (!phba->sli4_hba.conf_regs_memmap_p) {
8324 dev_printk(KERN_ERR, &pdev->dev,
8325 "ioremap failed for SLI4 PCI config "
8326 "registers.\n");
8327 goto out;
8328 }
James Smartf5ca6f22013-09-06 12:21:09 -04008329 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008330 /* Set up BAR0 PCI config space register memory map */
8331 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05008332 } else {
8333 phba->pci_bar0_map = pci_resource_start(pdev, 1);
8334 bar0map_len = pci_resource_len(pdev, 1);
James Smart2fcee4b2010-12-15 17:57:46 -05008335 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
8336 dev_printk(KERN_ERR, &pdev->dev,
8337 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
8338 goto out;
8339 }
8340 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008341 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008342 if (!phba->sli4_hba.conf_regs_memmap_p) {
8343 dev_printk(KERN_ERR, &pdev->dev,
8344 "ioremap failed for SLI4 PCI config "
8345 "registers.\n");
8346 goto out;
8347 }
8348 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04008349 }
8350
James Smartc31098c2011-04-16 11:03:33 -04008351 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04008352 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
James Smart2fcee4b2010-12-15 17:57:46 -05008353 /*
8354 * Map SLI4 if type 0 HBA Control Register base to a kernel
8355 * virtual address and setup the registers.
8356 */
James Smartf5ca6f22013-09-06 12:21:09 -04008357 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
8358 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
James Smart2fcee4b2010-12-15 17:57:46 -05008359 phba->sli4_hba.ctrl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008360 ioremap(phba->pci_bar1_map, bar1map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008361 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
8362 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04008363 "ioremap failed for SLI4 HBA control registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008364 goto out_iounmap_conf;
8365 }
James Smartf5ca6f22013-09-06 12:21:09 -04008366 phba->pci_bar2_memmap_p = phba->sli4_hba.ctrl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008367 lpfc_sli4_bar1_register_memmap(phba);
James Smartda0436e2009-05-22 14:51:39 -04008368 }
8369
James Smartc31098c2011-04-16 11:03:33 -04008370 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04008371 (pci_resource_start(pdev, PCI_64BIT_BAR4))) {
James Smart2fcee4b2010-12-15 17:57:46 -05008372 /*
8373 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
8374 * virtual address and setup the registers.
8375 */
James Smartf5ca6f22013-09-06 12:21:09 -04008376 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
8377 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
James Smart2fcee4b2010-12-15 17:57:46 -05008378 phba->sli4_hba.drbl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008379 ioremap(phba->pci_bar2_map, bar2map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008380 if (!phba->sli4_hba.drbl_regs_memmap_p) {
8381 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04008382 "ioremap failed for SLI4 HBA doorbell registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008383 goto out_iounmap_ctrl;
8384 }
James Smartf5ca6f22013-09-06 12:21:09 -04008385 phba->pci_bar4_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008386 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
8387 if (error)
8388 goto out_iounmap_all;
James Smartda0436e2009-05-22 14:51:39 -04008389 }
8390
James Smartda0436e2009-05-22 14:51:39 -04008391 return 0;
8392
8393out_iounmap_all:
8394 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
8395out_iounmap_ctrl:
8396 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
8397out_iounmap_conf:
8398 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8399out:
8400 return error;
8401}
8402
8403/**
8404 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
8405 * @phba: pointer to lpfc hba data structure.
8406 *
8407 * This routine is invoked to unset the PCI device memory space for device
8408 * with SLI-4 interface spec.
8409 **/
8410static void
8411lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
8412{
James Smart2e90f4b2011-12-13 13:22:37 -05008413 uint32_t if_type;
8414 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -04008415
James Smart2e90f4b2011-12-13 13:22:37 -05008416 switch (if_type) {
8417 case LPFC_SLI_INTF_IF_TYPE_0:
8418 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
8419 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
8420 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8421 break;
8422 case LPFC_SLI_INTF_IF_TYPE_2:
8423 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8424 break;
8425 case LPFC_SLI_INTF_IF_TYPE_1:
8426 default:
8427 dev_printk(KERN_ERR, &phba->pcidev->dev,
8428 "FATAL - unsupported SLI4 interface type - %d\n",
8429 if_type);
8430 break;
8431 }
James Smartda0436e2009-05-22 14:51:39 -04008432}
8433
8434/**
James Smart3772a992009-05-22 14:50:54 -04008435 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
8436 * @phba: pointer to lpfc hba data structure.
8437 *
8438 * This routine is invoked to enable the MSI-X interrupt vectors to device
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008439 * with SLI-3 interface specs. The kernel function pci_enable_msix_exact()
8440 * is called to enable the MSI-X vectors. Note that pci_enable_msix_exact(),
8441 * once invoked, enables either all or nothing, depending on the current
James Smart3772a992009-05-22 14:50:54 -04008442 * availability of PCI vector resources. The device driver is responsible
8443 * for calling the individual request_irq() to register each MSI-X vector
8444 * with a interrupt handler, which is done in this function. Note that
8445 * later when device is unloading, the driver should always call free_irq()
8446 * on all MSI-X vectors it has done request_irq() on before calling
8447 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
8448 * will be left with MSI-X enabled and leaks its vectors.
8449 *
8450 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008451 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008452 * other values - error
8453 **/
8454static int
8455lpfc_sli_enable_msix(struct lpfc_hba *phba)
8456{
8457 int rc, i;
8458 LPFC_MBOXQ_t *pmb;
8459
8460 /* Set up MSI-X multi-message vectors */
8461 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8462 phba->msix_entries[i].entry = i;
8463
8464 /* Configure MSI-X capability structure */
Alexander Gordeev4f871e12014-09-03 12:56:29 -04008465 rc = pci_enable_msix_exact(phba->pcidev, phba->msix_entries,
8466 LPFC_MSIX_VECTORS);
James Smart3772a992009-05-22 14:50:54 -04008467 if (rc) {
8468 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8469 "0420 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02008470 goto vec_fail_out;
James Smart3772a992009-05-22 14:50:54 -04008471 }
8472 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8473 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8474 "0477 MSI-X entry[%d]: vector=x%x "
8475 "message=%d\n", i,
8476 phba->msix_entries[i].vector,
8477 phba->msix_entries[i].entry);
8478 /*
8479 * Assign MSI-X vectors to interrupt handlers
8480 */
8481
8482 /* vector-0 is associated to slow-path handler */
8483 rc = request_irq(phba->msix_entries[0].vector,
James Smarted243d32015-05-21 13:55:25 -04008484 &lpfc_sli_sp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04008485 LPFC_SP_DRIVER_HANDLER_NAME, phba);
8486 if (rc) {
8487 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8488 "0421 MSI-X slow-path request_irq failed "
8489 "(%d)\n", rc);
8490 goto msi_fail_out;
8491 }
8492
8493 /* vector-1 is associated to fast-path handler */
8494 rc = request_irq(phba->msix_entries[1].vector,
James Smarted243d32015-05-21 13:55:25 -04008495 &lpfc_sli_fp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04008496 LPFC_FP_DRIVER_HANDLER_NAME, phba);
8497
8498 if (rc) {
8499 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8500 "0429 MSI-X fast-path request_irq failed "
8501 "(%d)\n", rc);
8502 goto irq_fail_out;
8503 }
8504
8505 /*
8506 * Configure HBA MSI-X attention conditions to messages
8507 */
8508 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8509
8510 if (!pmb) {
8511 rc = -ENOMEM;
8512 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8513 "0474 Unable to allocate memory for issuing "
8514 "MBOX_CONFIG_MSI command\n");
8515 goto mem_fail_out;
8516 }
8517 rc = lpfc_config_msi(phba, pmb);
8518 if (rc)
8519 goto mbx_fail_out;
8520 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
8521 if (rc != MBX_SUCCESS) {
8522 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
8523 "0351 Config MSI mailbox command failed, "
8524 "mbxCmd x%x, mbxStatus x%x\n",
8525 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
8526 goto mbx_fail_out;
8527 }
8528
8529 /* Free memory allocated for mailbox command */
8530 mempool_free(pmb, phba->mbox_mem_pool);
8531 return rc;
8532
8533mbx_fail_out:
8534 /* Free memory allocated for mailbox command */
8535 mempool_free(pmb, phba->mbox_mem_pool);
8536
8537mem_fail_out:
8538 /* free the irq already requested */
8539 free_irq(phba->msix_entries[1].vector, phba);
8540
8541irq_fail_out:
8542 /* free the irq already requested */
8543 free_irq(phba->msix_entries[0].vector, phba);
8544
8545msi_fail_out:
8546 /* Unconfigure MSI-X capability structure */
8547 pci_disable_msix(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02008548
8549vec_fail_out:
James Smart3772a992009-05-22 14:50:54 -04008550 return rc;
8551}
8552
8553/**
8554 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
8555 * @phba: pointer to lpfc hba data structure.
8556 *
8557 * This routine is invoked to release the MSI-X vectors and then disable the
8558 * MSI-X interrupt mode to device with SLI-3 interface spec.
8559 **/
8560static void
8561lpfc_sli_disable_msix(struct lpfc_hba *phba)
8562{
8563 int i;
8564
8565 /* Free up MSI-X multi-message vectors */
8566 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
8567 free_irq(phba->msix_entries[i].vector, phba);
8568 /* Disable MSI-X */
8569 pci_disable_msix(phba->pcidev);
8570
8571 return;
8572}
8573
8574/**
8575 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
8576 * @phba: pointer to lpfc hba data structure.
8577 *
8578 * This routine is invoked to enable the MSI interrupt mode to device with
8579 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
8580 * enable the MSI vector. The device driver is responsible for calling the
8581 * request_irq() to register MSI vector with a interrupt the handler, which
8582 * is done in this function.
8583 *
8584 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008585 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008586 * other values - error
8587 */
8588static int
8589lpfc_sli_enable_msi(struct lpfc_hba *phba)
8590{
8591 int rc;
8592
8593 rc = pci_enable_msi(phba->pcidev);
8594 if (!rc)
8595 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8596 "0462 PCI enable MSI mode success.\n");
8597 else {
8598 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8599 "0471 PCI enable MSI mode failed (%d)\n", rc);
8600 return rc;
8601 }
8602
8603 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04008604 0, LPFC_DRIVER_NAME, phba);
James Smart3772a992009-05-22 14:50:54 -04008605 if (rc) {
8606 pci_disable_msi(phba->pcidev);
8607 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8608 "0478 MSI request_irq failed (%d)\n", rc);
8609 }
8610 return rc;
8611}
8612
8613/**
8614 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
8615 * @phba: pointer to lpfc hba data structure.
8616 *
8617 * This routine is invoked to disable the MSI interrupt mode to device with
8618 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
8619 * done request_irq() on before calling pci_disable_msi(). Failure to do so
8620 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
8621 * its vector.
8622 */
8623static void
8624lpfc_sli_disable_msi(struct lpfc_hba *phba)
8625{
8626 free_irq(phba->pcidev->irq, phba);
8627 pci_disable_msi(phba->pcidev);
8628 return;
8629}
8630
8631/**
8632 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
8633 * @phba: pointer to lpfc hba data structure.
8634 *
8635 * This routine is invoked to enable device interrupt and associate driver's
8636 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
8637 * spec. Depends on the interrupt mode configured to the driver, the driver
8638 * will try to fallback from the configured interrupt mode to an interrupt
8639 * mode which is supported by the platform, kernel, and device in the order
8640 * of:
8641 * MSI-X -> MSI -> IRQ.
8642 *
8643 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008644 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008645 * other values - error
8646 **/
8647static uint32_t
8648lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
8649{
8650 uint32_t intr_mode = LPFC_INTR_ERROR;
8651 int retval;
8652
8653 if (cfg_mode == 2) {
8654 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
8655 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
8656 if (!retval) {
8657 /* Now, try to enable MSI-X interrupt mode */
8658 retval = lpfc_sli_enable_msix(phba);
8659 if (!retval) {
8660 /* Indicate initialization to MSI-X mode */
8661 phba->intr_type = MSIX;
8662 intr_mode = 2;
8663 }
8664 }
8665 }
8666
8667 /* Fallback to MSI if MSI-X initialization failed */
8668 if (cfg_mode >= 1 && phba->intr_type == NONE) {
8669 retval = lpfc_sli_enable_msi(phba);
8670 if (!retval) {
8671 /* Indicate initialization to MSI mode */
8672 phba->intr_type = MSI;
8673 intr_mode = 1;
8674 }
8675 }
8676
8677 /* Fallback to INTx if both MSI-X/MSI initalization failed */
8678 if (phba->intr_type == NONE) {
8679 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
8680 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
8681 if (!retval) {
8682 /* Indicate initialization to INTx mode */
8683 phba->intr_type = INTx;
8684 intr_mode = 0;
8685 }
8686 }
8687 return intr_mode;
8688}
8689
8690/**
8691 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
8692 * @phba: pointer to lpfc hba data structure.
8693 *
8694 * This routine is invoked to disable device interrupt and disassociate the
8695 * driver's interrupt handler(s) from interrupt vector(s) to device with
8696 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
8697 * release the interrupt vector(s) for the message signaled interrupt.
8698 **/
8699static void
8700lpfc_sli_disable_intr(struct lpfc_hba *phba)
8701{
8702 /* Disable the currently initialized interrupt mode */
8703 if (phba->intr_type == MSIX)
8704 lpfc_sli_disable_msix(phba);
8705 else if (phba->intr_type == MSI)
8706 lpfc_sli_disable_msi(phba);
8707 else if (phba->intr_type == INTx)
8708 free_irq(phba->pcidev->irq, phba);
8709
8710 /* Reset interrupt management states */
8711 phba->intr_type = NONE;
8712 phba->sli.slistat.sli_intr = 0;
8713
8714 return;
8715}
8716
8717/**
James Smart7bb03bb2013-04-17 20:19:16 -04008718 * lpfc_find_next_cpu - Find next available CPU that matches the phys_id
8719 * @phba: pointer to lpfc hba data structure.
8720 *
8721 * Find next available CPU to use for IRQ to CPU affinity.
8722 */
8723static int
8724lpfc_find_next_cpu(struct lpfc_hba *phba, uint32_t phys_id)
8725{
8726 struct lpfc_vector_map_info *cpup;
8727 int cpu;
8728
8729 cpup = phba->sli4_hba.cpu_map;
8730 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8731 /* CPU must be online */
8732 if (cpu_online(cpu)) {
8733 if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
8734 (lpfc_used_cpu[cpu] == LPFC_VECTOR_MAP_EMPTY) &&
8735 (cpup->phys_id == phys_id)) {
8736 return cpu;
8737 }
8738 }
8739 cpup++;
8740 }
8741
8742 /*
8743 * If we get here, we have used ALL CPUs for the specific
8744 * phys_id. Now we need to clear out lpfc_used_cpu and start
8745 * reusing CPUs.
8746 */
8747
8748 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8749 if (lpfc_used_cpu[cpu] == phys_id)
8750 lpfc_used_cpu[cpu] = LPFC_VECTOR_MAP_EMPTY;
8751 }
8752
8753 cpup = phba->sli4_hba.cpu_map;
8754 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8755 /* CPU must be online */
8756 if (cpu_online(cpu)) {
8757 if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
8758 (cpup->phys_id == phys_id)) {
8759 return cpu;
8760 }
8761 }
8762 cpup++;
8763 }
8764 return LPFC_VECTOR_MAP_EMPTY;
8765}
8766
8767/**
8768 * lpfc_sli4_set_affinity - Set affinity for HBA IRQ vectors
8769 * @phba: pointer to lpfc hba data structure.
8770 * @vectors: number of HBA vectors
8771 *
8772 * Affinitize MSIX IRQ vectors to CPUs. Try to equally spread vector
8773 * affinization across multple physical CPUs (numa nodes).
8774 * In addition, this routine will assign an IO channel for each CPU
8775 * to use when issuing I/Os.
8776 */
8777static int
8778lpfc_sli4_set_affinity(struct lpfc_hba *phba, int vectors)
8779{
8780 int i, idx, saved_chann, used_chann, cpu, phys_id;
James Smartec2087a2013-09-06 12:20:36 -04008781 int max_phys_id, min_phys_id;
8782 int num_io_channel, first_cpu, chan;
James Smart7bb03bb2013-04-17 20:19:16 -04008783 struct lpfc_vector_map_info *cpup;
8784#ifdef CONFIG_X86
8785 struct cpuinfo_x86 *cpuinfo;
8786#endif
James Smart7bb03bb2013-04-17 20:19:16 -04008787 uint8_t chann[LPFC_FCP_IO_CHAN_MAX+1];
8788
8789 /* If there is no mapping, just return */
8790 if (!phba->cfg_fcp_cpu_map)
8791 return 1;
8792
8793 /* Init cpu_map array */
8794 memset(phba->sli4_hba.cpu_map, 0xff,
8795 (sizeof(struct lpfc_vector_map_info) *
8796 phba->sli4_hba.num_present_cpu));
8797
8798 max_phys_id = 0;
James Smartec2087a2013-09-06 12:20:36 -04008799 min_phys_id = 0xff;
James Smart7bb03bb2013-04-17 20:19:16 -04008800 phys_id = 0;
8801 num_io_channel = 0;
8802 first_cpu = LPFC_VECTOR_MAP_EMPTY;
8803
8804 /* Update CPU map with physical id and core id of each CPU */
8805 cpup = phba->sli4_hba.cpu_map;
8806 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8807#ifdef CONFIG_X86
8808 cpuinfo = &cpu_data(cpu);
8809 cpup->phys_id = cpuinfo->phys_proc_id;
8810 cpup->core_id = cpuinfo->cpu_core_id;
8811#else
8812 /* No distinction between CPUs for other platforms */
8813 cpup->phys_id = 0;
8814 cpup->core_id = 0;
8815#endif
8816
8817 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8818 "3328 CPU physid %d coreid %d\n",
8819 cpup->phys_id, cpup->core_id);
8820
8821 if (cpup->phys_id > max_phys_id)
8822 max_phys_id = cpup->phys_id;
James Smartec2087a2013-09-06 12:20:36 -04008823 if (cpup->phys_id < min_phys_id)
8824 min_phys_id = cpup->phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008825 cpup++;
8826 }
8827
James Smartec2087a2013-09-06 12:20:36 -04008828 phys_id = min_phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008829 /* Now associate the HBA vectors with specific CPUs */
8830 for (idx = 0; idx < vectors; idx++) {
8831 cpup = phba->sli4_hba.cpu_map;
8832 cpu = lpfc_find_next_cpu(phba, phys_id);
8833 if (cpu == LPFC_VECTOR_MAP_EMPTY) {
8834
8835 /* Try for all phys_id's */
8836 for (i = 1; i < max_phys_id; i++) {
8837 phys_id++;
8838 if (phys_id > max_phys_id)
James Smartec2087a2013-09-06 12:20:36 -04008839 phys_id = min_phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008840 cpu = lpfc_find_next_cpu(phba, phys_id);
8841 if (cpu == LPFC_VECTOR_MAP_EMPTY)
8842 continue;
8843 goto found;
8844 }
8845
James Smartec2087a2013-09-06 12:20:36 -04008846 /* Use round robin for scheduling */
8847 phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_ROUND_ROBIN;
8848 chan = 0;
8849 cpup = phba->sli4_hba.cpu_map;
8850 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
8851 cpup->channel_id = chan;
8852 cpup++;
8853 chan++;
8854 if (chan >= phba->cfg_fcp_io_channel)
8855 chan = 0;
8856 }
8857
James Smart7bb03bb2013-04-17 20:19:16 -04008858 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8859 "3329 Cannot set affinity:"
8860 "Error mapping vector %d (%d)\n",
8861 idx, vectors);
8862 return 0;
8863 }
8864found:
8865 cpup += cpu;
8866 if (phba->cfg_fcp_cpu_map == LPFC_DRIVER_CPU_MAP)
8867 lpfc_used_cpu[cpu] = phys_id;
8868
8869 /* Associate vector with selected CPU */
8870 cpup->irq = phba->sli4_hba.msix_entries[idx].vector;
8871
8872 /* Associate IO channel with selected CPU */
8873 cpup->channel_id = idx;
8874 num_io_channel++;
8875
8876 if (first_cpu == LPFC_VECTOR_MAP_EMPTY)
8877 first_cpu = cpu;
8878
8879 /* Now affinitize to the selected CPU */
James Smart7bb03bb2013-04-17 20:19:16 -04008880 i = irq_set_affinity_hint(phba->sli4_hba.msix_entries[idx].
Ian Mitchellc0365c02015-08-31 16:48:12 -04008881 vector, get_cpu_mask(cpu));
James Smart7bb03bb2013-04-17 20:19:16 -04008882
8883 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8884 "3330 Set Affinity: CPU %d channel %d "
8885 "irq %d (%x)\n",
8886 cpu, cpup->channel_id,
8887 phba->sli4_hba.msix_entries[idx].vector, i);
8888
8889 /* Spread vector mapping across multple physical CPU nodes */
8890 phys_id++;
8891 if (phys_id > max_phys_id)
James Smartec2087a2013-09-06 12:20:36 -04008892 phys_id = min_phys_id;
James Smart7bb03bb2013-04-17 20:19:16 -04008893 }
8894
8895 /*
8896 * Finally fill in the IO channel for any remaining CPUs.
8897 * At this point, all IO channels have been assigned to a specific
8898 * MSIx vector, mapped to a specific CPU.
8899 * Base the remaining IO channel assigned, to IO channels already
8900 * assigned to other CPUs on the same phys_id.
8901 */
James Smartec2087a2013-09-06 12:20:36 -04008902 for (i = min_phys_id; i <= max_phys_id; i++) {
James Smart7bb03bb2013-04-17 20:19:16 -04008903 /*
8904 * If there are no io channels already mapped to
8905 * this phys_id, just round robin thru the io_channels.
8906 * Setup chann[] for round robin.
8907 */
8908 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
8909 chann[idx] = idx;
8910
8911 saved_chann = 0;
8912 used_chann = 0;
8913
8914 /*
8915 * First build a list of IO channels already assigned
8916 * to this phys_id before reassigning the same IO
8917 * channels to the remaining CPUs.
8918 */
8919 cpup = phba->sli4_hba.cpu_map;
8920 cpu = first_cpu;
8921 cpup += cpu;
8922 for (idx = 0; idx < phba->sli4_hba.num_present_cpu;
8923 idx++) {
8924 if (cpup->phys_id == i) {
8925 /*
8926 * Save any IO channels that are
8927 * already mapped to this phys_id.
8928 */
8929 if (cpup->irq != LPFC_VECTOR_MAP_EMPTY) {
James Smart6690e0d2015-12-16 18:11:56 -05008930 if (saved_chann <=
8931 LPFC_FCP_IO_CHAN_MAX) {
8932 chann[saved_chann] =
8933 cpup->channel_id;
8934 saved_chann++;
8935 }
James Smart7bb03bb2013-04-17 20:19:16 -04008936 goto out;
8937 }
8938
8939 /* See if we are using round-robin */
8940 if (saved_chann == 0)
8941 saved_chann =
8942 phba->cfg_fcp_io_channel;
8943
8944 /* Associate next IO channel with CPU */
8945 cpup->channel_id = chann[used_chann];
8946 num_io_channel++;
8947 used_chann++;
8948 if (used_chann == saved_chann)
8949 used_chann = 0;
8950
8951 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8952 "3331 Set IO_CHANN "
8953 "CPU %d channel %d\n",
8954 idx, cpup->channel_id);
8955 }
8956out:
8957 cpu++;
8958 if (cpu >= phba->sli4_hba.num_present_cpu) {
8959 cpup = phba->sli4_hba.cpu_map;
8960 cpu = 0;
8961 } else {
8962 cpup++;
8963 }
8964 }
8965 }
8966
8967 if (phba->sli4_hba.num_online_cpu != phba->sli4_hba.num_present_cpu) {
8968 cpup = phba->sli4_hba.cpu_map;
8969 for (idx = 0; idx < phba->sli4_hba.num_present_cpu; idx++) {
8970 if (cpup->channel_id == LPFC_VECTOR_MAP_EMPTY) {
8971 cpup->channel_id = 0;
8972 num_io_channel++;
8973
8974 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8975 "3332 Assign IO_CHANN "
8976 "CPU %d channel %d\n",
8977 idx, cpup->channel_id);
8978 }
8979 cpup++;
8980 }
8981 }
8982
8983 /* Sanity check */
8984 if (num_io_channel != phba->sli4_hba.num_present_cpu)
8985 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8986 "3333 Set affinity mismatch:"
James Smartec2087a2013-09-06 12:20:36 -04008987 "%d chann != %d cpus: %d vectors\n",
James Smart7bb03bb2013-04-17 20:19:16 -04008988 num_io_channel, phba->sli4_hba.num_present_cpu,
8989 vectors);
8990
James Smartec2087a2013-09-06 12:20:36 -04008991 /* Enable using cpu affinity for scheduling */
James Smart7bb03bb2013-04-17 20:19:16 -04008992 phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_BY_CPU;
8993 return 1;
8994}
8995
8996
8997/**
James Smartda0436e2009-05-22 14:51:39 -04008998 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
8999 * @phba: pointer to lpfc hba data structure.
9000 *
9001 * This routine is invoked to enable the MSI-X interrupt vectors to device
Alexander Gordeev4f871e12014-09-03 12:56:29 -04009002 * with SLI-4 interface spec. The kernel function pci_enable_msix_range()
9003 * is called to enable the MSI-X vectors. The device driver is responsible
9004 * for calling the individual request_irq() to register each MSI-X vector
9005 * with a interrupt handler, which is done in this function. Note that
9006 * later when device is unloading, the driver should always call free_irq()
9007 * on all MSI-X vectors it has done request_irq() on before calling
9008 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
9009 * will be left with MSI-X enabled and leaks its vectors.
James Smartda0436e2009-05-22 14:51:39 -04009010 *
9011 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009012 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009013 * other values - error
9014 **/
9015static int
9016lpfc_sli4_enable_msix(struct lpfc_hba *phba)
9017{
James Smart75baf692010-06-08 18:31:21 -04009018 int vectors, rc, index;
James Smartda0436e2009-05-22 14:51:39 -04009019
9020 /* Set up MSI-X multi-message vectors */
James Smart82c3e9b2012-09-29 11:29:50 -04009021 for (index = 0; index < phba->cfg_fcp_io_channel; index++)
James Smartda0436e2009-05-22 14:51:39 -04009022 phba->sli4_hba.msix_entries[index].entry = index;
9023
9024 /* Configure MSI-X capability structure */
James Smart82c3e9b2012-09-29 11:29:50 -04009025 vectors = phba->cfg_fcp_io_channel;
James Smart1ba981f2014-02-20 09:56:45 -05009026 if (phba->cfg_fof) {
9027 phba->sli4_hba.msix_entries[index].entry = index;
9028 vectors++;
9029 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -04009030 rc = pci_enable_msix_range(phba->pcidev, phba->sli4_hba.msix_entries,
9031 2, vectors);
9032 if (rc < 0) {
James Smartda0436e2009-05-22 14:51:39 -04009033 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9034 "0484 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009035 goto vec_fail_out;
James Smartda0436e2009-05-22 14:51:39 -04009036 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -04009037 vectors = rc;
James Smart75baf692010-06-08 18:31:21 -04009038
James Smartda0436e2009-05-22 14:51:39 -04009039 /* Log MSI-X vector assignment */
James Smart75baf692010-06-08 18:31:21 -04009040 for (index = 0; index < vectors; index++)
James Smartda0436e2009-05-22 14:51:39 -04009041 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9042 "0489 MSI-X entry[%d]: vector=x%x "
9043 "message=%d\n", index,
9044 phba->sli4_hba.msix_entries[index].vector,
9045 phba->sli4_hba.msix_entries[index].entry);
James Smart67d12732012-08-03 12:36:13 -04009046
James Smart7bb03bb2013-04-17 20:19:16 -04009047 /* Assign MSI-X vectors to interrupt handlers */
James Smart67d12732012-08-03 12:36:13 -04009048 for (index = 0; index < vectors; index++) {
James Smart4305f182012-08-03 12:36:33 -04009049 memset(&phba->sli4_hba.handler_name[index], 0, 16);
James Smarta2fc4aef2014-09-03 12:57:55 -04009050 snprintf((char *)&phba->sli4_hba.handler_name[index],
9051 LPFC_SLI4_HANDLER_NAME_SZ,
James Smart4305f182012-08-03 12:36:33 -04009052 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -04009053
James Smart67d12732012-08-03 12:36:13 -04009054 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9055 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
James Smartba20c852012-08-03 12:36:52 -04009056 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].fcp_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -05009057 if (phba->cfg_fof && (index == (vectors - 1)))
9058 rc = request_irq(
9059 phba->sli4_hba.msix_entries[index].vector,
James Smarted243d32015-05-21 13:55:25 -04009060 &lpfc_sli4_fof_intr_handler, 0,
James Smart1ba981f2014-02-20 09:56:45 -05009061 (char *)&phba->sli4_hba.handler_name[index],
9062 &phba->sli4_hba.fcp_eq_hdl[index]);
9063 else
9064 rc = request_irq(
9065 phba->sli4_hba.msix_entries[index].vector,
James Smarted243d32015-05-21 13:55:25 -04009066 &lpfc_sli4_hba_intr_handler, 0,
James Smart4305f182012-08-03 12:36:33 -04009067 (char *)&phba->sli4_hba.handler_name[index],
James Smart67d12732012-08-03 12:36:13 -04009068 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -04009069 if (rc) {
9070 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9071 "0486 MSI-X fast-path (%d) "
9072 "request_irq failed (%d)\n", index, rc);
9073 goto cfg_fail_out;
9074 }
9075 }
9076
James Smart1ba981f2014-02-20 09:56:45 -05009077 if (phba->cfg_fof)
9078 vectors--;
9079
James Smart82c3e9b2012-09-29 11:29:50 -04009080 if (vectors != phba->cfg_fcp_io_channel) {
9081 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9082 "3238 Reducing IO channels to match number of "
9083 "MSI-X vectors, requested %d got %d\n",
9084 phba->cfg_fcp_io_channel, vectors);
9085 phba->cfg_fcp_io_channel = vectors;
9086 }
James Smart7bb03bb2013-04-17 20:19:16 -04009087
James Smart8b0dff12015-05-22 10:42:38 -04009088 if (!shost_use_blk_mq(lpfc_shost_from_vport(phba->pport)))
9089 lpfc_sli4_set_affinity(phba, vectors);
James Smartda0436e2009-05-22 14:51:39 -04009090 return rc;
9091
9092cfg_fail_out:
9093 /* free the irq already requested */
James Smartacbd8612013-09-06 12:21:19 -04009094 for (--index; index >= 0; index--) {
9095 irq_set_affinity_hint(phba->sli4_hba.msix_entries[index].
9096 vector, NULL);
James Smart67d12732012-08-03 12:36:13 -04009097 free_irq(phba->sli4_hba.msix_entries[index].vector,
9098 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartacbd8612013-09-06 12:21:19 -04009099 }
James Smartda0436e2009-05-22 14:51:39 -04009100
James Smartda0436e2009-05-22 14:51:39 -04009101 /* Unconfigure MSI-X capability structure */
9102 pci_disable_msix(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009103
9104vec_fail_out:
James Smartda0436e2009-05-22 14:51:39 -04009105 return rc;
9106}
9107
9108/**
9109 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
9110 * @phba: pointer to lpfc hba data structure.
9111 *
9112 * This routine is invoked to release the MSI-X vectors and then disable the
9113 * MSI-X interrupt mode to device with SLI-4 interface spec.
9114 **/
9115static void
9116lpfc_sli4_disable_msix(struct lpfc_hba *phba)
9117{
9118 int index;
9119
9120 /* Free up MSI-X multi-message vectors */
James Smartacbd8612013-09-06 12:21:19 -04009121 for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
9122 irq_set_affinity_hint(phba->sli4_hba.msix_entries[index].
9123 vector, NULL);
James Smartda0436e2009-05-22 14:51:39 -04009124 free_irq(phba->sli4_hba.msix_entries[index].vector,
James Smart67d12732012-08-03 12:36:13 -04009125 &phba->sli4_hba.fcp_eq_hdl[index]);
James Smartacbd8612013-09-06 12:21:19 -04009126 }
James Smart1ba981f2014-02-20 09:56:45 -05009127 if (phba->cfg_fof) {
9128 free_irq(phba->sli4_hba.msix_entries[index].vector,
9129 &phba->sli4_hba.fcp_eq_hdl[index]);
9130 }
James Smartda0436e2009-05-22 14:51:39 -04009131 /* Disable MSI-X */
9132 pci_disable_msix(phba->pcidev);
9133
9134 return;
9135}
9136
9137/**
9138 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
9139 * @phba: pointer to lpfc hba data structure.
9140 *
9141 * This routine is invoked to enable the MSI interrupt mode to device with
9142 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
9143 * to enable the MSI vector. The device driver is responsible for calling
9144 * the request_irq() to register MSI vector with a interrupt the handler,
9145 * which is done in this function.
9146 *
9147 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009148 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009149 * other values - error
9150 **/
9151static int
9152lpfc_sli4_enable_msi(struct lpfc_hba *phba)
9153{
9154 int rc, index;
9155
9156 rc = pci_enable_msi(phba->pcidev);
9157 if (!rc)
9158 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9159 "0487 PCI enable MSI mode success.\n");
9160 else {
9161 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9162 "0488 PCI enable MSI mode failed (%d)\n", rc);
9163 return rc;
9164 }
9165
9166 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04009167 0, LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -04009168 if (rc) {
9169 pci_disable_msi(phba->pcidev);
9170 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9171 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -04009172 return rc;
James Smartda0436e2009-05-22 14:51:39 -04009173 }
9174
James Smart67d12732012-08-03 12:36:13 -04009175 for (index = 0; index < phba->cfg_fcp_io_channel; index++) {
James Smartda0436e2009-05-22 14:51:39 -04009176 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9177 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9178 }
9179
James Smart1ba981f2014-02-20 09:56:45 -05009180 if (phba->cfg_fof) {
9181 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9182 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9183 }
James Smart75baf692010-06-08 18:31:21 -04009184 return 0;
James Smartda0436e2009-05-22 14:51:39 -04009185}
9186
9187/**
9188 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
9189 * @phba: pointer to lpfc hba data structure.
9190 *
9191 * This routine is invoked to disable the MSI interrupt mode to device with
9192 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
9193 * done request_irq() on before calling pci_disable_msi(). Failure to do so
9194 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
9195 * its vector.
9196 **/
9197static void
9198lpfc_sli4_disable_msi(struct lpfc_hba *phba)
9199{
9200 free_irq(phba->pcidev->irq, phba);
9201 pci_disable_msi(phba->pcidev);
9202 return;
9203}
9204
9205/**
9206 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
9207 * @phba: pointer to lpfc hba data structure.
9208 *
9209 * This routine is invoked to enable device interrupt and associate driver's
9210 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
9211 * interface spec. Depends on the interrupt mode configured to the driver,
9212 * the driver will try to fallback from the configured interrupt mode to an
9213 * interrupt mode which is supported by the platform, kernel, and device in
9214 * the order of:
9215 * MSI-X -> MSI -> IRQ.
9216 *
9217 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009218 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009219 * other values - error
9220 **/
9221static uint32_t
9222lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9223{
9224 uint32_t intr_mode = LPFC_INTR_ERROR;
9225 int retval, index;
9226
9227 if (cfg_mode == 2) {
9228 /* Preparation before conf_msi mbox cmd */
9229 retval = 0;
9230 if (!retval) {
9231 /* Now, try to enable MSI-X interrupt mode */
9232 retval = lpfc_sli4_enable_msix(phba);
9233 if (!retval) {
9234 /* Indicate initialization to MSI-X mode */
9235 phba->intr_type = MSIX;
9236 intr_mode = 2;
9237 }
9238 }
9239 }
9240
9241 /* Fallback to MSI if MSI-X initialization failed */
9242 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9243 retval = lpfc_sli4_enable_msi(phba);
9244 if (!retval) {
9245 /* Indicate initialization to MSI mode */
9246 phba->intr_type = MSI;
9247 intr_mode = 1;
9248 }
9249 }
9250
9251 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9252 if (phba->intr_type == NONE) {
9253 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
9254 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9255 if (!retval) {
9256 /* Indicate initialization to INTx mode */
9257 phba->intr_type = INTx;
9258 intr_mode = 0;
James Smart67d12732012-08-03 12:36:13 -04009259 for (index = 0; index < phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04009260 index++) {
9261 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9262 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
James Smartba20c852012-08-03 12:36:52 -04009263 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
9264 fcp_eq_in_use, 1);
James Smartda0436e2009-05-22 14:51:39 -04009265 }
James Smart1ba981f2014-02-20 09:56:45 -05009266 if (phba->cfg_fof) {
9267 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
9268 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
9269 atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].
9270 fcp_eq_in_use, 1);
9271 }
James Smartda0436e2009-05-22 14:51:39 -04009272 }
9273 }
9274 return intr_mode;
9275}
9276
9277/**
9278 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
9279 * @phba: pointer to lpfc hba data structure.
9280 *
9281 * This routine is invoked to disable device interrupt and disassociate
9282 * the driver's interrupt handler(s) from interrupt vector(s) to device
9283 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
9284 * will release the interrupt vector(s) for the message signaled interrupt.
9285 **/
9286static void
9287lpfc_sli4_disable_intr(struct lpfc_hba *phba)
9288{
9289 /* Disable the currently initialized interrupt mode */
9290 if (phba->intr_type == MSIX)
9291 lpfc_sli4_disable_msix(phba);
9292 else if (phba->intr_type == MSI)
9293 lpfc_sli4_disable_msi(phba);
9294 else if (phba->intr_type == INTx)
9295 free_irq(phba->pcidev->irq, phba);
9296
9297 /* Reset interrupt management states */
9298 phba->intr_type = NONE;
9299 phba->sli.slistat.sli_intr = 0;
9300
9301 return;
9302}
9303
9304/**
James Smart3772a992009-05-22 14:50:54 -04009305 * lpfc_unset_hba - Unset SLI3 hba device initialization
9306 * @phba: pointer to lpfc hba data structure.
9307 *
9308 * This routine is invoked to unset the HBA device initialization steps to
9309 * a device with SLI-3 interface spec.
9310 **/
9311static void
9312lpfc_unset_hba(struct lpfc_hba *phba)
9313{
9314 struct lpfc_vport *vport = phba->pport;
9315 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9316
9317 spin_lock_irq(shost->host_lock);
9318 vport->load_flag |= FC_UNLOADING;
9319 spin_unlock_irq(shost->host_lock);
9320
James Smart72859902012-01-18 16:25:38 -05009321 kfree(phba->vpi_bmask);
9322 kfree(phba->vpi_ids);
9323
James Smart3772a992009-05-22 14:50:54 -04009324 lpfc_stop_hba_timers(phba);
9325
9326 phba->pport->work_port_events = 0;
9327
9328 lpfc_sli_hba_down(phba);
9329
9330 lpfc_sli_brdrestart(phba);
9331
9332 lpfc_sli_disable_intr(phba);
9333
9334 return;
9335}
9336
9337/**
James Smart5af5eee2010-10-22 11:06:38 -04009338 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
9339 * @phba: Pointer to HBA context object.
9340 *
9341 * This function is called in the SLI4 code path to wait for completion
9342 * of device's XRIs exchange busy. It will check the XRI exchange busy
9343 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
9344 * that, it will check the XRI exchange busy on outstanding FCP and ELS
9345 * I/Os every 30 seconds, log error message, and wait forever. Only when
9346 * all XRI exchange busy complete, the driver unload shall proceed with
9347 * invoking the function reset ioctl mailbox command to the CNA and the
9348 * the rest of the driver unload resource release.
9349 **/
9350static void
9351lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
9352{
9353 int wait_time = 0;
9354 int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
9355 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9356
9357 while (!fcp_xri_cmpl || !els_xri_cmpl) {
9358 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
9359 if (!fcp_xri_cmpl)
9360 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9361 "2877 FCP XRI exchange busy "
9362 "wait time: %d seconds.\n",
9363 wait_time/1000);
9364 if (!els_xri_cmpl)
9365 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9366 "2878 ELS XRI exchange busy "
9367 "wait time: %d seconds.\n",
9368 wait_time/1000);
9369 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
9370 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
9371 } else {
9372 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
9373 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
9374 }
9375 fcp_xri_cmpl =
9376 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
9377 els_xri_cmpl =
9378 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9379 }
9380}
9381
9382/**
James Smartda0436e2009-05-22 14:51:39 -04009383 * lpfc_sli4_hba_unset - Unset the fcoe hba
9384 * @phba: Pointer to HBA context object.
9385 *
9386 * This function is called in the SLI4 code path to reset the HBA's FCoE
9387 * function. The caller is not required to hold any lock. This routine
9388 * issues PCI function reset mailbox command to reset the FCoE function.
9389 * At the end of the function, it calls lpfc_hba_down_post function to
9390 * free any pending commands.
9391 **/
9392static void
9393lpfc_sli4_hba_unset(struct lpfc_hba *phba)
9394{
9395 int wait_cnt = 0;
9396 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -04009397 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -04009398
9399 lpfc_stop_hba_timers(phba);
9400 phba->sli4_hba.intr_enable = 0;
9401
9402 /*
9403 * Gracefully wait out the potential current outstanding asynchronous
9404 * mailbox command.
9405 */
9406
9407 /* First, block any pending async mailbox command from posted */
9408 spin_lock_irq(&phba->hbalock);
9409 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
9410 spin_unlock_irq(&phba->hbalock);
9411 /* Now, trying to wait it out if we can */
9412 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9413 msleep(10);
9414 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
9415 break;
9416 }
9417 /* Forcefully release the outstanding mailbox command if timed out */
9418 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9419 spin_lock_irq(&phba->hbalock);
9420 mboxq = phba->sli.mbox_active;
9421 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
9422 __lpfc_mbox_cmpl_put(phba, mboxq);
9423 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9424 phba->sli.mbox_active = NULL;
9425 spin_unlock_irq(&phba->hbalock);
9426 }
9427
James Smart5af5eee2010-10-22 11:06:38 -04009428 /* Abort all iocbs associated with the hba */
9429 lpfc_sli_hba_iocb_abort(phba);
9430
9431 /* Wait for completion of device XRI exchange busy */
9432 lpfc_sli4_xri_exchange_busy_wait(phba);
9433
James Smartda0436e2009-05-22 14:51:39 -04009434 /* Disable PCI subsystem interrupt */
9435 lpfc_sli4_disable_intr(phba);
9436
James Smart912e3ac2011-05-24 11:42:11 -04009437 /* Disable SR-IOV if enabled */
9438 if (phba->cfg_sriov_nr_virtfn)
9439 pci_disable_sriov(pdev);
9440
James Smartda0436e2009-05-22 14:51:39 -04009441 /* Stop kthread signal shall trigger work_done one more time */
9442 kthread_stop(phba->worker_thread);
9443
James Smart3677a3a2010-09-29 11:19:14 -04009444 /* Reset SLI4 HBA FCoE function */
9445 lpfc_pci_function_reset(phba);
James Smart5350d872011-10-10 21:33:49 -04009446 lpfc_sli4_queue_destroy(phba);
James Smart3677a3a2010-09-29 11:19:14 -04009447
James Smartda0436e2009-05-22 14:51:39 -04009448 /* Stop the SLI4 device port */
9449 phba->pport->work_port_events = 0;
9450}
9451
James Smart28baac72010-02-12 14:42:03 -05009452 /**
9453 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
9454 * @phba: Pointer to HBA context object.
9455 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9456 *
9457 * This function is called in the SLI4 code path to read the port's
9458 * sli4 capabilities.
9459 *
9460 * This function may be be called from any context that can block-wait
9461 * for the completion. The expectation is that this routine is called
9462 * typically from probe_one or from the online routine.
9463 **/
9464int
9465lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9466{
9467 int rc;
9468 struct lpfc_mqe *mqe;
9469 struct lpfc_pc_sli4_params *sli4_params;
9470 uint32_t mbox_tmo;
9471
9472 rc = 0;
9473 mqe = &mboxq->u.mqe;
9474
9475 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -05009476 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -05009477 if (!phba->sli4_hba.intr_enable)
9478 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9479 else {
James Smarta183a152011-10-10 21:32:43 -04009480 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -05009481 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
9482 }
9483
9484 if (unlikely(rc))
9485 return 1;
9486
9487 sli4_params = &phba->sli4_hba.pc_sli4_params;
9488 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
9489 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
9490 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
9491 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
9492 &mqe->un.sli4_params);
9493 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
9494 &mqe->un.sli4_params);
9495 sli4_params->proto_types = mqe->un.sli4_params.word3;
9496 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
9497 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
9498 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
9499 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
9500 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
9501 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
9502 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
9503 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
9504 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
9505 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
9506 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
9507 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
9508 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
9509 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
9510 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
9511 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
9512 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
9513 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
9514 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
9515 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -04009516
9517 /* Make sure that sge_supp_len can be handled by the driver */
9518 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
9519 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
9520
James Smart28baac72010-02-12 14:42:03 -05009521 return rc;
9522}
9523
James Smartda0436e2009-05-22 14:51:39 -04009524/**
James Smartfedd3b72011-02-16 12:39:24 -05009525 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
9526 * @phba: Pointer to HBA context object.
9527 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9528 *
9529 * This function is called in the SLI4 code path to read the port's
9530 * sli4 capabilities.
9531 *
9532 * This function may be be called from any context that can block-wait
9533 * for the completion. The expectation is that this routine is called
9534 * typically from probe_one or from the online routine.
9535 **/
9536int
9537lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9538{
9539 int rc;
9540 struct lpfc_mqe *mqe = &mboxq->u.mqe;
9541 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -04009542 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -05009543 int length;
9544 struct lpfc_sli4_parameters *mbx_sli4_parameters;
9545
James Smart6d368e52011-05-24 11:44:12 -04009546 /*
9547 * By default, the driver assumes the SLI4 port requires RPI
9548 * header postings. The SLI4_PARAM response will correct this
9549 * assumption.
9550 */
9551 phba->sli4_hba.rpi_hdrs_in_use = 1;
9552
James Smartfedd3b72011-02-16 12:39:24 -05009553 /* Read the port's SLI4 Config Parameters */
9554 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
9555 sizeof(struct lpfc_sli4_cfg_mhdr));
9556 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9557 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
9558 length, LPFC_SLI4_MBX_EMBED);
9559 if (!phba->sli4_hba.intr_enable)
9560 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -04009561 else {
9562 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
9563 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
9564 }
James Smartfedd3b72011-02-16 12:39:24 -05009565 if (unlikely(rc))
9566 return rc;
9567 sli4_params = &phba->sli4_hba.pc_sli4_params;
9568 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
9569 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
9570 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
9571 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
9572 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
9573 mbx_sli4_parameters);
9574 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
9575 mbx_sli4_parameters);
9576 if (bf_get(cfg_phwq, mbx_sli4_parameters))
9577 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
9578 else
9579 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
9580 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
9581 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
James Smart1ba981f2014-02-20 09:56:45 -05009582 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -05009583 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
9584 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
9585 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
9586 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
James Smart0c651872013-07-15 18:33:23 -04009587 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -05009588 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
9589 mbx_sli4_parameters);
9590 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
9591 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -04009592 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
9593 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart05580562011-05-24 11:40:48 -04009594
9595 /* Make sure that sge_supp_len can be handled by the driver */
9596 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
9597 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
9598
James Smartb5c53952016-03-31 14:12:30 -07009599 /*
9600 * Issue IOs with CDB embedded in WQE to minimized the number
9601 * of DMAs the firmware has to do. Setting this to 1 also forces
9602 * the driver to use 128 bytes WQEs for FCP IOs.
9603 */
9604 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
9605 phba->fcp_embed_io = 1;
9606 else
9607 phba->fcp_embed_io = 0;
James Smart7bdedb32016-07-06 12:36:00 -07009608
9609 /*
9610 * Check if the SLI port supports MDS Diagnostics
9611 */
9612 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
9613 phba->mds_diags_support = 1;
9614 else
9615 phba->mds_diags_support = 0;
James Smartfedd3b72011-02-16 12:39:24 -05009616 return 0;
9617}
9618
9619/**
James Smart3772a992009-05-22 14:50:54 -04009620 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
9621 * @pdev: pointer to PCI device
9622 * @pid: pointer to PCI device identifier
9623 *
9624 * This routine is to be called to attach a device with SLI-3 interface spec
9625 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9626 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
9627 * information of the device and driver to see if the driver state that it can
9628 * support this kind of device. If the match is successful, the driver core
9629 * invokes this routine. If this routine determines it can claim the HBA, it
9630 * does all the initialization that it needs to do to handle the HBA properly.
9631 *
9632 * Return code
9633 * 0 - driver can claim the device
9634 * negative value - driver can not claim the device
9635 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009636static int
James Smart3772a992009-05-22 14:50:54 -04009637lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
9638{
9639 struct lpfc_hba *phba;
9640 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -04009641 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -04009642 int error;
9643 uint32_t cfg_mode, intr_mode;
9644
9645 /* Allocate memory for HBA structure */
9646 phba = lpfc_hba_alloc(pdev);
9647 if (!phba)
9648 return -ENOMEM;
9649
9650 /* Perform generic PCI device enabling operation */
9651 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -04009652 if (error)
James Smart3772a992009-05-22 14:50:54 -04009653 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -04009654
9655 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
9656 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
9657 if (error)
9658 goto out_disable_pci_dev;
9659
9660 /* Set up SLI-3 specific device PCI memory space */
9661 error = lpfc_sli_pci_mem_setup(phba);
9662 if (error) {
9663 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9664 "1402 Failed to set up pci memory space.\n");
9665 goto out_disable_pci_dev;
9666 }
9667
9668 /* Set up phase-1 common device driver resources */
9669 error = lpfc_setup_driver_resource_phase1(phba);
9670 if (error) {
9671 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9672 "1403 Failed to set up driver resource.\n");
9673 goto out_unset_pci_mem_s3;
9674 }
9675
9676 /* Set up SLI-3 specific device driver resources */
9677 error = lpfc_sli_driver_resource_setup(phba);
9678 if (error) {
9679 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9680 "1404 Failed to set up driver resource.\n");
9681 goto out_unset_pci_mem_s3;
9682 }
9683
9684 /* Initialize and populate the iocb list per host */
9685 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
9686 if (error) {
9687 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9688 "1405 Failed to initialize iocb list.\n");
9689 goto out_unset_driver_resource_s3;
9690 }
9691
9692 /* Set up common device driver resources */
9693 error = lpfc_setup_driver_resource_phase2(phba);
9694 if (error) {
9695 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9696 "1406 Failed to set up driver resource.\n");
9697 goto out_free_iocb_list;
9698 }
9699
James Smart079b5c92011-08-21 21:48:49 -04009700 /* Get the default values for Model Name and Description */
9701 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
9702
James Smart3772a992009-05-22 14:50:54 -04009703 /* Create SCSI host to the physical port */
9704 error = lpfc_create_shost(phba);
9705 if (error) {
9706 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9707 "1407 Failed to create scsi host.\n");
9708 goto out_unset_driver_resource;
9709 }
9710
9711 /* Configure sysfs attributes */
9712 vport = phba->pport;
9713 error = lpfc_alloc_sysfs_attr(vport);
9714 if (error) {
9715 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9716 "1476 Failed to allocate sysfs attr\n");
9717 goto out_destroy_shost;
9718 }
9719
James Smart6669f9b2009-10-02 15:16:45 -04009720 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -04009721 /* Now, trying to enable interrupt and bring up the device */
9722 cfg_mode = phba->cfg_use_msi;
9723 while (true) {
9724 /* Put device to a known state before enabling interrupt */
9725 lpfc_stop_port(phba);
9726 /* Configure and enable interrupt */
9727 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
9728 if (intr_mode == LPFC_INTR_ERROR) {
9729 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9730 "0431 Failed to enable interrupt.\n");
9731 error = -ENODEV;
9732 goto out_free_sysfs_attr;
9733 }
9734 /* SLI-3 HBA setup */
9735 if (lpfc_sli_hba_setup(phba)) {
9736 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9737 "1477 Failed to set up hba\n");
9738 error = -ENODEV;
9739 goto out_remove_device;
9740 }
9741
9742 /* Wait 50ms for the interrupts of previous mailbox commands */
9743 msleep(50);
9744 /* Check active interrupts on message signaled interrupts */
9745 if (intr_mode == 0 ||
9746 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
9747 /* Log the current active interrupt mode */
9748 phba->intr_mode = intr_mode;
9749 lpfc_log_intr_mode(phba, intr_mode);
9750 break;
9751 } else {
9752 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9753 "0447 Configure interrupt mode (%d) "
9754 "failed active interrupt test.\n",
9755 intr_mode);
9756 /* Disable the current interrupt mode */
9757 lpfc_sli_disable_intr(phba);
9758 /* Try next level of interrupt mode */
9759 cfg_mode = --intr_mode;
9760 }
9761 }
9762
9763 /* Perform post initialization setup */
9764 lpfc_post_init_setup(phba);
9765
9766 /* Check if there are static vports to be created. */
9767 lpfc_create_static_vport(phba);
9768
9769 return 0;
9770
9771out_remove_device:
9772 lpfc_unset_hba(phba);
9773out_free_sysfs_attr:
9774 lpfc_free_sysfs_attr(vport);
9775out_destroy_shost:
9776 lpfc_destroy_shost(phba);
9777out_unset_driver_resource:
9778 lpfc_unset_driver_resource_phase2(phba);
9779out_free_iocb_list:
9780 lpfc_free_iocb_list(phba);
9781out_unset_driver_resource_s3:
9782 lpfc_sli_driver_resource_unset(phba);
9783out_unset_pci_mem_s3:
9784 lpfc_sli_pci_mem_unset(phba);
9785out_disable_pci_dev:
9786 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -04009787 if (shost)
9788 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -04009789out_free_phba:
9790 lpfc_hba_free(phba);
9791 return error;
9792}
9793
9794/**
9795 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -04009796 * @pdev: pointer to PCI device
9797 *
James Smart3772a992009-05-22 14:50:54 -04009798 * This routine is to be called to disattach a device with SLI-3 interface
9799 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9800 * removed from PCI bus, it performs all the necessary cleanup for the HBA
9801 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -04009802 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009803static void
James Smart3772a992009-05-22 14:50:54 -04009804lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -05009805{
James Smart2e0fef82007-06-17 19:56:36 -05009806 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9807 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -05009808 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -05009809 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -05009810 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05009811 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
9812
James Smart549e55c2007-08-02 11:09:51 -04009813 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04009814 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04009815 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05009816
James Smart858c9f62007-06-17 19:56:39 -05009817 lpfc_free_sysfs_attr(vport);
9818
James Smarteada2722008-12-04 22:39:13 -05009819 /* Release all the vports against this physical port */
9820 vports = lpfc_create_vport_work_array(phba);
9821 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -04009822 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9823 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
9824 continue;
James Smarteada2722008-12-04 22:39:13 -05009825 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -04009826 }
James Smarteada2722008-12-04 22:39:13 -05009827 lpfc_destroy_vport_work_array(phba, vports);
9828
9829 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -05009830 fc_remove_host(shost);
9831 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04009832 lpfc_cleanup(vport);
9833
James Smart2e0fef82007-06-17 19:56:36 -05009834 /*
9835 * Bring down the SLI Layer. This step disable all interrupts,
9836 * clears the rings, discards all mailbox commands, and resets
9837 * the HBA.
9838 */
James Smarta257bf92009-04-06 18:48:10 -04009839
Justin P. Mattock48e34d02010-12-30 15:07:58 -08009840 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -05009841 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -04009842 /* Stop kthread signal shall trigger work_done one more time */
9843 kthread_stop(phba->worker_thread);
9844 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -05009845 lpfc_sli_brdrestart(phba);
9846
James Smart72859902012-01-18 16:25:38 -05009847 kfree(phba->vpi_bmask);
9848 kfree(phba->vpi_ids);
9849
James Smart3772a992009-05-22 14:50:54 -04009850 lpfc_stop_hba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05009851 spin_lock_irq(&phba->hbalock);
9852 list_del_init(&vport->listentry);
9853 spin_unlock_irq(&phba->hbalock);
9854
James Smart858c9f62007-06-17 19:56:39 -05009855 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05009856
James Smart912e3ac2011-05-24 11:42:11 -04009857 /* Disable SR-IOV if enabled */
9858 if (phba->cfg_sriov_nr_virtfn)
9859 pci_disable_sriov(pdev);
9860
James Smart5b75da22008-12-04 22:39:35 -05009861 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009862 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -05009863
James Smart858c9f62007-06-17 19:56:39 -05009864 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05009865
9866 /*
9867 * Call scsi_free before mem_free since scsi bufs are released to their
9868 * corresponding pools here.
9869 */
9870 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -04009871 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -05009872
James Smart34b02dc2008-08-24 21:49:55 -04009873 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
9874 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -05009875
James Smart2e0fef82007-06-17 19:56:36 -05009876 /* Free resources associated with SLI2 interface */
9877 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -04009878 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -05009879
9880 /* unmap adapter SLIM and Control Registers */
9881 iounmap(phba->ctrl_regs_memmap_p);
9882 iounmap(phba->slim_memmap_p);
9883
James Smart3772a992009-05-22 14:50:54 -04009884 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -05009885
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05009886 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05009887 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05009888}
9889
Linas Vepstas8d63f372007-02-14 14:28:36 -06009890/**
James Smart3772a992009-05-22 14:50:54 -04009891 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05009892 * @pdev: pointer to PCI device
9893 * @msg: power management message
9894 *
James Smart3772a992009-05-22 14:50:54 -04009895 * This routine is to be called from the kernel's PCI subsystem to support
9896 * system Power Management (PM) to device with SLI-3 interface spec. When
9897 * PM invokes this method, it quiesces the device by stopping the driver's
9898 * worker thread for the device, turning off device's interrupt and DMA,
9899 * and bring the device offline. Note that as the driver implements the
9900 * minimum PM requirements to a power-aware driver's PM support for the
9901 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
9902 * to the suspend() method call will be treated as SUSPEND and the driver will
9903 * fully reinitialize its device during resume() method call, the driver will
9904 * set device to PCI_D3hot state in PCI config space instead of setting it
9905 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -05009906 *
9907 * Return code
James Smart3772a992009-05-22 14:50:54 -04009908 * 0 - driver suspended the device
9909 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05009910 **/
9911static int
James Smart3772a992009-05-22 14:50:54 -04009912lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -05009913{
9914 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9915 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9916
9917 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9918 "0473 PCI device Power Management suspend.\n");
9919
9920 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -04009921 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -05009922 lpfc_offline(phba);
9923 kthread_stop(phba->worker_thread);
9924
9925 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -04009926 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -05009927
9928 /* Save device state to PCI config space */
9929 pci_save_state(pdev);
9930 pci_set_power_state(pdev, PCI_D3hot);
9931
9932 return 0;
9933}
9934
9935/**
James Smart3772a992009-05-22 14:50:54 -04009936 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05009937 * @pdev: pointer to PCI device
9938 *
James Smart3772a992009-05-22 14:50:54 -04009939 * This routine is to be called from the kernel's PCI subsystem to support
9940 * system Power Management (PM) to device with SLI-3 interface spec. When PM
9941 * invokes this method, it restores the device's PCI config space state and
9942 * fully reinitializes the device and brings it online. Note that as the
9943 * driver implements the minimum PM requirements to a power-aware driver's
9944 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
9945 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
9946 * driver will fully reinitialize its device during resume() method call,
9947 * the device will be set to PCI_D0 directly in PCI config space before
9948 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -05009949 *
9950 * Return code
James Smart3772a992009-05-22 14:50:54 -04009951 * 0 - driver suspended the device
9952 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05009953 **/
9954static int
James Smart3772a992009-05-22 14:50:54 -04009955lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -05009956{
9957 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9958 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -05009959 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05009960 int error;
9961
9962 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9963 "0452 PCI device Power Management resume.\n");
9964
9965 /* Restore device state from PCI config space */
9966 pci_set_power_state(pdev, PCI_D0);
9967 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -04009968
James Smart1dfb5a42010-02-12 14:40:50 -05009969 /*
9970 * As the new kernel behavior of pci_restore_state() API call clears
9971 * device saved_state flag, need to save the restored state again.
9972 */
9973 pci_save_state(pdev);
9974
James Smart3a55b532008-12-04 22:38:54 -05009975 if (pdev->is_busmaster)
9976 pci_set_master(pdev);
9977
9978 /* Startup the kernel thread for this host adapter. */
9979 phba->worker_thread = kthread_run(lpfc_do_work, phba,
9980 "lpfc_worker_%d", phba->brd_no);
9981 if (IS_ERR(phba->worker_thread)) {
9982 error = PTR_ERR(phba->worker_thread);
9983 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9984 "0434 PM resume failed to start worker "
9985 "thread: error=x%x.\n", error);
9986 return error;
9987 }
9988
James Smart5b75da22008-12-04 22:39:35 -05009989 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009990 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05009991 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -05009992 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -05009993 "0430 PM resume Failed to enable interrupt\n");
9994 return -EIO;
9995 } else
9996 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05009997
9998 /* Restart HBA and bring it online */
9999 lpfc_sli_brdrestart(phba);
10000 lpfc_online(phba);
10001
James Smart5b75da22008-12-04 22:39:35 -050010002 /* Log the current active interrupt mode */
10003 lpfc_log_intr_mode(phba, phba->intr_mode);
10004
James Smart3a55b532008-12-04 22:38:54 -050010005 return 0;
10006}
10007
10008/**
James Smart891478a2009-11-18 15:40:23 -050010009 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
10010 * @phba: pointer to lpfc hba data structure.
10011 *
10012 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -040010013 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -050010014 **/
10015static void
10016lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
10017{
10018 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10019 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -040010020
10021 /*
10022 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10023 * and let the SCSI mid-layer to retry them to recover.
10024 */
James Smartdb55fba2014-04-04 13:52:02 -040010025 lpfc_sli_abort_fcp_rings(phba);
James Smart891478a2009-11-18 15:40:23 -050010026}
10027
10028/**
James Smart0d878412009-10-02 15:16:56 -040010029 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
10030 * @phba: pointer to lpfc hba data structure.
10031 *
10032 * This routine is called to prepare the SLI3 device for PCI slot reset. It
10033 * disables the device interrupt and pci device, and aborts the internal FCP
10034 * pending I/Os.
10035 **/
10036static void
10037lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
10038{
James Smart0d878412009-10-02 15:16:56 -040010039 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050010040 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -040010041
James Smart75baf692010-06-08 18:31:21 -040010042 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040010043 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010044
James Smarte2af0d22010-03-15 11:25:32 -040010045 /* Block all SCSI devices' I/Os on the host */
10046 lpfc_scsi_dev_block(phba);
10047
James Smartea714f32013-04-17 20:18:47 -040010048 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10049 lpfc_sli_flush_fcp_rings(phba);
10050
James Smarte2af0d22010-03-15 11:25:32 -040010051 /* stop all timers */
10052 lpfc_stop_hba_timers(phba);
10053
James Smart0d878412009-10-02 15:16:56 -040010054 /* Disable interrupt and pci device */
10055 lpfc_sli_disable_intr(phba);
10056 pci_disable_device(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -040010057}
10058
10059/**
10060 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
10061 * @phba: pointer to lpfc hba data structure.
10062 *
10063 * This routine is called to prepare the SLI3 device for PCI slot permanently
10064 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10065 * pending I/Os.
10066 **/
10067static void
James Smart75baf692010-06-08 18:31:21 -040010068lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -040010069{
10070 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050010071 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -040010072 /* Block all SCSI devices' I/Os on the host */
10073 lpfc_scsi_dev_block(phba);
10074
10075 /* stop all timers */
10076 lpfc_stop_hba_timers(phba);
10077
James Smart0d878412009-10-02 15:16:56 -040010078 /* Clean up all driver's outstanding SCSI I/Os */
10079 lpfc_sli_flush_fcp_rings(phba);
10080}
10081
10082/**
James Smart3772a992009-05-22 14:50:54 -040010083 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -040010084 * @pdev: pointer to PCI device.
10085 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010086 *
James Smart3772a992009-05-22 14:50:54 -040010087 * This routine is called from the PCI subsystem for I/O error handling to
10088 * device with SLI-3 interface spec. This function is called by the PCI
10089 * subsystem after a PCI bus error affecting this device has been detected.
10090 * When this function is invoked, it will need to stop all the I/Os and
10091 * interrupt(s) to the device. Once that is done, it will return
10092 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
10093 * as desired.
James Smarte59058c2008-08-24 21:49:00 -040010094 *
10095 * Return codes
James Smart0d878412009-10-02 15:16:56 -040010096 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -040010097 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10098 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -040010099 **/
James Smart3772a992009-05-22 14:50:54 -040010100static pci_ers_result_t
10101lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010102{
James Smart51ef4c22007-08-02 11:10:31 -040010103 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10104 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010105
James Smart0d878412009-10-02 15:16:56 -040010106 switch (state) {
10107 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -050010108 /* Non-fatal error, prepare for recovery */
10109 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -040010110 return PCI_ERS_RESULT_CAN_RECOVER;
10111 case pci_channel_io_frozen:
10112 /* Fatal error, prepare for slot reset */
10113 lpfc_sli_prep_dev_for_reset(phba);
10114 return PCI_ERS_RESULT_NEED_RESET;
10115 case pci_channel_io_perm_failure:
10116 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -040010117 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010118 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -040010119 default:
10120 /* Unknown state, prepare and request slot reset */
10121 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10122 "0472 Unknown PCI error state: x%x\n", state);
10123 lpfc_sli_prep_dev_for_reset(phba);
10124 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -040010125 }
Linas Vepstas8d63f372007-02-14 14:28:36 -060010126}
10127
10128/**
James Smart3772a992009-05-22 14:50:54 -040010129 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -040010130 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010131 *
James Smart3772a992009-05-22 14:50:54 -040010132 * This routine is called from the PCI subsystem for error handling to
10133 * device with SLI-3 interface spec. This is called after PCI bus has been
10134 * reset to restart the PCI card from scratch, as if from a cold-boot.
10135 * During the PCI subsystem error recovery, after driver returns
10136 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10137 * recovery and then call this routine before calling the .resume method
10138 * to recover the device. This function will initialize the HBA device,
10139 * enable the interrupt, but it will just put the HBA to offline state
10140 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -040010141 *
10142 * Return codes
James Smart3772a992009-05-22 14:50:54 -040010143 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10144 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -060010145 */
James Smart3772a992009-05-22 14:50:54 -040010146static pci_ers_result_t
10147lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010148{
James Smart51ef4c22007-08-02 11:10:31 -040010149 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10150 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010151 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -050010152 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010153
10154 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +110010155 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -060010156 printk(KERN_ERR "lpfc: Cannot re-enable "
10157 "PCI device after reset.\n");
10158 return PCI_ERS_RESULT_DISCONNECT;
10159 }
10160
James Smart97207482008-12-04 22:39:19 -050010161 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050010162
10163 /*
10164 * As the new kernel behavior of pci_restore_state() API call clears
10165 * device saved_state flag, need to save the restored state again.
10166 */
10167 pci_save_state(pdev);
10168
James Smart97207482008-12-04 22:39:19 -050010169 if (pdev->is_busmaster)
10170 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010171
James Smart92d7f7b2007-06-17 19:56:38 -050010172 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040010173 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -050010174 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010175
James Smart5b75da22008-12-04 22:39:35 -050010176 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040010177 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050010178 if (intr_mode == LPFC_INTR_ERROR) {
10179 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10180 "0427 Cannot re-enable interrupt after "
10181 "slot reset.\n");
10182 return PCI_ERS_RESULT_DISCONNECT;
10183 } else
10184 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010185
James Smart75baf692010-06-08 18:31:21 -040010186 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -040010187 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010188 lpfc_offline(phba);
10189 lpfc_sli_brdrestart(phba);
10190
James Smart5b75da22008-12-04 22:39:35 -050010191 /* Log the current active interrupt mode */
10192 lpfc_log_intr_mode(phba, phba->intr_mode);
10193
Linas Vepstas8d63f372007-02-14 14:28:36 -060010194 return PCI_ERS_RESULT_RECOVERED;
10195}
10196
10197/**
James Smart3772a992009-05-22 14:50:54 -040010198 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -040010199 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -060010200 *
James Smart3772a992009-05-22 14:50:54 -040010201 * This routine is called from the PCI subsystem for error handling to device
10202 * with SLI-3 interface spec. It is called when kernel error recovery tells
10203 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10204 * error recovery. After this call, traffic can start to flow from this device
10205 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010206 */
James Smart3772a992009-05-22 14:50:54 -040010207static void
10208lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010209{
James Smart51ef4c22007-08-02 11:10:31 -040010210 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10211 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010212
James Smarte2af0d22010-03-15 11:25:32 -040010213 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -040010214 lpfc_online(phba);
James Smart0d878412009-10-02 15:16:56 -040010215
10216 /* Clean up Advanced Error Reporting (AER) if needed */
10217 if (phba->hba_flag & HBA_AER_ENABLED)
10218 pci_cleanup_aer_uncorrect_error_status(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010219}
10220
James Smart3772a992009-05-22 14:50:54 -040010221/**
James Smartda0436e2009-05-22 14:51:39 -040010222 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
10223 * @phba: pointer to lpfc hba data structure.
10224 *
10225 * returns the number of ELS/CT IOCBs to reserve
10226 **/
10227int
10228lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
10229{
10230 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
10231
James Smartf1126682009-06-10 17:22:44 -040010232 if (phba->sli_rev == LPFC_SLI_REV4) {
10233 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -040010234 return 10;
James Smartf1126682009-06-10 17:22:44 -040010235 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -040010236 return 25;
James Smartf1126682009-06-10 17:22:44 -040010237 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -040010238 return 50;
James Smartf1126682009-06-10 17:22:44 -040010239 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -040010240 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -040010241 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -040010242 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -040010243 else if (max_xri <= 2048)
10244 return 200;
10245 else
10246 return 250;
James Smartf1126682009-06-10 17:22:44 -040010247 } else
10248 return 0;
James Smartda0436e2009-05-22 14:51:39 -040010249}
10250
10251/**
James Smart52d52442011-05-24 11:42:45 -040010252 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -040010253 * @fw: pointer to firmware image returned from request_firmware.
James Smartce396282012-09-29 11:30:56 -040010254 * @phba: pointer to lpfc hba data structure.
James Smart52d52442011-05-24 11:42:45 -040010255 *
James Smart52d52442011-05-24 11:42:45 -040010256 **/
James Smartce396282012-09-29 11:30:56 -040010257static void
10258lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -040010259{
James Smartce396282012-09-29 11:30:56 -040010260 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -050010261 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -040010262 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -040010263 struct list_head dma_buffer_list;
10264 int i, rc = 0;
10265 struct lpfc_dmabuf *dmabuf, *next;
10266 uint32_t offset = 0, temp_offset = 0;
10267
James Smartc71ab862012-10-31 14:44:33 -040010268 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -040010269 if (!fw) {
10270 rc = -ENXIO;
10271 goto out;
10272 }
10273 image = (struct lpfc_grp_hdr *)fw->data;
10274
James Smart52d52442011-05-24 11:42:45 -040010275 INIT_LIST_HEAD(&dma_buffer_list);
James Smart079b5c92011-08-21 21:48:49 -040010276 if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) ||
10277 (bf_get_be32(lpfc_grp_hdr_file_type, image) !=
10278 LPFC_FILE_TYPE_GROUP) ||
10279 (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) ||
10280 (be32_to_cpu(image->size) != fw->size)) {
James Smart52d52442011-05-24 11:42:45 -040010281 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10282 "3022 Invalid FW image found. "
James Smart079b5c92011-08-21 21:48:49 -040010283 "Magic:%x Type:%x ID:%x\n",
10284 be32_to_cpu(image->magic_number),
10285 bf_get_be32(lpfc_grp_hdr_file_type, image),
10286 bf_get_be32(lpfc_grp_hdr_id, image));
James Smartce396282012-09-29 11:30:56 -040010287 rc = -EINVAL;
10288 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010289 }
10290 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -040010291 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -040010292 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartce396282012-09-29 11:30:56 -040010293 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -040010294 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -040010295 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -040010296 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
10297 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
10298 GFP_KERNEL);
10299 if (!dmabuf) {
10300 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040010301 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010302 }
10303 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
10304 SLI4_PAGE_SIZE,
10305 &dmabuf->phys,
10306 GFP_KERNEL);
10307 if (!dmabuf->virt) {
10308 kfree(dmabuf);
10309 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040010310 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010311 }
10312 list_add_tail(&dmabuf->list, &dma_buffer_list);
10313 }
10314 while (offset < fw->size) {
10315 temp_offset = offset;
10316 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -040010317 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -040010318 memcpy(dmabuf->virt,
10319 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -040010320 fw->size - temp_offset);
10321 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -040010322 break;
10323 }
James Smart52d52442011-05-24 11:42:45 -040010324 memcpy(dmabuf->virt, fw->data + temp_offset,
10325 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -040010326 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -040010327 }
10328 rc = lpfc_wr_object(phba, &dma_buffer_list,
10329 (fw->size - offset), &offset);
James Smartce396282012-09-29 11:30:56 -040010330 if (rc)
10331 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010332 }
10333 rc = offset;
10334 }
James Smartce396282012-09-29 11:30:56 -040010335
10336release_out:
James Smart52d52442011-05-24 11:42:45 -040010337 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
10338 list_del(&dmabuf->list);
10339 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
10340 dmabuf->virt, dmabuf->phys);
10341 kfree(dmabuf);
10342 }
James Smartce396282012-09-29 11:30:56 -040010343 release_firmware(fw);
10344out:
10345 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc71ab862012-10-31 14:44:33 -040010346 "3024 Firmware update done: %d.\n", rc);
James Smartce396282012-09-29 11:30:56 -040010347 return;
James Smart52d52442011-05-24 11:42:45 -040010348}
10349
10350/**
James Smartc71ab862012-10-31 14:44:33 -040010351 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
10352 * @phba: pointer to lpfc hba data structure.
10353 *
10354 * This routine is called to perform Linux generic firmware upgrade on device
10355 * that supports such feature.
10356 **/
10357int
10358lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
10359{
10360 uint8_t file_name[ELX_MODEL_NAME_SIZE];
10361 int ret;
10362 const struct firmware *fw;
10363
10364 /* Only supported on SLI4 interface type 2 for now */
10365 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
10366 LPFC_SLI_INTF_IF_TYPE_2)
10367 return -EPERM;
10368
10369 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
10370
10371 if (fw_upgrade == INT_FW_UPGRADE) {
10372 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
10373 file_name, &phba->pcidev->dev,
10374 GFP_KERNEL, (void *)phba,
10375 lpfc_write_firmware);
10376 } else if (fw_upgrade == RUN_FW_UPGRADE) {
10377 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
10378 if (!ret)
10379 lpfc_write_firmware(fw, (void *)phba);
10380 } else {
10381 ret = -EINVAL;
10382 }
10383
10384 return ret;
10385}
10386
10387/**
James Smartda0436e2009-05-22 14:51:39 -040010388 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
10389 * @pdev: pointer to PCI device
10390 * @pid: pointer to PCI device identifier
10391 *
10392 * This routine is called from the kernel's PCI subsystem to device with
10393 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10394 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10395 * information of the device and driver to see if the driver state that it
10396 * can support this kind of device. If the match is successful, the driver
10397 * core invokes this routine. If this routine determines it can claim the HBA,
10398 * it does all the initialization that it needs to do to handle the HBA
10399 * properly.
10400 *
10401 * Return code
10402 * 0 - driver can claim the device
10403 * negative value - driver can not claim the device
10404 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010405static int
James Smartda0436e2009-05-22 14:51:39 -040010406lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
10407{
10408 struct lpfc_hba *phba;
10409 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040010410 struct Scsi_Host *shost = NULL;
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040010411 int error;
James Smartda0436e2009-05-22 14:51:39 -040010412 uint32_t cfg_mode, intr_mode;
James Smart67d12732012-08-03 12:36:13 -040010413 int adjusted_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -040010414
10415 /* Allocate memory for HBA structure */
10416 phba = lpfc_hba_alloc(pdev);
10417 if (!phba)
10418 return -ENOMEM;
10419
10420 /* Perform generic PCI device enabling operation */
10421 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040010422 if (error)
James Smartda0436e2009-05-22 14:51:39 -040010423 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -040010424
10425 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
10426 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
10427 if (error)
10428 goto out_disable_pci_dev;
10429
10430 /* Set up SLI-4 specific device PCI memory space */
10431 error = lpfc_sli4_pci_mem_setup(phba);
10432 if (error) {
10433 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10434 "1410 Failed to set up pci memory space.\n");
10435 goto out_disable_pci_dev;
10436 }
10437
10438 /* Set up phase-1 common device driver resources */
10439 error = lpfc_setup_driver_resource_phase1(phba);
10440 if (error) {
10441 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10442 "1411 Failed to set up driver resource.\n");
10443 goto out_unset_pci_mem_s4;
10444 }
10445
10446 /* Set up SLI-4 Specific device driver resources */
10447 error = lpfc_sli4_driver_resource_setup(phba);
10448 if (error) {
10449 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10450 "1412 Failed to set up driver resource.\n");
10451 goto out_unset_pci_mem_s4;
10452 }
10453
10454 /* Initialize and populate the iocb list per host */
James Smart2a9bf3d2010-06-07 15:24:45 -040010455
10456 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10457 "2821 initialize iocb list %d.\n",
10458 phba->cfg_iocb_cnt*1024);
10459 error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
10460
James Smartda0436e2009-05-22 14:51:39 -040010461 if (error) {
10462 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10463 "1413 Failed to initialize iocb list.\n");
10464 goto out_unset_driver_resource_s4;
10465 }
10466
James Smart19ca7602010-11-20 23:11:55 -050010467 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -040010468 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -050010469
James Smartda0436e2009-05-22 14:51:39 -040010470 /* Set up common device driver resources */
10471 error = lpfc_setup_driver_resource_phase2(phba);
10472 if (error) {
10473 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10474 "1414 Failed to set up driver resource.\n");
10475 goto out_free_iocb_list;
10476 }
10477
James Smart079b5c92011-08-21 21:48:49 -040010478 /* Get the default values for Model Name and Description */
10479 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
10480
James Smartda0436e2009-05-22 14:51:39 -040010481 /* Create SCSI host to the physical port */
10482 error = lpfc_create_shost(phba);
10483 if (error) {
10484 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10485 "1415 Failed to create scsi host.\n");
10486 goto out_unset_driver_resource;
10487 }
10488
10489 /* Configure sysfs attributes */
10490 vport = phba->pport;
10491 error = lpfc_alloc_sysfs_attr(vport);
10492 if (error) {
10493 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10494 "1416 Failed to allocate sysfs attr\n");
10495 goto out_destroy_shost;
10496 }
10497
James Smart6669f9b2009-10-02 15:16:45 -040010498 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -040010499 /* Now, trying to enable interrupt and bring up the device */
10500 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -040010501
James Smart7b15db32013-01-03 15:43:29 -050010502 /* Put device to a known state before enabling interrupt */
10503 lpfc_stop_port(phba);
10504 /* Configure and enable interrupt */
10505 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
10506 if (intr_mode == LPFC_INTR_ERROR) {
10507 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10508 "0426 Failed to enable interrupt.\n");
10509 error = -ENODEV;
10510 goto out_free_sysfs_attr;
James Smartda0436e2009-05-22 14:51:39 -040010511 }
James Smart7b15db32013-01-03 15:43:29 -050010512 /* Default to single EQ for non-MSI-X */
10513 if (phba->intr_type != MSIX)
10514 adjusted_fcp_io_channel = 1;
10515 else
10516 adjusted_fcp_io_channel = phba->cfg_fcp_io_channel;
10517 phba->cfg_fcp_io_channel = adjusted_fcp_io_channel;
10518 /* Set up SLI-4 HBA */
10519 if (lpfc_sli4_hba_setup(phba)) {
10520 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10521 "1421 Failed to set up hba\n");
10522 error = -ENODEV;
10523 goto out_disable_intr;
10524 }
10525
10526 /* Log the current active interrupt mode */
10527 phba->intr_mode = intr_mode;
10528 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -040010529
10530 /* Perform post initialization setup */
10531 lpfc_post_init_setup(phba);
10532
James Smartc71ab862012-10-31 14:44:33 -040010533 /* check for firmware upgrade or downgrade */
10534 if (phba->cfg_request_firmware_upgrade)
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040010535 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -040010536
James Smart1c6834a2009-07-19 10:01:26 -040010537 /* Check if there are static vports to be created. */
10538 lpfc_create_static_vport(phba);
James Smartda0436e2009-05-22 14:51:39 -040010539 return 0;
10540
10541out_disable_intr:
10542 lpfc_sli4_disable_intr(phba);
10543out_free_sysfs_attr:
10544 lpfc_free_sysfs_attr(vport);
10545out_destroy_shost:
10546 lpfc_destroy_shost(phba);
10547out_unset_driver_resource:
10548 lpfc_unset_driver_resource_phase2(phba);
10549out_free_iocb_list:
10550 lpfc_free_iocb_list(phba);
10551out_unset_driver_resource_s4:
10552 lpfc_sli4_driver_resource_unset(phba);
10553out_unset_pci_mem_s4:
10554 lpfc_sli4_pci_mem_unset(phba);
10555out_disable_pci_dev:
10556 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040010557 if (shost)
10558 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -040010559out_free_phba:
10560 lpfc_hba_free(phba);
10561 return error;
10562}
10563
10564/**
10565 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
10566 * @pdev: pointer to PCI device
10567 *
10568 * This routine is called from the kernel's PCI subsystem to device with
10569 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10570 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10571 * device to be removed from the PCI subsystem properly.
10572 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010573static void
James Smartda0436e2009-05-22 14:51:39 -040010574lpfc_pci_remove_one_s4(struct pci_dev *pdev)
10575{
10576 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10577 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
10578 struct lpfc_vport **vports;
10579 struct lpfc_hba *phba = vport->phba;
10580 int i;
10581
10582 /* Mark the device unloading flag */
10583 spin_lock_irq(&phba->hbalock);
10584 vport->load_flag |= FC_UNLOADING;
10585 spin_unlock_irq(&phba->hbalock);
10586
10587 /* Free the HBA sysfs attributes */
10588 lpfc_free_sysfs_attr(vport);
10589
10590 /* Release all the vports against this physical port */
10591 vports = lpfc_create_vport_work_array(phba);
10592 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040010593 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10594 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
10595 continue;
James Smartda0436e2009-05-22 14:51:39 -040010596 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040010597 }
James Smartda0436e2009-05-22 14:51:39 -040010598 lpfc_destroy_vport_work_array(phba, vports);
10599
10600 /* Remove FC host and then SCSI host with the physical port */
10601 fc_remove_host(shost);
10602 scsi_remove_host(shost);
10603
10604 /* Perform cleanup on the physical port */
10605 lpfc_cleanup(vport);
10606
10607 /*
10608 * Bring down the SLI Layer. This step disables all interrupts,
10609 * clears the rings, discards all mailbox commands, and resets
10610 * the HBA FCoE function.
10611 */
10612 lpfc_debugfs_terminate(vport);
10613 lpfc_sli4_hba_unset(phba);
10614
10615 spin_lock_irq(&phba->hbalock);
10616 list_del_init(&vport->listentry);
10617 spin_unlock_irq(&phba->hbalock);
10618
James Smart3677a3a2010-09-29 11:19:14 -040010619 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -040010620 * buffers are released to their corresponding pools here.
10621 */
10622 lpfc_scsi_free(phba);
James Smart67d12732012-08-03 12:36:13 -040010623
James Smartda0436e2009-05-22 14:51:39 -040010624 lpfc_sli4_driver_resource_unset(phba);
10625
10626 /* Unmap adapter Control and Doorbell registers */
10627 lpfc_sli4_pci_mem_unset(phba);
10628
10629 /* Release PCI resources and disable device's PCI function */
10630 scsi_host_put(shost);
10631 lpfc_disable_pci_dev(phba);
10632
10633 /* Finally, free the driver's device data structure */
10634 lpfc_hba_free(phba);
10635
10636 return;
10637}
10638
10639/**
10640 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
10641 * @pdev: pointer to PCI device
10642 * @msg: power management message
10643 *
10644 * This routine is called from the kernel's PCI subsystem to support system
10645 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
10646 * this method, it quiesces the device by stopping the driver's worker
10647 * thread for the device, turning off device's interrupt and DMA, and bring
10648 * the device offline. Note that as the driver implements the minimum PM
10649 * requirements to a power-aware driver's PM support for suspend/resume -- all
10650 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
10651 * method call will be treated as SUSPEND and the driver will fully
10652 * reinitialize its device during resume() method call, the driver will set
10653 * device to PCI_D3hot state in PCI config space instead of setting it
10654 * according to the @msg provided by the PM.
10655 *
10656 * Return code
10657 * 0 - driver suspended the device
10658 * Error otherwise
10659 **/
10660static int
10661lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
10662{
10663 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10664 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10665
10666 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -040010667 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -040010668
10669 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040010670 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -040010671 lpfc_offline(phba);
10672 kthread_stop(phba->worker_thread);
10673
10674 /* Disable interrupt from device */
10675 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040010676 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040010677
10678 /* Save device state to PCI config space */
10679 pci_save_state(pdev);
10680 pci_set_power_state(pdev, PCI_D3hot);
10681
10682 return 0;
10683}
10684
10685/**
10686 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
10687 * @pdev: pointer to PCI device
10688 *
10689 * This routine is called from the kernel's PCI subsystem to support system
10690 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
10691 * this method, it restores the device's PCI config space state and fully
10692 * reinitializes the device and brings it online. Note that as the driver
10693 * implements the minimum PM requirements to a power-aware driver's PM for
10694 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10695 * to the suspend() method call will be treated as SUSPEND and the driver
10696 * will fully reinitialize its device during resume() method call, the device
10697 * will be set to PCI_D0 directly in PCI config space before restoring the
10698 * state.
10699 *
10700 * Return code
10701 * 0 - driver suspended the device
10702 * Error otherwise
10703 **/
10704static int
10705lpfc_pci_resume_one_s4(struct pci_dev *pdev)
10706{
10707 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10708 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10709 uint32_t intr_mode;
10710 int error;
10711
10712 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10713 "0292 PCI device Power Management resume.\n");
10714
10715 /* Restore device state from PCI config space */
10716 pci_set_power_state(pdev, PCI_D0);
10717 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050010718
10719 /*
10720 * As the new kernel behavior of pci_restore_state() API call clears
10721 * device saved_state flag, need to save the restored state again.
10722 */
10723 pci_save_state(pdev);
10724
James Smartda0436e2009-05-22 14:51:39 -040010725 if (pdev->is_busmaster)
10726 pci_set_master(pdev);
10727
10728 /* Startup the kernel thread for this host adapter. */
10729 phba->worker_thread = kthread_run(lpfc_do_work, phba,
10730 "lpfc_worker_%d", phba->brd_no);
10731 if (IS_ERR(phba->worker_thread)) {
10732 error = PTR_ERR(phba->worker_thread);
10733 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10734 "0293 PM resume failed to start worker "
10735 "thread: error=x%x.\n", error);
10736 return error;
10737 }
10738
10739 /* Configure and enable interrupt */
10740 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
10741 if (intr_mode == LPFC_INTR_ERROR) {
10742 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10743 "0294 PM resume Failed to enable interrupt\n");
10744 return -EIO;
10745 } else
10746 phba->intr_mode = intr_mode;
10747
10748 /* Restart HBA and bring it online */
10749 lpfc_sli_brdrestart(phba);
10750 lpfc_online(phba);
10751
10752 /* Log the current active interrupt mode */
10753 lpfc_log_intr_mode(phba, phba->intr_mode);
10754
10755 return 0;
10756}
10757
10758/**
James Smart75baf692010-06-08 18:31:21 -040010759 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
10760 * @phba: pointer to lpfc hba data structure.
10761 *
10762 * This routine is called to prepare the SLI4 device for PCI slot recover. It
10763 * aborts all the outstanding SCSI I/Os to the pci device.
10764 **/
10765static void
10766lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
10767{
James Smart75baf692010-06-08 18:31:21 -040010768 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10769 "2828 PCI channel I/O abort preparing for recovery\n");
10770 /*
10771 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10772 * and let the SCSI mid-layer to retry them to recover.
10773 */
James Smartdb55fba2014-04-04 13:52:02 -040010774 lpfc_sli_abort_fcp_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040010775}
10776
10777/**
10778 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
10779 * @phba: pointer to lpfc hba data structure.
10780 *
10781 * This routine is called to prepare the SLI4 device for PCI slot reset. It
10782 * disables the device interrupt and pci device, and aborts the internal FCP
10783 * pending I/Os.
10784 **/
10785static void
10786lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
10787{
10788 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10789 "2826 PCI channel disable preparing for reset\n");
10790
10791 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040010792 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010793
10794 /* Block all SCSI devices' I/Os on the host */
10795 lpfc_scsi_dev_block(phba);
10796
James Smartea714f32013-04-17 20:18:47 -040010797 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10798 lpfc_sli_flush_fcp_rings(phba);
10799
James Smart75baf692010-06-08 18:31:21 -040010800 /* stop all timers */
10801 lpfc_stop_hba_timers(phba);
10802
10803 /* Disable interrupt and pci device */
10804 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040010805 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -040010806 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -040010807}
10808
10809/**
10810 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
10811 * @phba: pointer to lpfc hba data structure.
10812 *
10813 * This routine is called to prepare the SLI4 device for PCI slot permanently
10814 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10815 * pending I/Os.
10816 **/
10817static void
10818lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
10819{
10820 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10821 "2827 PCI channel permanent disable for failure\n");
10822
10823 /* Block all SCSI devices' I/Os on the host */
10824 lpfc_scsi_dev_block(phba);
10825
10826 /* stop all timers */
10827 lpfc_stop_hba_timers(phba);
10828
10829 /* Clean up all driver's outstanding SCSI I/Os */
10830 lpfc_sli_flush_fcp_rings(phba);
10831}
10832
10833/**
James Smartda0436e2009-05-22 14:51:39 -040010834 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
10835 * @pdev: pointer to PCI device.
10836 * @state: the current PCI connection state.
10837 *
10838 * This routine is called from the PCI subsystem for error handling to device
10839 * with SLI-4 interface spec. This function is called by the PCI subsystem
10840 * after a PCI bus error affecting this device has been detected. When this
10841 * function is invoked, it will need to stop all the I/Os and interrupt(s)
10842 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
10843 * for the PCI subsystem to perform proper recovery as desired.
10844 *
10845 * Return codes
10846 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10847 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10848 **/
10849static pci_ers_result_t
10850lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
10851{
James Smart75baf692010-06-08 18:31:21 -040010852 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10853 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10854
10855 switch (state) {
10856 case pci_channel_io_normal:
10857 /* Non-fatal error, prepare for recovery */
10858 lpfc_sli4_prep_dev_for_recover(phba);
10859 return PCI_ERS_RESULT_CAN_RECOVER;
10860 case pci_channel_io_frozen:
10861 /* Fatal error, prepare for slot reset */
10862 lpfc_sli4_prep_dev_for_reset(phba);
10863 return PCI_ERS_RESULT_NEED_RESET;
10864 case pci_channel_io_perm_failure:
10865 /* Permanent failure, prepare for device down */
10866 lpfc_sli4_prep_dev_for_perm_failure(phba);
10867 return PCI_ERS_RESULT_DISCONNECT;
10868 default:
10869 /* Unknown state, prepare and request slot reset */
10870 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10871 "2825 Unknown PCI error state: x%x\n", state);
10872 lpfc_sli4_prep_dev_for_reset(phba);
10873 return PCI_ERS_RESULT_NEED_RESET;
10874 }
James Smartda0436e2009-05-22 14:51:39 -040010875}
10876
10877/**
10878 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
10879 * @pdev: pointer to PCI device.
10880 *
10881 * This routine is called from the PCI subsystem for error handling to device
10882 * with SLI-4 interface spec. It is called after PCI bus has been reset to
10883 * restart the PCI card from scratch, as if from a cold-boot. During the
10884 * PCI subsystem error recovery, after the driver returns
10885 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10886 * recovery and then call this routine before calling the .resume method to
10887 * recover the device. This function will initialize the HBA device, enable
10888 * the interrupt, but it will just put the HBA to offline state without
10889 * passing any I/O traffic.
10890 *
10891 * Return codes
10892 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10893 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10894 */
10895static pci_ers_result_t
10896lpfc_io_slot_reset_s4(struct pci_dev *pdev)
10897{
James Smart75baf692010-06-08 18:31:21 -040010898 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10899 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10900 struct lpfc_sli *psli = &phba->sli;
10901 uint32_t intr_mode;
10902
10903 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
10904 if (pci_enable_device_mem(pdev)) {
10905 printk(KERN_ERR "lpfc: Cannot re-enable "
10906 "PCI device after reset.\n");
10907 return PCI_ERS_RESULT_DISCONNECT;
10908 }
10909
10910 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040010911
10912 /*
10913 * As the new kernel behavior of pci_restore_state() API call clears
10914 * device saved_state flag, need to save the restored state again.
10915 */
10916 pci_save_state(pdev);
10917
James Smart75baf692010-06-08 18:31:21 -040010918 if (pdev->is_busmaster)
10919 pci_set_master(pdev);
10920
10921 spin_lock_irq(&phba->hbalock);
10922 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
10923 spin_unlock_irq(&phba->hbalock);
10924
10925 /* Configure and enable interrupt */
10926 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
10927 if (intr_mode == LPFC_INTR_ERROR) {
10928 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10929 "2824 Cannot re-enable interrupt after "
10930 "slot reset.\n");
10931 return PCI_ERS_RESULT_DISCONNECT;
10932 } else
10933 phba->intr_mode = intr_mode;
10934
10935 /* Log the current active interrupt mode */
10936 lpfc_log_intr_mode(phba, phba->intr_mode);
10937
James Smartda0436e2009-05-22 14:51:39 -040010938 return PCI_ERS_RESULT_RECOVERED;
10939}
10940
10941/**
10942 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
10943 * @pdev: pointer to PCI device
10944 *
10945 * This routine is called from the PCI subsystem for error handling to device
10946 * with SLI-4 interface spec. It is called when kernel error recovery tells
10947 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10948 * error recovery. After this call, traffic can start to flow from this device
10949 * again.
10950 **/
10951static void
10952lpfc_io_resume_s4(struct pci_dev *pdev)
10953{
James Smart75baf692010-06-08 18:31:21 -040010954 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10955 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10956
10957 /*
10958 * In case of slot reset, as function reset is performed through
10959 * mailbox command which needs DMA to be enabled, this operation
10960 * has to be moved to the io resume phase. Taking device offline
10961 * will perform the necessary cleanup.
10962 */
10963 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
10964 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040010965 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010966 lpfc_offline(phba);
10967 lpfc_sli_brdrestart(phba);
10968 /* Bring the device back online */
10969 lpfc_online(phba);
10970 }
10971
10972 /* Clean up Advanced Error Reporting (AER) if needed */
10973 if (phba->hba_flag & HBA_AER_ENABLED)
10974 pci_cleanup_aer_uncorrect_error_status(pdev);
James Smartda0436e2009-05-22 14:51:39 -040010975}
10976
10977/**
James Smart3772a992009-05-22 14:50:54 -040010978 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
10979 * @pdev: pointer to PCI device
10980 * @pid: pointer to PCI device identifier
10981 *
10982 * This routine is to be registered to the kernel's PCI subsystem. When an
10983 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
10984 * at PCI device-specific information of the device and driver to see if the
10985 * driver state that it can support this kind of device. If the match is
10986 * successful, the driver core invokes this routine. This routine dispatches
10987 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
10988 * do all the initialization that it needs to do to handle the HBA device
10989 * properly.
10990 *
10991 * Return code
10992 * 0 - driver can claim the device
10993 * negative value - driver can not claim the device
10994 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010995static int
James Smart3772a992009-05-22 14:50:54 -040010996lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
10997{
10998 int rc;
James Smart8fa38512009-07-19 10:01:03 -040010999 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040011000
James Smart28baac72010-02-12 14:42:03 -050011001 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040011002 return -ENODEV;
11003
James Smart8fa38512009-07-19 10:01:03 -040011004 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050011005 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040011006 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040011007 else
James Smart3772a992009-05-22 14:50:54 -040011008 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040011009
James Smart3772a992009-05-22 14:50:54 -040011010 return rc;
11011}
11012
11013/**
11014 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
11015 * @pdev: pointer to PCI device
11016 *
11017 * This routine is to be registered to the kernel's PCI subsystem. When an
11018 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
11019 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
11020 * remove routine, which will perform all the necessary cleanup for the
11021 * device to be removed from the PCI subsystem properly.
11022 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011023static void
James Smart3772a992009-05-22 14:50:54 -040011024lpfc_pci_remove_one(struct pci_dev *pdev)
11025{
11026 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11027 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11028
11029 switch (phba->pci_dev_grp) {
11030 case LPFC_PCI_DEV_LP:
11031 lpfc_pci_remove_one_s3(pdev);
11032 break;
James Smartda0436e2009-05-22 14:51:39 -040011033 case LPFC_PCI_DEV_OC:
11034 lpfc_pci_remove_one_s4(pdev);
11035 break;
James Smart3772a992009-05-22 14:50:54 -040011036 default:
11037 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11038 "1424 Invalid PCI device group: 0x%x\n",
11039 phba->pci_dev_grp);
11040 break;
11041 }
11042 return;
11043}
11044
11045/**
11046 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
11047 * @pdev: pointer to PCI device
11048 * @msg: power management message
11049 *
11050 * This routine is to be registered to the kernel's PCI subsystem to support
11051 * system Power Management (PM). When PM invokes this method, it dispatches
11052 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
11053 * suspend the device.
11054 *
11055 * Return code
11056 * 0 - driver suspended the device
11057 * Error otherwise
11058 **/
11059static int
11060lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
11061{
11062 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11063 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11064 int rc = -ENODEV;
11065
11066 switch (phba->pci_dev_grp) {
11067 case LPFC_PCI_DEV_LP:
11068 rc = lpfc_pci_suspend_one_s3(pdev, msg);
11069 break;
James Smartda0436e2009-05-22 14:51:39 -040011070 case LPFC_PCI_DEV_OC:
11071 rc = lpfc_pci_suspend_one_s4(pdev, msg);
11072 break;
James Smart3772a992009-05-22 14:50:54 -040011073 default:
11074 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11075 "1425 Invalid PCI device group: 0x%x\n",
11076 phba->pci_dev_grp);
11077 break;
11078 }
11079 return rc;
11080}
11081
11082/**
11083 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
11084 * @pdev: pointer to PCI device
11085 *
11086 * This routine is to be registered to the kernel's PCI subsystem to support
11087 * system Power Management (PM). When PM invokes this method, it dispatches
11088 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
11089 * resume the device.
11090 *
11091 * Return code
11092 * 0 - driver suspended the device
11093 * Error otherwise
11094 **/
11095static int
11096lpfc_pci_resume_one(struct pci_dev *pdev)
11097{
11098 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11099 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11100 int rc = -ENODEV;
11101
11102 switch (phba->pci_dev_grp) {
11103 case LPFC_PCI_DEV_LP:
11104 rc = lpfc_pci_resume_one_s3(pdev);
11105 break;
James Smartda0436e2009-05-22 14:51:39 -040011106 case LPFC_PCI_DEV_OC:
11107 rc = lpfc_pci_resume_one_s4(pdev);
11108 break;
James Smart3772a992009-05-22 14:50:54 -040011109 default:
11110 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11111 "1426 Invalid PCI device group: 0x%x\n",
11112 phba->pci_dev_grp);
11113 break;
11114 }
11115 return rc;
11116}
11117
11118/**
11119 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
11120 * @pdev: pointer to PCI device.
11121 * @state: the current PCI connection state.
11122 *
11123 * This routine is registered to the PCI subsystem for error handling. This
11124 * function is called by the PCI subsystem after a PCI bus error affecting
11125 * this device has been detected. When this routine is invoked, it dispatches
11126 * the action to the proper SLI-3 or SLI-4 device error detected handling
11127 * routine, which will perform the proper error detected operation.
11128 *
11129 * Return codes
11130 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11131 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11132 **/
11133static pci_ers_result_t
11134lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
11135{
11136 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11137 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11138 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11139
11140 switch (phba->pci_dev_grp) {
11141 case LPFC_PCI_DEV_LP:
11142 rc = lpfc_io_error_detected_s3(pdev, state);
11143 break;
James Smartda0436e2009-05-22 14:51:39 -040011144 case LPFC_PCI_DEV_OC:
11145 rc = lpfc_io_error_detected_s4(pdev, state);
11146 break;
James Smart3772a992009-05-22 14:50:54 -040011147 default:
11148 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11149 "1427 Invalid PCI device group: 0x%x\n",
11150 phba->pci_dev_grp);
11151 break;
11152 }
11153 return rc;
11154}
11155
11156/**
11157 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
11158 * @pdev: pointer to PCI device.
11159 *
11160 * This routine is registered to the PCI subsystem for error handling. This
11161 * function is called after PCI bus has been reset to restart the PCI card
11162 * from scratch, as if from a cold-boot. When this routine is invoked, it
11163 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
11164 * routine, which will perform the proper device reset.
11165 *
11166 * Return codes
11167 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11168 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11169 **/
11170static pci_ers_result_t
11171lpfc_io_slot_reset(struct pci_dev *pdev)
11172{
11173 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11174 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11175 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11176
11177 switch (phba->pci_dev_grp) {
11178 case LPFC_PCI_DEV_LP:
11179 rc = lpfc_io_slot_reset_s3(pdev);
11180 break;
James Smartda0436e2009-05-22 14:51:39 -040011181 case LPFC_PCI_DEV_OC:
11182 rc = lpfc_io_slot_reset_s4(pdev);
11183 break;
James Smart3772a992009-05-22 14:50:54 -040011184 default:
11185 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11186 "1428 Invalid PCI device group: 0x%x\n",
11187 phba->pci_dev_grp);
11188 break;
11189 }
11190 return rc;
11191}
11192
11193/**
11194 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
11195 * @pdev: pointer to PCI device
11196 *
11197 * This routine is registered to the PCI subsystem for error handling. It
11198 * is called when kernel error recovery tells the lpfc driver that it is
11199 * OK to resume normal PCI operation after PCI bus error recovery. When
11200 * this routine is invoked, it dispatches the action to the proper SLI-3
11201 * or SLI-4 device io_resume routine, which will resume the device operation.
11202 **/
11203static void
11204lpfc_io_resume(struct pci_dev *pdev)
11205{
11206 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11207 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11208
11209 switch (phba->pci_dev_grp) {
11210 case LPFC_PCI_DEV_LP:
11211 lpfc_io_resume_s3(pdev);
11212 break;
James Smartda0436e2009-05-22 14:51:39 -040011213 case LPFC_PCI_DEV_OC:
11214 lpfc_io_resume_s4(pdev);
11215 break;
James Smart3772a992009-05-22 14:50:54 -040011216 default:
11217 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11218 "1429 Invalid PCI device group: 0x%x\n",
11219 phba->pci_dev_grp);
11220 break;
11221 }
11222 return;
11223}
11224
James Smart1ba981f2014-02-20 09:56:45 -050011225/**
11226 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
11227 * @phba: pointer to lpfc hba data structure.
11228 *
11229 * This routine checks to see if OAS is supported for this adapter. If
11230 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
11231 * the enable oas flag is cleared and the pool created for OAS device data
11232 * is destroyed.
11233 *
11234 **/
11235void
11236lpfc_sli4_oas_verify(struct lpfc_hba *phba)
11237{
11238
11239 if (!phba->cfg_EnableXLane)
11240 return;
11241
11242 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
11243 phba->cfg_fof = 1;
11244 } else {
James Smartf38fa0b2014-04-04 13:52:21 -040011245 phba->cfg_fof = 0;
James Smart1ba981f2014-02-20 09:56:45 -050011246 if (phba->device_data_mem_pool)
11247 mempool_destroy(phba->device_data_mem_pool);
11248 phba->device_data_mem_pool = NULL;
11249 }
11250
11251 return;
11252}
11253
11254/**
11255 * lpfc_fof_queue_setup - Set up all the fof queues
11256 * @phba: pointer to lpfc hba data structure.
11257 *
11258 * This routine is invoked to set up all the fof queues for the FC HBA
11259 * operation.
11260 *
11261 * Return codes
11262 * 0 - successful
11263 * -ENOMEM - No available memory
11264 **/
11265int
11266lpfc_fof_queue_setup(struct lpfc_hba *phba)
11267{
11268 struct lpfc_sli *psli = &phba->sli;
11269 int rc;
11270
11271 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
11272 if (rc)
11273 return -ENOMEM;
11274
James Smartf38fa0b2014-04-04 13:52:21 -040011275 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050011276
11277 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
11278 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
11279 if (rc)
11280 goto out_oas_cq;
11281
11282 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
11283 phba->sli4_hba.oas_cq, LPFC_FCP);
11284 if (rc)
11285 goto out_oas_wq;
11286
11287 phba->sli4_hba.oas_cq->pring = &psli->ring[LPFC_FCP_OAS_RING];
11288 phba->sli4_hba.oas_ring = &psli->ring[LPFC_FCP_OAS_RING];
11289 }
11290
11291 return 0;
11292
11293out_oas_wq:
James Smartf38fa0b2014-04-04 13:52:21 -040011294 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
James Smart1ba981f2014-02-20 09:56:45 -050011295out_oas_cq:
11296 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
11297 return rc;
11298
11299}
11300
11301/**
11302 * lpfc_fof_queue_create - Create all the fof queues
11303 * @phba: pointer to lpfc hba data structure.
11304 *
11305 * This routine is invoked to allocate all the fof queues for the FC HBA
11306 * operation. For each SLI4 queue type, the parameters such as queue entry
11307 * count (queue depth) shall be taken from the module parameter. For now,
11308 * we just use some constant number as place holder.
11309 *
11310 * Return codes
11311 * 0 - successful
11312 * -ENOMEM - No availble memory
11313 * -EIO - The mailbox failed to complete successfully.
11314 **/
11315int
11316lpfc_fof_queue_create(struct lpfc_hba *phba)
11317{
11318 struct lpfc_queue *qdesc;
11319
11320 /* Create FOF EQ */
11321 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
11322 phba->sli4_hba.eq_ecount);
11323 if (!qdesc)
11324 goto out_error;
11325
11326 phba->sli4_hba.fof_eq = qdesc;
11327
James Smartf38fa0b2014-04-04 13:52:21 -040011328 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050011329
11330 /* Create OAS CQ */
11331 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
11332 phba->sli4_hba.cq_ecount);
11333 if (!qdesc)
11334 goto out_error;
11335
11336 phba->sli4_hba.oas_cq = qdesc;
11337
11338 /* Create OAS WQ */
11339 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
11340 phba->sli4_hba.wq_ecount);
11341 if (!qdesc)
11342 goto out_error;
11343
11344 phba->sli4_hba.oas_wq = qdesc;
11345
11346 }
11347 return 0;
11348
11349out_error:
11350 lpfc_fof_queue_destroy(phba);
11351 return -ENOMEM;
11352}
11353
11354/**
11355 * lpfc_fof_queue_destroy - Destroy all the fof queues
11356 * @phba: pointer to lpfc hba data structure.
11357 *
11358 * This routine is invoked to release all the SLI4 queues with the FC HBA
11359 * operation.
11360 *
11361 * Return codes
11362 * 0 - successful
11363 **/
11364int
11365lpfc_fof_queue_destroy(struct lpfc_hba *phba)
11366{
11367 /* Release FOF Event queue */
11368 if (phba->sli4_hba.fof_eq != NULL) {
11369 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
11370 phba->sli4_hba.fof_eq = NULL;
11371 }
11372
11373 /* Release OAS Completion queue */
11374 if (phba->sli4_hba.oas_cq != NULL) {
11375 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
11376 phba->sli4_hba.oas_cq = NULL;
11377 }
11378
11379 /* Release OAS Work queue */
11380 if (phba->sli4_hba.oas_wq != NULL) {
11381 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
11382 phba->sli4_hba.oas_wq = NULL;
11383 }
11384 return 0;
11385}
11386
dea31012005-04-17 16:05:31 -050011387static struct pci_device_id lpfc_id_table[] = {
11388 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
11389 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -040011390 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
11391 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011392 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
11393 PCI_ANY_ID, PCI_ANY_ID, },
11394 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
11395 PCI_ANY_ID, PCI_ANY_ID, },
11396 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
11397 PCI_ANY_ID, PCI_ANY_ID, },
11398 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
11399 PCI_ANY_ID, PCI_ANY_ID, },
11400 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
11401 PCI_ANY_ID, PCI_ANY_ID, },
11402 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
11403 PCI_ANY_ID, PCI_ANY_ID, },
11404 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
11405 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011406 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
11407 PCI_ANY_ID, PCI_ANY_ID, },
11408 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
11409 PCI_ANY_ID, PCI_ANY_ID, },
11410 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
11411 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011412 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
11413 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011414 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
11415 PCI_ANY_ID, PCI_ANY_ID, },
11416 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
11417 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011418 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
11419 PCI_ANY_ID, PCI_ANY_ID, },
11420 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
11421 PCI_ANY_ID, PCI_ANY_ID, },
11422 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
11423 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -040011424 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
11425 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011426 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
11427 PCI_ANY_ID, PCI_ANY_ID, },
11428 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
11429 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011430 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
11431 PCI_ANY_ID, PCI_ANY_ID, },
11432 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
11433 PCI_ANY_ID, PCI_ANY_ID, },
11434 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
11435 PCI_ANY_ID, PCI_ANY_ID, },
11436 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
11437 PCI_ANY_ID, PCI_ANY_ID, },
11438 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
11439 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -050011440 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
11441 PCI_ANY_ID, PCI_ANY_ID, },
11442 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
11443 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -040011444 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
11445 PCI_ANY_ID, PCI_ANY_ID, },
11446 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
11447 PCI_ANY_ID, PCI_ANY_ID, },
11448 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
11449 PCI_ANY_ID, PCI_ANY_ID, },
11450 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
11451 PCI_ANY_ID, PCI_ANY_ID, },
11452 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
11453 PCI_ANY_ID, PCI_ANY_ID, },
11454 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
11455 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -040011456 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
11457 PCI_ANY_ID, PCI_ANY_ID, },
11458 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
11459 PCI_ANY_ID, PCI_ANY_ID, },
11460 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
11461 PCI_ANY_ID, PCI_ANY_ID, },
James Smart3772a992009-05-22 14:50:54 -040011462 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
11463 PCI_ANY_ID, PCI_ANY_ID, },
James Smarta747c9c2009-11-18 15:41:10 -050011464 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT,
11465 PCI_ANY_ID, PCI_ANY_ID, },
11466 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON,
James Smart6669f9b2009-10-02 15:16:45 -040011467 PCI_ANY_ID, PCI_ANY_ID, },
James Smart98fc5dd2010-06-07 15:24:29 -040011468 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS,
11469 PCI_ANY_ID, PCI_ANY_ID, },
James Smart085c6472010-11-20 23:11:37 -050011470 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC,
11471 PCI_ANY_ID, PCI_ANY_ID, },
11472 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE,
11473 PCI_ANY_ID, PCI_ANY_ID, },
James Smartc0c11512011-05-24 11:41:34 -040011474 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF,
11475 PCI_ANY_ID, PCI_ANY_ID, },
11476 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF,
11477 PCI_ANY_ID, PCI_ANY_ID, },
James Smartd38dd522015-08-31 16:48:17 -040011478 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_G6_FC,
11479 PCI_ANY_ID, PCI_ANY_ID, },
James Smartf8cafd32012-08-03 12:42:51 -040011480 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK,
11481 PCI_ANY_ID, PCI_ANY_ID, },
11482 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF,
11483 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -050011484 { 0 }
11485};
11486
11487MODULE_DEVICE_TABLE(pci, lpfc_id_table);
11488
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070011489static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060011490 .error_detected = lpfc_io_error_detected,
11491 .slot_reset = lpfc_io_slot_reset,
11492 .resume = lpfc_io_resume,
11493};
11494
dea31012005-04-17 16:05:31 -050011495static struct pci_driver lpfc_driver = {
11496 .name = LPFC_DRIVER_NAME,
11497 .id_table = lpfc_id_table,
11498 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011499 .remove = lpfc_pci_remove_one,
James Smart3a55b532008-12-04 22:38:54 -050011500 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040011501 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050011502 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050011503};
11504
James Smart3ef6d242012-01-18 16:23:48 -050011505static const struct file_operations lpfc_mgmt_fop = {
Al Viro858feac2013-04-14 22:39:37 -040011506 .owner = THIS_MODULE,
James Smart3ef6d242012-01-18 16:23:48 -050011507};
11508
11509static struct miscdevice lpfc_mgmt_dev = {
11510 .minor = MISC_DYNAMIC_MINOR,
11511 .name = "lpfcmgmt",
11512 .fops = &lpfc_mgmt_fop,
11513};
11514
James Smarte59058c2008-08-24 21:49:00 -040011515/**
James Smart3621a712009-04-06 18:47:14 -040011516 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040011517 *
11518 * This routine is to be invoked when the lpfc module is loaded into the
11519 * kernel. The special kernel macro module_init() is used to indicate the
11520 * role of this routine to the kernel as lpfc module entry point.
11521 *
11522 * Return codes
11523 * 0 - successful
11524 * -ENOMEM - FC attach transport failed
11525 * all others - failed
11526 */
dea31012005-04-17 16:05:31 -050011527static int __init
11528lpfc_init(void)
11529{
James Smart7bb03bb2013-04-17 20:19:16 -040011530 int cpu;
dea31012005-04-17 16:05:31 -050011531 int error = 0;
11532
11533 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040011534 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050011535
James Smart3ef6d242012-01-18 16:23:48 -050011536 error = misc_register(&lpfc_mgmt_dev);
11537 if (error)
11538 printk(KERN_ERR "Could not register lpfcmgmt device, "
11539 "misc_register returned with status %d", error);
11540
James Smart7ee5d432007-10-27 13:37:17 -040011541 if (lpfc_enable_npiv) {
11542 lpfc_transport_functions.vport_create = lpfc_vport_create;
11543 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
11544 }
dea31012005-04-17 16:05:31 -050011545 lpfc_transport_template =
11546 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040011547 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050011548 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040011549 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -040011550 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -040011551 fc_attach_transport(&lpfc_vport_transport_functions);
11552 if (lpfc_vport_transport_template == NULL) {
11553 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040011554 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -040011555 }
James Smart7ee5d432007-10-27 13:37:17 -040011556 }
James Smart7bb03bb2013-04-17 20:19:16 -040011557
11558 /* Initialize in case vector mapping is needed */
James Smartb246de12013-05-31 17:03:07 -040011559 lpfc_used_cpu = NULL;
11560 lpfc_present_cpu = 0;
11561 for_each_present_cpu(cpu)
11562 lpfc_present_cpu++;
James Smart7bb03bb2013-04-17 20:19:16 -040011563
dea31012005-04-17 16:05:31 -050011564 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050011565 if (error) {
dea31012005-04-17 16:05:31 -050011566 fc_release_transport(lpfc_transport_template);
James Smartd7c255b2008-08-24 21:50:00 -040011567 if (lpfc_enable_npiv)
11568 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050011569 }
dea31012005-04-17 16:05:31 -050011570
11571 return error;
11572}
11573
James Smarte59058c2008-08-24 21:49:00 -040011574/**
James Smart3621a712009-04-06 18:47:14 -040011575 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040011576 *
11577 * This routine is invoked when the lpfc module is removed from the kernel.
11578 * The special kernel macro module_exit() is used to indicate the role of
11579 * this routine to the kernel as lpfc module exit point.
11580 */
dea31012005-04-17 16:05:31 -050011581static void __exit
11582lpfc_exit(void)
11583{
James Smart3ef6d242012-01-18 16:23:48 -050011584 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050011585 pci_unregister_driver(&lpfc_driver);
11586 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040011587 if (lpfc_enable_npiv)
11588 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050011589 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040011590 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
11591 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050011592 (1L << _dump_buf_data_order), _dump_buf_data);
11593 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
11594 }
11595
11596 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040011597 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
11598 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050011599 (1L << _dump_buf_dif_order), _dump_buf_dif);
11600 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
11601 }
James Smartb246de12013-05-31 17:03:07 -040011602 kfree(lpfc_used_cpu);
Johannes Thumshirn79739672015-08-31 16:48:11 -040011603 idr_destroy(&lpfc_hba_index);
dea31012005-04-17 16:05:31 -050011604}
11605
11606module_init(lpfc_init);
11607module_exit(lpfc_exit);
11608MODULE_LICENSE("GPL");
11609MODULE_DESCRIPTION(LPFC_MODULE_DESC);
11610MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
11611MODULE_VERSION("0:" LPFC_DRIVER_VERSION);