blob: bdb8f2da27cc978f48c199125768ff48aa579ae9 [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 Smart792581d2011-03-11 16:06:44 -05004 * Copyright (C) 2004-2011 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>
27#include <linux/kthread.h>
28#include <linux/pci.h>
29#include <linux/spinlock.h>
James Smart92d7f7b2007-06-17 19:56:38 -050030#include <linux/ctype.h>
James Smart0d878412009-10-02 15:16:56 -040031#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
James Smart52d52442011-05-24 11:42:45 -040033#include <linux/firmware.h>
dea31012005-04-17 16:05:31 -050034
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040035#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050036#include <scsi/scsi_device.h>
37#include <scsi/scsi_host.h>
38#include <scsi/scsi_transport_fc.h>
39
James Smartda0436e2009-05-22 14:51:39 -040040#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050041#include "lpfc_hw.h"
42#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040043#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040044#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050045#include "lpfc_disc.h"
46#include "lpfc_scsi.h"
47#include "lpfc.h"
48#include "lpfc_logmsg.h"
49#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050050#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050051#include "lpfc_version.h"
52
James Smart81301a92008-12-04 22:39:46 -050053char *_dump_buf_data;
54unsigned long _dump_buf_data_order;
55char *_dump_buf_dif;
56unsigned long _dump_buf_dif_order;
57spinlock_t _dump_buf_lock;
58
dea31012005-04-17 16:05:31 -050059static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
60static int lpfc_post_rcv_buf(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040061static int lpfc_sli4_queue_create(struct lpfc_hba *);
62static void lpfc_sli4_queue_destroy(struct lpfc_hba *);
63static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
64static int lpfc_setup_endian_order(struct lpfc_hba *);
65static int lpfc_sli4_read_config(struct lpfc_hba *);
66static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
67static void lpfc_free_sgl_list(struct lpfc_hba *);
68static int lpfc_init_sgl_list(struct lpfc_hba *);
69static int lpfc_init_active_sgl_array(struct lpfc_hba *);
70static void lpfc_free_active_sgl(struct lpfc_hba *);
71static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
72static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
73static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
74static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
75static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
dea31012005-04-17 16:05:31 -050076
77static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050078static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -050079static DEFINE_IDR(lpfc_hba_index);
80
James Smarte59058c2008-08-24 21:49:00 -040081/**
James Smart3621a712009-04-06 18:47:14 -040082 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
James Smarte59058c2008-08-24 21:49:00 -040083 * @phba: pointer to lpfc hba data structure.
84 *
85 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
86 * mailbox command. It retrieves the revision information from the HBA and
87 * collects the Vital Product Data (VPD) about the HBA for preparing the
88 * configuration of the HBA.
89 *
90 * Return codes:
91 * 0 - success.
92 * -ERESTART - requests the SLI layer to reset the HBA and try again.
93 * Any other value - indicates an error.
94 **/
dea31012005-04-17 16:05:31 -050095int
James Smart2e0fef82007-06-17 19:56:36 -050096lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -050097{
98 lpfc_vpd_t *vp = &phba->vpd;
99 int i = 0, rc;
100 LPFC_MBOXQ_t *pmb;
101 MAILBOX_t *mb;
102 char *lpfc_vpd_data = NULL;
103 uint16_t offset = 0;
104 static char licensed[56] =
105 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -0400106 static int init_key = 1;
dea31012005-04-17 16:05:31 -0500107
108 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
109 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500110 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500111 return -ENOMEM;
112 }
113
James Smart04c68492009-05-22 14:52:52 -0400114 mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -0500115 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -0500116
117 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -0400118 if (init_key) {
119 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -0500120
James Smart65a29c12006-07-06 15:50:50 -0400121 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
122 *ptext = cpu_to_be32(*ptext);
123 init_key = 0;
124 }
dea31012005-04-17 16:05:31 -0500125
126 lpfc_read_nv(phba, pmb);
127 memset((char*)mb->un.varRDnvp.rsvd3, 0,
128 sizeof (mb->un.varRDnvp.rsvd3));
129 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
130 sizeof (licensed));
131
132 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
133
134 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500135 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400136 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500137 "error, mbxCmd x%x READ_NVPARM, "
138 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500139 mb->mbxCommand, mb->mbxStatus);
140 mempool_free(pmb, phba->mbox_mem_pool);
141 return -ERESTART;
142 }
143 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500144 sizeof(phba->wwnn));
145 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
146 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500147 }
148
James Smart92d7f7b2007-06-17 19:56:38 -0500149 phba->sli3_options = 0x0;
150
dea31012005-04-17 16:05:31 -0500151 /* Setup and issue mailbox READ REV command */
152 lpfc_read_rev(phba, pmb);
153 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
154 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500155 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400156 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500157 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500158 mb->mbxCommand, mb->mbxStatus);
159 mempool_free( pmb, phba->mbox_mem_pool);
160 return -ERESTART;
161 }
162
James Smart92d7f7b2007-06-17 19:56:38 -0500163
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500164 /*
165 * The value of rr must be 1 since the driver set the cv field to 1.
166 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500167 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500168 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500169 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500170 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400171 "0440 Adapter failed to init, READ_REV has "
172 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500173 mempool_free(pmb, phba->mbox_mem_pool);
174 return -ERESTART;
dea31012005-04-17 16:05:31 -0500175 }
176
James Smart495a7142008-06-14 22:52:59 -0400177 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
178 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500179 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400180 }
James Smarted957682007-06-17 19:56:37 -0500181
dea31012005-04-17 16:05:31 -0500182 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500183 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500184 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500185 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
186 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
187 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
188 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500189 vp->rev.biuRev = mb->un.varRdRev.biuRev;
190 vp->rev.smRev = mb->un.varRdRev.smRev;
191 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
192 vp->rev.endecRev = mb->un.varRdRev.endecRev;
193 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
194 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
195 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
196 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
197 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
198 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
199
James Smart92d7f7b2007-06-17 19:56:38 -0500200 /* If the sli feature level is less then 9, we must
201 * tear down all RPIs and VPIs on link down if NPIV
202 * is enabled.
203 */
204 if (vp->rev.feaLevelHigh < 9)
205 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
206
dea31012005-04-17 16:05:31 -0500207 if (lpfc_is_LC_HBA(phba->pcidev->device))
208 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
209 sizeof (phba->RandomData));
210
dea31012005-04-17 16:05:31 -0500211 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500212 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
213 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400214 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500215 do {
James Smarta0c87cb2009-07-19 10:01:10 -0400216 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
dea31012005-04-17 16:05:31 -0500217 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
218
219 if (rc != MBX_SUCCESS) {
220 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400221 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500222 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500223 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500224 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500225 }
James Smart04c68492009-05-22 14:52:52 -0400226 /* dump mem may return a zero when finished or we got a
227 * mailbox error, either way we are done.
228 */
229 if (mb->un.varDmp.word_cnt == 0)
230 break;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500231 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
232 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400233 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
234 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500235 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500236 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500237 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
238 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500239
240 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500241out_free_mbox:
242 mempool_free(pmb, phba->mbox_mem_pool);
243 return 0;
244}
245
James Smarte59058c2008-08-24 21:49:00 -0400246/**
James Smart3621a712009-04-06 18:47:14 -0400247 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
James Smarte59058c2008-08-24 21:49:00 -0400248 * @phba: pointer to lpfc hba data structure.
249 * @pmboxq: pointer to the driver internal queue element for mailbox command.
250 *
251 * This is the completion handler for driver's configuring asynchronous event
252 * mailbox command to the device. If the mailbox command returns successfully,
253 * it will set internal async event support flag to 1; otherwise, it will
254 * set internal async event support flag to 0.
255 **/
James Smart57127f12007-10-27 13:37:05 -0400256static void
257lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
258{
James Smart04c68492009-05-22 14:52:52 -0400259 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
James Smart57127f12007-10-27 13:37:05 -0400260 phba->temp_sensor_support = 1;
261 else
262 phba->temp_sensor_support = 0;
263 mempool_free(pmboxq, phba->mbox_mem_pool);
264 return;
265}
266
James Smarte59058c2008-08-24 21:49:00 -0400267/**
James Smart3621a712009-04-06 18:47:14 -0400268 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
James Smart97207482008-12-04 22:39:19 -0500269 * @phba: pointer to lpfc hba data structure.
270 * @pmboxq: pointer to the driver internal queue element for mailbox command.
271 *
272 * This is the completion handler for dump mailbox command for getting
273 * wake up parameters. When this command complete, the response contain
274 * Option rom version of the HBA. This function translate the version number
275 * into a human readable string and store it in OptionROMVersion.
276 **/
277static void
278lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
279{
280 struct prog_id *prg;
281 uint32_t prog_id_word;
282 char dist = ' ';
283 /* character array used for decoding dist type. */
284 char dist_char[] = "nabx";
285
James Smart04c68492009-05-22 14:52:52 -0400286 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
James Smart9f1e1b52008-12-04 22:39:40 -0500287 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500288 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500289 }
James Smart97207482008-12-04 22:39:19 -0500290
291 prg = (struct prog_id *) &prog_id_word;
292
293 /* word 7 contain option rom version */
James Smart04c68492009-05-22 14:52:52 -0400294 prog_id_word = pmboxq->u.mb.un.varWords[7];
James Smart97207482008-12-04 22:39:19 -0500295
296 /* Decode the Option rom version word to a readable string */
297 if (prg->dist < 4)
298 dist = dist_char[prg->dist];
299
300 if ((prg->dist == 3) && (prg->num == 0))
301 sprintf(phba->OptionROMVersion, "%d.%d%d",
302 prg->ver, prg->rev, prg->lev);
303 else
304 sprintf(phba->OptionROMVersion, "%d.%d%d%c%d",
305 prg->ver, prg->rev, prg->lev,
306 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500307 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500308 return;
309}
310
311/**
James Smart05580562011-05-24 11:40:48 -0400312 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
313 * cfg_soft_wwnn, cfg_soft_wwpn
314 * @vport: pointer to lpfc vport data structure.
315 *
316 *
317 * Return codes
318 * None.
319 **/
320void
321lpfc_update_vport_wwn(struct lpfc_vport *vport)
322{
323 /* If the soft name exists then update it using the service params */
324 if (vport->phba->cfg_soft_wwnn)
325 u64_to_wwn(vport->phba->cfg_soft_wwnn,
326 vport->fc_sparam.nodeName.u.wwn);
327 if (vport->phba->cfg_soft_wwpn)
328 u64_to_wwn(vport->phba->cfg_soft_wwpn,
329 vport->fc_sparam.portName.u.wwn);
330
331 /*
332 * If the name is empty or there exists a soft name
333 * then copy the service params name, otherwise use the fc name
334 */
335 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
336 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
337 sizeof(struct lpfc_name));
338 else
339 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
340 sizeof(struct lpfc_name));
341
342 if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn)
343 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
344 sizeof(struct lpfc_name));
345 else
346 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
347 sizeof(struct lpfc_name));
348}
349
350/**
James Smart3621a712009-04-06 18:47:14 -0400351 * lpfc_config_port_post - Perform lpfc initialization after config port
James Smarte59058c2008-08-24 21:49:00 -0400352 * @phba: pointer to lpfc hba data structure.
353 *
354 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
355 * command call. It performs all internal resource and state setups on the
356 * port: post IOCB buffers, enable appropriate host interrupt attentions,
357 * ELS ring timers, etc.
358 *
359 * Return codes
360 * 0 - success.
361 * Any other value - error.
362 **/
dea31012005-04-17 16:05:31 -0500363int
James Smart2e0fef82007-06-17 19:56:36 -0500364lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500365{
James Smart2e0fef82007-06-17 19:56:36 -0500366 struct lpfc_vport *vport = phba->pport;
James Smarta257bf92009-04-06 18:48:10 -0400367 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500368 LPFC_MBOXQ_t *pmb;
369 MAILBOX_t *mb;
370 struct lpfc_dmabuf *mp;
371 struct lpfc_sli *psli = &phba->sli;
372 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500373 int i, j;
374 int rc;
dea31012005-04-17 16:05:31 -0500375
James Smart7af67052007-10-27 13:38:11 -0400376 spin_lock_irq(&phba->hbalock);
377 /*
378 * If the Config port completed correctly the HBA is not
379 * over heated any more.
380 */
381 if (phba->over_temp_state == HBA_OVER_TEMP)
382 phba->over_temp_state = HBA_NORMAL_TEMP;
383 spin_unlock_irq(&phba->hbalock);
384
dea31012005-04-17 16:05:31 -0500385 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
386 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500387 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500388 return -ENOMEM;
389 }
James Smart04c68492009-05-22 14:52:52 -0400390 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500391
dea31012005-04-17 16:05:31 -0500392 /* Get login parameters for NID. */
James Smart9f1177a2010-02-26 14:12:57 -0500393 rc = lpfc_read_sparam(phba, pmb, 0);
394 if (rc) {
395 mempool_free(pmb, phba->mbox_mem_pool);
396 return -ENOMEM;
397 }
398
James Smarted957682007-06-17 19:56:37 -0500399 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500400 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500401 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400402 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500403 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500404 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500405 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500406 mp = (struct lpfc_dmabuf *) pmb->context1;
James Smart9f1177a2010-02-26 14:12:57 -0500407 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500408 lpfc_mbuf_free(phba, mp->virt, mp->phys);
409 kfree(mp);
410 return -EIO;
411 }
412
413 mp = (struct lpfc_dmabuf *) pmb->context1;
414
James Smart2e0fef82007-06-17 19:56:36 -0500415 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500416 lpfc_mbuf_free(phba, mp->virt, mp->phys);
417 kfree(mp);
418 pmb->context1 = NULL;
James Smart05580562011-05-24 11:40:48 -0400419 lpfc_update_vport_wwn(vport);
James Smarta257bf92009-04-06 18:48:10 -0400420
421 /* Update the fc_host data structures with new wwn. */
422 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
423 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart21e9a0a2009-05-22 14:53:21 -0400424 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smarta257bf92009-04-06 18:48:10 -0400425
dea31012005-04-17 16:05:31 -0500426 /* If no serial number in VPD data, use low 6 bytes of WWNN */
427 /* This should be consolidated into parse_vpd ? - mr */
428 if (phba->SerialNumber[0] == 0) {
429 uint8_t *outptr;
430
James Smart2e0fef82007-06-17 19:56:36 -0500431 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500432 for (i = 0; i < 12; i++) {
433 status = *outptr++;
434 j = ((status & 0xf0) >> 4);
435 if (j <= 9)
436 phba->SerialNumber[i] =
437 (char)((uint8_t) 0x30 + (uint8_t) j);
438 else
439 phba->SerialNumber[i] =
440 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
441 i++;
442 j = (status & 0xf);
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 }
450 }
451
dea31012005-04-17 16:05:31 -0500452 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500453 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500454 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500455 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400456 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500457 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500458 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500459 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500460 mempool_free( pmb, phba->mbox_mem_pool);
461 return -EIO;
462 }
463
James Smarta0c87cb2009-07-19 10:01:10 -0400464 /* Check if the port is disabled */
465 lpfc_sli_read_link_ste(phba);
466
dea31012005-04-17 16:05:31 -0500467 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
468 if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
469 phba->cfg_hba_queue_depth =
James Smartf1126682009-06-10 17:22:44 -0400470 (mb->un.varRdConfig.max_xri + 1) -
471 lpfc_sli4_get_els_iocb_cnt(phba);
dea31012005-04-17 16:05:31 -0500472
473 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500474
475 /* Get the default values for Model Name and Description */
476 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
477
James Smart76a95d72010-11-20 23:11:48 -0500478 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_16G)
479 || ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500480 && !(phba->lmt & LMT_1Gb))
James Smart76a95d72010-11-20 23:11:48 -0500481 || ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500482 && !(phba->lmt & LMT_2Gb))
James Smart76a95d72010-11-20 23:11:48 -0500483 || ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500484 && !(phba->lmt & LMT_4Gb))
James Smart76a95d72010-11-20 23:11:48 -0500485 || ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500486 && !(phba->lmt & LMT_8Gb))
James Smart76a95d72010-11-20 23:11:48 -0500487 || ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G)
488 && !(phba->lmt & LMT_10Gb))
489 || ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G)
490 && !(phba->lmt & LMT_16Gb))) {
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500491 /* Reset link speed to auto */
James Smartab56dc22011-02-16 12:39:57 -0500492 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400493 "1302 Invalid speed for this board: "
dea31012005-04-17 16:05:31 -0500494 "Reset link speed to auto: x%x\n",
dea31012005-04-17 16:05:31 -0500495 phba->cfg_link_speed);
James Smart76a95d72010-11-20 23:11:48 -0500496 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
dea31012005-04-17 16:05:31 -0500497 }
498
James Smart2e0fef82007-06-17 19:56:36 -0500499 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500500
James Smart0b727fe2007-10-27 13:37:25 -0400501 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smarta4bc3372006-12-02 13:34:16 -0500502 if (psli->ring[psli->extra_ring].cmdringaddr)
503 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500504 if (psli->ring[psli->fcp_ring].cmdringaddr)
505 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
506 if (psli->ring[psli->next_ring].cmdringaddr)
507 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
508
509 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500510 if (phba->sli_rev != 3)
511 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500512
James Smart93996272008-08-24 21:50:30 -0400513 /*
514 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
515 */
516 if (phba->intr_type == MSIX) {
517 rc = lpfc_config_msi(phba, pmb);
518 if (rc) {
519 mempool_free(pmb, phba->mbox_mem_pool);
520 return -EIO;
521 }
522 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
523 if (rc != MBX_SUCCESS) {
524 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
525 "0352 Config MSI mailbox command "
526 "failed, mbxCmd x%x, mbxStatus x%x\n",
James Smart04c68492009-05-22 14:52:52 -0400527 pmb->u.mb.mbxCommand,
528 pmb->u.mb.mbxStatus);
James Smart93996272008-08-24 21:50:30 -0400529 mempool_free(pmb, phba->mbox_mem_pool);
530 return -EIO;
531 }
532 }
533
James Smart04c68492009-05-22 14:52:52 -0400534 spin_lock_irq(&phba->hbalock);
James Smart93996272008-08-24 21:50:30 -0400535 /* Initialize ERATT handling flag */
536 phba->hba_flag &= ~HBA_ERATT_HANDLED;
537
dea31012005-04-17 16:05:31 -0500538 /* Enable appropriate host interrupts */
James Smart9940b972011-03-11 16:06:12 -0500539 if (lpfc_readl(phba->HCregaddr, &status)) {
540 spin_unlock_irq(&phba->hbalock);
541 return -EIO;
542 }
dea31012005-04-17 16:05:31 -0500543 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
544 if (psli->num_rings > 0)
545 status |= HC_R0INT_ENA;
546 if (psli->num_rings > 1)
547 status |= HC_R1INT_ENA;
548 if (psli->num_rings > 2)
549 status |= HC_R2INT_ENA;
550 if (psli->num_rings > 3)
551 status |= HC_R3INT_ENA;
552
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500553 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
554 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400555 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500556
dea31012005-04-17 16:05:31 -0500557 writel(status, phba->HCregaddr);
558 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500559 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500560
James Smart93996272008-08-24 21:50:30 -0400561 /* Set up ring-0 (ELS) timer */
562 timeout = phba->fc_ratov * 2;
James Smart2e0fef82007-06-17 19:56:36 -0500563 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
James Smart93996272008-08-24 21:50:30 -0400564 /* Set up heart beat (HB) timer */
James Smart858c9f62007-06-17 19:56:39 -0500565 mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
566 phba->hb_outstanding = 0;
567 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400568 /* Set up error attention (ERATT) polling timer */
569 mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
dea31012005-04-17 16:05:31 -0500570
James Smarta0c87cb2009-07-19 10:01:10 -0400571 if (phba->hba_flag & LINK_DISABLED) {
572 lpfc_printf_log(phba,
573 KERN_ERR, LOG_INIT,
574 "2598 Adapter Link is disabled.\n");
575 lpfc_down_link(phba, pmb);
576 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
577 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
578 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
579 lpfc_printf_log(phba,
580 KERN_ERR, LOG_INIT,
581 "2599 Adapter failed to issue DOWN_LINK"
582 " mbox command rc 0x%x\n", rc);
583
584 mempool_free(pmb, phba->mbox_mem_pool);
585 return -EIO;
586 }
James Smarte40a02c2010-02-26 14:13:54 -0500587 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
James Smarta0c87cb2009-07-19 10:01:10 -0400588 lpfc_init_link(phba, pmb, phba->cfg_topology,
589 phba->cfg_link_speed);
590 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
591 lpfc_set_loopback_flag(phba);
592 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
593 if (rc != MBX_SUCCESS) {
594 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400595 "0454 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500596 "INIT_LINK, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500597 mb->mbxCommand, mb->mbxStatus);
598
James Smarta0c87cb2009-07-19 10:01:10 -0400599 /* Clear all interrupt enable conditions */
600 writel(0, phba->HCregaddr);
601 readl(phba->HCregaddr); /* flush */
602 /* Clear all pending interrupts */
603 writel(0xffffffff, phba->HAregaddr);
604 readl(phba->HAregaddr); /* flush */
James Smarta0c87cb2009-07-19 10:01:10 -0400605 phba->link_state = LPFC_HBA_ERROR;
606 if (rc != MBX_BUSY)
607 mempool_free(pmb, phba->mbox_mem_pool);
608 return -EIO;
609 }
dea31012005-04-17 16:05:31 -0500610 }
611 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400612 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500613 if (!pmb) {
614 phba->link_state = LPFC_HBA_ERROR;
615 return -ENOMEM;
616 }
617
James Smart57127f12007-10-27 13:37:05 -0400618 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
619 pmb->mbox_cmpl = lpfc_config_async_cmpl;
620 pmb->vport = phba->pport;
621 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500622
James Smart57127f12007-10-27 13:37:05 -0400623 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
624 lpfc_printf_log(phba,
625 KERN_ERR,
626 LOG_INIT,
627 "0456 Adapter failed to issue "
James Smarte4e74272009-07-19 10:01:38 -0400628 "ASYNCEVT_ENABLE mbox status x%x\n",
James Smart57127f12007-10-27 13:37:05 -0400629 rc);
630 mempool_free(pmb, phba->mbox_mem_pool);
631 }
James Smart97207482008-12-04 22:39:19 -0500632
633 /* Get Option rom version */
634 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500635 if (!pmb) {
636 phba->link_state = LPFC_HBA_ERROR;
637 return -ENOMEM;
638 }
639
James Smart97207482008-12-04 22:39:19 -0500640 lpfc_dump_wakeup_param(phba, pmb);
641 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
642 pmb->vport = phba->pport;
643 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
644
645 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
646 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
James Smarte4e74272009-07-19 10:01:38 -0400647 "to get Option ROM version status x%x\n", rc);
James Smart97207482008-12-04 22:39:19 -0500648 mempool_free(pmb, phba->mbox_mem_pool);
649 }
650
James Smartd7c255b2008-08-24 21:50:00 -0400651 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400652}
653
James Smarte59058c2008-08-24 21:49:00 -0400654/**
James Smart84d1b002010-02-12 14:42:33 -0500655 * lpfc_hba_init_link - Initialize the FC link
656 * @phba: pointer to lpfc hba data structure.
James Smart6e7288d2010-06-07 15:23:35 -0400657 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500658 *
659 * This routine will issue the INIT_LINK mailbox command call.
660 * It is available to other drivers through the lpfc_hba data
661 * structure for use as a delayed link up mechanism with the
662 * module parameter lpfc_suppress_link_up.
663 *
664 * Return code
665 * 0 - success
666 * Any other value - error
667 **/
668int
James Smart6e7288d2010-06-07 15:23:35 -0400669lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500670{
671 struct lpfc_vport *vport = phba->pport;
672 LPFC_MBOXQ_t *pmb;
673 MAILBOX_t *mb;
674 int rc;
675
676 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
677 if (!pmb) {
678 phba->link_state = LPFC_HBA_ERROR;
679 return -ENOMEM;
680 }
681 mb = &pmb->u.mb;
682 pmb->vport = vport;
683
James Smart76a95d72010-11-20 23:11:48 -0500684 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
James Smart84d1b002010-02-12 14:42:33 -0500685 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
686 lpfc_set_loopback_flag(phba);
James Smart6e7288d2010-06-07 15:23:35 -0400687 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart76a95d72010-11-20 23:11:48 -0500688 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
James Smart84d1b002010-02-12 14:42:33 -0500689 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
690 "0498 Adapter failed to init, mbxCmd x%x "
691 "INIT_LINK, mbxStatus x%x\n",
692 mb->mbxCommand, mb->mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -0500693 if (phba->sli_rev <= LPFC_SLI_REV3) {
694 /* Clear all interrupt enable conditions */
695 writel(0, phba->HCregaddr);
696 readl(phba->HCregaddr); /* flush */
697 /* Clear all pending interrupts */
698 writel(0xffffffff, phba->HAregaddr);
699 readl(phba->HAregaddr); /* flush */
700 }
James Smart84d1b002010-02-12 14:42:33 -0500701 phba->link_state = LPFC_HBA_ERROR;
James Smart6e7288d2010-06-07 15:23:35 -0400702 if (rc != MBX_BUSY || flag == MBX_POLL)
James Smart84d1b002010-02-12 14:42:33 -0500703 mempool_free(pmb, phba->mbox_mem_pool);
704 return -EIO;
705 }
James Smarte40a02c2010-02-26 14:13:54 -0500706 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
James Smart6e7288d2010-06-07 15:23:35 -0400707 if (flag == MBX_POLL)
708 mempool_free(pmb, phba->mbox_mem_pool);
James Smart84d1b002010-02-12 14:42:33 -0500709
710 return 0;
711}
712
713/**
714 * lpfc_hba_down_link - this routine downs the FC link
James Smart6e7288d2010-06-07 15:23:35 -0400715 * @phba: pointer to lpfc hba data structure.
716 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500717 *
718 * This routine will issue the DOWN_LINK mailbox command call.
719 * It is available to other drivers through the lpfc_hba data
720 * structure for use to stop the link.
721 *
722 * Return code
723 * 0 - success
724 * Any other value - error
725 **/
726int
James Smart6e7288d2010-06-07 15:23:35 -0400727lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500728{
729 LPFC_MBOXQ_t *pmb;
730 int rc;
731
732 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
733 if (!pmb) {
734 phba->link_state = LPFC_HBA_ERROR;
735 return -ENOMEM;
736 }
737
738 lpfc_printf_log(phba,
739 KERN_ERR, LOG_INIT,
740 "0491 Adapter Link is disabled.\n");
741 lpfc_down_link(phba, pmb);
742 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart6e7288d2010-06-07 15:23:35 -0400743 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart84d1b002010-02-12 14:42:33 -0500744 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
745 lpfc_printf_log(phba,
746 KERN_ERR, LOG_INIT,
747 "2522 Adapter failed to issue DOWN_LINK"
748 " mbox command rc 0x%x\n", rc);
749
750 mempool_free(pmb, phba->mbox_mem_pool);
751 return -EIO;
752 }
James Smart6e7288d2010-06-07 15:23:35 -0400753 if (flag == MBX_POLL)
754 mempool_free(pmb, phba->mbox_mem_pool);
755
James Smart84d1b002010-02-12 14:42:33 -0500756 return 0;
757}
758
759/**
James Smart3621a712009-04-06 18:47:14 -0400760 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400761 * @phba: pointer to lpfc HBA data structure.
762 *
763 * This routine will do LPFC uninitialization before the HBA is reset when
764 * bringing down the SLI Layer.
765 *
766 * Return codes
767 * 0 - success.
768 * Any other value - error.
769 **/
dea31012005-04-17 16:05:31 -0500770int
James Smart2e0fef82007-06-17 19:56:36 -0500771lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500772{
James Smart1b32f6a2008-02-08 18:49:39 -0500773 struct lpfc_vport **vports;
774 int i;
James Smart3772a992009-05-22 14:50:54 -0400775
776 if (phba->sli_rev <= LPFC_SLI_REV3) {
777 /* Disable interrupts */
778 writel(0, phba->HCregaddr);
779 readl(phba->HCregaddr); /* flush */
780 }
dea31012005-04-17 16:05:31 -0500781
James Smart1b32f6a2008-02-08 18:49:39 -0500782 if (phba->pport->load_flag & FC_UNLOADING)
783 lpfc_cleanup_discovery_resources(phba->pport);
784 else {
785 vports = lpfc_create_vport_work_array(phba);
786 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -0400787 for (i = 0; i <= phba->max_vports &&
788 vports[i] != NULL; i++)
James Smart1b32f6a2008-02-08 18:49:39 -0500789 lpfc_cleanup_discovery_resources(vports[i]);
790 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500791 }
792 return 0;
dea31012005-04-17 16:05:31 -0500793}
794
James Smarte59058c2008-08-24 21:49:00 -0400795/**
James Smart3772a992009-05-22 14:50:54 -0400796 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400797 * @phba: pointer to lpfc HBA data structure.
798 *
799 * This routine will do uninitialization after the HBA is reset when bring
800 * down the SLI Layer.
801 *
802 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200803 * 0 - success.
James Smarte59058c2008-08-24 21:49:00 -0400804 * Any other value - error.
805 **/
James Smart3772a992009-05-22 14:50:54 -0400806static int
807lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500808{
809 struct lpfc_sli *psli = &phba->sli;
810 struct lpfc_sli_ring *pring;
811 struct lpfc_dmabuf *mp, *next_mp;
James Smart09372822008-01-11 01:52:54 -0500812 LIST_HEAD(completions);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500813 int i;
814
James Smart92d7f7b2007-06-17 19:56:38 -0500815 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
816 lpfc_sli_hbqbuf_free_all(phba);
817 else {
818 /* Cleanup preposted buffers on the ELS ring */
819 pring = &psli->ring[LPFC_ELS_RING];
820 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
821 list_del(&mp->list);
822 pring->postbufq_cnt--;
823 lpfc_mbuf_free(phba, mp->virt, mp->phys);
824 kfree(mp);
825 }
Jamie Wellnitz41415862006-02-28 19:25:27 -0500826 }
827
James Smart09372822008-01-11 01:52:54 -0500828 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500829 for (i = 0; i < psli->num_rings; i++) {
830 pring = &psli->ring[i];
James Smart09372822008-01-11 01:52:54 -0500831
832 /* At this point in time the HBA is either reset or DOA. Either
833 * way, nothing should be on txcmplq as it will NEVER complete.
834 */
835 list_splice_init(&pring->txcmplq, &completions);
836 pring->txcmplq_cnt = 0;
837 spin_unlock_irq(&phba->hbalock);
838
James Smarta257bf92009-04-06 18:48:10 -0400839 /* Cancel all the IOCBs from the completions list */
840 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
841 IOERR_SLI_ABORTED);
James Smart09372822008-01-11 01:52:54 -0500842
Jamie Wellnitz41415862006-02-28 19:25:27 -0500843 lpfc_sli_abort_iocb_ring(phba, pring);
James Smart09372822008-01-11 01:52:54 -0500844 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500845 }
James Smart09372822008-01-11 01:52:54 -0500846 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500847
848 return 0;
849}
James Smart5af5eee2010-10-22 11:06:38 -0400850
James Smartda0436e2009-05-22 14:51:39 -0400851/**
852 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
853 * @phba: pointer to lpfc HBA data structure.
854 *
855 * This routine will do uninitialization after the HBA is reset when bring
856 * down the SLI Layer.
857 *
858 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200859 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -0400860 * Any other value - error.
861 **/
862static int
863lpfc_hba_down_post_s4(struct lpfc_hba *phba)
864{
865 struct lpfc_scsi_buf *psb, *psb_next;
866 LIST_HEAD(aborts);
867 int ret;
868 unsigned long iflag = 0;
James Smart0f65ff62010-02-26 14:14:23 -0500869 struct lpfc_sglq *sglq_entry = NULL;
870
James Smartda0436e2009-05-22 14:51:39 -0400871 ret = lpfc_hba_down_post_s3(phba);
872 if (ret)
873 return ret;
874 /* At this point in time the HBA is either reset or DOA. Either
875 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
876 * on the lpfc_sgl_list so that it can either be freed if the
877 * driver is unloading or reposted if the driver is restarting
878 * the port.
879 */
880 spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */
881 /* scsl_buf_list */
882 /* abts_sgl_list_lock required because worker thread uses this
883 * list.
884 */
885 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -0500886 list_for_each_entry(sglq_entry,
887 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
888 sglq_entry->state = SGL_FREED;
889
James Smartda0436e2009-05-22 14:51:39 -0400890 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
891 &phba->sli4_hba.lpfc_sgl_list);
892 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
893 /* abts_scsi_buf_list_lock required because worker thread uses this
894 * list.
895 */
896 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
897 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
898 &aborts);
899 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
900 spin_unlock_irq(&phba->hbalock);
901
902 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
903 psb->pCmd = NULL;
904 psb->status = IOSTAT_SUCCESS;
905 }
906 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
907 list_splice(&aborts, &phba->lpfc_scsi_buf_list);
908 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
909 return 0;
910}
911
912/**
913 * lpfc_hba_down_post - Wrapper func for hba down post routine
914 * @phba: pointer to lpfc HBA data structure.
915 *
916 * This routine wraps the actual SLI3 or SLI4 routine for performing
917 * uninitialization after the HBA is reset when bring down the SLI Layer.
918 *
919 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200920 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -0400921 * Any other value - error.
922 **/
923int
924lpfc_hba_down_post(struct lpfc_hba *phba)
925{
926 return (*phba->lpfc_hba_down_post)(phba);
927}
Jamie Wellnitz41415862006-02-28 19:25:27 -0500928
James Smarte59058c2008-08-24 21:49:00 -0400929/**
James Smart3621a712009-04-06 18:47:14 -0400930 * lpfc_hb_timeout - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -0400931 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
932 *
933 * This is the HBA-timer timeout handler registered to the lpfc driver. When
934 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
935 * work-port-events bitmap and the worker thread is notified. This timeout
936 * event will be used by the worker thread to invoke the actual timeout
937 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
938 * be performed in the timeout handler and the HBA timeout event bit shall
939 * be cleared by the worker thread after it has taken the event bitmap out.
940 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +0100941static void
James Smart858c9f62007-06-17 19:56:39 -0500942lpfc_hb_timeout(unsigned long ptr)
943{
944 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -0400945 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -0500946 unsigned long iflag;
947
948 phba = (struct lpfc_hba *)ptr;
James Smart93996272008-08-24 21:50:30 -0400949
950 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -0500951 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -0400952 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
953 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -0500954 phba->pport->work_port_events |= WORKER_HB_TMO;
955 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
956
James Smart93996272008-08-24 21:50:30 -0400957 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -0400958 if (!tmo_posted)
959 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -0500960 return;
961}
962
James Smarte59058c2008-08-24 21:49:00 -0400963/**
James Smart19ca7602010-11-20 23:11:55 -0500964 * lpfc_rrq_timeout - The RRQ-timer timeout handler
965 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
966 *
967 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
968 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
969 * work-port-events bitmap and the worker thread is notified. This timeout
970 * event will be used by the worker thread to invoke the actual timeout
971 * handler routine, lpfc_rrq_handler. Any periodical operations will
972 * be performed in the timeout handler and the RRQ timeout event bit shall
973 * be cleared by the worker thread after it has taken the event bitmap out.
974 **/
975static void
976lpfc_rrq_timeout(unsigned long ptr)
977{
978 struct lpfc_hba *phba;
James Smart19ca7602010-11-20 23:11:55 -0500979 unsigned long iflag;
980
981 phba = (struct lpfc_hba *)ptr;
982 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart1151e3e2011-02-16 12:39:35 -0500983 phba->hba_flag |= HBA_RRQ_ACTIVE;
James Smart19ca7602010-11-20 23:11:55 -0500984 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
James Smart1151e3e2011-02-16 12:39:35 -0500985 lpfc_worker_wake_up(phba);
James Smart19ca7602010-11-20 23:11:55 -0500986}
987
988/**
James Smart3621a712009-04-06 18:47:14 -0400989 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -0400990 * @phba: pointer to lpfc hba data structure.
991 * @pmboxq: pointer to the driver internal queue element for mailbox command.
992 *
993 * This is the callback function to the lpfc heart-beat mailbox command.
994 * If configured, the lpfc driver issues the heart-beat mailbox command to
995 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
996 * heart-beat mailbox command is issued, the driver shall set up heart-beat
997 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
998 * heart-beat outstanding state. Once the mailbox command comes back and
999 * no error conditions detected, the heart-beat mailbox command timer is
1000 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1001 * state is cleared for the next heart-beat. If the timer expired with the
1002 * heart-beat outstanding state set, the driver will put the HBA offline.
1003 **/
James Smart858c9f62007-06-17 19:56:39 -05001004static void
1005lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1006{
1007 unsigned long drvr_flag;
1008
1009 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1010 phba->hb_outstanding = 0;
1011 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1012
James Smart93996272008-08-24 21:50:30 -04001013 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -05001014 mempool_free(pmboxq, phba->mbox_mem_pool);
1015 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1016 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -04001017 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -05001018 mod_timer(&phba->hb_tmofunc,
1019 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
1020 return;
1021}
1022
James Smarte59058c2008-08-24 21:49:00 -04001023/**
James Smart3621a712009-04-06 18:47:14 -04001024 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001025 * @phba: pointer to lpfc hba data structure.
1026 *
1027 * This is the actual HBA-timer timeout handler to be invoked by the worker
1028 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1029 * handler performs any periodic operations needed for the device. If such
1030 * periodic event has already been attended to either in the interrupt handler
1031 * or by processing slow-ring or fast-ring events within the HBA-timer
1032 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1033 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1034 * is configured and there is no heart-beat mailbox command outstanding, a
1035 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1036 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1037 * to offline.
1038 **/
James Smart858c9f62007-06-17 19:56:39 -05001039void
1040lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1041{
James Smart45ed1192009-10-02 15:17:02 -04001042 struct lpfc_vport **vports;
James Smart858c9f62007-06-17 19:56:39 -05001043 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -05001044 struct lpfc_dmabuf *buf_ptr;
James Smart45ed1192009-10-02 15:17:02 -04001045 int retval, i;
James Smart858c9f62007-06-17 19:56:39 -05001046 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -05001047 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -05001048
James Smart45ed1192009-10-02 15:17:02 -04001049 vports = lpfc_create_vport_work_array(phba);
1050 if (vports != NULL)
1051 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
1052 lpfc_rcv_seq_check_edtov(vports[i]);
1053 lpfc_destroy_vport_work_array(phba, vports);
1054
James Smart858c9f62007-06-17 19:56:39 -05001055 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -04001056 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -05001057 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1058 return;
1059
1060 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -05001061
1062 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
1063 jiffies)) {
1064 spin_unlock_irq(&phba->pport->work_port_lock);
1065 if (!phba->hb_outstanding)
1066 mod_timer(&phba->hb_tmofunc,
1067 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
1068 else
1069 mod_timer(&phba->hb_tmofunc,
1070 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
1071 return;
1072 }
1073 spin_unlock_irq(&phba->pport->work_port_lock);
1074
James Smart0ff10d42008-01-11 01:52:36 -05001075 if (phba->elsbuf_cnt &&
1076 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1077 spin_lock_irq(&phba->hbalock);
1078 list_splice_init(&phba->elsbuf, &completions);
1079 phba->elsbuf_cnt = 0;
1080 phba->elsbuf_prev_cnt = 0;
1081 spin_unlock_irq(&phba->hbalock);
1082
1083 while (!list_empty(&completions)) {
1084 list_remove_head(&completions, buf_ptr,
1085 struct lpfc_dmabuf, list);
1086 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1087 kfree(buf_ptr);
1088 }
1089 }
1090 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1091
James Smart858c9f62007-06-17 19:56:39 -05001092 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -05001093 if (phba->cfg_enable_hba_heartbeat) {
1094 if (!phba->hb_outstanding) {
James Smartbc739052010-08-04 16:11:18 -04001095 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1096 (list_empty(&psli->mboxq))) {
1097 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1098 GFP_KERNEL);
1099 if (!pmboxq) {
1100 mod_timer(&phba->hb_tmofunc,
1101 jiffies +
1102 HZ * LPFC_HB_MBOX_INTERVAL);
1103 return;
1104 }
James Smart13815c82008-01-11 01:52:48 -05001105
James Smartbc739052010-08-04 16:11:18 -04001106 lpfc_heart_beat(phba, pmboxq);
1107 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1108 pmboxq->vport = phba->pport;
1109 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1110 MBX_NOWAIT);
James Smart13815c82008-01-11 01:52:48 -05001111
James Smartbc739052010-08-04 16:11:18 -04001112 if (retval != MBX_BUSY &&
1113 retval != MBX_SUCCESS) {
1114 mempool_free(pmboxq,
1115 phba->mbox_mem_pool);
1116 mod_timer(&phba->hb_tmofunc,
1117 jiffies +
1118 HZ * LPFC_HB_MBOX_INTERVAL);
1119 return;
1120 }
1121 phba->skipped_hb = 0;
1122 phba->hb_outstanding = 1;
1123 } else if (time_before_eq(phba->last_completion_time,
1124 phba->skipped_hb)) {
1125 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1126 "2857 Last completion time not "
1127 " updated in %d ms\n",
1128 jiffies_to_msecs(jiffies
1129 - phba->last_completion_time));
1130 } else
1131 phba->skipped_hb = jiffies;
1132
James Smart858c9f62007-06-17 19:56:39 -05001133 mod_timer(&phba->hb_tmofunc,
James Smart13815c82008-01-11 01:52:48 -05001134 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
James Smart858c9f62007-06-17 19:56:39 -05001135 return;
James Smart13815c82008-01-11 01:52:48 -05001136 } else {
1137 /*
1138 * If heart beat timeout called with hb_outstanding set
James Smartdcf2a4e2010-09-29 11:18:53 -04001139 * we need to give the hb mailbox cmd a chance to
1140 * complete or TMO.
James Smart13815c82008-01-11 01:52:48 -05001141 */
James Smartdcf2a4e2010-09-29 11:18:53 -04001142 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1143 "0459 Adapter heartbeat still out"
1144 "standing:last compl time was %d ms.\n",
1145 jiffies_to_msecs(jiffies
1146 - phba->last_completion_time));
1147 mod_timer(&phba->hb_tmofunc,
1148 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
James Smart858c9f62007-06-17 19:56:39 -05001149 }
James Smart858c9f62007-06-17 19:56:39 -05001150 }
1151}
1152
James Smarte59058c2008-08-24 21:49:00 -04001153/**
James Smart3621a712009-04-06 18:47:14 -04001154 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -04001155 * @phba: pointer to lpfc hba data structure.
1156 *
1157 * This routine is called to bring the HBA offline when HBA hardware error
1158 * other than Port Error 6 has been detected.
1159 **/
James Smart09372822008-01-11 01:52:54 -05001160static void
1161lpfc_offline_eratt(struct lpfc_hba *phba)
1162{
1163 struct lpfc_sli *psli = &phba->sli;
1164
1165 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001166 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -05001167 spin_unlock_irq(&phba->hbalock);
1168 lpfc_offline_prep(phba);
1169
1170 lpfc_offline(phba);
1171 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001172 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001173 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001174 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001175 lpfc_hba_down_post(phba);
1176 lpfc_sli_brdready(phba, HS_MBRDY);
1177 lpfc_unblock_mgmt_io(phba);
1178 phba->link_state = LPFC_HBA_ERROR;
1179 return;
1180}
1181
James Smarte59058c2008-08-24 21:49:00 -04001182/**
James Smartda0436e2009-05-22 14:51:39 -04001183 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1184 * @phba: pointer to lpfc hba data structure.
1185 *
1186 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1187 * other than Port Error 6 has been detected.
1188 **/
1189static void
1190lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1191{
1192 lpfc_offline_prep(phba);
1193 lpfc_offline(phba);
1194 lpfc_sli4_brdreset(phba);
1195 lpfc_hba_down_post(phba);
1196 lpfc_sli4_post_status_check(phba);
1197 lpfc_unblock_mgmt_io(phba);
1198 phba->link_state = LPFC_HBA_ERROR;
1199}
1200
1201/**
James Smarta257bf92009-04-06 18:48:10 -04001202 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1203 * @phba: pointer to lpfc hba data structure.
1204 *
1205 * This routine is invoked to handle the deferred HBA hardware error
1206 * conditions. This type of error is indicated by HBA by setting ER1
1207 * and another ER bit in the host status register. The driver will
1208 * wait until the ER1 bit clears before handling the error condition.
1209 **/
1210static void
1211lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1212{
1213 uint32_t old_host_status = phba->work_hs;
1214 struct lpfc_sli_ring *pring;
1215 struct lpfc_sli *psli = &phba->sli;
1216
James Smartf4b4c682009-05-22 14:53:12 -04001217 /* If the pci channel is offline, ignore possible errors,
1218 * since we cannot communicate with the pci card anyway.
1219 */
1220 if (pci_channel_offline(phba->pcidev)) {
1221 spin_lock_irq(&phba->hbalock);
1222 phba->hba_flag &= ~DEFER_ERATT;
1223 spin_unlock_irq(&phba->hbalock);
1224 return;
1225 }
1226
James Smarta257bf92009-04-06 18:48:10 -04001227 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1228 "0479 Deferred Adapter Hardware Error "
1229 "Data: x%x x%x x%x\n",
1230 phba->work_hs,
1231 phba->work_status[0], phba->work_status[1]);
1232
1233 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001234 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001235 spin_unlock_irq(&phba->hbalock);
1236
1237
1238 /*
1239 * Firmware stops when it triggred erratt. That could cause the I/Os
1240 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1241 * SCSI layer retry it after re-establishing link.
1242 */
1243 pring = &psli->ring[psli->fcp_ring];
1244 lpfc_sli_abort_iocb_ring(phba, pring);
1245
1246 /*
1247 * There was a firmware error. Take the hba offline and then
1248 * attempt to restart it.
1249 */
1250 lpfc_offline_prep(phba);
1251 lpfc_offline(phba);
1252
1253 /* Wait for the ER1 bit to clear.*/
1254 while (phba->work_hs & HS_FFER1) {
1255 msleep(100);
James Smart9940b972011-03-11 16:06:12 -05001256 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1257 phba->work_hs = UNPLUG_ERR ;
1258 break;
1259 }
James Smarta257bf92009-04-06 18:48:10 -04001260 /* If driver is unloading let the worker thread continue */
1261 if (phba->pport->load_flag & FC_UNLOADING) {
1262 phba->work_hs = 0;
1263 break;
1264 }
1265 }
1266
1267 /*
1268 * This is to ptrotect against a race condition in which
1269 * first write to the host attention register clear the
1270 * host status register.
1271 */
1272 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1273 phba->work_hs = old_host_status & ~HS_FFER1;
1274
James Smart3772a992009-05-22 14:50:54 -04001275 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001276 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001277 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001278 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1279 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1280}
1281
James Smart3772a992009-05-22 14:50:54 -04001282static void
1283lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1284{
1285 struct lpfc_board_event_header board_event;
1286 struct Scsi_Host *shost;
1287
1288 board_event.event_type = FC_REG_BOARD_EVENT;
1289 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1290 shost = lpfc_shost_from_vport(phba->pport);
1291 fc_host_post_vendor_event(shost, fc_get_event_number(),
1292 sizeof(board_event),
1293 (char *) &board_event,
1294 LPFC_NL_VENDOR_ID);
1295}
1296
James Smarta257bf92009-04-06 18:48:10 -04001297/**
James Smart3772a992009-05-22 14:50:54 -04001298 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001299 * @phba: pointer to lpfc hba data structure.
1300 *
1301 * This routine is invoked to handle the following HBA hardware error
1302 * conditions:
1303 * 1 - HBA error attention interrupt
1304 * 2 - DMA ring index out of range
1305 * 3 - Mailbox command came back as unknown
1306 **/
James Smart3772a992009-05-22 14:50:54 -04001307static void
1308lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001309{
James Smart2e0fef82007-06-17 19:56:36 -05001310 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001311 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001312 struct lpfc_sli_ring *pring;
James Smartd2873e42006-08-18 17:46:43 -04001313 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001314 unsigned long temperature;
1315 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001316 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001317
Linas Vepstas8d63f372007-02-14 14:28:36 -06001318 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001319 * since we cannot communicate with the pci card anyway.
1320 */
1321 if (pci_channel_offline(phba->pcidev)) {
1322 spin_lock_irq(&phba->hbalock);
1323 phba->hba_flag &= ~DEFER_ERATT;
1324 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001325 return;
James Smart3772a992009-05-22 14:50:54 -04001326 }
1327
James Smart13815c82008-01-11 01:52:48 -05001328 /* If resets are disabled then leave the HBA alone and return */
1329 if (!phba->cfg_enable_hba_reset)
1330 return;
dea31012005-04-17 16:05:31 -05001331
James Smartea2151b2008-09-07 11:52:10 -04001332 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001333 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001334
James Smarta257bf92009-04-06 18:48:10 -04001335 if (phba->hba_flag & DEFER_ERATT)
1336 lpfc_handle_deferred_eratt(phba);
1337
James Smartdcf2a4e2010-09-29 11:18:53 -04001338 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1339 if (phba->work_hs & HS_FFER6)
1340 /* Re-establishing Link */
1341 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1342 "1301 Re-establishing Link "
1343 "Data: x%x x%x x%x\n",
1344 phba->work_hs, phba->work_status[0],
1345 phba->work_status[1]);
1346 if (phba->work_hs & HS_FFER8)
1347 /* Device Zeroization */
1348 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1349 "2861 Host Authentication device "
1350 "zeroization Data:x%x x%x x%x\n",
1351 phba->work_hs, phba->work_status[0],
1352 phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001353
James Smart92d7f7b2007-06-17 19:56:38 -05001354 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001355 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001356 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001357
1358 /*
1359 * Firmware stops when it triggled erratt with HS_FFER6.
1360 * That could cause the I/Os dropped by the firmware.
1361 * Error iocb (I/O) on txcmplq and let the SCSI layer
1362 * retry it after re-establishing link.
1363 */
1364 pring = &psli->ring[psli->fcp_ring];
1365 lpfc_sli_abort_iocb_ring(phba, pring);
1366
dea31012005-04-17 16:05:31 -05001367 /*
1368 * There was a firmware error. Take the hba offline and then
1369 * attempt to restart it.
1370 */
James Smart46fa3112007-04-25 09:51:45 -04001371 lpfc_offline_prep(phba);
dea31012005-04-17 16:05:31 -05001372 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001373 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001374 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001375 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001376 return;
1377 }
James Smart46fa3112007-04-25 09:51:45 -04001378 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001379 } else if (phba->work_hs & HS_CRIT_TEMP) {
1380 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1381 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1382 temp_event_data.event_code = LPFC_CRIT_TEMP;
1383 temp_event_data.data = (uint32_t)temperature;
1384
1385 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001386 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001387 "(%ld), taking this port offline "
1388 "Data: x%x x%x x%x\n",
1389 temperature, phba->work_hs,
1390 phba->work_status[0], phba->work_status[1]);
1391
1392 shost = lpfc_shost_from_vport(phba->pport);
1393 fc_host_post_vendor_event(shost, fc_get_event_number(),
1394 sizeof(temp_event_data),
1395 (char *) &temp_event_data,
1396 SCSI_NL_VID_TYPE_PCI
1397 | PCI_VENDOR_ID_EMULEX);
1398
James Smart7af67052007-10-27 13:38:11 -04001399 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001400 phba->over_temp_state = HBA_OVER_TEMP;
1401 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001402 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001403
dea31012005-04-17 16:05:31 -05001404 } else {
1405 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001406 * failure is a value other than FFER6. Do not call the offline
1407 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001408 */
1409 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001410 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001411 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001412 phba->work_hs,
dea31012005-04-17 16:05:31 -05001413 phba->work_status[0], phba->work_status[1]);
1414
James Smartd2873e42006-08-18 17:46:43 -04001415 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001416 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001417 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001418 sizeof(event_data), (char *) &event_data,
1419 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1420
James Smart09372822008-01-11 01:52:54 -05001421 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001422 }
James Smart93996272008-08-24 21:50:30 -04001423 return;
dea31012005-04-17 16:05:31 -05001424}
1425
James Smarte59058c2008-08-24 21:49:00 -04001426/**
James Smartda0436e2009-05-22 14:51:39 -04001427 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1428 * @phba: pointer to lpfc hba data structure.
1429 *
1430 * This routine is invoked to handle the SLI4 HBA hardware error attention
1431 * conditions.
1432 **/
1433static void
1434lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1435{
1436 struct lpfc_vport *vport = phba->pport;
1437 uint32_t event_data;
1438 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001439 uint32_t if_type;
1440 struct lpfc_register portstat_reg;
James Smart73d91e52011-10-10 21:32:10 -04001441 int rc;
James Smartda0436e2009-05-22 14:51:39 -04001442
1443 /* If the pci channel is offline, ignore possible errors, since
1444 * we cannot communicate with the pci card anyway.
1445 */
1446 if (pci_channel_offline(phba->pcidev))
1447 return;
1448 /* If resets are disabled then leave the HBA alone and return */
1449 if (!phba->cfg_enable_hba_reset)
1450 return;
1451
1452 /* Send an internal error event to mgmt application */
1453 lpfc_board_errevt_to_mgmt(phba);
1454
1455 /* For now, the actual action for SLI4 device handling is not
1456 * specified yet, just treated it as adaptor hardware failure
1457 */
James Smartda0436e2009-05-22 14:51:39 -04001458 event_data = FC_REG_DUMP_EVENT;
1459 shost = lpfc_shost_from_vport(vport);
1460 fc_host_post_vendor_event(shost, fc_get_event_number(),
1461 sizeof(event_data), (char *) &event_data,
1462 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1463
James Smart2fcee4b2010-12-15 17:57:46 -05001464 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1465 switch (if_type) {
1466 case LPFC_SLI_INTF_IF_TYPE_0:
1467 lpfc_sli4_offline_eratt(phba);
1468 break;
1469 case LPFC_SLI_INTF_IF_TYPE_2:
1470 portstat_reg.word0 =
1471 readl(phba->sli4_hba.u.if_type2.STATUSregaddr);
1472
1473 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
1474 /* TODO: Register for Overtemp async events. */
1475 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1476 "2889 Port Overtemperature event, "
1477 "taking port\n");
1478 spin_lock_irq(&phba->hbalock);
1479 phba->over_temp_state = HBA_OVER_TEMP;
1480 spin_unlock_irq(&phba->hbalock);
1481 lpfc_sli4_offline_eratt(phba);
1482 return;
1483 }
James Smart73d91e52011-10-10 21:32:10 -04001484 /*
1485 * On error status condition, driver need to wait for port
1486 * ready before performing reset.
1487 */
1488 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1489 if (!rc) {
James Smart079b5c92011-08-21 21:48:49 -04001490 /* need reset: attempt for port recovery */
James Smart2fcee4b2010-12-15 17:57:46 -05001491 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1492 "2887 Port Error: Attempting "
1493 "Port Recovery\n");
James Smart079b5c92011-08-21 21:48:49 -04001494 lpfc_offline_prep(phba);
1495 lpfc_offline(phba);
1496 lpfc_sli_brdrestart(phba);
1497 if (lpfc_online(phba) == 0) {
1498 lpfc_unblock_mgmt_io(phba);
1499 return;
1500 }
1501 /* fall through for not able to recover */
James Smart2fcee4b2010-12-15 17:57:46 -05001502 }
1503 lpfc_sli4_offline_eratt(phba);
1504 break;
1505 case LPFC_SLI_INTF_IF_TYPE_1:
1506 default:
1507 break;
1508 }
James Smartda0436e2009-05-22 14:51:39 -04001509}
1510
1511/**
1512 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1513 * @phba: pointer to lpfc HBA data structure.
1514 *
1515 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1516 * routine from the API jump table function pointer from the lpfc_hba struct.
1517 *
1518 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001519 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001520 * Any other value - error.
1521 **/
1522void
1523lpfc_handle_eratt(struct lpfc_hba *phba)
1524{
1525 (*phba->lpfc_handle_eratt)(phba);
1526}
1527
1528/**
James Smart3621a712009-04-06 18:47:14 -04001529 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04001530 * @phba: pointer to lpfc hba data structure.
1531 *
1532 * This routine is invoked from the worker thread to handle a HBA host
1533 * attention link event.
1534 **/
dea31012005-04-17 16:05:31 -05001535void
James Smart2e0fef82007-06-17 19:56:36 -05001536lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001537{
James Smart2e0fef82007-06-17 19:56:36 -05001538 struct lpfc_vport *vport = phba->pport;
1539 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001540 LPFC_MBOXQ_t *pmb;
1541 volatile uint32_t control;
1542 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05001543 int rc = 0;
dea31012005-04-17 16:05:31 -05001544
1545 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001546 if (!pmb) {
1547 rc = 1;
dea31012005-04-17 16:05:31 -05001548 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05001549 }
dea31012005-04-17 16:05:31 -05001550
1551 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001552 if (!mp) {
1553 rc = 2;
dea31012005-04-17 16:05:31 -05001554 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05001555 }
dea31012005-04-17 16:05:31 -05001556
1557 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05001558 if (!mp->virt) {
1559 rc = 3;
dea31012005-04-17 16:05:31 -05001560 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05001561 }
dea31012005-04-17 16:05:31 -05001562
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001563 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04001564 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05001565
1566 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05001567 lpfc_read_topology(phba, pmb, mp);
1568 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05001569 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04001570 /* Block ELS IOCBs until we have processed this mbox command */
1571 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04001572 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05001573 if (rc == MBX_NOT_FINISHED) {
1574 rc = 4;
James Smart14691152006-12-02 13:34:28 -05001575 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05001576 }
dea31012005-04-17 16:05:31 -05001577
1578 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05001579 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001580 writel(HA_LATT, phba->HAregaddr);
1581 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001582 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001583
1584 return;
1585
James Smart14691152006-12-02 13:34:28 -05001586lpfc_handle_latt_free_mbuf:
James Smart0d2b6b82008-06-14 22:52:47 -04001587 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05001588 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05001589lpfc_handle_latt_free_mp:
1590 kfree(mp);
1591lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04001592 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001593lpfc_handle_latt_err_exit:
1594 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001595 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001596 psli->sli_flag |= LPFC_PROCESS_LA;
1597 control = readl(phba->HCregaddr);
1598 control |= HC_LAINT_ENA;
1599 writel(control, phba->HCregaddr);
1600 readl(phba->HCregaddr); /* flush */
1601
1602 /* Clear Link Attention in HA REG */
1603 writel(HA_LATT, phba->HAregaddr);
1604 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001605 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001606 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001607 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001608
James Smart09372822008-01-11 01:52:54 -05001609 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1610 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05001611
1612 return;
1613}
1614
James Smarte59058c2008-08-24 21:49:00 -04001615/**
James Smart3621a712009-04-06 18:47:14 -04001616 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04001617 * @phba: pointer to lpfc hba data structure.
1618 * @vpd: pointer to the vital product data.
1619 * @len: length of the vital product data in bytes.
1620 *
1621 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1622 * an array of characters. In this routine, the ModelName, ProgramType, and
1623 * ModelDesc, etc. fields of the phba data structure will be populated.
1624 *
1625 * Return codes
1626 * 0 - pointer to the VPD passed in is NULL
1627 * 1 - success
1628 **/
James Smart3772a992009-05-22 14:50:54 -04001629int
James Smart2e0fef82007-06-17 19:56:36 -05001630lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05001631{
1632 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05001633 int Length;
dea31012005-04-17 16:05:31 -05001634 int i, j;
1635 int finished = 0;
1636 int index = 0;
1637
1638 if (!vpd)
1639 return 0;
1640
1641 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05001642 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001643 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001644 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
1645 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001646 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05001647 switch (vpd[index]) {
1648 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001649 case 0x91:
dea31012005-04-17 16:05:31 -05001650 index += 1;
1651 lenlo = vpd[index];
1652 index += 1;
1653 lenhi = vpd[index];
1654 index += 1;
1655 i = ((((unsigned short)lenhi) << 8) + lenlo);
1656 index += i;
1657 break;
1658 case 0x90:
1659 index += 1;
1660 lenlo = vpd[index];
1661 index += 1;
1662 lenhi = vpd[index];
1663 index += 1;
1664 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001665 if (Length > len - index)
1666 Length = len - index;
dea31012005-04-17 16:05:31 -05001667 while (Length > 0) {
1668 /* Look for Serial Number */
1669 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
1670 index += 2;
1671 i = vpd[index];
1672 index += 1;
1673 j = 0;
1674 Length -= (3+i);
1675 while(i--) {
1676 phba->SerialNumber[j++] = vpd[index++];
1677 if (j == 31)
1678 break;
1679 }
1680 phba->SerialNumber[j] = 0;
1681 continue;
1682 }
1683 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
1684 phba->vpd_flag |= VPD_MODEL_DESC;
1685 index += 2;
1686 i = vpd[index];
1687 index += 1;
1688 j = 0;
1689 Length -= (3+i);
1690 while(i--) {
1691 phba->ModelDesc[j++] = vpd[index++];
1692 if (j == 255)
1693 break;
1694 }
1695 phba->ModelDesc[j] = 0;
1696 continue;
1697 }
1698 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
1699 phba->vpd_flag |= VPD_MODEL_NAME;
1700 index += 2;
1701 i = vpd[index];
1702 index += 1;
1703 j = 0;
1704 Length -= (3+i);
1705 while(i--) {
1706 phba->ModelName[j++] = vpd[index++];
1707 if (j == 79)
1708 break;
1709 }
1710 phba->ModelName[j] = 0;
1711 continue;
1712 }
1713 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
1714 phba->vpd_flag |= VPD_PROGRAM_TYPE;
1715 index += 2;
1716 i = vpd[index];
1717 index += 1;
1718 j = 0;
1719 Length -= (3+i);
1720 while(i--) {
1721 phba->ProgramType[j++] = vpd[index++];
1722 if (j == 255)
1723 break;
1724 }
1725 phba->ProgramType[j] = 0;
1726 continue;
1727 }
1728 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1729 phba->vpd_flag |= VPD_PORT;
1730 index += 2;
1731 i = vpd[index];
1732 index += 1;
1733 j = 0;
1734 Length -= (3+i);
1735 while(i--) {
1736 phba->Port[j++] = vpd[index++];
1737 if (j == 19)
1738 break;
1739 }
1740 phba->Port[j] = 0;
1741 continue;
1742 }
1743 else {
1744 index += 2;
1745 i = vpd[index];
1746 index += 1;
1747 index += i;
1748 Length -= (3 + i);
1749 }
1750 }
1751 finished = 0;
1752 break;
1753 case 0x78:
1754 finished = 1;
1755 break;
1756 default:
1757 index ++;
1758 break;
1759 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001760 }
dea31012005-04-17 16:05:31 -05001761
1762 return(1);
1763}
1764
James Smarte59058c2008-08-24 21:49:00 -04001765/**
James Smart3621a712009-04-06 18:47:14 -04001766 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04001767 * @phba: pointer to lpfc hba data structure.
1768 * @mdp: pointer to the data structure to hold the derived model name.
1769 * @descp: pointer to the data structure to hold the derived description.
1770 *
1771 * This routine retrieves HBA's description based on its registered PCI device
1772 * ID. The @descp passed into this function points to an array of 256 chars. It
1773 * shall be returned with the model name, maximum speed, and the host bus type.
1774 * The @mdp passed into this function points to an array of 80 chars. When the
1775 * function returns, the @mdp will be filled with the model name.
1776 **/
dea31012005-04-17 16:05:31 -05001777static void
James Smart2e0fef82007-06-17 19:56:36 -05001778lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05001779{
1780 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05001781 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001782 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04001783 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04001784 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001785 struct {
James Smarta747c9c2009-11-18 15:41:10 -05001786 char *name;
1787 char *bus;
1788 char *function;
1789 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001790
1791 if (mdp && mdp[0] != '\0'
1792 && descp && descp[0] != '\0')
1793 return;
1794
James Smartc0c11512011-05-24 11:41:34 -04001795 if (phba->lmt & LMT_16Gb)
1796 max_speed = 16;
1797 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001798 max_speed = 10;
1799 else if (phba->lmt & LMT_8Gb)
1800 max_speed = 8;
1801 else if (phba->lmt & LMT_4Gb)
1802 max_speed = 4;
1803 else if (phba->lmt & LMT_2Gb)
1804 max_speed = 2;
1805 else
1806 max_speed = 1;
dea31012005-04-17 16:05:31 -05001807
1808 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05001809
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001810 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001811 case PCI_DEVICE_ID_FIREFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001812 m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001813 break;
dea31012005-04-17 16:05:31 -05001814 case PCI_DEVICE_ID_SUPERFLY:
1815 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smarta747c9c2009-11-18 15:41:10 -05001816 m = (typeof(m)){"LP7000", "PCI",
1817 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001818 else
James Smarta747c9c2009-11-18 15:41:10 -05001819 m = (typeof(m)){"LP7000E", "PCI",
1820 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001821 break;
1822 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001823 m = (typeof(m)){"LP8000", "PCI",
1824 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001825 break;
1826 case PCI_DEVICE_ID_CENTAUR:
1827 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smarta747c9c2009-11-18 15:41:10 -05001828 m = (typeof(m)){"LP9002", "PCI",
1829 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001830 else
James Smarta747c9c2009-11-18 15:41:10 -05001831 m = (typeof(m)){"LP9000", "PCI",
1832 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001833 break;
1834 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001835 m = (typeof(m)){"LP952", "PCI",
1836 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001837 break;
1838 case PCI_DEVICE_ID_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05001839 m = (typeof(m)){"LP9802", "PCI-X",
1840 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001841 break;
1842 case PCI_DEVICE_ID_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05001843 m = (typeof(m)){"LP10000", "PCI-X",
1844 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001845 break;
1846 case PCI_DEVICE_ID_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05001847 m = (typeof(m)){"LPX1000", "PCI-X",
1848 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001849 break;
1850 case PCI_DEVICE_ID_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001851 m = (typeof(m)){"LP982", "PCI-X",
1852 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001853 break;
1854 case PCI_DEVICE_ID_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001855 m = (typeof(m)){"LP1050", "PCI-X",
1856 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001857 break;
1858 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05001859 m = (typeof(m)){"LP11000", "PCI-X2",
1860 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001861 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001862 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001863 m = (typeof(m)){"LP11000-SP", "PCI-X2",
1864 "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001865 break;
1866 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001867 m = (typeof(m)){"LP11002-SP", "PCI-X2",
1868 "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001869 break;
1870 case PCI_DEVICE_ID_NEPTUNE:
James Smarta747c9c2009-11-18 15:41:10 -05001871 m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001872 break;
1873 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001874 m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001875 break;
1876 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001877 m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001878 break;
dea31012005-04-17 16:05:31 -05001879 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05001880 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001881 break;
1882 case PCI_DEVICE_ID_BSMB:
James Smarta747c9c2009-11-18 15:41:10 -05001883 m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001884 break;
1885 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05001886 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001887 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001888 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001889 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001890 break;
1891 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001892 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04001893 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001894 break;
dea31012005-04-17 16:05:31 -05001895 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05001896 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001897 break;
1898 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05001899 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001900 break;
1901 case PCI_DEVICE_ID_LP101:
James Smarta747c9c2009-11-18 15:41:10 -05001902 m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001903 break;
1904 case PCI_DEVICE_ID_LP10000S:
James Smarta747c9c2009-11-18 15:41:10 -05001905 m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001906 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001907 case PCI_DEVICE_ID_LP11000S:
James Smarta747c9c2009-11-18 15:41:10 -05001908 m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05001909 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001910 case PCI_DEVICE_ID_LPE11000S:
James Smarta747c9c2009-11-18 15:41:10 -05001911 m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001912 break;
James Smartb87eab32007-04-25 09:53:28 -04001913 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05001914 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04001915 break;
1916 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05001917 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04001918 break;
1919 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05001920 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04001921 break;
1922 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001923 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04001924 break;
1925 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001926 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04001927 break;
1928 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05001929 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04001930 break;
James Smart84774a42008-08-24 21:50:06 -04001931 case PCI_DEVICE_ID_HORNET:
James Smarta747c9c2009-11-18 15:41:10 -05001932 m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04001933 GE = 1;
1934 break;
1935 case PCI_DEVICE_ID_PROTEUS_VF:
James Smarta747c9c2009-11-18 15:41:10 -05001936 m = (typeof(m)){"LPev12000", "PCIe IOV",
1937 "Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04001938 break;
1939 case PCI_DEVICE_ID_PROTEUS_PF:
James Smarta747c9c2009-11-18 15:41:10 -05001940 m = (typeof(m)){"LPev12000", "PCIe IOV",
1941 "Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04001942 break;
1943 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05001944 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
1945 "Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04001946 break;
James Smartda0436e2009-05-22 14:51:39 -04001947 case PCI_DEVICE_ID_TIGERSHARK:
1948 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05001949 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04001950 break;
James Smarta747c9c2009-11-18 15:41:10 -05001951 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04001952 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05001953 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
1954 break;
1955 case PCI_DEVICE_ID_FALCON:
1956 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
1957 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04001958 break;
James Smart98fc5dd2010-06-07 15:24:29 -04001959 case PCI_DEVICE_ID_BALIUS:
1960 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
1961 "Fibre Channel Adapter"};
1962 break;
James Smart085c6472010-11-20 23:11:37 -05001963 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04001964 case PCI_DEVICE_ID_LANCER_FC_VF:
1965 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05001966 break;
1967 case PCI_DEVICE_ID_LANCER_FCOE:
James Smartc0c11512011-05-24 11:41:34 -04001968 case PCI_DEVICE_ID_LANCER_FCOE_VF:
James Smart085c6472010-11-20 23:11:37 -05001969 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04001970 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05001971 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001972 default:
James Smarta747c9c2009-11-18 15:41:10 -05001973 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001974 break;
dea31012005-04-17 16:05:31 -05001975 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001976
1977 if (mdp && mdp[0] == '\0')
1978 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04001979 /*
1980 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04001981 * and we put the port number on the end
1982 */
1983 if (descp && descp[0] == '\0') {
1984 if (oneConnect)
1985 snprintf(descp, 255,
James Smarta747c9c2009-11-18 15:41:10 -05001986 "Emulex OneConnect %s, %s Initiator, Port %s",
1987 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04001988 phba->Port);
1989 else
1990 snprintf(descp, 255,
1991 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05001992 m.name, max_speed, (GE) ? "GE" : "Gb",
1993 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04001994 }
dea31012005-04-17 16:05:31 -05001995}
1996
James Smarte59058c2008-08-24 21:49:00 -04001997/**
James Smart3621a712009-04-06 18:47:14 -04001998 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04001999 * @phba: pointer to lpfc hba data structure.
2000 * @pring: pointer to a IOCB ring.
2001 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2002 *
2003 * This routine posts a given number of IOCBs with the associated DMA buffer
2004 * descriptors specified by the cnt argument to the given IOCB ring.
2005 *
2006 * Return codes
2007 * The number of IOCBs NOT able to be posted to the IOCB ring.
2008 **/
dea31012005-04-17 16:05:31 -05002009int
James Smart495a7142008-06-14 22:52:59 -04002010lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002011{
2012 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002013 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002014 struct lpfc_dmabuf *mp1, *mp2;
2015
2016 cnt += pring->missbufcnt;
2017
2018 /* While there are buffers to post */
2019 while (cnt > 0) {
2020 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002021 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002022 if (iocb == NULL) {
2023 pring->missbufcnt = cnt;
2024 return cnt;
2025 }
dea31012005-04-17 16:05:31 -05002026 icmd = &iocb->iocb;
2027
2028 /* 2 buffers can be posted per command */
2029 /* Allocate buffer to post */
2030 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2031 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002032 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2033 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002034 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002035 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002036 pring->missbufcnt = cnt;
2037 return cnt;
2038 }
2039
2040 INIT_LIST_HEAD(&mp1->list);
2041 /* Allocate buffer to post */
2042 if (cnt > 1) {
2043 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2044 if (mp2)
2045 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2046 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002047 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002048 kfree(mp2);
dea31012005-04-17 16:05:31 -05002049 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2050 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002051 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002052 pring->missbufcnt = cnt;
2053 return cnt;
2054 }
2055
2056 INIT_LIST_HEAD(&mp2->list);
2057 } else {
2058 mp2 = NULL;
2059 }
2060
2061 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2062 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2063 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2064 icmd->ulpBdeCount = 1;
2065 cnt--;
2066 if (mp2) {
2067 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2068 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2069 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2070 cnt--;
2071 icmd->ulpBdeCount = 2;
2072 }
2073
2074 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2075 icmd->ulpLe = 1;
2076
James Smart3772a992009-05-22 14:50:54 -04002077 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2078 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002079 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2080 kfree(mp1);
2081 cnt++;
2082 if (mp2) {
2083 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2084 kfree(mp2);
2085 cnt++;
2086 }
James Bottomley604a3e32005-10-29 10:28:33 -05002087 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002088 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002089 return cnt;
2090 }
dea31012005-04-17 16:05:31 -05002091 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002092 if (mp2)
dea31012005-04-17 16:05:31 -05002093 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002094 }
2095 pring->missbufcnt = 0;
2096 return 0;
2097}
2098
James Smarte59058c2008-08-24 21:49:00 -04002099/**
James Smart3621a712009-04-06 18:47:14 -04002100 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002101 * @phba: pointer to lpfc hba data structure.
2102 *
2103 * This routine posts initial receive IOCB buffers to the ELS ring. The
2104 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2105 * set to 64 IOCBs.
2106 *
2107 * Return codes
2108 * 0 - success (currently always success)
2109 **/
dea31012005-04-17 16:05:31 -05002110static int
James Smart2e0fef82007-06-17 19:56:36 -05002111lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002112{
2113 struct lpfc_sli *psli = &phba->sli;
2114
2115 /* Ring 0, ELS / CT buffers */
James Smart495a7142008-06-14 22:52:59 -04002116 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002117 /* Ring 2 - FCP no buffers needed */
2118
2119 return 0;
2120}
2121
2122#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2123
James Smarte59058c2008-08-24 21:49:00 -04002124/**
James Smart3621a712009-04-06 18:47:14 -04002125 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002126 * @HashResultPointer: pointer to an array as hash table.
2127 *
2128 * This routine sets up the initial values to the array of hash table entries
2129 * for the LC HBAs.
2130 **/
dea31012005-04-17 16:05:31 -05002131static void
2132lpfc_sha_init(uint32_t * HashResultPointer)
2133{
2134 HashResultPointer[0] = 0x67452301;
2135 HashResultPointer[1] = 0xEFCDAB89;
2136 HashResultPointer[2] = 0x98BADCFE;
2137 HashResultPointer[3] = 0x10325476;
2138 HashResultPointer[4] = 0xC3D2E1F0;
2139}
2140
James Smarte59058c2008-08-24 21:49:00 -04002141/**
James Smart3621a712009-04-06 18:47:14 -04002142 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002143 * @HashResultPointer: pointer to an initial/result hash table.
2144 * @HashWorkingPointer: pointer to an working hash table.
2145 *
2146 * This routine iterates an initial hash table pointed by @HashResultPointer
2147 * with the values from the working hash table pointeed by @HashWorkingPointer.
2148 * The results are putting back to the initial hash table, returned through
2149 * the @HashResultPointer as the result hash table.
2150 **/
dea31012005-04-17 16:05:31 -05002151static void
2152lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2153{
2154 int t;
2155 uint32_t TEMP;
2156 uint32_t A, B, C, D, E;
2157 t = 16;
2158 do {
2159 HashWorkingPointer[t] =
2160 S(1,
2161 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2162 8] ^
2163 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2164 } while (++t <= 79);
2165 t = 0;
2166 A = HashResultPointer[0];
2167 B = HashResultPointer[1];
2168 C = HashResultPointer[2];
2169 D = HashResultPointer[3];
2170 E = HashResultPointer[4];
2171
2172 do {
2173 if (t < 20) {
2174 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2175 } else if (t < 40) {
2176 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2177 } else if (t < 60) {
2178 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2179 } else {
2180 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2181 }
2182 TEMP += S(5, A) + E + HashWorkingPointer[t];
2183 E = D;
2184 D = C;
2185 C = S(30, B);
2186 B = A;
2187 A = TEMP;
2188 } while (++t <= 79);
2189
2190 HashResultPointer[0] += A;
2191 HashResultPointer[1] += B;
2192 HashResultPointer[2] += C;
2193 HashResultPointer[3] += D;
2194 HashResultPointer[4] += E;
2195
2196}
2197
James Smarte59058c2008-08-24 21:49:00 -04002198/**
James Smart3621a712009-04-06 18:47:14 -04002199 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002200 * @RandomChallenge: pointer to the entry of host challenge random number array.
2201 * @HashWorking: pointer to the entry of the working hash array.
2202 *
2203 * This routine calculates the working hash array referred by @HashWorking
2204 * from the challenge random numbers associated with the host, referred by
2205 * @RandomChallenge. The result is put into the entry of the working hash
2206 * array and returned by reference through @HashWorking.
2207 **/
dea31012005-04-17 16:05:31 -05002208static void
2209lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2210{
2211 *HashWorking = (*RandomChallenge ^ *HashWorking);
2212}
2213
James Smarte59058c2008-08-24 21:49:00 -04002214/**
James Smart3621a712009-04-06 18:47:14 -04002215 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002216 * @phba: pointer to lpfc hba data structure.
2217 * @hbainit: pointer to an array of unsigned 32-bit integers.
2218 *
2219 * This routine performs the special handling for LC HBA initialization.
2220 **/
dea31012005-04-17 16:05:31 -05002221void
2222lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2223{
2224 int t;
2225 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002226 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002227
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002228 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002229 if (!HashWorking)
2230 return;
2231
dea31012005-04-17 16:05:31 -05002232 HashWorking[0] = HashWorking[78] = *pwwnn++;
2233 HashWorking[1] = HashWorking[79] = *pwwnn;
2234
2235 for (t = 0; t < 7; t++)
2236 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2237
2238 lpfc_sha_init(hbainit);
2239 lpfc_sha_iterate(hbainit, HashWorking);
2240 kfree(HashWorking);
2241}
2242
James Smarte59058c2008-08-24 21:49:00 -04002243/**
James Smart3621a712009-04-06 18:47:14 -04002244 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002245 * @vport: pointer to a virtual N_Port data structure.
2246 *
2247 * This routine performs the necessary cleanups before deleting the @vport.
2248 * It invokes the discovery state machine to perform necessary state
2249 * transitions and to release the ndlps associated with the @vport. Note,
2250 * the physical port is treated as @vport 0.
2251 **/
James Smart87af33f2007-10-27 13:37:43 -04002252void
James Smart2e0fef82007-06-17 19:56:36 -05002253lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002254{
James Smart87af33f2007-10-27 13:37:43 -04002255 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002256 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002257 int i = 0;
dea31012005-04-17 16:05:31 -05002258
James Smart87af33f2007-10-27 13:37:43 -04002259 if (phba->link_state > LPFC_LINK_DOWN)
2260 lpfc_port_link_failure(vport);
2261
2262 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002263 if (!NLP_CHK_NODE_ACT(ndlp)) {
2264 ndlp = lpfc_enable_node(vport, ndlp,
2265 NLP_STE_UNUSED_NODE);
2266 if (!ndlp)
2267 continue;
2268 spin_lock_irq(&phba->ndlp_lock);
2269 NLP_SET_FREE_REQ(ndlp);
2270 spin_unlock_irq(&phba->ndlp_lock);
2271 /* Trigger the release of the ndlp memory */
2272 lpfc_nlp_put(ndlp);
2273 continue;
2274 }
2275 spin_lock_irq(&phba->ndlp_lock);
2276 if (NLP_CHK_FREE_REQ(ndlp)) {
2277 /* The ndlp should not be in memory free mode already */
2278 spin_unlock_irq(&phba->ndlp_lock);
2279 continue;
2280 } else
2281 /* Indicate request for freeing ndlp memory */
2282 NLP_SET_FREE_REQ(ndlp);
2283 spin_unlock_irq(&phba->ndlp_lock);
2284
James Smart58da1ff2008-04-07 10:15:56 -04002285 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2286 ndlp->nlp_DID == Fabric_DID) {
2287 /* Just free up ndlp with Fabric_DID for vports */
2288 lpfc_nlp_put(ndlp);
2289 continue;
2290 }
2291
James Smart87af33f2007-10-27 13:37:43 -04002292 if (ndlp->nlp_type & NLP_FABRIC)
2293 lpfc_disc_state_machine(vport, ndlp, NULL,
2294 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002295
James Smart87af33f2007-10-27 13:37:43 -04002296 lpfc_disc_state_machine(vport, ndlp, NULL,
2297 NLP_EVT_DEVICE_RM);
James Smart495a7142008-06-14 22:52:59 -04002298
James Smart87af33f2007-10-27 13:37:43 -04002299 }
2300
James Smarta8adb832007-10-27 13:37:53 -04002301 /* At this point, ALL ndlp's should be gone
2302 * because of the previous NLP_EVT_DEVICE_RM.
2303 * Lets wait for this to happen, if needed.
2304 */
James Smart87af33f2007-10-27 13:37:43 -04002305 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002306 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04002307 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04002308 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002309 list_for_each_entry_safe(ndlp, next_ndlp,
2310 &vport->fc_nodes, nlp_listp) {
2311 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2312 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04002313 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05002314 "usgmap:x%x refcnt:%d\n",
2315 ndlp->nlp_DID, (void *)ndlp,
2316 ndlp->nlp_usg_map,
2317 atomic_read(
2318 &ndlp->kref.refcount));
2319 }
James Smarta8adb832007-10-27 13:37:53 -04002320 break;
James Smart87af33f2007-10-27 13:37:43 -04002321 }
James Smarta8adb832007-10-27 13:37:53 -04002322
2323 /* Wait for any activity on ndlps to settle */
2324 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002325 }
James Smart1151e3e2011-02-16 12:39:35 -05002326 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002327}
2328
James Smarte59058c2008-08-24 21:49:00 -04002329/**
James Smart3621a712009-04-06 18:47:14 -04002330 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002331 * @vport: pointer to a virtual N_Port data structure.
2332 *
2333 * This routine stops all the timers associated with a @vport. This function
2334 * is invoked before disabling or deleting a @vport. Note that the physical
2335 * port is treated as @vport 0.
2336 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002337void
2338lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002339{
James Smart92d7f7b2007-06-17 19:56:38 -05002340 del_timer_sync(&vport->els_tmofunc);
2341 del_timer_sync(&vport->fc_fdmitmo);
James Smart92494142011-02-16 12:39:44 -05002342 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002343 lpfc_can_disctmo(vport);
2344 return;
dea31012005-04-17 16:05:31 -05002345}
2346
James Smarte59058c2008-08-24 21:49:00 -04002347/**
James Smartecfd03c2010-02-12 14:41:27 -05002348 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2349 * @phba: pointer to lpfc hba data structure.
2350 *
2351 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2352 * caller of this routine should already hold the host lock.
2353 **/
2354void
2355__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2356{
James Smart5ac6b302010-10-22 11:05:36 -04002357 /* Clear pending FCF rediscovery wait flag */
2358 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2359
James Smartecfd03c2010-02-12 14:41:27 -05002360 /* Now, try to stop the timer */
2361 del_timer(&phba->fcf.redisc_wait);
2362}
2363
2364/**
2365 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2366 * @phba: pointer to lpfc hba data structure.
2367 *
2368 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2369 * checks whether the FCF rediscovery wait timer is pending with the host
2370 * lock held before proceeding with disabling the timer and clearing the
2371 * wait timer pendig flag.
2372 **/
2373void
2374lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2375{
2376 spin_lock_irq(&phba->hbalock);
2377 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2378 /* FCF rediscovery timer already fired or stopped */
2379 spin_unlock_irq(&phba->hbalock);
2380 return;
2381 }
2382 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002383 /* Clear failover in progress flags */
2384 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002385 spin_unlock_irq(&phba->hbalock);
2386}
2387
2388/**
James Smart3772a992009-05-22 14:50:54 -04002389 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002390 * @phba: pointer to lpfc hba data structure.
2391 *
2392 * This routine stops all the timers associated with a HBA. This function is
2393 * invoked before either putting a HBA offline or unloading the driver.
2394 **/
James Smart3772a992009-05-22 14:50:54 -04002395void
2396lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002397{
James Smart51ef4c22007-08-02 11:10:31 -04002398 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05002399 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002400 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002401 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002402 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002403 if (phba->sli_rev == LPFC_SLI_REV4) {
2404 del_timer_sync(&phba->rrq_tmr);
2405 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2406 }
James Smart3772a992009-05-22 14:50:54 -04002407 phba->hb_outstanding = 0;
2408
2409 switch (phba->pci_dev_grp) {
2410 case LPFC_PCI_DEV_LP:
2411 /* Stop any LightPulse device specific driver timers */
2412 del_timer_sync(&phba->fcp_poll_timer);
2413 break;
2414 case LPFC_PCI_DEV_OC:
2415 /* Stop any OneConnect device sepcific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002416 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002417 break;
2418 default:
2419 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2420 "0297 Invalid device group (x%x)\n",
2421 phba->pci_dev_grp);
2422 break;
2423 }
James Smart2e0fef82007-06-17 19:56:36 -05002424 return;
dea31012005-04-17 16:05:31 -05002425}
2426
James Smarte59058c2008-08-24 21:49:00 -04002427/**
James Smart3621a712009-04-06 18:47:14 -04002428 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002429 * @phba: pointer to lpfc hba data structure.
2430 *
2431 * This routine marks a HBA's management interface as blocked. Once the HBA's
2432 * management interface is marked as blocked, all the user space access to
2433 * the HBA, whether they are from sysfs interface or libdfc interface will
2434 * all be blocked. The HBA is set to block the management interface when the
2435 * driver prepares the HBA interface for online or offline.
2436 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01002437static void
2438lpfc_block_mgmt_io(struct lpfc_hba * phba)
2439{
2440 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04002441 uint8_t actcmd = MBX_HEARTBEAT;
2442 unsigned long timeout;
2443
Adrian Bunka6ababd2007-11-05 18:07:33 +01002444
2445 spin_lock_irqsave(&phba->hbalock, iflag);
2446 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart6e7288d2010-06-07 15:23:35 -04002447 if (phba->sli.mbox_active)
2448 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
Adrian Bunka6ababd2007-11-05 18:07:33 +01002449 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart6e7288d2010-06-07 15:23:35 -04002450 /* Determine how long we might wait for the active mailbox
2451 * command to be gracefully completed by firmware.
2452 */
2453 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
2454 jiffies;
2455 /* Wait for the outstnading mailbox command to complete */
2456 while (phba->sli.mbox_active) {
2457 /* Check active mailbox complete status every 2ms */
2458 msleep(2);
2459 if (time_after(jiffies, timeout)) {
2460 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2461 "2813 Mgmt IO is Blocked %x "
2462 "- mbox cmd %x still active\n",
2463 phba->sli.sli_flag, actcmd);
2464 break;
2465 }
2466 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002467}
2468
James Smarte59058c2008-08-24 21:49:00 -04002469/**
James Smart3621a712009-04-06 18:47:14 -04002470 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04002471 * @phba: pointer to lpfc hba data structure.
2472 *
2473 * This routine initializes the HBA and brings a HBA online. During this
2474 * process, the management interface is blocked to prevent user space access
2475 * to the HBA interfering with the driver initialization.
2476 *
2477 * Return codes
2478 * 0 - successful
2479 * 1 - failed
2480 **/
dea31012005-04-17 16:05:31 -05002481int
James Smart2e0fef82007-06-17 19:56:36 -05002482lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002483{
Julia Lawall372bd282008-12-16 16:15:08 +01002484 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04002485 struct lpfc_vport **vports;
2486 int i;
James Smart2e0fef82007-06-17 19:56:36 -05002487
dea31012005-04-17 16:05:31 -05002488 if (!phba)
2489 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01002490 vport = phba->pport;
dea31012005-04-17 16:05:31 -05002491
James Smart2e0fef82007-06-17 19:56:36 -05002492 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05002493 return 0;
2494
James Smarted957682007-06-17 19:56:37 -05002495 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002496 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05002497
James Smart46fa3112007-04-25 09:51:45 -04002498 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002499
James Smart46fa3112007-04-25 09:51:45 -04002500 if (!lpfc_sli_queue_setup(phba)) {
2501 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002502 return 1;
James Smart46fa3112007-04-25 09:51:45 -04002503 }
2504
James Smartda0436e2009-05-22 14:51:39 -04002505 if (phba->sli_rev == LPFC_SLI_REV4) {
2506 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
2507 lpfc_unblock_mgmt_io(phba);
2508 return 1;
2509 }
2510 } else {
2511 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
2512 lpfc_unblock_mgmt_io(phba);
2513 return 1;
2514 }
James Smart46fa3112007-04-25 09:51:45 -04002515 }
dea31012005-04-17 16:05:31 -05002516
James Smart549e55c2007-08-02 11:09:51 -04002517 vports = lpfc_create_vport_work_array(phba);
2518 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002519 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002520 struct Scsi_Host *shost;
2521 shost = lpfc_shost_from_vport(vports[i]);
2522 spin_lock_irq(shost->host_lock);
2523 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
2524 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2525 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart1c6834a2009-07-19 10:01:26 -04002526 if (phba->sli_rev == LPFC_SLI_REV4)
2527 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart549e55c2007-08-02 11:09:51 -04002528 spin_unlock_irq(shost->host_lock);
2529 }
James Smart09372822008-01-11 01:52:54 -05002530 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002531
James Smart46fa3112007-04-25 09:51:45 -04002532 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002533 return 0;
2534}
2535
James Smarte59058c2008-08-24 21:49:00 -04002536/**
James Smart3621a712009-04-06 18:47:14 -04002537 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04002538 * @phba: pointer to lpfc hba data structure.
2539 *
2540 * This routine marks a HBA's management interface as not blocked. Once the
2541 * HBA's management interface is marked as not blocked, all the user space
2542 * access to the HBA, whether they are from sysfs interface or libdfc
2543 * interface will be allowed. The HBA is set to block the management interface
2544 * when the driver prepares the HBA interface for online or offline and then
2545 * set to unblock the management interface afterwards.
2546 **/
James Smart46fa3112007-04-25 09:51:45 -04002547void
James Smart46fa3112007-04-25 09:51:45 -04002548lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
2549{
2550 unsigned long iflag;
2551
James Smart2e0fef82007-06-17 19:56:36 -05002552 spin_lock_irqsave(&phba->hbalock, iflag);
2553 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
2554 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04002555}
2556
James Smarte59058c2008-08-24 21:49:00 -04002557/**
James Smart3621a712009-04-06 18:47:14 -04002558 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04002559 * @phba: pointer to lpfc hba data structure.
2560 *
2561 * This routine is invoked to prepare a HBA to be brought offline. It performs
2562 * unregistration login to all the nodes on all vports and flushes the mailbox
2563 * queue to make it ready to be brought offline.
2564 **/
James Smart46fa3112007-04-25 09:51:45 -04002565void
2566lpfc_offline_prep(struct lpfc_hba * phba)
2567{
James Smart2e0fef82007-06-17 19:56:36 -05002568 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04002569 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04002570 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05002571 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04002572 int i;
dea31012005-04-17 16:05:31 -05002573
James Smart2e0fef82007-06-17 19:56:36 -05002574 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002575 return;
dea31012005-04-17 16:05:31 -05002576
James Smart46fa3112007-04-25 09:51:45 -04002577 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002578
2579 lpfc_linkdown(phba);
2580
James Smart87af33f2007-10-27 13:37:43 -04002581 /* Issue an unreg_login to all nodes on all vports */
2582 vports = lpfc_create_vport_work_array(phba);
2583 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04002584 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04002585 if (vports[i]->load_flag & FC_UNLOADING)
2586 continue;
James Smart72100cc2010-02-12 14:43:01 -05002587 shost = lpfc_shost_from_vport(vports[i]);
2588 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05002589 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002590 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2591 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05002592 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05002593
James Smart87af33f2007-10-27 13:37:43 -04002594 shost = lpfc_shost_from_vport(vports[i]);
2595 list_for_each_entry_safe(ndlp, next_ndlp,
2596 &vports[i]->fc_nodes,
2597 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002598 if (!NLP_CHK_NODE_ACT(ndlp))
2599 continue;
James Smart87af33f2007-10-27 13:37:43 -04002600 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2601 continue;
2602 if (ndlp->nlp_type & NLP_FABRIC) {
2603 lpfc_disc_state_machine(vports[i], ndlp,
2604 NULL, NLP_EVT_DEVICE_RECOVERY);
2605 lpfc_disc_state_machine(vports[i], ndlp,
2606 NULL, NLP_EVT_DEVICE_RM);
2607 }
2608 spin_lock_irq(shost->host_lock);
2609 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2610 spin_unlock_irq(shost->host_lock);
2611 lpfc_unreg_rpi(vports[i], ndlp);
2612 }
2613 }
2614 }
James Smart09372822008-01-11 01:52:54 -05002615 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002616
James Smart04c68492009-05-22 14:52:52 -04002617 lpfc_sli_mbox_sys_shutdown(phba);
James Smart46fa3112007-04-25 09:51:45 -04002618}
2619
James Smarte59058c2008-08-24 21:49:00 -04002620/**
James Smart3621a712009-04-06 18:47:14 -04002621 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04002622 * @phba: pointer to lpfc hba data structure.
2623 *
2624 * This routine actually brings a HBA offline. It stops all the timers
2625 * associated with the HBA, brings down the SLI layer, and eventually
2626 * marks the HBA as in offline state for the upper layer protocol.
2627 **/
James Smart46fa3112007-04-25 09:51:45 -04002628void
James Smart2e0fef82007-06-17 19:56:36 -05002629lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04002630{
James Smart549e55c2007-08-02 11:09:51 -04002631 struct Scsi_Host *shost;
2632 struct lpfc_vport **vports;
2633 int i;
James Smart46fa3112007-04-25 09:51:45 -04002634
James Smart549e55c2007-08-02 11:09:51 -04002635 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002636 return;
James Smart688a8862006-07-06 15:49:56 -04002637
James Smartda0436e2009-05-22 14:51:39 -04002638 /* stop port and all timers associated with this hba */
2639 lpfc_stop_port(phba);
James Smart51ef4c22007-08-02 11:10:31 -04002640 vports = lpfc_create_vport_work_array(phba);
2641 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002642 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04002643 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05002644 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05002645 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002646 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05002647 /* Bring down the SLI Layer and cleanup. The HBA is offline
2648 now. */
2649 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002650 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04002651 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05002652 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04002653 vports = lpfc_create_vport_work_array(phba);
2654 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002655 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002656 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04002657 spin_lock_irq(shost->host_lock);
2658 vports[i]->work_port_events = 0;
2659 vports[i]->fc_flag |= FC_OFFLINE_MODE;
2660 spin_unlock_irq(shost->host_lock);
2661 }
James Smart09372822008-01-11 01:52:54 -05002662 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002663}
2664
James Smarte59058c2008-08-24 21:49:00 -04002665/**
James Smart3621a712009-04-06 18:47:14 -04002666 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04002667 * @phba: pointer to lpfc hba data structure.
2668 *
2669 * This routine is to free all the SCSI buffers and IOCBs from the driver
2670 * list back to kernel. It is called from lpfc_pci_remove_one to free
2671 * the internal resources before the device is removed from the system.
2672 *
2673 * Return codes
2674 * 0 - successful (for now, it always returns 0)
2675 **/
dea31012005-04-17 16:05:31 -05002676static int
James Smart2e0fef82007-06-17 19:56:36 -05002677lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002678{
2679 struct lpfc_scsi_buf *sb, *sb_next;
2680 struct lpfc_iocbq *io, *io_next;
2681
James Smart2e0fef82007-06-17 19:56:36 -05002682 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002683 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smart1c6f4ef52009-11-18 15:40:49 -05002684 spin_lock(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05002685 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
2686 list_del(&sb->list);
2687 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05002688 sb->dma_handle);
dea31012005-04-17 16:05:31 -05002689 kfree(sb);
2690 phba->total_scsi_bufs--;
2691 }
James Smart1c6f4ef52009-11-18 15:40:49 -05002692 spin_unlock(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05002693
2694 /* Release all the lpfc_iocbq entries maintained by this host. */
2695 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
2696 list_del(&io->list);
2697 kfree(io);
2698 phba->total_iocbq_bufs--;
2699 }
James Smart6d368e52011-05-24 11:44:12 -04002700
James Smart2e0fef82007-06-17 19:56:36 -05002701 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002702 return 0;
2703}
2704
James Smarte59058c2008-08-24 21:49:00 -04002705/**
James Smart3621a712009-04-06 18:47:14 -04002706 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04002707 * @phba: pointer to lpfc hba data structure.
2708 * @instance: a unique integer ID to this FC port.
2709 * @dev: pointer to the device data structure.
2710 *
2711 * This routine creates a FC port for the upper layer protocol. The FC port
2712 * can be created on top of either a physical port or a virtual port provided
2713 * by the HBA. This routine also allocates a SCSI host data structure (shost)
2714 * and associates the FC port created before adding the shost into the SCSI
2715 * layer.
2716 *
2717 * Return codes
2718 * @vport - pointer to the virtual N_Port data structure.
2719 * NULL - port create failed.
2720 **/
James Smart2e0fef82007-06-17 19:56:36 -05002721struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04002722lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04002723{
James Smart2e0fef82007-06-17 19:56:36 -05002724 struct lpfc_vport *vport;
2725 struct Scsi_Host *shost;
2726 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04002727
James Smart3de2a652007-08-02 11:09:59 -04002728 if (dev != &phba->pcidev->dev)
2729 shost = scsi_host_alloc(&lpfc_vport_template,
2730 sizeof(struct lpfc_vport));
2731 else
2732 shost = scsi_host_alloc(&lpfc_template,
2733 sizeof(struct lpfc_vport));
James Smart2e0fef82007-06-17 19:56:36 -05002734 if (!shost)
2735 goto out;
James Smart47a86172007-04-25 09:53:22 -04002736
James Smart2e0fef82007-06-17 19:56:36 -05002737 vport = (struct lpfc_vport *) shost->hostdata;
2738 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05002739 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05002740 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05002741 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04002742
James Smart3de2a652007-08-02 11:09:59 -04002743 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002744 shost->unique_id = instance;
2745 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04002746 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05002747 shost->this_id = -1;
2748 shost->max_cmd_len = 16;
James Smartda0436e2009-05-22 14:51:39 -04002749 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05002750 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04002751 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smartda0436e2009-05-22 14:51:39 -04002752 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
2753 }
James Smart81301a92008-12-04 22:39:46 -05002754
James Smart47a86172007-04-25 09:53:22 -04002755 /*
James Smart2e0fef82007-06-17 19:56:36 -05002756 * Set initial can_queue value since 0 is no longer supported and
2757 * scsi_add_host will fail. This will be adjusted later based on the
2758 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04002759 */
James Smart2e0fef82007-06-17 19:56:36 -05002760 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04002761 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05002762 shost->transportt = lpfc_vport_transport_template;
2763 vport->port_type = LPFC_NPIV_PORT;
2764 } else {
2765 shost->transportt = lpfc_transport_template;
2766 vport->port_type = LPFC_PHYSICAL_PORT;
2767 }
James Smart47a86172007-04-25 09:53:22 -04002768
James Smart2e0fef82007-06-17 19:56:36 -05002769 /* Initialize all internally managed lists. */
2770 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04002771 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05002772 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04002773
James Smart2e0fef82007-06-17 19:56:36 -05002774 init_timer(&vport->fc_disctmo);
2775 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05002776 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04002777
James Smart2e0fef82007-06-17 19:56:36 -05002778 init_timer(&vport->fc_fdmitmo);
2779 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
James Smart92d7f7b2007-06-17 19:56:38 -05002780 vport->fc_fdmitmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04002781
James Smart2e0fef82007-06-17 19:56:36 -05002782 init_timer(&vport->els_tmofunc);
2783 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05002784 vport->els_tmofunc.data = (unsigned long)vport;
James Smart92494142011-02-16 12:39:44 -05002785
2786 init_timer(&vport->delayed_disc_tmo);
2787 vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
2788 vport->delayed_disc_tmo.data = (unsigned long)vport;
2789
James Bottomleyd139b9b2009-11-05 13:33:12 -06002790 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05002791 if (error)
2792 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04002793
James Smart549e55c2007-08-02 11:09:51 -04002794 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05002795 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04002796 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05002797 return vport;
James Smart47a86172007-04-25 09:53:22 -04002798
James Smart2e0fef82007-06-17 19:56:36 -05002799out_put_shost:
2800 scsi_host_put(shost);
2801out:
2802 return NULL;
James Smart47a86172007-04-25 09:53:22 -04002803}
2804
James Smarte59058c2008-08-24 21:49:00 -04002805/**
James Smart3621a712009-04-06 18:47:14 -04002806 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04002807 * @vport: pointer to an lpfc virtual N_Port data structure.
2808 *
2809 * This routine destroys a FC port from the upper layer protocol. All the
2810 * resources associated with the port are released.
2811 **/
James Smart2e0fef82007-06-17 19:56:36 -05002812void
2813destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04002814{
James Smart92d7f7b2007-06-17 19:56:38 -05002815 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2816 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04002817
James Smart858c9f62007-06-17 19:56:39 -05002818 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05002819 fc_remove_host(shost);
2820 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04002821
James Smart92d7f7b2007-06-17 19:56:38 -05002822 spin_lock_irq(&phba->hbalock);
2823 list_del_init(&vport->listentry);
2824 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04002825
James Smart92d7f7b2007-06-17 19:56:38 -05002826 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04002827 return;
James Smart47a86172007-04-25 09:53:22 -04002828}
2829
James Smarte59058c2008-08-24 21:49:00 -04002830/**
James Smart3621a712009-04-06 18:47:14 -04002831 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04002832 *
2833 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
2834 * uses the kernel idr facility to perform the task.
2835 *
2836 * Return codes:
2837 * instance - a unique integer ID allocated as the new instance.
2838 * -1 - lpfc get instance failed.
2839 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002840int
2841lpfc_get_instance(void)
2842{
2843 int instance = 0;
2844
2845 /* Assign an unused number */
2846 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
2847 return -1;
2848 if (idr_get_new(&lpfc_hba_index, NULL, &instance))
2849 return -1;
2850 return instance;
2851}
2852
James Smarte59058c2008-08-24 21:49:00 -04002853/**
James Smart3621a712009-04-06 18:47:14 -04002854 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04002855 * @shost: pointer to SCSI host data structure.
2856 * @time: elapsed time of the scan in jiffies.
2857 *
2858 * This routine is called by the SCSI layer with a SCSI host to determine
2859 * whether the scan host is finished.
2860 *
2861 * Note: there is no scan_start function as adapter initialization will have
2862 * asynchronously kicked off the link initialization.
2863 *
2864 * Return codes
2865 * 0 - SCSI host scan is not over yet.
2866 * 1 - SCSI host scan is over.
2867 **/
James Smart47a86172007-04-25 09:53:22 -04002868int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
2869{
James Smart2e0fef82007-06-17 19:56:36 -05002870 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2871 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05002872 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04002873
James Smart858c9f62007-06-17 19:56:39 -05002874 spin_lock_irq(shost->host_lock);
2875
James Smart51ef4c22007-08-02 11:10:31 -04002876 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05002877 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002878 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05002879 }
James Smart2e0fef82007-06-17 19:56:36 -05002880 if (time >= 30 * HZ) {
2881 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002882 "0461 Scanning longer than 30 "
2883 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05002884 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002885 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002886 }
2887 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
2888 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002889 "0465 Link down longer than 15 "
2890 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05002891 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05002892 goto finished;
James Smart47a86172007-04-25 09:53:22 -04002893 }
2894
James Smart2e0fef82007-06-17 19:56:36 -05002895 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05002896 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002897 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05002898 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002899 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
James Smart858c9f62007-06-17 19:56:39 -05002900 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002901 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05002902 goto finished;
2903
2904 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002905
2906finished:
James Smart858c9f62007-06-17 19:56:39 -05002907 spin_unlock_irq(shost->host_lock);
2908 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05002909}
2910
James Smarte59058c2008-08-24 21:49:00 -04002911/**
James Smart3621a712009-04-06 18:47:14 -04002912 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04002913 * @shost: pointer to SCSI host data structure.
2914 *
2915 * This routine initializes a given SCSI host attributes on a FC port. The
2916 * SCSI host can be either on top of a physical port or a virtual port.
2917 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002918void lpfc_host_attrib_init(struct Scsi_Host *shost)
2919{
2920 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2921 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04002922 /*
James Smart2e0fef82007-06-17 19:56:36 -05002923 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04002924 */
2925
James Smart2e0fef82007-06-17 19:56:36 -05002926 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
2927 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04002928 fc_host_supported_classes(shost) = FC_COS_CLASS3;
2929
2930 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05002931 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04002932 fc_host_supported_fc4s(shost)[2] = 1;
2933 fc_host_supported_fc4s(shost)[7] = 1;
2934
James Smart92d7f7b2007-06-17 19:56:38 -05002935 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
2936 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04002937
2938 fc_host_supported_speeds(shost) = 0;
James Smart88a2cfb2011-07-22 18:36:33 -04002939 if (phba->lmt & LMT_16Gb)
2940 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
James Smart47a86172007-04-25 09:53:22 -04002941 if (phba->lmt & LMT_10Gb)
2942 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04002943 if (phba->lmt & LMT_8Gb)
2944 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04002945 if (phba->lmt & LMT_4Gb)
2946 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
2947 if (phba->lmt & LMT_2Gb)
2948 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
2949 if (phba->lmt & LMT_1Gb)
2950 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
2951
2952 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05002953 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
2954 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04002955
Mike Christie0af5d702010-09-15 16:52:31 -05002956 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
2957
James Smart47a86172007-04-25 09:53:22 -04002958 /* This value is also unchanging */
2959 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05002960 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04002961 fc_host_active_fc4s(shost)[2] = 1;
2962 fc_host_active_fc4s(shost)[7] = 1;
2963
James Smart92d7f7b2007-06-17 19:56:38 -05002964 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04002965 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04002966 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04002967 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04002968}
dea31012005-04-17 16:05:31 -05002969
James Smarte59058c2008-08-24 21:49:00 -04002970/**
James Smartda0436e2009-05-22 14:51:39 -04002971 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04002972 * @phba: pointer to lpfc hba data structure.
2973 *
James Smartda0436e2009-05-22 14:51:39 -04002974 * This routine is invoked to stop an SLI3 device port, it stops the device
2975 * from generating interrupts and stops the device driver's timers for the
2976 * device.
James Smarte59058c2008-08-24 21:49:00 -04002977 **/
James Smartdb2378e2008-02-08 18:49:51 -05002978static void
James Smartda0436e2009-05-22 14:51:39 -04002979lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05002980{
James Smartda0436e2009-05-22 14:51:39 -04002981 /* Clear all interrupt enable conditions */
2982 writel(0, phba->HCregaddr);
2983 readl(phba->HCregaddr); /* flush */
2984 /* Clear all pending interrupts */
2985 writel(0xffffffff, phba->HAregaddr);
2986 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04002987
James Smartda0436e2009-05-22 14:51:39 -04002988 /* Reset some HBA SLI setup states */
2989 lpfc_stop_hba_timers(phba);
2990 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05002991}
2992
James Smarte59058c2008-08-24 21:49:00 -04002993/**
James Smartda0436e2009-05-22 14:51:39 -04002994 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05002995 * @phba: pointer to lpfc hba data structure.
2996 *
James Smartda0436e2009-05-22 14:51:39 -04002997 * This routine is invoked to stop an SLI4 device port, it stops the device
2998 * from generating interrupts and stops the device driver's timers for the
2999 * device.
3000 **/
3001static void
3002lpfc_stop_port_s4(struct lpfc_hba *phba)
3003{
3004 /* Reset some HBA SLI4 setup states */
3005 lpfc_stop_hba_timers(phba);
3006 phba->pport->work_port_events = 0;
3007 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04003008}
3009
3010/**
3011 * lpfc_stop_port - Wrapper function for stopping hba port
3012 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05003013 *
James Smartda0436e2009-05-22 14:51:39 -04003014 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3015 * the API jump table function pointer from the lpfc_hba struct.
3016 **/
3017void
3018lpfc_stop_port(struct lpfc_hba *phba)
3019{
3020 phba->lpfc_stop_port(phba);
3021}
3022
3023/**
James Smartecfd03c2010-02-12 14:41:27 -05003024 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3025 * @phba: Pointer to hba for which this call is being executed.
3026 *
3027 * This routine starts the timer waiting for the FCF rediscovery to complete.
3028 **/
3029void
3030lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
3031{
3032 unsigned long fcf_redisc_wait_tmo =
3033 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
3034 /* Start fcf rediscovery wait period timer */
3035 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
3036 spin_lock_irq(&phba->hbalock);
3037 /* Allow action to new fcf asynchronous event */
3038 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
3039 /* Mark the FCF rediscovery pending state */
3040 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
3041 spin_unlock_irq(&phba->hbalock);
3042}
3043
3044/**
3045 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
3046 * @ptr: Map to lpfc_hba data structure pointer.
3047 *
3048 * This routine is invoked when waiting for FCF table rediscover has been
3049 * timed out. If new FCF record(s) has (have) been discovered during the
3050 * wait period, a new FCF event shall be added to the FCOE async event
3051 * list, and then worker thread shall be waked up for processing from the
3052 * worker thread context.
3053 **/
3054void
3055lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
3056{
3057 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
3058
3059 /* Don't send FCF rediscovery event if timer cancelled */
3060 spin_lock_irq(&phba->hbalock);
3061 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
3062 spin_unlock_irq(&phba->hbalock);
3063 return;
3064 }
3065 /* Clear FCF rediscovery timer pending flag */
3066 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
3067 /* FCF rediscovery event to worker thread */
3068 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
3069 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003070 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04003071 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05003072 /* wake up worker thread */
3073 lpfc_worker_wake_up(phba);
3074}
3075
3076/**
James Smartda0436e2009-05-22 14:51:39 -04003077 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
3078 * @phba: pointer to lpfc hba data structure.
3079 * @acqe_link: pointer to the async link completion queue entry.
3080 *
3081 * This routine is to parse the SLI4 link-attention link fault code and
3082 * translate it into the base driver's read link attention mailbox command
3083 * status.
3084 *
3085 * Return: Link-attention status in terms of base driver's coding.
3086 **/
3087static uint16_t
3088lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
3089 struct lpfc_acqe_link *acqe_link)
3090{
3091 uint16_t latt_fault;
3092
3093 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
3094 case LPFC_ASYNC_LINK_FAULT_NONE:
3095 case LPFC_ASYNC_LINK_FAULT_LOCAL:
3096 case LPFC_ASYNC_LINK_FAULT_REMOTE:
3097 latt_fault = 0;
3098 break;
3099 default:
3100 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3101 "0398 Invalid link fault code: x%x\n",
3102 bf_get(lpfc_acqe_link_fault, acqe_link));
3103 latt_fault = MBXERR_ERROR;
3104 break;
3105 }
3106 return latt_fault;
3107}
3108
3109/**
3110 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
3111 * @phba: pointer to lpfc hba data structure.
3112 * @acqe_link: pointer to the async link completion queue entry.
3113 *
3114 * This routine is to parse the SLI4 link attention type and translate it
3115 * into the base driver's link attention type coding.
3116 *
3117 * Return: Link attention type in terms of base driver's coding.
3118 **/
3119static uint8_t
3120lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
3121 struct lpfc_acqe_link *acqe_link)
3122{
3123 uint8_t att_type;
3124
3125 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
3126 case LPFC_ASYNC_LINK_STATUS_DOWN:
3127 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05003128 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04003129 break;
3130 case LPFC_ASYNC_LINK_STATUS_UP:
3131 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05003132 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003133 break;
3134 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05003135 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04003136 break;
3137 default:
3138 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3139 "0399 Invalid link attention type: x%x\n",
3140 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003141 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003142 break;
3143 }
3144 return att_type;
3145}
3146
3147/**
3148 * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
3149 * @phba: pointer to lpfc hba data structure.
3150 * @acqe_link: pointer to the async link completion queue entry.
3151 *
3152 * This routine is to parse the SLI4 link-attention link speed and translate
3153 * it into the base driver's link-attention link speed coding.
3154 *
3155 * Return: Link-attention link speed in terms of base driver's coding.
3156 **/
3157static uint8_t
3158lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba,
3159 struct lpfc_acqe_link *acqe_link)
3160{
3161 uint8_t link_speed;
3162
3163 switch (bf_get(lpfc_acqe_link_speed, acqe_link)) {
3164 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smartda0436e2009-05-22 14:51:39 -04003165 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smartda0436e2009-05-22 14:51:39 -04003166 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart76a95d72010-11-20 23:11:48 -05003167 link_speed = LPFC_LINK_SPEED_UNKNOWN;
James Smartda0436e2009-05-22 14:51:39 -04003168 break;
3169 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart76a95d72010-11-20 23:11:48 -05003170 link_speed = LPFC_LINK_SPEED_1GHZ;
James Smartda0436e2009-05-22 14:51:39 -04003171 break;
3172 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart76a95d72010-11-20 23:11:48 -05003173 link_speed = LPFC_LINK_SPEED_10GHZ;
James Smartda0436e2009-05-22 14:51:39 -04003174 break;
3175 default:
3176 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3177 "0483 Invalid link-attention link speed: x%x\n",
3178 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003179 link_speed = LPFC_LINK_SPEED_UNKNOWN;
James Smartda0436e2009-05-22 14:51:39 -04003180 break;
3181 }
3182 return link_speed;
3183}
3184
3185/**
James Smart70f3c072010-12-15 17:57:33 -05003186 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04003187 * @phba: pointer to lpfc hba data structure.
3188 * @acqe_link: pointer to the async link completion queue entry.
3189 *
James Smart70f3c072010-12-15 17:57:33 -05003190 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04003191 **/
3192static void
3193lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
3194 struct lpfc_acqe_link *acqe_link)
3195{
3196 struct lpfc_dmabuf *mp;
3197 LPFC_MBOXQ_t *pmb;
3198 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05003199 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04003200 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05003201 int rc;
James Smartda0436e2009-05-22 14:51:39 -04003202
3203 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05003204 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04003205 return;
James Smart32b97932009-07-19 10:01:21 -04003206 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04003207 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3208 if (!pmb) {
3209 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3210 "0395 The mboxq allocation failed\n");
3211 return;
3212 }
3213 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3214 if (!mp) {
3215 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3216 "0396 The lpfc_dmabuf allocation failed\n");
3217 goto out_free_pmb;
3218 }
3219 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
3220 if (!mp->virt) {
3221 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3222 "0397 The mbuf allocation failed\n");
3223 goto out_free_dmabuf;
3224 }
3225
3226 /* Cleanup any outstanding ELS commands */
3227 lpfc_els_flush_all_cmd(phba);
3228
3229 /* Block ELS IOCBs until we have done process link event */
3230 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
3231
3232 /* Update link event statistics */
3233 phba->sli.slistat.link_event++;
3234
James Smart76a95d72010-11-20 23:11:48 -05003235 /* Create lpfc_handle_latt mailbox command from link ACQE */
3236 lpfc_read_topology(phba, pmb, mp);
3237 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04003238 pmb->vport = phba->pport;
3239
James Smartda0436e2009-05-22 14:51:39 -04003240 /* Keep the link status for extra SLI4 state machine reference */
3241 phba->sli4_hba.link_state.speed =
3242 bf_get(lpfc_acqe_link_speed, acqe_link);
3243 phba->sli4_hba.link_state.duplex =
3244 bf_get(lpfc_acqe_link_duplex, acqe_link);
3245 phba->sli4_hba.link_state.status =
3246 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05003247 phba->sli4_hba.link_state.type =
3248 bf_get(lpfc_acqe_link_type, acqe_link);
3249 phba->sli4_hba.link_state.number =
3250 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04003251 phba->sli4_hba.link_state.fault =
3252 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05003253 phba->sli4_hba.link_state.logical_speed =
James Smart70f3c072010-12-15 17:57:33 -05003254 bf_get(lpfc_acqe_logical_link_speed, acqe_link);
3255 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04003256 "2900 Async FC/FCoE Link event - Speed:%dGBit "
3257 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
3258 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05003259 phba->sli4_hba.link_state.speed,
3260 phba->sli4_hba.link_state.topology,
3261 phba->sli4_hba.link_state.status,
3262 phba->sli4_hba.link_state.type,
3263 phba->sli4_hba.link_state.number,
3264 phba->sli4_hba.link_state.logical_speed * 10,
3265 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05003266 /*
3267 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
3268 * topology info. Note: Optional for non FC-AL ports.
3269 */
3270 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3271 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3272 if (rc == MBX_NOT_FINISHED)
3273 goto out_free_dmabuf;
3274 return;
3275 }
3276 /*
3277 * For FCoE Mode: fill in all the topology information we need and call
3278 * the READ_TOPOLOGY completion routine to continue without actually
3279 * sending the READ_TOPOLOGY mailbox command to the port.
3280 */
3281 /* Parse and translate status field */
3282 mb = &pmb->u.mb;
3283 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
3284
3285 /* Parse and translate link attention fields */
3286 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3287 la->eventTag = acqe_link->event_tag;
3288 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
3289 bf_set(lpfc_mbx_read_top_link_spd, la,
3290 lpfc_sli4_parse_latt_link_speed(phba, acqe_link));
3291
3292 /* Fake the the following irrelvant fields */
3293 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
3294 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
3295 bf_set(lpfc_mbx_read_top_il, la, 0);
3296 bf_set(lpfc_mbx_read_top_pb, la, 0);
3297 bf_set(lpfc_mbx_read_top_fa, la, 0);
3298 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04003299
3300 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05003301 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04003302
3303 return;
3304
3305out_free_dmabuf:
3306 kfree(mp);
3307out_free_pmb:
3308 mempool_free(pmb, phba->mbox_mem_pool);
3309}
3310
3311/**
James Smart70f3c072010-12-15 17:57:33 -05003312 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
3313 * @phba: pointer to lpfc hba data structure.
3314 * @acqe_fc: pointer to the async fc completion queue entry.
3315 *
3316 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
3317 * that the event was received and then issue a read_topology mailbox command so
3318 * that the rest of the driver will treat it the same as SLI3.
3319 **/
3320static void
3321lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
3322{
3323 struct lpfc_dmabuf *mp;
3324 LPFC_MBOXQ_t *pmb;
3325 int rc;
3326
3327 if (bf_get(lpfc_trailer_type, acqe_fc) !=
3328 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
3329 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3330 "2895 Non FC link Event detected.(%d)\n",
3331 bf_get(lpfc_trailer_type, acqe_fc));
3332 return;
3333 }
3334 /* Keep the link status for extra SLI4 state machine reference */
3335 phba->sli4_hba.link_state.speed =
3336 bf_get(lpfc_acqe_fc_la_speed, acqe_fc);
3337 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
3338 phba->sli4_hba.link_state.topology =
3339 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
3340 phba->sli4_hba.link_state.status =
3341 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
3342 phba->sli4_hba.link_state.type =
3343 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
3344 phba->sli4_hba.link_state.number =
3345 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
3346 phba->sli4_hba.link_state.fault =
3347 bf_get(lpfc_acqe_link_fault, acqe_fc);
3348 phba->sli4_hba.link_state.logical_speed =
3349 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc);
3350 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3351 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
3352 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
3353 "%dMbps Fault:%d\n",
3354 phba->sli4_hba.link_state.speed,
3355 phba->sli4_hba.link_state.topology,
3356 phba->sli4_hba.link_state.status,
3357 phba->sli4_hba.link_state.type,
3358 phba->sli4_hba.link_state.number,
3359 phba->sli4_hba.link_state.logical_speed * 10,
3360 phba->sli4_hba.link_state.fault);
3361 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3362 if (!pmb) {
3363 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3364 "2897 The mboxq allocation failed\n");
3365 return;
3366 }
3367 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3368 if (!mp) {
3369 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3370 "2898 The lpfc_dmabuf allocation failed\n");
3371 goto out_free_pmb;
3372 }
3373 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
3374 if (!mp->virt) {
3375 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3376 "2899 The mbuf allocation failed\n");
3377 goto out_free_dmabuf;
3378 }
3379
3380 /* Cleanup any outstanding ELS commands */
3381 lpfc_els_flush_all_cmd(phba);
3382
3383 /* Block ELS IOCBs until we have done process link event */
3384 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
3385
3386 /* Update link event statistics */
3387 phba->sli.slistat.link_event++;
3388
3389 /* Create lpfc_handle_latt mailbox command from link ACQE */
3390 lpfc_read_topology(phba, pmb, mp);
3391 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
3392 pmb->vport = phba->pport;
3393
3394 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3395 if (rc == MBX_NOT_FINISHED)
3396 goto out_free_dmabuf;
3397 return;
3398
3399out_free_dmabuf:
3400 kfree(mp);
3401out_free_pmb:
3402 mempool_free(pmb, phba->mbox_mem_pool);
3403}
3404
3405/**
3406 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
3407 * @phba: pointer to lpfc hba data structure.
3408 * @acqe_fc: pointer to the async SLI completion queue entry.
3409 *
3410 * This routine is to handle the SLI4 asynchronous SLI events.
3411 **/
3412static void
3413lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
3414{
3415 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3416 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
3417 "x%08x SLI Event Type:%d",
3418 acqe_sli->event_data1, acqe_sli->event_data2,
3419 bf_get(lpfc_trailer_type, acqe_sli));
3420 return;
3421}
3422
3423/**
James Smartfc2b9892010-02-26 14:15:29 -05003424 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
3425 * @vport: pointer to vport data structure.
3426 *
3427 * This routine is to perform Clear Virtual Link (CVL) on a vport in
3428 * response to a CVL event.
3429 *
3430 * Return the pointer to the ndlp with the vport if successful, otherwise
3431 * return NULL.
3432 **/
3433static struct lpfc_nodelist *
3434lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
3435{
3436 struct lpfc_nodelist *ndlp;
3437 struct Scsi_Host *shost;
3438 struct lpfc_hba *phba;
3439
3440 if (!vport)
3441 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05003442 phba = vport->phba;
3443 if (!phba)
3444 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04003445 ndlp = lpfc_findnode_did(vport, Fabric_DID);
3446 if (!ndlp) {
3447 /* Cannot find existing Fabric ndlp, so allocate a new one */
3448 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3449 if (!ndlp)
3450 return 0;
3451 lpfc_nlp_init(vport, ndlp, Fabric_DID);
3452 /* Set the node type */
3453 ndlp->nlp_type |= NLP_FABRIC;
3454 /* Put ndlp onto node list */
3455 lpfc_enqueue_node(vport, ndlp);
3456 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3457 /* re-setup ndlp without removing from node list */
3458 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3459 if (!ndlp)
3460 return 0;
3461 }
James Smart63e801c2010-11-20 23:14:19 -05003462 if ((phba->pport->port_state < LPFC_FLOGI) &&
3463 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05003464 return NULL;
3465 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05003466 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
3467 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05003468 return NULL;
3469 shost = lpfc_shost_from_vport(vport);
3470 if (!shost)
3471 return NULL;
3472 lpfc_linkdown_port(vport);
3473 lpfc_cleanup_pending_mbox(vport);
3474 spin_lock_irq(shost->host_lock);
3475 vport->fc_flag |= FC_VPORT_CVL_RCVD;
3476 spin_unlock_irq(shost->host_lock);
3477
3478 return ndlp;
3479}
3480
3481/**
3482 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
3483 * @vport: pointer to lpfc hba data structure.
3484 *
3485 * This routine is to perform Clear Virtual Link (CVL) on all vports in
3486 * response to a FCF dead event.
3487 **/
3488static void
3489lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
3490{
3491 struct lpfc_vport **vports;
3492 int i;
3493
3494 vports = lpfc_create_vport_work_array(phba);
3495 if (vports)
3496 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
3497 lpfc_sli4_perform_vport_cvl(vports[i]);
3498 lpfc_destroy_vport_work_array(phba, vports);
3499}
3500
3501/**
James Smart76a95d72010-11-20 23:11:48 -05003502 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04003503 * @phba: pointer to lpfc hba data structure.
3504 * @acqe_link: pointer to the async fcoe completion queue entry.
3505 *
3506 * This routine is to handle the SLI4 asynchronous fcoe event.
3507 **/
3508static void
James Smart76a95d72010-11-20 23:11:48 -05003509lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05003510 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04003511{
James Smart70f3c072010-12-15 17:57:33 -05003512 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04003513 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04003514 struct lpfc_vport *vport;
3515 struct lpfc_nodelist *ndlp;
3516 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05003517 int active_vlink_present;
3518 struct lpfc_vport **vports;
3519 int i;
James Smartda0436e2009-05-22 14:51:39 -04003520
James Smart70f3c072010-12-15 17:57:33 -05003521 phba->fc_eventTag = acqe_fip->event_tag;
3522 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04003523 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05003524 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
3525 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
3526 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04003527 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
3528 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04003529 "2546 New FCF event, evt_tag:x%x, "
3530 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05003531 acqe_fip->event_tag,
3532 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04003533 else
3534 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
3535 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04003536 "2788 FCF param modified event, "
3537 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05003538 acqe_fip->event_tag,
3539 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04003540 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05003541 /*
3542 * During period of FCF discovery, read the FCF
3543 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04003544 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05003545 */
3546 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
3547 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04003548 "2779 Read FCF (x%x) for updating "
3549 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05003550 acqe_fip->index);
3551 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05003552 }
James Smart38b92ef2010-08-04 16:11:39 -04003553
3554 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04003555 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04003556 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04003557 spin_unlock_irq(&phba->hbalock);
3558 break;
3559 }
3560 /* If fast FCF failover rescan event is pending, do nothing */
3561 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
3562 spin_unlock_irq(&phba->hbalock);
3563 break;
3564 }
3565
3566 /* If the FCF has been in discovered state, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04003567 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
3568 spin_unlock_irq(&phba->hbalock);
3569 break;
3570 }
3571 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04003572
James Smart0c9ab6f2010-02-26 14:15:57 -05003573 /* Otherwise, scan the entire FCF table and re-discover SAN */
3574 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04003575 "2770 Start FCF table scan per async FCF "
3576 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05003577 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05003578 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3579 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04003580 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05003581 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
3582 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04003583 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04003584 break;
3585
James Smart70f3c072010-12-15 17:57:33 -05003586 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04003587 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04003588 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05003589 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
3590 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04003591 break;
3592
James Smart70f3c072010-12-15 17:57:33 -05003593 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart0c9ab6f2010-02-26 14:15:57 -05003594 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04003595 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05003596 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04003597 /*
3598 * If we are in the middle of FCF failover process, clear
3599 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04003600 */
James Smartfc2b9892010-02-26 14:15:29 -05003601 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003602 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05003603 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003604 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05003605 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05003606 break;
3607 }
James Smart38b92ef2010-08-04 16:11:39 -04003608 spin_unlock_irq(&phba->hbalock);
3609
3610 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05003611 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04003612 break;
3613
3614 /*
3615 * Otherwise, request the port to rediscover the entire FCF
3616 * table for a fast recovery from case that the current FCF
3617 * is no longer valid as we are not in the middle of FCF
3618 * failover process already.
3619 */
3620 spin_lock_irq(&phba->hbalock);
James Smartfc2b9892010-02-26 14:15:29 -05003621 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05003622 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05003623 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04003624
James Smart0c9ab6f2010-02-26 14:15:57 -05003625 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3626 "2771 Start FCF fast failover process due to "
3627 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
James Smart70f3c072010-12-15 17:57:33 -05003628 "\n", acqe_fip->event_tag, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05003629 rc = lpfc_sli4_redisc_fcf_table(phba);
3630 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05003631 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
3632 LOG_DISCOVERY,
3633 "2772 Issue FCF rediscover mabilbox "
3634 "command failed, fail through to FCF "
3635 "dead event\n");
James Smartfc2b9892010-02-26 14:15:29 -05003636 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003637 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05003638 spin_unlock_irq(&phba->hbalock);
3639 /*
3640 * Last resort will fail over by treating this
3641 * as a link down to FCF registration.
3642 */
3643 lpfc_sli4_fcf_dead_failthrough(phba);
James Smart38b92ef2010-08-04 16:11:39 -04003644 } else {
3645 /* Reset FCF roundrobin bmask for new discovery */
James Smart7d791df2011-07-22 18:37:52 -04003646 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart38b92ef2010-08-04 16:11:39 -04003647 /*
3648 * Handling fast FCF failover to a DEAD FCF event is
3649 * considered equalivant to receiving CVL to all vports.
James Smartfc2b9892010-02-26 14:15:29 -05003650 */
3651 lpfc_sli4_perform_all_vport_cvl(phba);
James Smart38b92ef2010-08-04 16:11:39 -04003652 }
James Smartda0436e2009-05-22 14:51:39 -04003653 break;
James Smart70f3c072010-12-15 17:57:33 -05003654 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart0c9ab6f2010-02-26 14:15:57 -05003655 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04003656 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05003657 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04003658
James Smart6669f9b2009-10-02 15:16:45 -04003659 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04003660 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05003661 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04003662 if (!ndlp)
3663 break;
James Smart695a8142010-01-26 23:08:03 -05003664 active_vlink_present = 0;
3665
3666 vports = lpfc_create_vport_work_array(phba);
3667 if (vports) {
3668 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
3669 i++) {
3670 if ((!(vports[i]->fc_flag &
3671 FC_VPORT_CVL_RCVD)) &&
3672 (vports[i]->port_state > LPFC_FDISC)) {
3673 active_vlink_present = 1;
3674 break;
3675 }
3676 }
3677 lpfc_destroy_vport_work_array(phba, vports);
3678 }
3679
3680 if (active_vlink_present) {
3681 /*
3682 * If there are other active VLinks present,
3683 * re-instantiate the Vlink using FDISC.
3684 */
James Smart6669f9b2009-10-02 15:16:45 -04003685 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
James Smartfc2b9892010-02-26 14:15:29 -05003686 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04003687 spin_lock_irq(shost->host_lock);
3688 ndlp->nlp_flag |= NLP_DELAY_TMO;
3689 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05003690 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
3691 vport->port_state = LPFC_FDISC;
3692 } else {
James Smartecfd03c2010-02-12 14:41:27 -05003693 /*
3694 * Otherwise, we request port to rediscover
3695 * the entire FCF table for a fast recovery
3696 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05003697 * is no longer valid if we are not already
3698 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05003699 */
James Smartfc2b9892010-02-26 14:15:29 -05003700 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003701 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05003702 spin_unlock_irq(&phba->hbalock);
3703 break;
3704 }
3705 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05003706 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05003707 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003708 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
3709 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04003710 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05003711 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05003712 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05003713 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05003714 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
3715 LOG_DISCOVERY,
3716 "2774 Issue FCF rediscover "
3717 "mabilbox command failed, "
3718 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05003719 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003720 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05003721 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05003722 /*
3723 * Last resort will be re-try on the
3724 * the current registered FCF entry.
3725 */
3726 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04003727 } else
3728 /*
3729 * Reset FCF roundrobin bmask for new
3730 * discovery.
3731 */
James Smart7d791df2011-07-22 18:37:52 -04003732 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04003733 }
3734 break;
James Smartda0436e2009-05-22 14:51:39 -04003735 default:
3736 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3737 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05003738 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04003739 break;
3740 }
3741}
3742
3743/**
3744 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
3745 * @phba: pointer to lpfc hba data structure.
3746 * @acqe_link: pointer to the async dcbx completion queue entry.
3747 *
3748 * This routine is to handle the SLI4 asynchronous dcbx event.
3749 **/
3750static void
3751lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
3752 struct lpfc_acqe_dcbx *acqe_dcbx)
3753{
James Smart4d9ab992009-10-02 15:16:39 -04003754 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04003755 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3756 "0290 The SLI4 DCBX asynchronous event is not "
3757 "handled yet\n");
3758}
3759
3760/**
James Smartb19a0612010-04-06 14:48:51 -04003761 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
3762 * @phba: pointer to lpfc hba data structure.
3763 * @acqe_link: pointer to the async grp5 completion queue entry.
3764 *
3765 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
3766 * is an asynchronous notified of a logical link speed change. The Port
3767 * reports the logical link speed in units of 10Mbps.
3768 **/
3769static void
3770lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
3771 struct lpfc_acqe_grp5 *acqe_grp5)
3772{
3773 uint16_t prev_ll_spd;
3774
3775 phba->fc_eventTag = acqe_grp5->event_tag;
3776 phba->fcoe_eventtag = acqe_grp5->event_tag;
3777 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
3778 phba->sli4_hba.link_state.logical_speed =
3779 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5));
3780 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3781 "2789 GRP5 Async Event: Updating logical link speed "
3782 "from %dMbps to %dMbps\n", (prev_ll_spd * 10),
3783 (phba->sli4_hba.link_state.logical_speed*10));
3784}
3785
3786/**
James Smartda0436e2009-05-22 14:51:39 -04003787 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
3788 * @phba: pointer to lpfc hba data structure.
3789 *
3790 * This routine is invoked by the worker thread to process all the pending
3791 * SLI4 asynchronous events.
3792 **/
3793void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
3794{
3795 struct lpfc_cq_event *cq_event;
3796
3797 /* First, declare the async event has been handled */
3798 spin_lock_irq(&phba->hbalock);
3799 phba->hba_flag &= ~ASYNC_EVENT;
3800 spin_unlock_irq(&phba->hbalock);
3801 /* Now, handle all the async events */
3802 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
3803 /* Get the first event from the head of the event queue */
3804 spin_lock_irq(&phba->hbalock);
3805 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
3806 cq_event, struct lpfc_cq_event, list);
3807 spin_unlock_irq(&phba->hbalock);
3808 /* Process the asynchronous event */
3809 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
3810 case LPFC_TRAILER_CODE_LINK:
3811 lpfc_sli4_async_link_evt(phba,
3812 &cq_event->cqe.acqe_link);
3813 break;
3814 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05003815 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04003816 break;
3817 case LPFC_TRAILER_CODE_DCBX:
3818 lpfc_sli4_async_dcbx_evt(phba,
3819 &cq_event->cqe.acqe_dcbx);
3820 break;
James Smartb19a0612010-04-06 14:48:51 -04003821 case LPFC_TRAILER_CODE_GRP5:
3822 lpfc_sli4_async_grp5_evt(phba,
3823 &cq_event->cqe.acqe_grp5);
3824 break;
James Smart70f3c072010-12-15 17:57:33 -05003825 case LPFC_TRAILER_CODE_FC:
3826 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
3827 break;
3828 case LPFC_TRAILER_CODE_SLI:
3829 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
3830 break;
James Smartda0436e2009-05-22 14:51:39 -04003831 default:
3832 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3833 "1804 Invalid asynchrous event code: "
3834 "x%x\n", bf_get(lpfc_trailer_code,
3835 &cq_event->cqe.mcqe_cmpl));
3836 break;
3837 }
3838 /* Free the completion event processed to the free pool */
3839 lpfc_sli4_cq_event_release(phba, cq_event);
3840 }
3841}
3842
3843/**
James Smartecfd03c2010-02-12 14:41:27 -05003844 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
3845 * @phba: pointer to lpfc hba data structure.
3846 *
3847 * This routine is invoked by the worker thread to process FCF table
3848 * rediscovery pending completion event.
3849 **/
3850void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
3851{
3852 int rc;
3853
3854 spin_lock_irq(&phba->hbalock);
3855 /* Clear FCF rediscovery timeout event */
3856 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
3857 /* Clear driver fast failover FCF record flag */
3858 phba->fcf.failover_rec.flag = 0;
3859 /* Set state for FCF fast failover */
3860 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
3861 spin_unlock_irq(&phba->hbalock);
3862
3863 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05003864 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04003865 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05003866 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05003867 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05003868 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
3869 "2747 Issue FCF scan read FCF mailbox "
3870 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05003871}
3872
3873/**
James Smartda0436e2009-05-22 14:51:39 -04003874 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
3875 * @phba: pointer to lpfc hba data structure.
3876 * @dev_grp: The HBA PCI-Device group number.
3877 *
3878 * This routine is invoked to set up the per HBA PCI-Device group function
3879 * API jump table entries.
3880 *
3881 * Return: 0 if success, otherwise -ENODEV
3882 **/
3883int
3884lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05003885{
3886 int rc;
3887
James Smartda0436e2009-05-22 14:51:39 -04003888 /* Set up lpfc PCI-device group */
3889 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05003890
James Smartda0436e2009-05-22 14:51:39 -04003891 /* The LPFC_PCI_DEV_OC uses SLI4 */
3892 if (dev_grp == LPFC_PCI_DEV_OC)
3893 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05003894
James Smartda0436e2009-05-22 14:51:39 -04003895 /* Set up device INIT API function jump table */
3896 rc = lpfc_init_api_table_setup(phba, dev_grp);
3897 if (rc)
3898 return -ENODEV;
3899 /* Set up SCSI API function jump table */
3900 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
3901 if (rc)
3902 return -ENODEV;
3903 /* Set up SLI API function jump table */
3904 rc = lpfc_sli_api_table_setup(phba, dev_grp);
3905 if (rc)
3906 return -ENODEV;
3907 /* Set up MBOX API function jump table */
3908 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
3909 if (rc)
3910 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05003911
James Smartda0436e2009-05-22 14:51:39 -04003912 return 0;
James Smart5b75da22008-12-04 22:39:35 -05003913}
3914
3915/**
James Smart3621a712009-04-06 18:47:14 -04003916 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05003917 * @phba: pointer to lpfc hba data structure.
3918 * @intr_mode: active interrupt mode adopted.
3919 *
3920 * This routine it invoked to log the currently used active interrupt mode
3921 * to the device.
James Smart3772a992009-05-22 14:50:54 -04003922 **/
3923static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05003924{
3925 switch (intr_mode) {
3926 case 0:
3927 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3928 "0470 Enable INTx interrupt mode.\n");
3929 break;
3930 case 1:
3931 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3932 "0481 Enabled MSI interrupt mode.\n");
3933 break;
3934 case 2:
3935 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3936 "0480 Enabled MSI-X interrupt mode.\n");
3937 break;
3938 default:
3939 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3940 "0482 Illegal interrupt mode.\n");
3941 break;
3942 }
3943 return;
3944}
3945
James Smart5b75da22008-12-04 22:39:35 -05003946/**
James Smart3772a992009-05-22 14:50:54 -04003947 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05003948 * @phba: pointer to lpfc hba data structure.
3949 *
James Smart3772a992009-05-22 14:50:54 -04003950 * This routine is invoked to enable the PCI device that is common to all
3951 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05003952 *
3953 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003954 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04003955 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05003956 **/
James Smart3772a992009-05-22 14:50:54 -04003957static int
3958lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05003959{
James Smart3772a992009-05-22 14:50:54 -04003960 struct pci_dev *pdev;
James Smart079b5c92011-08-21 21:48:49 -04003961 int bars = 0;
James Smart5b75da22008-12-04 22:39:35 -05003962
James Smart3772a992009-05-22 14:50:54 -04003963 /* Obtain PCI device reference */
3964 if (!phba->pcidev)
3965 goto out_error;
3966 else
3967 pdev = phba->pcidev;
3968 /* Select PCI BARs */
3969 bars = pci_select_bars(pdev, IORESOURCE_MEM);
3970 /* Enable PCI device */
3971 if (pci_enable_device_mem(pdev))
3972 goto out_error;
3973 /* Request PCI resource for the device */
3974 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
3975 goto out_disable_device;
3976 /* Set up device as PCI master and save state for EEH */
3977 pci_set_master(pdev);
3978 pci_try_set_mwi(pdev);
3979 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05003980
James Smart05580562011-05-24 11:40:48 -04003981 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
3982 if (pci_find_capability(pdev, PCI_CAP_ID_EXP))
3983 pdev->needs_freset = 1;
3984
James Smart3772a992009-05-22 14:50:54 -04003985 return 0;
James Smart5b75da22008-12-04 22:39:35 -05003986
James Smart3772a992009-05-22 14:50:54 -04003987out_disable_device:
3988 pci_disable_device(pdev);
3989out_error:
James Smart079b5c92011-08-21 21:48:49 -04003990 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3991 "1401 Failed to enable pci device, bars:x%x\n", bars);
James Smart3772a992009-05-22 14:50:54 -04003992 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05003993}
3994
3995/**
James Smart3772a992009-05-22 14:50:54 -04003996 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05003997 * @phba: pointer to lpfc hba data structure.
3998 *
James Smart3772a992009-05-22 14:50:54 -04003999 * This routine is invoked to disable the PCI device that is common to all
4000 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05004001 **/
4002static void
James Smart3772a992009-05-22 14:50:54 -04004003lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05004004{
James Smart3772a992009-05-22 14:50:54 -04004005 struct pci_dev *pdev;
4006 int bars;
James Smart5b75da22008-12-04 22:39:35 -05004007
James Smart3772a992009-05-22 14:50:54 -04004008 /* Obtain PCI device reference */
4009 if (!phba->pcidev)
4010 return;
4011 else
4012 pdev = phba->pcidev;
4013 /* Select PCI BARs */
4014 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4015 /* Release PCI resource and disable PCI device */
4016 pci_release_selected_regions(pdev, bars);
4017 pci_disable_device(pdev);
4018 /* Null out PCI private reference to driver */
4019 pci_set_drvdata(pdev, NULL);
James Smart5b75da22008-12-04 22:39:35 -05004020
4021 return;
4022}
4023
4024/**
James Smart3772a992009-05-22 14:50:54 -04004025 * lpfc_reset_hba - Reset a hba
4026 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04004027 *
James Smart3772a992009-05-22 14:50:54 -04004028 * This routine is invoked to reset a hba device. It brings the HBA
4029 * offline, performs a board restart, and then brings the board back
4030 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
4031 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04004032 **/
James Smart3772a992009-05-22 14:50:54 -04004033void
4034lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05004035{
James Smart3772a992009-05-22 14:50:54 -04004036 /* If resets are disabled then set error state and return. */
4037 if (!phba->cfg_enable_hba_reset) {
4038 phba->link_state = LPFC_HBA_ERROR;
4039 return;
4040 }
4041 lpfc_offline_prep(phba);
4042 lpfc_offline(phba);
4043 lpfc_sli_brdrestart(phba);
4044 lpfc_online(phba);
4045 lpfc_unblock_mgmt_io(phba);
4046}
dea31012005-04-17 16:05:31 -05004047
James Smart3772a992009-05-22 14:50:54 -04004048/**
James Smart0a96e972011-07-22 18:37:28 -04004049 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
4050 * @phba: pointer to lpfc hba data structure.
4051 *
4052 * This function enables the PCI SR-IOV virtual functions to a physical
4053 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4054 * enable the number of virtual functions to the physical function. As
4055 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4056 * API call does not considered as an error condition for most of the device.
4057 **/
4058uint16_t
4059lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
4060{
4061 struct pci_dev *pdev = phba->pcidev;
4062 uint16_t nr_virtfn;
4063 int pos;
4064
James Smart0a96e972011-07-22 18:37:28 -04004065 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4066 if (pos == 0)
4067 return 0;
4068
4069 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
4070 return nr_virtfn;
4071}
4072
4073/**
James Smart912e3ac2011-05-24 11:42:11 -04004074 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
4075 * @phba: pointer to lpfc hba data structure.
4076 * @nr_vfn: number of virtual functions to be enabled.
4077 *
4078 * This function enables the PCI SR-IOV virtual functions to a physical
4079 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4080 * enable the number of virtual functions to the physical function. As
4081 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4082 * API call does not considered as an error condition for most of the device.
4083 **/
4084int
4085lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
4086{
4087 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04004088 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04004089 int rc;
4090
James Smart0a96e972011-07-22 18:37:28 -04004091 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
4092 if (nr_vfn > max_nr_vfn) {
4093 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4094 "3057 Requested vfs (%d) greater than "
4095 "supported vfs (%d)", nr_vfn, max_nr_vfn);
4096 return -EINVAL;
4097 }
4098
James Smart912e3ac2011-05-24 11:42:11 -04004099 rc = pci_enable_sriov(pdev, nr_vfn);
4100 if (rc) {
4101 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4102 "2806 Failed to enable sriov on this device "
4103 "with vfn number nr_vf:%d, rc:%d\n",
4104 nr_vfn, rc);
4105 } else
4106 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4107 "2807 Successful enable sriov on this device "
4108 "with vfn number nr_vf:%d\n", nr_vfn);
4109 return rc;
4110}
4111
4112/**
James Smart3772a992009-05-22 14:50:54 -04004113 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
4114 * @phba: pointer to lpfc hba data structure.
4115 *
4116 * This routine is invoked to set up the driver internal resources specific to
4117 * support the SLI-3 HBA device it attached to.
4118 *
4119 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004120 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004121 * other values - error
4122 **/
4123static int
4124lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
4125{
4126 struct lpfc_sli *psli;
James Smart912e3ac2011-05-24 11:42:11 -04004127 int rc;
dea31012005-04-17 16:05:31 -05004128
James Smart3772a992009-05-22 14:50:54 -04004129 /*
4130 * Initialize timers used by driver
4131 */
dea31012005-04-17 16:05:31 -05004132
James Smart3772a992009-05-22 14:50:54 -04004133 /* Heartbeat timer */
4134 init_timer(&phba->hb_tmofunc);
4135 phba->hb_tmofunc.function = lpfc_hb_timeout;
4136 phba->hb_tmofunc.data = (unsigned long)phba;
4137
4138 psli = &phba->sli;
4139 /* MBOX heartbeat timer */
4140 init_timer(&psli->mbox_tmo);
4141 psli->mbox_tmo.function = lpfc_mbox_timeout;
4142 psli->mbox_tmo.data = (unsigned long) phba;
4143 /* FCP polling mode timer */
4144 init_timer(&phba->fcp_poll_timer);
4145 phba->fcp_poll_timer.function = lpfc_poll_timeout;
4146 phba->fcp_poll_timer.data = (unsigned long) phba;
4147 /* Fabric block timer */
4148 init_timer(&phba->fabric_block_timer);
4149 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
4150 phba->fabric_block_timer.data = (unsigned long) phba;
4151 /* EA polling mode timer */
4152 init_timer(&phba->eratt_poll);
4153 phba->eratt_poll.function = lpfc_poll_eratt;
4154 phba->eratt_poll.data = (unsigned long) phba;
4155
4156 /* Host attention work mask setup */
4157 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
4158 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
4159
4160 /* Get all the module params for configuring this host */
4161 lpfc_get_cfgparam(phba);
James Smart49198b32010-04-06 15:04:33 -04004162 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
4163 phba->menlo_flag |= HBA_MENLO_SUPPORT;
4164 /* check for menlo minimum sg count */
4165 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
4166 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
4167 }
4168
James Smart3772a992009-05-22 14:50:54 -04004169 /*
4170 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
4171 * used to create the sg_dma_buf_pool must be dynamically calculated.
4172 * 2 segments are added since the IOCB needs a command and response bde.
4173 */
4174 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
4175 sizeof(struct fcp_rsp) +
4176 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
4177
4178 if (phba->cfg_enable_bg) {
4179 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT;
4180 phba->cfg_sg_dma_buf_size +=
4181 phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64);
4182 }
4183
4184 /* Also reinitialize the host templates with new values. */
4185 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4186 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4187
4188 phba->max_vpi = LPFC_MAX_VPI;
4189 /* This will be set to correct value after config_port mbox */
4190 phba->max_vports = 0;
4191
4192 /*
4193 * Initialize the SLI Layer to run with lpfc HBAs.
4194 */
4195 lpfc_sli_setup(phba);
4196 lpfc_sli_queue_setup(phba);
4197
4198 /* Allocate device driver memory */
4199 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
4200 return -ENOMEM;
4201
James Smart912e3ac2011-05-24 11:42:11 -04004202 /*
4203 * Enable sr-iov virtual functions if supported and configured
4204 * through the module parameter.
4205 */
4206 if (phba->cfg_sriov_nr_virtfn > 0) {
4207 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
4208 phba->cfg_sriov_nr_virtfn);
4209 if (rc) {
4210 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4211 "2808 Requested number of SR-IOV "
4212 "virtual functions (%d) is not "
4213 "supported\n",
4214 phba->cfg_sriov_nr_virtfn);
4215 phba->cfg_sriov_nr_virtfn = 0;
4216 }
4217 }
4218
James Smart3772a992009-05-22 14:50:54 -04004219 return 0;
4220}
4221
4222/**
4223 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
4224 * @phba: pointer to lpfc hba data structure.
4225 *
4226 * This routine is invoked to unset the driver internal resources set up
4227 * specific for supporting the SLI-3 HBA device it attached to.
4228 **/
4229static void
4230lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
4231{
4232 /* Free device driver memory allocated */
4233 lpfc_mem_free_all(phba);
4234
4235 return;
4236}
4237
4238/**
James Smartda0436e2009-05-22 14:51:39 -04004239 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
4240 * @phba: pointer to lpfc hba data structure.
4241 *
4242 * This routine is invoked to set up the driver internal resources specific to
4243 * support the SLI-4 HBA device it attached to.
4244 *
4245 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004246 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04004247 * other values - error
4248 **/
4249static int
4250lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
4251{
4252 struct lpfc_sli *psli;
James Smart28baac72010-02-12 14:42:03 -05004253 LPFC_MBOXQ_t *mboxq;
4254 int rc, i, hbq_count, buf_size, dma_buf_size, max_buf_size;
4255 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
4256 struct lpfc_mqe *mqe;
James Smart085c6472010-11-20 23:11:37 -05004257 int longs, sli_family;
James Smartda0436e2009-05-22 14:51:39 -04004258
4259 /* Before proceed, wait for POST done and device ready */
4260 rc = lpfc_sli4_post_status_check(phba);
4261 if (rc)
4262 return -ENODEV;
4263
4264 /*
4265 * Initialize timers used by driver
4266 */
4267
4268 /* Heartbeat timer */
4269 init_timer(&phba->hb_tmofunc);
4270 phba->hb_tmofunc.function = lpfc_hb_timeout;
4271 phba->hb_tmofunc.data = (unsigned long)phba;
James Smart19ca7602010-11-20 23:11:55 -05004272 init_timer(&phba->rrq_tmr);
4273 phba->rrq_tmr.function = lpfc_rrq_timeout;
4274 phba->rrq_tmr.data = (unsigned long)phba;
James Smartda0436e2009-05-22 14:51:39 -04004275
4276 psli = &phba->sli;
4277 /* MBOX heartbeat timer */
4278 init_timer(&psli->mbox_tmo);
4279 psli->mbox_tmo.function = lpfc_mbox_timeout;
4280 psli->mbox_tmo.data = (unsigned long) phba;
4281 /* Fabric block timer */
4282 init_timer(&phba->fabric_block_timer);
4283 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
4284 phba->fabric_block_timer.data = (unsigned long) phba;
4285 /* EA polling mode timer */
4286 init_timer(&phba->eratt_poll);
4287 phba->eratt_poll.function = lpfc_poll_eratt;
4288 phba->eratt_poll.data = (unsigned long) phba;
James Smartecfd03c2010-02-12 14:41:27 -05004289 /* FCF rediscover timer */
4290 init_timer(&phba->fcf.redisc_wait);
4291 phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
4292 phba->fcf.redisc_wait.data = (unsigned long)phba;
4293
James Smartda0436e2009-05-22 14:51:39 -04004294 /*
James Smart7ad20aa2011-05-24 11:44:28 -04004295 * Control structure for handling external multi-buffer mailbox
4296 * command pass-through.
4297 */
4298 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
4299 sizeof(struct lpfc_mbox_ext_buf_ctx));
4300 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
4301
4302 /*
James Smartda0436e2009-05-22 14:51:39 -04004303 * We need to do a READ_CONFIG mailbox command here before
4304 * calling lpfc_get_cfgparam. For VFs this will report the
4305 * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings.
4306 * All of the resources allocated
4307 * for this Port are tied to these values.
4308 */
4309 /* Get all the module params for configuring this host */
4310 lpfc_get_cfgparam(phba);
4311 phba->max_vpi = LPFC_MAX_VPI;
4312 /* This will be set to correct value after the read_config mbox */
4313 phba->max_vports = 0;
4314
4315 /* Program the default value of vlan_id and fc_map */
4316 phba->valid_vlan = 0;
4317 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
4318 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
4319 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
4320
4321 /*
4322 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
4323 * used to create the sg_dma_buf_pool must be dynamically calculated.
4324 * 2 segments are added since the IOCB needs a command and response bde.
4325 * To insure that the scsi sgl does not cross a 4k page boundary only
James Smart28baac72010-02-12 14:42:03 -05004326 * sgl sizes of must be a power of 2.
James Smartda0436e2009-05-22 14:51:39 -04004327 */
James Smart28baac72010-02-12 14:42:03 -05004328 buf_size = (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp) +
4329 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge)));
James Smart085c6472010-11-20 23:11:37 -05004330
4331 sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf);
4332 max_buf_size = LPFC_SLI4_MAX_BUF_SIZE;
4333 switch (sli_family) {
4334 case LPFC_SLI_INTF_FAMILY_BE2:
4335 case LPFC_SLI_INTF_FAMILY_BE3:
4336 /* There is a single hint for BE - 2 pages per BPL. */
4337 if (bf_get(lpfc_sli_intf_sli_hint1, &phba->sli4_hba.sli_intf) ==
4338 LPFC_SLI_INTF_SLI_HINT1_1)
4339 max_buf_size = LPFC_SLI4_FL1_MAX_BUF_SIZE;
4340 break;
4341 case LPFC_SLI_INTF_FAMILY_LNCR_A0:
4342 case LPFC_SLI_INTF_FAMILY_LNCR_B0:
4343 default:
4344 break;
4345 }
James Smart28baac72010-02-12 14:42:03 -05004346 for (dma_buf_size = LPFC_SLI4_MIN_BUF_SIZE;
4347 dma_buf_size < max_buf_size && buf_size > dma_buf_size;
4348 dma_buf_size = dma_buf_size << 1)
4349 ;
4350 if (dma_buf_size == max_buf_size)
4351 phba->cfg_sg_seg_cnt = (dma_buf_size -
4352 sizeof(struct fcp_cmnd) - sizeof(struct fcp_rsp) -
4353 (2 * sizeof(struct sli4_sge))) /
4354 sizeof(struct sli4_sge);
4355 phba->cfg_sg_dma_buf_size = dma_buf_size;
James Smartda0436e2009-05-22 14:51:39 -04004356
4357 /* Initialize buffer queue management fields */
4358 hbq_count = lpfc_sli_hbq_count();
4359 for (i = 0; i < hbq_count; ++i)
4360 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
4361 INIT_LIST_HEAD(&phba->rb_pend_list);
4362 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
4363 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
4364
4365 /*
4366 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
4367 */
4368 /* Initialize the Abort scsi buffer list used by driver */
4369 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
4370 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
4371 /* This abort list used by worker thread */
4372 spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
4373
4374 /*
James Smart6d368e52011-05-24 11:44:12 -04004375 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04004376 */
4377
4378 /* Driver internel slow-path CQ Event pool */
4379 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
4380 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04004381 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04004382 /* Asynchronous event CQ Event work queue list */
4383 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
4384 /* Fast-path XRI aborted CQ Event work queue list */
4385 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
4386 /* Slow-path XRI aborted CQ Event work queue list */
4387 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
4388 /* Receive queue CQ Event work queue list */
4389 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
4390
James Smart6d368e52011-05-24 11:44:12 -04004391 /* Initialize extent block lists. */
4392 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
4393 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
4394 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
4395 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
4396
James Smartda0436e2009-05-22 14:51:39 -04004397 /* Initialize the driver internal SLI layer lists. */
4398 lpfc_sli_setup(phba);
4399 lpfc_sli_queue_setup(phba);
4400
4401 /* Allocate device driver memory */
4402 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
4403 if (rc)
4404 return -ENOMEM;
4405
James Smart2fcee4b2010-12-15 17:57:46 -05004406 /* IF Type 2 ports get initialized now. */
4407 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
4408 LPFC_SLI_INTF_IF_TYPE_2) {
4409 rc = lpfc_pci_function_reset(phba);
4410 if (unlikely(rc))
4411 return -ENODEV;
4412 }
4413
James Smartda0436e2009-05-22 14:51:39 -04004414 /* Create the bootstrap mailbox command */
4415 rc = lpfc_create_bootstrap_mbox(phba);
4416 if (unlikely(rc))
4417 goto out_free_mem;
4418
4419 /* Set up the host's endian order with the device. */
4420 rc = lpfc_setup_endian_order(phba);
4421 if (unlikely(rc))
4422 goto out_free_bsmbx;
4423
4424 /* Set up the hba's configuration parameters. */
4425 rc = lpfc_sli4_read_config(phba);
4426 if (unlikely(rc))
4427 goto out_free_bsmbx;
4428
James Smart2fcee4b2010-12-15 17:57:46 -05004429 /* IF Type 0 ports get initialized now. */
4430 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
4431 LPFC_SLI_INTF_IF_TYPE_0) {
4432 rc = lpfc_pci_function_reset(phba);
4433 if (unlikely(rc))
4434 goto out_free_bsmbx;
4435 }
James Smartda0436e2009-05-22 14:51:39 -04004436
James Smartcb5172e2010-03-15 11:25:07 -04004437 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
4438 GFP_KERNEL);
4439 if (!mboxq) {
4440 rc = -ENOMEM;
4441 goto out_free_bsmbx;
4442 }
4443
James Smartfedd3b72011-02-16 12:39:24 -05004444 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04004445 lpfc_supported_pages(mboxq);
4446 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05004447 if (!rc) {
4448 mqe = &mboxq->u.mqe;
4449 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
4450 LPFC_MAX_SUPPORTED_PAGES);
4451 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
4452 switch (pn_page[i]) {
4453 case LPFC_SLI4_PARAMETERS:
4454 phba->sli4_hba.pc_sli4_params.supported = 1;
4455 break;
4456 default:
4457 break;
4458 }
4459 }
4460 /* Read the port's SLI4 Parameters capabilities if supported. */
4461 if (phba->sli4_hba.pc_sli4_params.supported)
4462 rc = lpfc_pc_sli4_params_get(phba, mboxq);
4463 if (rc) {
4464 mempool_free(mboxq, phba->mbox_mem_pool);
4465 rc = -EIO;
4466 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04004467 }
4468 }
James Smartfedd3b72011-02-16 12:39:24 -05004469 /*
4470 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04004471 * If this call fails, it isn't critical unless the SLI4 parameters come
4472 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05004473 */
James Smart6d368e52011-05-24 11:44:12 -04004474 rc = lpfc_get_sli4_parameters(phba, mboxq);
4475 if (rc) {
4476 if (phba->sli4_hba.extents_in_use &&
4477 phba->sli4_hba.rpi_hdrs_in_use) {
4478 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4479 "2999 Unsupported SLI4 Parameters "
4480 "Extents and RPI headers enabled.\n");
4481 goto out_free_bsmbx;
4482 }
4483 }
James Smartcb5172e2010-03-15 11:25:07 -04004484 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04004485 /* Create all the SLI4 queues */
4486 rc = lpfc_sli4_queue_create(phba);
4487 if (rc)
4488 goto out_free_bsmbx;
4489
4490 /* Create driver internal CQE event pool */
4491 rc = lpfc_sli4_cq_event_pool_create(phba);
4492 if (rc)
4493 goto out_destroy_queue;
4494
4495 /* Initialize and populate the iocb list per host */
4496 rc = lpfc_init_sgl_list(phba);
4497 if (rc) {
4498 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4499 "1400 Failed to initialize sgl list.\n");
4500 goto out_destroy_cq_event_pool;
4501 }
4502 rc = lpfc_init_active_sgl_array(phba);
4503 if (rc) {
4504 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4505 "1430 Failed to initialize sgl list.\n");
4506 goto out_free_sgl_list;
4507 }
James Smartda0436e2009-05-22 14:51:39 -04004508 rc = lpfc_sli4_init_rpi_hdrs(phba);
4509 if (rc) {
4510 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4511 "1432 Failed to initialize rpi headers.\n");
4512 goto out_free_active_sgl;
4513 }
4514
James Smarta93ff372010-10-22 11:06:08 -04004515 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05004516 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
4517 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
4518 GFP_KERNEL);
4519 if (!phba->fcf.fcf_rr_bmask) {
4520 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4521 "2759 Failed allocate memory for FCF round "
4522 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04004523 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05004524 goto out_remove_rpi_hdrs;
4525 }
4526
James Smartda0436e2009-05-22 14:51:39 -04004527 phba->sli4_hba.fcp_eq_hdl = kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
4528 phba->cfg_fcp_eq_count), GFP_KERNEL);
4529 if (!phba->sli4_hba.fcp_eq_hdl) {
4530 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4531 "2572 Failed allocate memory for fast-path "
4532 "per-EQ handle array\n");
James Smart05580562011-05-24 11:40:48 -04004533 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05004534 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04004535 }
4536
4537 phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
4538 phba->sli4_hba.cfg_eqn), GFP_KERNEL);
4539 if (!phba->sli4_hba.msix_entries) {
4540 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4541 "2573 Failed allocate memory for msi-x "
4542 "interrupt vector entries\n");
James Smart05580562011-05-24 11:40:48 -04004543 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04004544 goto out_free_fcp_eq_hdl;
4545 }
4546
James Smart912e3ac2011-05-24 11:42:11 -04004547 /*
4548 * Enable sr-iov virtual functions if supported and configured
4549 * through the module parameter.
4550 */
4551 if (phba->cfg_sriov_nr_virtfn > 0) {
4552 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
4553 phba->cfg_sriov_nr_virtfn);
4554 if (rc) {
4555 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4556 "3020 Requested number of SR-IOV "
4557 "virtual functions (%d) is not "
4558 "supported\n",
4559 phba->cfg_sriov_nr_virtfn);
4560 phba->cfg_sriov_nr_virtfn = 0;
4561 }
4562 }
4563
James Smart5248a742011-07-22 18:37:06 -04004564 return 0;
James Smartda0436e2009-05-22 14:51:39 -04004565
4566out_free_fcp_eq_hdl:
4567 kfree(phba->sli4_hba.fcp_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05004568out_free_fcf_rr_bmask:
4569 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04004570out_remove_rpi_hdrs:
4571 lpfc_sli4_remove_rpi_hdrs(phba);
4572out_free_active_sgl:
4573 lpfc_free_active_sgl(phba);
4574out_free_sgl_list:
4575 lpfc_free_sgl_list(phba);
4576out_destroy_cq_event_pool:
4577 lpfc_sli4_cq_event_pool_destroy(phba);
4578out_destroy_queue:
4579 lpfc_sli4_queue_destroy(phba);
4580out_free_bsmbx:
4581 lpfc_destroy_bootstrap_mbox(phba);
4582out_free_mem:
4583 lpfc_mem_free(phba);
4584 return rc;
4585}
4586
4587/**
4588 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
4589 * @phba: pointer to lpfc hba data structure.
4590 *
4591 * This routine is invoked to unset the driver internal resources set up
4592 * specific for supporting the SLI-4 HBA device it attached to.
4593 **/
4594static void
4595lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
4596{
4597 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
4598
James Smartda0436e2009-05-22 14:51:39 -04004599 /* Free memory allocated for msi-x interrupt vector entries */
4600 kfree(phba->sli4_hba.msix_entries);
4601
4602 /* Free memory allocated for fast-path work queue handles */
4603 kfree(phba->sli4_hba.fcp_eq_hdl);
4604
4605 /* Free the allocated rpi headers. */
4606 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04004607 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04004608
James Smart0c9ab6f2010-02-26 14:15:57 -05004609 /* Free eligible FCF index bmask */
4610 kfree(phba->fcf.fcf_rr_bmask);
4611
James Smartda0436e2009-05-22 14:51:39 -04004612 /* Free the ELS sgl list */
4613 lpfc_free_active_sgl(phba);
4614 lpfc_free_sgl_list(phba);
4615
4616 /* Free the SCSI sgl management array */
4617 kfree(phba->sli4_hba.lpfc_scsi_psb_array);
4618
4619 /* Free the SLI4 queues */
4620 lpfc_sli4_queue_destroy(phba);
4621
4622 /* Free the completion queue EQ event pool */
4623 lpfc_sli4_cq_event_release_all(phba);
4624 lpfc_sli4_cq_event_pool_destroy(phba);
4625
James Smart6d368e52011-05-24 11:44:12 -04004626 /* Release resource identifiers. */
4627 lpfc_sli4_dealloc_resource_identifiers(phba);
4628
James Smartda0436e2009-05-22 14:51:39 -04004629 /* Free the bsmbx region. */
4630 lpfc_destroy_bootstrap_mbox(phba);
4631
4632 /* Free the SLI Layer memory with SLI4 HBAs */
4633 lpfc_mem_free_all(phba);
4634
4635 /* Free the current connect table */
4636 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04004637 &phba->fcf_conn_rec_list, list) {
4638 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04004639 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04004640 }
James Smartda0436e2009-05-22 14:51:39 -04004641
4642 return;
4643}
4644
4645/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004646 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04004647 * @phba: The hba struct for which this call is being executed.
4648 * @dev_grp: The HBA PCI-Device group number.
4649 *
4650 * This routine sets up the device INIT interface API function jump table
4651 * in @phba struct.
4652 *
4653 * Returns: 0 - success, -ENODEV - failure.
4654 **/
4655int
4656lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
4657{
James Smart84d1b002010-02-12 14:42:33 -05004658 phba->lpfc_hba_init_link = lpfc_hba_init_link;
4659 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05004660 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04004661 switch (dev_grp) {
4662 case LPFC_PCI_DEV_LP:
4663 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
4664 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
4665 phba->lpfc_stop_port = lpfc_stop_port_s3;
4666 break;
James Smartda0436e2009-05-22 14:51:39 -04004667 case LPFC_PCI_DEV_OC:
4668 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
4669 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
4670 phba->lpfc_stop_port = lpfc_stop_port_s4;
4671 break;
James Smart3772a992009-05-22 14:50:54 -04004672 default:
4673 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4674 "1431 Invalid HBA PCI-device group: 0x%x\n",
4675 dev_grp);
4676 return -ENODEV;
4677 break;
4678 }
4679 return 0;
4680}
4681
4682/**
4683 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
4684 * @phba: pointer to lpfc hba data structure.
4685 *
4686 * This routine is invoked to set up the driver internal resources before the
4687 * device specific resource setup to support the HBA device it attached to.
4688 *
4689 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004690 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004691 * other values - error
4692 **/
4693static int
4694lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
4695{
4696 /*
4697 * Driver resources common to all SLI revisions
4698 */
James Smartea2151b2008-09-07 11:52:10 -04004699 atomic_set(&phba->fast_event_count, 0);
James Smart2e0fef82007-06-17 19:56:36 -05004700 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004701
James Smarte47c9092008-02-08 18:49:26 -05004702 /* Initialize ndlp management spinlock */
4703 spin_lock_init(&phba->ndlp_lock);
4704
James Smart2e0fef82007-06-17 19:56:36 -05004705 INIT_LIST_HEAD(&phba->port_list);
James Smart3772a992009-05-22 14:50:54 -04004706 INIT_LIST_HEAD(&phba->work_list);
James Smart84774a42008-08-24 21:50:06 -04004707 init_waitqueue_head(&phba->wait_4_mlo_m_q);
dea31012005-04-17 16:05:31 -05004708
James Smart3772a992009-05-22 14:50:54 -04004709 /* Initialize the wait queue head for the kernel thread */
4710 init_waitqueue_head(&phba->work_waitq);
James Smart858c9f62007-06-17 19:56:39 -05004711
James Smart3772a992009-05-22 14:50:54 -04004712 /* Initialize the scsi buffer list used by driver for scsi IO */
4713 spin_lock_init(&phba->scsi_buf_list_lock);
4714 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
dea31012005-04-17 16:05:31 -05004715
James Smart3772a992009-05-22 14:50:54 -04004716 /* Initialize the fabric iocb list */
4717 INIT_LIST_HEAD(&phba->fabric_iocb_list);
dea31012005-04-17 16:05:31 -05004718
James Smart3772a992009-05-22 14:50:54 -04004719 /* Initialize list to save ELS buffers */
4720 INIT_LIST_HEAD(&phba->elsbuf);
dea31012005-04-17 16:05:31 -05004721
James Smart3772a992009-05-22 14:50:54 -04004722 /* Initialize FCF connection rec list */
4723 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
dea31012005-04-17 16:05:31 -05004724
James Smart3772a992009-05-22 14:50:54 -04004725 return 0;
4726}
dea31012005-04-17 16:05:31 -05004727
James Smart3772a992009-05-22 14:50:54 -04004728/**
4729 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
4730 * @phba: pointer to lpfc hba data structure.
4731 *
4732 * This routine is invoked to set up the driver internal resources after the
4733 * device specific resource setup to support the HBA device it attached to.
4734 *
4735 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004736 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004737 * other values - error
4738 **/
4739static int
4740lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
4741{
4742 int error;
4743
4744 /* Startup the kernel thread for this host adapter. */
4745 phba->worker_thread = kthread_run(lpfc_do_work, phba,
4746 "lpfc_worker_%d", phba->brd_no);
4747 if (IS_ERR(phba->worker_thread)) {
4748 error = PTR_ERR(phba->worker_thread);
4749 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05004750 }
4751
James Smart3772a992009-05-22 14:50:54 -04004752 return 0;
4753}
4754
4755/**
4756 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
4757 * @phba: pointer to lpfc hba data structure.
4758 *
4759 * This routine is invoked to unset the driver internal resources set up after
4760 * the device specific resource setup for supporting the HBA device it
4761 * attached to.
4762 **/
4763static void
4764lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
4765{
4766 /* Stop kernel worker thread */
4767 kthread_stop(phba->worker_thread);
4768}
4769
4770/**
4771 * lpfc_free_iocb_list - Free iocb list.
4772 * @phba: pointer to lpfc hba data structure.
4773 *
4774 * This routine is invoked to free the driver's IOCB list and memory.
4775 **/
4776static void
4777lpfc_free_iocb_list(struct lpfc_hba *phba)
4778{
4779 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
4780
4781 spin_lock_irq(&phba->hbalock);
4782 list_for_each_entry_safe(iocbq_entry, iocbq_next,
4783 &phba->lpfc_iocb_list, list) {
4784 list_del(&iocbq_entry->list);
4785 kfree(iocbq_entry);
4786 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05004787 }
James Smart3772a992009-05-22 14:50:54 -04004788 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004789
James Smart3772a992009-05-22 14:50:54 -04004790 return;
4791}
dea31012005-04-17 16:05:31 -05004792
James Smart3772a992009-05-22 14:50:54 -04004793/**
4794 * lpfc_init_iocb_list - Allocate and initialize iocb list.
4795 * @phba: pointer to lpfc hba data structure.
4796 *
4797 * This routine is invoked to allocate and initizlize the driver's IOCB
4798 * list and set up the IOCB tag array accordingly.
4799 *
4800 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004801 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004802 * other values - error
4803 **/
4804static int
4805lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
4806{
4807 struct lpfc_iocbq *iocbq_entry = NULL;
4808 uint16_t iotag;
4809 int i;
dea31012005-04-17 16:05:31 -05004810
4811 /* Initialize and populate the iocb list per host. */
4812 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04004813 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07004814 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05004815 if (iocbq_entry == NULL) {
4816 printk(KERN_ERR "%s: only allocated %d iocbs of "
4817 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07004818 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05004819 goto out_free_iocbq;
4820 }
4821
James Bottomley604a3e32005-10-29 10:28:33 -05004822 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
4823 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04004824 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05004825 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04004826 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05004827 goto out_free_iocbq;
4828 }
James Smart6d368e52011-05-24 11:44:12 -04004829 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04004830 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05004831
4832 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004833 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
4834 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05004835 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004836 }
4837
James Smart3772a992009-05-22 14:50:54 -04004838 return 0;
4839
4840out_free_iocbq:
4841 lpfc_free_iocb_list(phba);
4842
4843 return -ENOMEM;
4844}
4845
4846/**
James Smartda0436e2009-05-22 14:51:39 -04004847 * lpfc_free_sgl_list - Free sgl list.
4848 * @phba: pointer to lpfc hba data structure.
4849 *
4850 * This routine is invoked to free the driver's sgl list and memory.
4851 **/
4852static void
4853lpfc_free_sgl_list(struct lpfc_hba *phba)
4854{
4855 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
4856 LIST_HEAD(sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04004857
4858 spin_lock_irq(&phba->hbalock);
4859 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
4860 spin_unlock_irq(&phba->hbalock);
4861
4862 list_for_each_entry_safe(sglq_entry, sglq_next,
4863 &sglq_list, list) {
4864 list_del(&sglq_entry->list);
4865 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
4866 kfree(sglq_entry);
4867 phba->sli4_hba.total_sglq_bufs--;
4868 }
James Smartda0436e2009-05-22 14:51:39 -04004869 kfree(phba->sli4_hba.lpfc_els_sgl_array);
4870}
4871
4872/**
4873 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
4874 * @phba: pointer to lpfc hba data structure.
4875 *
4876 * This routine is invoked to allocate the driver's active sgl memory.
4877 * This array will hold the sglq_entry's for active IOs.
4878 **/
4879static int
4880lpfc_init_active_sgl_array(struct lpfc_hba *phba)
4881{
4882 int size;
4883 size = sizeof(struct lpfc_sglq *);
4884 size *= phba->sli4_hba.max_cfg_param.max_xri;
4885
4886 phba->sli4_hba.lpfc_sglq_active_list =
4887 kzalloc(size, GFP_KERNEL);
4888 if (!phba->sli4_hba.lpfc_sglq_active_list)
4889 return -ENOMEM;
4890 return 0;
4891}
4892
4893/**
4894 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
4895 * @phba: pointer to lpfc hba data structure.
4896 *
4897 * This routine is invoked to walk through the array of active sglq entries
4898 * and free all of the resources.
4899 * This is just a place holder for now.
4900 **/
4901static void
4902lpfc_free_active_sgl(struct lpfc_hba *phba)
4903{
4904 kfree(phba->sli4_hba.lpfc_sglq_active_list);
4905}
4906
4907/**
4908 * lpfc_init_sgl_list - Allocate and initialize sgl list.
4909 * @phba: pointer to lpfc hba data structure.
4910 *
4911 * This routine is invoked to allocate and initizlize the driver's sgl
4912 * list and set up the sgl xritag tag array accordingly.
4913 *
4914 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004915 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04004916 * other values - error
4917 **/
4918static int
4919lpfc_init_sgl_list(struct lpfc_hba *phba)
4920{
4921 struct lpfc_sglq *sglq_entry = NULL;
4922 int i;
4923 int els_xri_cnt;
4924
4925 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
4926 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04004927 "2400 ELS XRI count %d.\n",
James Smartda0436e2009-05-22 14:51:39 -04004928 els_xri_cnt);
4929 /* Initialize and populate the sglq list per host/VF. */
4930 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
4931 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
4932
4933 /* Sanity check on XRI management */
4934 if (phba->sli4_hba.max_cfg_param.max_xri <= els_xri_cnt) {
4935 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4936 "2562 No room left for SCSI XRI allocation: "
4937 "max_xri=%d, els_xri=%d\n",
4938 phba->sli4_hba.max_cfg_param.max_xri,
4939 els_xri_cnt);
4940 return -ENOMEM;
4941 }
4942
4943 /* Allocate memory for the ELS XRI management array */
4944 phba->sli4_hba.lpfc_els_sgl_array =
4945 kzalloc((sizeof(struct lpfc_sglq *) * els_xri_cnt),
4946 GFP_KERNEL);
4947
4948 if (!phba->sli4_hba.lpfc_els_sgl_array) {
4949 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4950 "2401 Failed to allocate memory for ELS "
4951 "XRI management array of size %d.\n",
4952 els_xri_cnt);
4953 return -ENOMEM;
4954 }
4955
4956 /* Keep the SCSI XRI into the XRI management array */
4957 phba->sli4_hba.scsi_xri_max =
4958 phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
4959 phba->sli4_hba.scsi_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04004960 phba->sli4_hba.lpfc_scsi_psb_array =
4961 kzalloc((sizeof(struct lpfc_scsi_buf *) *
4962 phba->sli4_hba.scsi_xri_max), GFP_KERNEL);
4963
4964 if (!phba->sli4_hba.lpfc_scsi_psb_array) {
4965 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4966 "2563 Failed to allocate memory for SCSI "
4967 "XRI management array of size %d.\n",
4968 phba->sli4_hba.scsi_xri_max);
4969 kfree(phba->sli4_hba.lpfc_els_sgl_array);
4970 return -ENOMEM;
4971 }
4972
4973 for (i = 0; i < els_xri_cnt; i++) {
4974 sglq_entry = kzalloc(sizeof(struct lpfc_sglq), GFP_KERNEL);
4975 if (sglq_entry == NULL) {
4976 printk(KERN_ERR "%s: only allocated %d sgls of "
4977 "expected %d count. Unloading driver.\n",
4978 __func__, i, els_xri_cnt);
4979 goto out_free_mem;
4980 }
4981
James Smartda0436e2009-05-22 14:51:39 -04004982 sglq_entry->buff_type = GEN_BUFF_TYPE;
4983 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, &sglq_entry->phys);
4984 if (sglq_entry->virt == NULL) {
4985 kfree(sglq_entry);
4986 printk(KERN_ERR "%s: failed to allocate mbuf.\n"
4987 "Unloading driver.\n", __func__);
4988 goto out_free_mem;
4989 }
4990 sglq_entry->sgl = sglq_entry->virt;
4991 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
4992
4993 /* The list order is used by later block SGL registraton */
4994 spin_lock_irq(&phba->hbalock);
James Smart0f65ff62010-02-26 14:14:23 -05004995 sglq_entry->state = SGL_FREED;
James Smartda0436e2009-05-22 14:51:39 -04004996 list_add_tail(&sglq_entry->list, &phba->sli4_hba.lpfc_sgl_list);
4997 phba->sli4_hba.lpfc_els_sgl_array[i] = sglq_entry;
4998 phba->sli4_hba.total_sglq_bufs++;
4999 spin_unlock_irq(&phba->hbalock);
5000 }
5001 return 0;
5002
5003out_free_mem:
5004 kfree(phba->sli4_hba.lpfc_scsi_psb_array);
5005 lpfc_free_sgl_list(phba);
5006 return -ENOMEM;
5007}
5008
5009/**
5010 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
5011 * @phba: pointer to lpfc hba data structure.
5012 *
5013 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04005014 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04005015 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04005016 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
5017 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04005018 *
5019 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005020 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04005021 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04005022 **/
5023int
5024lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
5025{
5026 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04005027 struct lpfc_rpi_hdr *rpi_hdr;
5028
5029 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartda0436e2009-05-22 14:51:39 -04005030 /*
James Smart6d368e52011-05-24 11:44:12 -04005031 * If the SLI4 port supports extents, posting the rpi header isn't
5032 * required. Set the expected maximum count and let the actual value
5033 * get set when extents are fully allocated.
James Smartda0436e2009-05-22 14:51:39 -04005034 */
James Smart6d368e52011-05-24 11:44:12 -04005035 if (!phba->sli4_hba.rpi_hdrs_in_use) {
5036 phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
5037 return rc;
5038 }
5039 if (phba->sli4_hba.extents_in_use)
5040 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04005041
5042 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
5043 if (!rpi_hdr) {
5044 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5045 "0391 Error during rpi post operation\n");
5046 lpfc_sli4_remove_rpis(phba);
5047 rc = -ENODEV;
5048 }
5049
5050 return rc;
5051}
5052
5053/**
5054 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
5055 * @phba: pointer to lpfc hba data structure.
5056 *
5057 * This routine is invoked to allocate a single 4KB memory region to
5058 * support rpis and stores them in the phba. This single region
5059 * provides support for up to 64 rpis. The region is used globally
5060 * by the device.
5061 *
5062 * Returns:
5063 * A valid rpi hdr on success.
5064 * A NULL pointer on any failure.
5065 **/
5066struct lpfc_rpi_hdr *
5067lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
5068{
5069 uint16_t rpi_limit, curr_rpi_range;
5070 struct lpfc_dmabuf *dmabuf;
5071 struct lpfc_rpi_hdr *rpi_hdr;
James Smart9589b0622011-04-16 11:03:17 -04005072 uint32_t rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04005073
James Smart6d368e52011-05-24 11:44:12 -04005074 /*
5075 * If the SLI4 port supports extents, posting the rpi header isn't
5076 * required. Set the expected maximum count and let the actual value
5077 * get set when extents are fully allocated.
5078 */
5079 if (!phba->sli4_hba.rpi_hdrs_in_use)
5080 return NULL;
5081 if (phba->sli4_hba.extents_in_use)
5082 return NULL;
5083
5084 /* The limit on the logical index is just the max_rpi count. */
James Smartda0436e2009-05-22 14:51:39 -04005085 rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
James Smart6d368e52011-05-24 11:44:12 -04005086 phba->sli4_hba.max_cfg_param.max_rpi - 1;
James Smartda0436e2009-05-22 14:51:39 -04005087
5088 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04005089 /*
5090 * Establish the starting RPI in this header block. The starting
5091 * rpi is normalized to a zero base because the physical rpi is
5092 * port based.
5093 */
5094 curr_rpi_range = phba->sli4_hba.next_rpi -
5095 phba->sli4_hba.max_cfg_param.rpi_base;
James Smartda0436e2009-05-22 14:51:39 -04005096 spin_unlock_irq(&phba->hbalock);
5097
5098 /*
5099 * The port has a limited number of rpis. The increment here
5100 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
5101 * and to allow the full max_rpi range per port.
5102 */
5103 if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
James Smart9589b0622011-04-16 11:03:17 -04005104 rpi_count = rpi_limit - curr_rpi_range;
5105 else
5106 rpi_count = LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04005107
James Smart6d368e52011-05-24 11:44:12 -04005108 if (!rpi_count)
5109 return NULL;
James Smartda0436e2009-05-22 14:51:39 -04005110 /*
5111 * First allocate the protocol header region for the port. The
5112 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
5113 */
5114 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5115 if (!dmabuf)
5116 return NULL;
5117
5118 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
5119 LPFC_HDR_TEMPLATE_SIZE,
5120 &dmabuf->phys,
5121 GFP_KERNEL);
5122 if (!dmabuf->virt) {
5123 rpi_hdr = NULL;
5124 goto err_free_dmabuf;
5125 }
5126
5127 memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE);
5128 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
5129 rpi_hdr = NULL;
5130 goto err_free_coherent;
5131 }
5132
5133 /* Save the rpi header data for cleanup later. */
5134 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
5135 if (!rpi_hdr)
5136 goto err_free_coherent;
5137
5138 rpi_hdr->dmabuf = dmabuf;
5139 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
5140 rpi_hdr->page_count = 1;
5141 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04005142
5143 /* The rpi_hdr stores the logical index only. */
5144 rpi_hdr->start_rpi = curr_rpi_range;
James Smartda0436e2009-05-22 14:51:39 -04005145 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
5146
5147 /*
James Smart6d368e52011-05-24 11:44:12 -04005148 * The next_rpi stores the next logical module-64 rpi value used
5149 * to post physical rpis in subsequent rpi postings.
James Smartda0436e2009-05-22 14:51:39 -04005150 */
James Smart9589b0622011-04-16 11:03:17 -04005151 phba->sli4_hba.next_rpi += rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04005152 spin_unlock_irq(&phba->hbalock);
5153 return rpi_hdr;
5154
5155 err_free_coherent:
5156 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
5157 dmabuf->virt, dmabuf->phys);
5158 err_free_dmabuf:
5159 kfree(dmabuf);
5160 return NULL;
5161}
5162
5163/**
5164 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
5165 * @phba: pointer to lpfc hba data structure.
5166 *
5167 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04005168 * to support rpis for SLI4 ports not supporting extents. This routine
5169 * presumes the caller has released all rpis consumed by fabric or port
5170 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04005171 **/
5172void
5173lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
5174{
5175 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
5176
James Smart6d368e52011-05-24 11:44:12 -04005177 if (!phba->sli4_hba.rpi_hdrs_in_use)
5178 goto exit;
5179
James Smartda0436e2009-05-22 14:51:39 -04005180 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
5181 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
5182 list_del(&rpi_hdr->list);
5183 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
5184 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
5185 kfree(rpi_hdr->dmabuf);
5186 kfree(rpi_hdr);
5187 }
James Smart6d368e52011-05-24 11:44:12 -04005188 exit:
5189 /* There are no rpis available to the port now. */
5190 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04005191}
5192
5193/**
James Smart3772a992009-05-22 14:50:54 -04005194 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
5195 * @pdev: pointer to pci device data structure.
5196 *
5197 * This routine is invoked to allocate the driver hba data structure for an
5198 * HBA device. If the allocation is successful, the phba reference to the
5199 * PCI device data structure is set.
5200 *
5201 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005202 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04005203 * NULL - error
5204 **/
5205static struct lpfc_hba *
5206lpfc_hba_alloc(struct pci_dev *pdev)
5207{
5208 struct lpfc_hba *phba;
5209
5210 /* Allocate memory for HBA structure */
5211 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
5212 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02005213 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04005214 return NULL;
5215 }
5216
5217 /* Set reference to PCI device in HBA structure */
5218 phba->pcidev = pdev;
5219
5220 /* Assign an unused board number */
5221 phba->brd_no = lpfc_get_instance();
5222 if (phba->brd_no < 0) {
5223 kfree(phba);
5224 return NULL;
5225 }
5226
James Smart4fede782010-01-26 23:08:55 -05005227 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04005228 INIT_LIST_HEAD(&phba->ct_ev_waiters);
5229
James Smart3772a992009-05-22 14:50:54 -04005230 return phba;
5231}
5232
5233/**
5234 * lpfc_hba_free - Free driver hba data structure with a device.
5235 * @phba: pointer to lpfc hba data structure.
5236 *
5237 * This routine is invoked to free the driver hba data structure with an
5238 * HBA device.
5239 **/
5240static void
5241lpfc_hba_free(struct lpfc_hba *phba)
5242{
5243 /* Release the driver assigned board number */
5244 idr_remove(&lpfc_hba_index, phba->brd_no);
5245
5246 kfree(phba);
5247 return;
5248}
5249
5250/**
5251 * lpfc_create_shost - Create hba physical port with associated scsi host.
5252 * @phba: pointer to lpfc hba data structure.
5253 *
5254 * This routine is invoked to create HBA physical port and associate a SCSI
5255 * host with it.
5256 *
5257 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005258 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005259 * other values - error
5260 **/
5261static int
5262lpfc_create_shost(struct lpfc_hba *phba)
5263{
5264 struct lpfc_vport *vport;
5265 struct Scsi_Host *shost;
5266
5267 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05005268 phba->fc_edtov = FF_DEF_EDTOV;
5269 phba->fc_ratov = FF_DEF_RATOV;
5270 phba->fc_altov = FF_DEF_ALTOV;
5271 phba->fc_arbtov = FF_DEF_ARBTOV;
5272
James Smartd7c47992010-06-08 18:31:54 -04005273 atomic_set(&phba->sdev_cnt, 0);
James Smart3de2a652007-08-02 11:09:59 -04005274 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05005275 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04005276 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05005277
5278 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05005279 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05005280 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04005281 /* Put reference to SCSI host to driver's device private data */
5282 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05005283
James Smart3772a992009-05-22 14:50:54 -04005284 return 0;
5285}
dea31012005-04-17 16:05:31 -05005286
James Smart3772a992009-05-22 14:50:54 -04005287/**
5288 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
5289 * @phba: pointer to lpfc hba data structure.
5290 *
5291 * This routine is invoked to destroy HBA physical port and the associated
5292 * SCSI host.
5293 **/
5294static void
5295lpfc_destroy_shost(struct lpfc_hba *phba)
5296{
5297 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04005298
James Smart3772a992009-05-22 14:50:54 -04005299 /* Destroy physical port that associated with the SCSI host */
5300 destroy_port(vport);
5301
5302 return;
5303}
5304
5305/**
5306 * lpfc_setup_bg - Setup Block guard structures and debug areas.
5307 * @phba: pointer to lpfc hba data structure.
5308 * @shost: the shost to be used to detect Block guard settings.
5309 *
5310 * This routine sets up the local Block guard protocol settings for @shost.
5311 * This routine also allocates memory for debugging bg buffers.
5312 **/
5313static void
5314lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
5315{
5316 int pagecnt = 10;
5317 if (lpfc_prot_mask && lpfc_prot_guard) {
5318 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5319 "1478 Registering BlockGuard with the "
5320 "SCSI layer\n");
5321 scsi_host_set_prot(shost, lpfc_prot_mask);
5322 scsi_host_set_guard(shost, lpfc_prot_guard);
James Smart98c9ea52007-10-27 13:37:33 -04005323 }
James Smart81301a92008-12-04 22:39:46 -05005324 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05005325 while (pagecnt) {
5326 spin_lock_init(&_dump_buf_lock);
5327 _dump_buf_data =
5328 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
5329 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04005330 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5331 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04005332 "_dump_buf_data at 0x%p\n",
5333 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05005334 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04005335 memset(_dump_buf_data, 0,
5336 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05005337 break;
James Smart3772a992009-05-22 14:50:54 -04005338 } else
James Smart81301a92008-12-04 22:39:46 -05005339 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05005340 }
James Smart81301a92008-12-04 22:39:46 -05005341 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04005342 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5343 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04005344 "memory for hexdump\n");
5345 } else
James Smart6a9c52c2009-10-02 15:16:51 -04005346 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5347 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05005348 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05005349 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05005350 while (pagecnt) {
5351 _dump_buf_dif =
5352 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
5353 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04005354 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5355 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04005356 "_dump_buf_dif at 0x%p\n",
5357 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05005358 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04005359 memset(_dump_buf_dif, 0,
5360 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05005361 break;
James Smart3772a992009-05-22 14:50:54 -04005362 } else
James Smart81301a92008-12-04 22:39:46 -05005363 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05005364 }
James Smart81301a92008-12-04 22:39:46 -05005365 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04005366 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5367 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04005368 "memory for hexdump\n");
5369 } else
James Smart6a9c52c2009-10-02 15:16:51 -04005370 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5371 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04005372 _dump_buf_dif);
5373}
5374
5375/**
5376 * lpfc_post_init_setup - Perform necessary device post initialization setup.
5377 * @phba: pointer to lpfc hba data structure.
5378 *
5379 * This routine is invoked to perform all the necessary post initialization
5380 * setup for the device.
5381 **/
5382static void
5383lpfc_post_init_setup(struct lpfc_hba *phba)
5384{
5385 struct Scsi_Host *shost;
5386 struct lpfc_adapter_event_header adapter_event;
5387
5388 /* Get the default values for Model Name and Description */
5389 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
5390
5391 /*
5392 * hba setup may have changed the hba_queue_depth so we need to
5393 * adjust the value of can_queue.
5394 */
5395 shost = pci_get_drvdata(phba->pcidev);
5396 shost->can_queue = phba->cfg_hba_queue_depth - 10;
5397 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
5398 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05005399
5400 lpfc_host_attrib_init(shost);
5401
James Smart2e0fef82007-06-17 19:56:36 -05005402 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
5403 spin_lock_irq(shost->host_lock);
5404 lpfc_poll_start_timer(phba);
5405 spin_unlock_irq(shost->host_lock);
5406 }
James Smart8f6d98d2006-08-01 07:34:00 -04005407
James Smart93996272008-08-24 21:50:30 -04005408 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5409 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04005410 /* Send board arrival event to upper layer */
5411 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
5412 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
5413 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04005414 sizeof(adapter_event),
5415 (char *) &adapter_event,
5416 LPFC_NL_VENDOR_ID);
5417 return;
5418}
5419
5420/**
5421 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
5422 * @phba: pointer to lpfc hba data structure.
5423 *
5424 * This routine is invoked to set up the PCI device memory space for device
5425 * with SLI-3 interface spec.
5426 *
5427 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005428 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005429 * other values - error
5430 **/
5431static int
5432lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
5433{
5434 struct pci_dev *pdev;
5435 unsigned long bar0map_len, bar2map_len;
5436 int i, hbq_count;
5437 void *ptr;
5438 int error = -ENODEV;
5439
5440 /* Obtain PCI device reference */
5441 if (!phba->pcidev)
5442 return error;
5443 else
5444 pdev = phba->pcidev;
5445
5446 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05005447 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
5448 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
5449 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
5450 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smart3772a992009-05-22 14:50:54 -04005451 return error;
Michael Reed8e685972009-09-18 12:02:05 -05005452 }
5453 }
James Smart3772a992009-05-22 14:50:54 -04005454
5455 /* Get the bus address of Bar0 and Bar2 and the number of bytes
5456 * required by each mapping.
5457 */
5458 phba->pci_bar0_map = pci_resource_start(pdev, 0);
5459 bar0map_len = pci_resource_len(pdev, 0);
5460
5461 phba->pci_bar2_map = pci_resource_start(pdev, 2);
5462 bar2map_len = pci_resource_len(pdev, 2);
5463
5464 /* Map HBA SLIM to a kernel virtual address. */
5465 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
5466 if (!phba->slim_memmap_p) {
5467 dev_printk(KERN_ERR, &pdev->dev,
5468 "ioremap failed for SLIM memory.\n");
5469 goto out;
5470 }
5471
5472 /* Map HBA Control Registers to a kernel virtual address. */
5473 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
5474 if (!phba->ctrl_regs_memmap_p) {
5475 dev_printk(KERN_ERR, &pdev->dev,
5476 "ioremap failed for HBA control registers.\n");
5477 goto out_iounmap_slim;
5478 }
5479
5480 /* Allocate memory for SLI-2 structures */
5481 phba->slim2p.virt = dma_alloc_coherent(&pdev->dev,
5482 SLI2_SLIM_SIZE,
5483 &phba->slim2p.phys,
5484 GFP_KERNEL);
5485 if (!phba->slim2p.virt)
5486 goto out_iounmap;
5487
5488 memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
5489 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04005490 phba->mbox_ext = (phba->slim2p.virt +
5491 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04005492 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
5493 phba->IOCBs = (phba->slim2p.virt +
5494 offsetof(struct lpfc_sli2_slim, IOCBs));
5495
5496 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
5497 lpfc_sli_hbq_size(),
5498 &phba->hbqslimp.phys,
5499 GFP_KERNEL);
5500 if (!phba->hbqslimp.virt)
5501 goto out_free_slim;
5502
5503 hbq_count = lpfc_sli_hbq_count();
5504 ptr = phba->hbqslimp.virt;
5505 for (i = 0; i < hbq_count; ++i) {
5506 phba->hbqs[i].hbq_virt = ptr;
5507 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
5508 ptr += (lpfc_hbq_defs[i]->entry_count *
5509 sizeof(struct lpfc_hbq_entry));
5510 }
5511 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
5512 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
5513
5514 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
5515
5516 INIT_LIST_HEAD(&phba->rb_pend_list);
5517
5518 phba->MBslimaddr = phba->slim_memmap_p;
5519 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
5520 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
5521 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
5522 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04005523
dea31012005-04-17 16:05:31 -05005524 return 0;
5525
dea31012005-04-17 16:05:31 -05005526out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04005527 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
5528 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05005529out_iounmap:
5530 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005531out_iounmap_slim:
dea31012005-04-17 16:05:31 -05005532 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05005533out:
5534 return error;
5535}
5536
James Smarte59058c2008-08-24 21:49:00 -04005537/**
James Smart3772a992009-05-22 14:50:54 -04005538 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
5539 * @phba: pointer to lpfc hba data structure.
5540 *
5541 * This routine is invoked to unset the PCI device memory space for device
5542 * with SLI-3 interface spec.
5543 **/
5544static void
5545lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
5546{
5547 struct pci_dev *pdev;
5548
5549 /* Obtain PCI device reference */
5550 if (!phba->pcidev)
5551 return;
5552 else
5553 pdev = phba->pcidev;
5554
5555 /* Free coherent DMA memory allocated */
5556 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
5557 phba->hbqslimp.virt, phba->hbqslimp.phys);
5558 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
5559 phba->slim2p.virt, phba->slim2p.phys);
5560
5561 /* I/O memory unmap */
5562 iounmap(phba->ctrl_regs_memmap_p);
5563 iounmap(phba->slim_memmap_p);
5564
5565 return;
5566}
5567
5568/**
James Smartda0436e2009-05-22 14:51:39 -04005569 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
5570 * @phba: pointer to lpfc hba data structure.
5571 *
5572 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
5573 * done and check status.
5574 *
5575 * Return 0 if successful, otherwise -ENODEV.
5576 **/
5577int
5578lpfc_sli4_post_status_check(struct lpfc_hba *phba)
5579{
James Smart2fcee4b2010-12-15 17:57:46 -05005580 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
5581 struct lpfc_register reg_data;
5582 int i, port_error = 0;
5583 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04005584
James Smart9940b972011-03-11 16:06:12 -05005585 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
5586 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05005587 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04005588 return -ENODEV;
5589
James Smartda0436e2009-05-22 14:51:39 -04005590 /* Wait up to 30 seconds for the SLI Port POST done and ready */
5591 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05005592 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
5593 &portsmphr_reg.word0) ||
5594 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05005595 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04005596 port_error = -ENODEV;
5597 break;
5598 }
James Smart2fcee4b2010-12-15 17:57:46 -05005599 if (LPFC_POST_STAGE_PORT_READY ==
5600 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04005601 break;
James Smartda0436e2009-05-22 14:51:39 -04005602 msleep(10);
5603 }
5604
James Smart2fcee4b2010-12-15 17:57:46 -05005605 /*
5606 * If there was a port error during POST, then don't proceed with
5607 * other register reads as the data may not be valid. Just exit.
5608 */
5609 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04005610 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05005611 "1408 Port Failed POST - portsmphr=0x%x, "
5612 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
5613 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
5614 portsmphr_reg.word0,
5615 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
5616 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
5617 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
5618 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
5619 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
5620 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
5621 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
5622 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
5623 } else {
James Smart28baac72010-02-12 14:42:03 -05005624 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05005625 "2534 Device Info: SLIFamily=0x%x, "
5626 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
5627 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05005628 bf_get(lpfc_sli_intf_sli_family,
5629 &phba->sli4_hba.sli_intf),
5630 bf_get(lpfc_sli_intf_slirev,
5631 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05005632 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05005633 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05005634 bf_get(lpfc_sli_intf_sli_hint1,
5635 &phba->sli4_hba.sli_intf),
5636 bf_get(lpfc_sli_intf_sli_hint2,
5637 &phba->sli4_hba.sli_intf),
5638 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05005639 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05005640 /*
5641 * Check for other Port errors during the initialization
5642 * process. Fail the load if the port did not come up
5643 * correctly.
5644 */
5645 if_type = bf_get(lpfc_sli_intf_if_type,
5646 &phba->sli4_hba.sli_intf);
5647 switch (if_type) {
5648 case LPFC_SLI_INTF_IF_TYPE_0:
5649 phba->sli4_hba.ue_mask_lo =
5650 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
5651 phba->sli4_hba.ue_mask_hi =
5652 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
5653 uerrlo_reg.word0 =
5654 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
5655 uerrhi_reg.word0 =
5656 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
5657 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
5658 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
5659 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5660 "1422 Unrecoverable Error "
5661 "Detected during POST "
5662 "uerr_lo_reg=0x%x, "
5663 "uerr_hi_reg=0x%x, "
5664 "ue_mask_lo_reg=0x%x, "
5665 "ue_mask_hi_reg=0x%x\n",
5666 uerrlo_reg.word0,
5667 uerrhi_reg.word0,
5668 phba->sli4_hba.ue_mask_lo,
5669 phba->sli4_hba.ue_mask_hi);
5670 port_error = -ENODEV;
5671 }
5672 break;
5673 case LPFC_SLI_INTF_IF_TYPE_2:
5674 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05005675 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
5676 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04005677 (bf_get(lpfc_sliport_status_err, &reg_data) &&
5678 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05005679 phba->work_status[0] =
5680 readl(phba->sli4_hba.u.if_type2.
5681 ERR1regaddr);
5682 phba->work_status[1] =
5683 readl(phba->sli4_hba.u.if_type2.
5684 ERR2regaddr);
5685 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5686 "2888 Port Error Detected "
5687 "during POST: "
5688 "port status reg 0x%x, "
5689 "port_smphr reg 0x%x, "
5690 "error 1=0x%x, error 2=0x%x\n",
5691 reg_data.word0,
5692 portsmphr_reg.word0,
5693 phba->work_status[0],
5694 phba->work_status[1]);
5695 port_error = -ENODEV;
5696 }
5697 break;
5698 case LPFC_SLI_INTF_IF_TYPE_1:
5699 default:
5700 break;
5701 }
James Smart28baac72010-02-12 14:42:03 -05005702 }
James Smartda0436e2009-05-22 14:51:39 -04005703 return port_error;
5704}
5705
5706/**
5707 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
5708 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05005709 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04005710 *
5711 * This routine is invoked to set up SLI4 BAR0 PCI config space register
5712 * memory map.
5713 **/
5714static void
James Smart2fcee4b2010-12-15 17:57:46 -05005715lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04005716{
James Smart2fcee4b2010-12-15 17:57:46 -05005717 switch (if_type) {
5718 case LPFC_SLI_INTF_IF_TYPE_0:
5719 phba->sli4_hba.u.if_type0.UERRLOregaddr =
5720 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
5721 phba->sli4_hba.u.if_type0.UERRHIregaddr =
5722 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
5723 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
5724 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
5725 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
5726 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
5727 phba->sli4_hba.SLIINTFregaddr =
5728 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
5729 break;
5730 case LPFC_SLI_INTF_IF_TYPE_2:
5731 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04005732 phba->sli4_hba.conf_regs_memmap_p +
5733 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05005734 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04005735 phba->sli4_hba.conf_regs_memmap_p +
5736 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05005737 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04005738 phba->sli4_hba.conf_regs_memmap_p +
5739 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05005740 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04005741 phba->sli4_hba.conf_regs_memmap_p +
5742 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05005743 phba->sli4_hba.SLIINTFregaddr =
5744 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
5745 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04005746 phba->sli4_hba.conf_regs_memmap_p +
5747 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05005748 phba->sli4_hba.RQDBregaddr =
5749 phba->sli4_hba.conf_regs_memmap_p + LPFC_RQ_DOORBELL;
5750 phba->sli4_hba.WQDBregaddr =
5751 phba->sli4_hba.conf_regs_memmap_p + LPFC_WQ_DOORBELL;
5752 phba->sli4_hba.EQCQDBregaddr =
5753 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
5754 phba->sli4_hba.MQDBregaddr =
5755 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
5756 phba->sli4_hba.BMBXregaddr =
5757 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
5758 break;
5759 case LPFC_SLI_INTF_IF_TYPE_1:
5760 default:
5761 dev_printk(KERN_ERR, &phba->pcidev->dev,
5762 "FATAL - unsupported SLI4 interface type - %d\n",
5763 if_type);
5764 break;
5765 }
James Smartda0436e2009-05-22 14:51:39 -04005766}
5767
5768/**
5769 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
5770 * @phba: pointer to lpfc hba data structure.
5771 *
5772 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
5773 * memory map.
5774 **/
5775static void
5776lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
5777{
James Smart2fcee4b2010-12-15 17:57:46 -05005778 phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
5779 LPFC_SLIPORT_IF0_SMPHR;
James Smartda0436e2009-05-22 14:51:39 -04005780 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05005781 LPFC_HST_ISR0;
James Smartda0436e2009-05-22 14:51:39 -04005782 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05005783 LPFC_HST_IMR0;
James Smartda0436e2009-05-22 14:51:39 -04005784 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05005785 LPFC_HST_ISCR0;
James Smartda0436e2009-05-22 14:51:39 -04005786}
5787
5788/**
5789 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
5790 * @phba: pointer to lpfc hba data structure.
5791 * @vf: virtual function number
5792 *
5793 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
5794 * based on the given viftual function number, @vf.
5795 *
5796 * Return 0 if successful, otherwise -ENODEV.
5797 **/
5798static int
5799lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
5800{
5801 if (vf > LPFC_VIR_FUNC_MAX)
5802 return -ENODEV;
5803
5804 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
5805 vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL);
5806 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
5807 vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL);
5808 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
5809 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
5810 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
5811 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
5812 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
5813 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
5814 return 0;
5815}
5816
5817/**
5818 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
5819 * @phba: pointer to lpfc hba data structure.
5820 *
5821 * This routine is invoked to create the bootstrap mailbox
5822 * region consistent with the SLI-4 interface spec. This
5823 * routine allocates all memory necessary to communicate
5824 * mailbox commands to the port and sets up all alignment
5825 * needs. No locks are expected to be held when calling
5826 * this routine.
5827 *
5828 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005829 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04005830 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04005831 **/
5832static int
5833lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
5834{
5835 uint32_t bmbx_size;
5836 struct lpfc_dmabuf *dmabuf;
5837 struct dma_address *dma_address;
5838 uint32_t pa_addr;
5839 uint64_t phys_addr;
5840
5841 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5842 if (!dmabuf)
5843 return -ENOMEM;
5844
5845 /*
5846 * The bootstrap mailbox region is comprised of 2 parts
5847 * plus an alignment restriction of 16 bytes.
5848 */
5849 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
5850 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
5851 bmbx_size,
5852 &dmabuf->phys,
5853 GFP_KERNEL);
5854 if (!dmabuf->virt) {
5855 kfree(dmabuf);
5856 return -ENOMEM;
5857 }
5858 memset(dmabuf->virt, 0, bmbx_size);
5859
5860 /*
5861 * Initialize the bootstrap mailbox pointers now so that the register
5862 * operations are simple later. The mailbox dma address is required
5863 * to be 16-byte aligned. Also align the virtual memory as each
5864 * maibox is copied into the bmbx mailbox region before issuing the
5865 * command to the port.
5866 */
5867 phba->sli4_hba.bmbx.dmabuf = dmabuf;
5868 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
5869
5870 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
5871 LPFC_ALIGN_16_BYTE);
5872 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
5873 LPFC_ALIGN_16_BYTE);
5874
5875 /*
5876 * Set the high and low physical addresses now. The SLI4 alignment
5877 * requirement is 16 bytes and the mailbox is posted to the port
5878 * as two 30-bit addresses. The other data is a bit marking whether
5879 * the 30-bit address is the high or low address.
5880 * Upcast bmbx aphys to 64bits so shift instruction compiles
5881 * clean on 32 bit machines.
5882 */
5883 dma_address = &phba->sli4_hba.bmbx.dma_address;
5884 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
5885 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
5886 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
5887 LPFC_BMBX_BIT1_ADDR_HI);
5888
5889 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
5890 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
5891 LPFC_BMBX_BIT1_ADDR_LO);
5892 return 0;
5893}
5894
5895/**
5896 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
5897 * @phba: pointer to lpfc hba data structure.
5898 *
5899 * This routine is invoked to teardown the bootstrap mailbox
5900 * region and release all host resources. This routine requires
5901 * the caller to ensure all mailbox commands recovered, no
5902 * additional mailbox comands are sent, and interrupts are disabled
5903 * before calling this routine.
5904 *
5905 **/
5906static void
5907lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
5908{
5909 dma_free_coherent(&phba->pcidev->dev,
5910 phba->sli4_hba.bmbx.bmbx_size,
5911 phba->sli4_hba.bmbx.dmabuf->virt,
5912 phba->sli4_hba.bmbx.dmabuf->phys);
5913
5914 kfree(phba->sli4_hba.bmbx.dmabuf);
5915 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
5916}
5917
5918/**
5919 * lpfc_sli4_read_config - Get the config parameters.
5920 * @phba: pointer to lpfc hba data structure.
5921 *
5922 * This routine is invoked to read the configuration parameters from the HBA.
5923 * The configuration parameters are used to set the base and maximum values
5924 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
5925 * allocation for the port.
5926 *
5927 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005928 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005929 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04005930 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04005931 **/
5932static int
5933lpfc_sli4_read_config(struct lpfc_hba *phba)
5934{
5935 LPFC_MBOXQ_t *pmb;
5936 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04005937 union lpfc_sli4_cfg_shdr *shdr;
5938 uint32_t shdr_status, shdr_add_status;
5939 struct lpfc_mbx_get_func_cfg *get_func_cfg;
5940 struct lpfc_rsrc_desc_fcfcoe *desc;
5941 uint32_t desc_count;
5942 int length, i, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04005943
5944 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5945 if (!pmb) {
5946 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5947 "2011 Unable to allocate memory for issuing "
5948 "SLI_CONFIG_SPECIAL mailbox command\n");
5949 return -ENOMEM;
5950 }
5951
5952 lpfc_read_config(phba, pmb);
5953
5954 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
5955 if (rc != MBX_SUCCESS) {
5956 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5957 "2012 Mailbox failed , mbxCmd x%x "
5958 "READ_CONFIG, mbxStatus x%x\n",
5959 bf_get(lpfc_mqe_command, &pmb->u.mqe),
5960 bf_get(lpfc_mqe_status, &pmb->u.mqe));
5961 rc = -EIO;
5962 } else {
5963 rd_config = &pmb->u.mqe.un.rd_config;
James Smart6d368e52011-05-24 11:44:12 -04005964 phba->sli4_hba.extents_in_use =
5965 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04005966 phba->sli4_hba.max_cfg_param.max_xri =
5967 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
5968 phba->sli4_hba.max_cfg_param.xri_base =
5969 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
5970 phba->sli4_hba.max_cfg_param.max_vpi =
5971 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
5972 phba->sli4_hba.max_cfg_param.vpi_base =
5973 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
5974 phba->sli4_hba.max_cfg_param.max_rpi =
5975 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
5976 phba->sli4_hba.max_cfg_param.rpi_base =
5977 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
5978 phba->sli4_hba.max_cfg_param.max_vfi =
5979 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
5980 phba->sli4_hba.max_cfg_param.vfi_base =
5981 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
5982 phba->sli4_hba.max_cfg_param.max_fcfi =
5983 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04005984 phba->sli4_hba.max_cfg_param.max_eq =
5985 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
5986 phba->sli4_hba.max_cfg_param.max_rq =
5987 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
5988 phba->sli4_hba.max_cfg_param.max_wq =
5989 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
5990 phba->sli4_hba.max_cfg_param.max_cq =
5991 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
5992 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
5993 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
5994 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
5995 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
5996 phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base;
James Smart5ffc2662009-11-18 15:39:44 -05005997 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
5998 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04005999 phba->max_vports = phba->max_vpi;
6000 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04006001 "2003 cfg params Extents? %d "
6002 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04006003 "VPI(B:%d M:%d) "
6004 "VFI(B:%d M:%d) "
6005 "RPI(B:%d M:%d) "
James Smart6d368e52011-05-24 11:44:12 -04006006 "FCFI(Count:%d)\n",
6007 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04006008 phba->sli4_hba.max_cfg_param.xri_base,
6009 phba->sli4_hba.max_cfg_param.max_xri,
6010 phba->sli4_hba.max_cfg_param.vpi_base,
6011 phba->sli4_hba.max_cfg_param.max_vpi,
6012 phba->sli4_hba.max_cfg_param.vfi_base,
6013 phba->sli4_hba.max_cfg_param.max_vfi,
6014 phba->sli4_hba.max_cfg_param.rpi_base,
6015 phba->sli4_hba.max_cfg_param.max_rpi,
James Smartda0436e2009-05-22 14:51:39 -04006016 phba->sli4_hba.max_cfg_param.max_fcfi);
6017 }
James Smart912e3ac2011-05-24 11:42:11 -04006018
6019 if (rc)
6020 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04006021
6022 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smartb92938b2010-06-07 15:24:12 -04006023 if (phba->cfg_hba_queue_depth >
6024 (phba->sli4_hba.max_cfg_param.max_xri -
6025 lpfc_sli4_get_els_iocb_cnt(phba)))
James Smartda0436e2009-05-22 14:51:39 -04006026 phba->cfg_hba_queue_depth =
James Smartb92938b2010-06-07 15:24:12 -04006027 phba->sli4_hba.max_cfg_param.max_xri -
6028 lpfc_sli4_get_els_iocb_cnt(phba);
James Smart912e3ac2011-05-24 11:42:11 -04006029
6030 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
6031 LPFC_SLI_INTF_IF_TYPE_2)
6032 goto read_cfg_out;
6033
6034 /* get the pf# and vf# for SLI4 if_type 2 port */
6035 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
6036 sizeof(struct lpfc_sli4_cfg_mhdr));
6037 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
6038 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
6039 length, LPFC_SLI4_MBX_EMBED);
6040
6041 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
6042 shdr = (union lpfc_sli4_cfg_shdr *)
6043 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
6044 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6045 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6046 if (rc || shdr_status || shdr_add_status) {
6047 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6048 "3026 Mailbox failed , mbxCmd x%x "
6049 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
6050 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6051 bf_get(lpfc_mqe_status, &pmb->u.mqe));
6052 rc = -EIO;
6053 goto read_cfg_out;
6054 }
6055
6056 /* search for fc_fcoe resrouce descriptor */
6057 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
6058 desc_count = get_func_cfg->func_cfg.rsrc_desc_count;
6059
6060 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
6061 desc = (struct lpfc_rsrc_desc_fcfcoe *)
6062 &get_func_cfg->func_cfg.desc[i];
6063 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
6064 bf_get(lpfc_rsrc_desc_pcie_type, desc)) {
6065 phba->sli4_hba.iov.pf_number =
6066 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
6067 phba->sli4_hba.iov.vf_number =
6068 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
6069 break;
6070 }
6071 }
6072
6073 if (i < LPFC_RSRC_DESC_MAX_NUM)
6074 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6075 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
6076 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
6077 phba->sli4_hba.iov.vf_number);
6078 else {
6079 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6080 "3028 GET_FUNCTION_CONFIG: failed to find "
6081 "Resrouce Descriptor:x%x\n",
6082 LPFC_RSRC_DESC_TYPE_FCFCOE);
6083 rc = -EIO;
6084 }
6085
6086read_cfg_out:
6087 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04006088 return rc;
6089}
6090
6091/**
James Smart2fcee4b2010-12-15 17:57:46 -05006092 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04006093 * @phba: pointer to lpfc hba data structure.
6094 *
James Smart2fcee4b2010-12-15 17:57:46 -05006095 * This routine is invoked to setup the port-side endian order when
6096 * the port if_type is 0. This routine has no function for other
6097 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04006098 *
6099 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006100 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006101 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006102 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006103 **/
6104static int
6105lpfc_setup_endian_order(struct lpfc_hba *phba)
6106{
6107 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05006108 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04006109 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
6110 HOST_ENDIAN_HIGH_WORD1};
6111
James Smart2fcee4b2010-12-15 17:57:46 -05006112 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
6113 switch (if_type) {
6114 case LPFC_SLI_INTF_IF_TYPE_0:
6115 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
6116 GFP_KERNEL);
6117 if (!mboxq) {
6118 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6119 "0492 Unable to allocate memory for "
6120 "issuing SLI_CONFIG_SPECIAL mailbox "
6121 "command\n");
6122 return -ENOMEM;
6123 }
James Smartda0436e2009-05-22 14:51:39 -04006124
James Smart2fcee4b2010-12-15 17:57:46 -05006125 /*
6126 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
6127 * two words to contain special data values and no other data.
6128 */
6129 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
6130 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
6131 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6132 if (rc != MBX_SUCCESS) {
6133 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6134 "0493 SLI_CONFIG_SPECIAL mailbox "
6135 "failed with status x%x\n",
6136 rc);
6137 rc = -EIO;
6138 }
6139 mempool_free(mboxq, phba->mbox_mem_pool);
6140 break;
6141 case LPFC_SLI_INTF_IF_TYPE_2:
6142 case LPFC_SLI_INTF_IF_TYPE_1:
6143 default:
6144 break;
James Smartda0436e2009-05-22 14:51:39 -04006145 }
James Smartda0436e2009-05-22 14:51:39 -04006146 return rc;
6147}
6148
6149/**
6150 * lpfc_sli4_queue_create - Create all the SLI4 queues
6151 * @phba: pointer to lpfc hba data structure.
6152 *
6153 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
6154 * operation. For each SLI4 queue type, the parameters such as queue entry
6155 * count (queue depth) shall be taken from the module parameter. For now,
6156 * we just use some constant number as place holder.
6157 *
6158 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006159 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006160 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006161 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006162 **/
6163static int
6164lpfc_sli4_queue_create(struct lpfc_hba *phba)
6165{
6166 struct lpfc_queue *qdesc;
6167 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
6168 int cfg_fcp_wq_count;
6169 int cfg_fcp_eq_count;
6170
6171 /*
6172 * Sanity check for confiugred queue parameters against the run-time
6173 * device parameters
6174 */
6175
6176 /* Sanity check on FCP fast-path WQ parameters */
6177 cfg_fcp_wq_count = phba->cfg_fcp_wq_count;
6178 if (cfg_fcp_wq_count >
6179 (phba->sli4_hba.max_cfg_param.max_wq - LPFC_SP_WQN_DEF)) {
6180 cfg_fcp_wq_count = phba->sli4_hba.max_cfg_param.max_wq -
6181 LPFC_SP_WQN_DEF;
6182 if (cfg_fcp_wq_count < LPFC_FP_WQN_MIN) {
6183 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6184 "2581 Not enough WQs (%d) from "
6185 "the pci function for supporting "
6186 "FCP WQs (%d)\n",
6187 phba->sli4_hba.max_cfg_param.max_wq,
6188 phba->cfg_fcp_wq_count);
6189 goto out_error;
6190 }
6191 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6192 "2582 Not enough WQs (%d) from the pci "
6193 "function for supporting the requested "
6194 "FCP WQs (%d), the actual FCP WQs can "
6195 "be supported: %d\n",
6196 phba->sli4_hba.max_cfg_param.max_wq,
6197 phba->cfg_fcp_wq_count, cfg_fcp_wq_count);
6198 }
6199 /* The actual number of FCP work queues adopted */
6200 phba->cfg_fcp_wq_count = cfg_fcp_wq_count;
6201
6202 /* Sanity check on FCP fast-path EQ parameters */
6203 cfg_fcp_eq_count = phba->cfg_fcp_eq_count;
6204 if (cfg_fcp_eq_count >
6205 (phba->sli4_hba.max_cfg_param.max_eq - LPFC_SP_EQN_DEF)) {
6206 cfg_fcp_eq_count = phba->sli4_hba.max_cfg_param.max_eq -
6207 LPFC_SP_EQN_DEF;
6208 if (cfg_fcp_eq_count < LPFC_FP_EQN_MIN) {
6209 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6210 "2574 Not enough EQs (%d) from the "
6211 "pci function for supporting FCP "
6212 "EQs (%d)\n",
6213 phba->sli4_hba.max_cfg_param.max_eq,
6214 phba->cfg_fcp_eq_count);
6215 goto out_error;
6216 }
6217 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6218 "2575 Not enough EQs (%d) from the pci "
6219 "function for supporting the requested "
6220 "FCP EQs (%d), the actual FCP EQs can "
6221 "be supported: %d\n",
6222 phba->sli4_hba.max_cfg_param.max_eq,
6223 phba->cfg_fcp_eq_count, cfg_fcp_eq_count);
6224 }
6225 /* It does not make sense to have more EQs than WQs */
6226 if (cfg_fcp_eq_count > phba->cfg_fcp_wq_count) {
6227 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smart6a9c52c2009-10-02 15:16:51 -04006228 "2593 The FCP EQ count(%d) cannot be greater "
6229 "than the FCP WQ count(%d), limiting the "
6230 "FCP EQ count to %d\n", cfg_fcp_eq_count,
James Smartda0436e2009-05-22 14:51:39 -04006231 phba->cfg_fcp_wq_count,
6232 phba->cfg_fcp_wq_count);
6233 cfg_fcp_eq_count = phba->cfg_fcp_wq_count;
6234 }
6235 /* The actual number of FCP event queues adopted */
6236 phba->cfg_fcp_eq_count = cfg_fcp_eq_count;
6237 /* The overall number of event queues used */
6238 phba->sli4_hba.cfg_eqn = phba->cfg_fcp_eq_count + LPFC_SP_EQN_DEF;
6239
6240 /*
6241 * Create Event Queues (EQs)
6242 */
6243
6244 /* Get EQ depth from module parameter, fake the default for now */
6245 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
6246 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
6247
6248 /* Create slow path event queue */
6249 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
6250 phba->sli4_hba.eq_ecount);
6251 if (!qdesc) {
6252 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6253 "0496 Failed allocate slow-path EQ\n");
6254 goto out_error;
6255 }
6256 phba->sli4_hba.sp_eq = qdesc;
6257
6258 /* Create fast-path FCP Event Queue(s) */
6259 phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) *
6260 phba->cfg_fcp_eq_count), GFP_KERNEL);
6261 if (!phba->sli4_hba.fp_eq) {
6262 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6263 "2576 Failed allocate memory for fast-path "
6264 "EQ record array\n");
6265 goto out_free_sp_eq;
6266 }
6267 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
6268 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
6269 phba->sli4_hba.eq_ecount);
6270 if (!qdesc) {
6271 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6272 "0497 Failed allocate fast-path EQ\n");
6273 goto out_free_fp_eq;
6274 }
6275 phba->sli4_hba.fp_eq[fcp_eqidx] = qdesc;
6276 }
6277
6278 /*
6279 * Create Complete Queues (CQs)
6280 */
6281
6282 /* Get CQ depth from module parameter, fake the default for now */
6283 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
6284 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
6285
6286 /* Create slow-path Mailbox Command Complete Queue */
6287 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
6288 phba->sli4_hba.cq_ecount);
6289 if (!qdesc) {
6290 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6291 "0500 Failed allocate slow-path mailbox CQ\n");
6292 goto out_free_fp_eq;
6293 }
6294 phba->sli4_hba.mbx_cq = qdesc;
6295
6296 /* Create slow-path ELS Complete Queue */
6297 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
6298 phba->sli4_hba.cq_ecount);
6299 if (!qdesc) {
6300 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6301 "0501 Failed allocate slow-path ELS CQ\n");
6302 goto out_free_mbx_cq;
6303 }
6304 phba->sli4_hba.els_cq = qdesc;
6305
James Smartda0436e2009-05-22 14:51:39 -04006306
6307 /* Create fast-path FCP Completion Queue(s), one-to-one with EQs */
6308 phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
6309 phba->cfg_fcp_eq_count), GFP_KERNEL);
6310 if (!phba->sli4_hba.fcp_cq) {
6311 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6312 "2577 Failed allocate memory for fast-path "
6313 "CQ record array\n");
James Smart4d9ab992009-10-02 15:16:39 -04006314 goto out_free_els_cq;
James Smartda0436e2009-05-22 14:51:39 -04006315 }
6316 for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) {
6317 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
6318 phba->sli4_hba.cq_ecount);
6319 if (!qdesc) {
6320 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6321 "0499 Failed allocate fast-path FCP "
6322 "CQ (%d)\n", fcp_cqidx);
6323 goto out_free_fcp_cq;
6324 }
6325 phba->sli4_hba.fcp_cq[fcp_cqidx] = qdesc;
6326 }
6327
6328 /* Create Mailbox Command Queue */
6329 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
6330 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
6331
6332 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
6333 phba->sli4_hba.mq_ecount);
6334 if (!qdesc) {
6335 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6336 "0505 Failed allocate slow-path MQ\n");
6337 goto out_free_fcp_cq;
6338 }
6339 phba->sli4_hba.mbx_wq = qdesc;
6340
6341 /*
6342 * Create all the Work Queues (WQs)
6343 */
6344 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
6345 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
6346
6347 /* Create slow-path ELS Work Queue */
6348 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
6349 phba->sli4_hba.wq_ecount);
6350 if (!qdesc) {
6351 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6352 "0504 Failed allocate slow-path ELS WQ\n");
6353 goto out_free_mbx_wq;
6354 }
6355 phba->sli4_hba.els_wq = qdesc;
6356
6357 /* Create fast-path FCP Work Queue(s) */
6358 phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
6359 phba->cfg_fcp_wq_count), GFP_KERNEL);
6360 if (!phba->sli4_hba.fcp_wq) {
6361 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6362 "2578 Failed allocate memory for fast-path "
6363 "WQ record array\n");
6364 goto out_free_els_wq;
6365 }
6366 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
6367 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
6368 phba->sli4_hba.wq_ecount);
6369 if (!qdesc) {
6370 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6371 "0503 Failed allocate fast-path FCP "
6372 "WQ (%d)\n", fcp_wqidx);
6373 goto out_free_fcp_wq;
6374 }
6375 phba->sli4_hba.fcp_wq[fcp_wqidx] = qdesc;
6376 }
6377
6378 /*
6379 * Create Receive Queue (RQ)
6380 */
6381 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
6382 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
6383
6384 /* Create Receive Queue for header */
6385 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
6386 phba->sli4_hba.rq_ecount);
6387 if (!qdesc) {
6388 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6389 "0506 Failed allocate receive HRQ\n");
6390 goto out_free_fcp_wq;
6391 }
6392 phba->sli4_hba.hdr_rq = qdesc;
6393
6394 /* Create Receive Queue for data */
6395 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
6396 phba->sli4_hba.rq_ecount);
6397 if (!qdesc) {
6398 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6399 "0507 Failed allocate receive DRQ\n");
6400 goto out_free_hdr_rq;
6401 }
6402 phba->sli4_hba.dat_rq = qdesc;
6403
6404 return 0;
6405
6406out_free_hdr_rq:
6407 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
6408 phba->sli4_hba.hdr_rq = NULL;
6409out_free_fcp_wq:
6410 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) {
6411 lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_wqidx]);
6412 phba->sli4_hba.fcp_wq[fcp_wqidx] = NULL;
6413 }
6414 kfree(phba->sli4_hba.fcp_wq);
6415out_free_els_wq:
6416 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
6417 phba->sli4_hba.els_wq = NULL;
6418out_free_mbx_wq:
6419 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
6420 phba->sli4_hba.mbx_wq = NULL;
6421out_free_fcp_cq:
6422 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) {
6423 lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_cqidx]);
6424 phba->sli4_hba.fcp_cq[fcp_cqidx] = NULL;
6425 }
6426 kfree(phba->sli4_hba.fcp_cq);
James Smartda0436e2009-05-22 14:51:39 -04006427out_free_els_cq:
6428 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
6429 phba->sli4_hba.els_cq = NULL;
6430out_free_mbx_cq:
6431 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
6432 phba->sli4_hba.mbx_cq = NULL;
6433out_free_fp_eq:
6434 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) {
6435 lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_eqidx]);
6436 phba->sli4_hba.fp_eq[fcp_eqidx] = NULL;
6437 }
6438 kfree(phba->sli4_hba.fp_eq);
6439out_free_sp_eq:
6440 lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
6441 phba->sli4_hba.sp_eq = NULL;
6442out_error:
6443 return -ENOMEM;
6444}
6445
6446/**
6447 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
6448 * @phba: pointer to lpfc hba data structure.
6449 *
6450 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
6451 * operation.
6452 *
6453 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006454 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006455 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006456 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006457 **/
6458static void
6459lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
6460{
6461 int fcp_qidx;
6462
6463 /* Release mailbox command work queue */
6464 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
6465 phba->sli4_hba.mbx_wq = NULL;
6466
6467 /* Release ELS work queue */
6468 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
6469 phba->sli4_hba.els_wq = NULL;
6470
6471 /* Release FCP work queue */
6472 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
6473 lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_qidx]);
6474 kfree(phba->sli4_hba.fcp_wq);
6475 phba->sli4_hba.fcp_wq = NULL;
6476
6477 /* Release unsolicited receive queue */
6478 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
6479 phba->sli4_hba.hdr_rq = NULL;
6480 lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
6481 phba->sli4_hba.dat_rq = NULL;
6482
James Smartda0436e2009-05-22 14:51:39 -04006483 /* Release ELS complete queue */
6484 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
6485 phba->sli4_hba.els_cq = NULL;
6486
6487 /* Release mailbox command complete queue */
6488 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
6489 phba->sli4_hba.mbx_cq = NULL;
6490
6491 /* Release FCP response complete queue */
James Smart05580562011-05-24 11:40:48 -04006492 fcp_qidx = 0;
6493 do
James Smartda0436e2009-05-22 14:51:39 -04006494 lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_qidx]);
James Smart05580562011-05-24 11:40:48 -04006495 while (++fcp_qidx < phba->cfg_fcp_eq_count);
James Smartda0436e2009-05-22 14:51:39 -04006496 kfree(phba->sli4_hba.fcp_cq);
6497 phba->sli4_hba.fcp_cq = NULL;
6498
6499 /* Release fast-path event queue */
6500 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
6501 lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]);
6502 kfree(phba->sli4_hba.fp_eq);
6503 phba->sli4_hba.fp_eq = NULL;
6504
6505 /* Release slow-path event queue */
6506 lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
6507 phba->sli4_hba.sp_eq = NULL;
6508
6509 return;
6510}
6511
6512/**
6513 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
6514 * @phba: pointer to lpfc hba data structure.
6515 *
6516 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
6517 * operation.
6518 *
6519 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006520 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006521 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006522 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006523 **/
6524int
6525lpfc_sli4_queue_setup(struct lpfc_hba *phba)
6526{
6527 int rc = -ENOMEM;
6528 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
6529 int fcp_cq_index = 0;
6530
6531 /*
6532 * Set up Event Queues (EQs)
6533 */
6534
6535 /* Set up slow-path event queue */
6536 if (!phba->sli4_hba.sp_eq) {
6537 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6538 "0520 Slow-path EQ not allocated\n");
6539 goto out_error;
6540 }
6541 rc = lpfc_eq_create(phba, phba->sli4_hba.sp_eq,
6542 LPFC_SP_DEF_IMAX);
6543 if (rc) {
6544 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6545 "0521 Failed setup of slow-path EQ: "
6546 "rc = 0x%x\n", rc);
6547 goto out_error;
6548 }
6549 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6550 "2583 Slow-path EQ setup: queue-id=%d\n",
6551 phba->sli4_hba.sp_eq->queue_id);
6552
6553 /* Set up fast-path event queue */
6554 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
6555 if (!phba->sli4_hba.fp_eq[fcp_eqidx]) {
6556 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6557 "0522 Fast-path EQ (%d) not "
6558 "allocated\n", fcp_eqidx);
6559 goto out_destroy_fp_eq;
6560 }
6561 rc = lpfc_eq_create(phba, phba->sli4_hba.fp_eq[fcp_eqidx],
6562 phba->cfg_fcp_imax);
6563 if (rc) {
6564 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6565 "0523 Failed setup of fast-path EQ "
6566 "(%d), rc = 0x%x\n", fcp_eqidx, rc);
6567 goto out_destroy_fp_eq;
6568 }
6569 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6570 "2584 Fast-path EQ setup: "
6571 "queue[%d]-id=%d\n", fcp_eqidx,
6572 phba->sli4_hba.fp_eq[fcp_eqidx]->queue_id);
6573 }
6574
6575 /*
6576 * Set up Complete Queues (CQs)
6577 */
6578
6579 /* Set up slow-path MBOX Complete Queue as the first CQ */
6580 if (!phba->sli4_hba.mbx_cq) {
6581 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6582 "0528 Mailbox CQ not allocated\n");
6583 goto out_destroy_fp_eq;
6584 }
6585 rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, phba->sli4_hba.sp_eq,
6586 LPFC_MCQ, LPFC_MBOX);
6587 if (rc) {
6588 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6589 "0529 Failed setup of slow-path mailbox CQ: "
6590 "rc = 0x%x\n", rc);
6591 goto out_destroy_fp_eq;
6592 }
6593 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6594 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
6595 phba->sli4_hba.mbx_cq->queue_id,
6596 phba->sli4_hba.sp_eq->queue_id);
6597
6598 /* Set up slow-path ELS Complete Queue */
6599 if (!phba->sli4_hba.els_cq) {
6600 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6601 "0530 ELS CQ not allocated\n");
6602 goto out_destroy_mbx_cq;
6603 }
6604 rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, phba->sli4_hba.sp_eq,
6605 LPFC_WCQ, LPFC_ELS);
6606 if (rc) {
6607 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6608 "0531 Failed setup of slow-path ELS CQ: "
6609 "rc = 0x%x\n", rc);
6610 goto out_destroy_mbx_cq;
6611 }
6612 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6613 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
6614 phba->sli4_hba.els_cq->queue_id,
6615 phba->sli4_hba.sp_eq->queue_id);
6616
James Smartda0436e2009-05-22 14:51:39 -04006617 /* Set up fast-path FCP Response Complete Queue */
James Smart05580562011-05-24 11:40:48 -04006618 fcp_cqidx = 0;
6619 do {
James Smartda0436e2009-05-22 14:51:39 -04006620 if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
6621 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6622 "0526 Fast-path FCP CQ (%d) not "
6623 "allocated\n", fcp_cqidx);
6624 goto out_destroy_fcp_cq;
6625 }
James Smart05580562011-05-24 11:40:48 -04006626 if (phba->cfg_fcp_eq_count)
6627 rc = lpfc_cq_create(phba,
6628 phba->sli4_hba.fcp_cq[fcp_cqidx],
6629 phba->sli4_hba.fp_eq[fcp_cqidx],
6630 LPFC_WCQ, LPFC_FCP);
6631 else
6632 rc = lpfc_cq_create(phba,
6633 phba->sli4_hba.fcp_cq[fcp_cqidx],
6634 phba->sli4_hba.sp_eq,
6635 LPFC_WCQ, LPFC_FCP);
James Smartda0436e2009-05-22 14:51:39 -04006636 if (rc) {
6637 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6638 "0527 Failed setup of fast-path FCP "
6639 "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc);
6640 goto out_destroy_fcp_cq;
6641 }
6642 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6643 "2588 FCP CQ setup: cq[%d]-id=%d, "
James Smart05580562011-05-24 11:40:48 -04006644 "parent %seq[%d]-id=%d\n",
James Smartda0436e2009-05-22 14:51:39 -04006645 fcp_cqidx,
6646 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
James Smart05580562011-05-24 11:40:48 -04006647 (phba->cfg_fcp_eq_count) ? "" : "sp_",
James Smartda0436e2009-05-22 14:51:39 -04006648 fcp_cqidx,
James Smart05580562011-05-24 11:40:48 -04006649 (phba->cfg_fcp_eq_count) ?
6650 phba->sli4_hba.fp_eq[fcp_cqidx]->queue_id :
6651 phba->sli4_hba.sp_eq->queue_id);
6652 } while (++fcp_cqidx < phba->cfg_fcp_eq_count);
James Smartda0436e2009-05-22 14:51:39 -04006653
6654 /*
6655 * Set up all the Work Queues (WQs)
6656 */
6657
6658 /* Set up Mailbox Command Queue */
6659 if (!phba->sli4_hba.mbx_wq) {
6660 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6661 "0538 Slow-path MQ not allocated\n");
6662 goto out_destroy_fcp_cq;
6663 }
6664 rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
6665 phba->sli4_hba.mbx_cq, LPFC_MBOX);
6666 if (rc) {
6667 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6668 "0539 Failed setup of slow-path MQ: "
6669 "rc = 0x%x\n", rc);
6670 goto out_destroy_fcp_cq;
6671 }
6672 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6673 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
6674 phba->sli4_hba.mbx_wq->queue_id,
6675 phba->sli4_hba.mbx_cq->queue_id);
6676
6677 /* Set up slow-path ELS Work Queue */
6678 if (!phba->sli4_hba.els_wq) {
6679 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6680 "0536 Slow-path ELS WQ not allocated\n");
6681 goto out_destroy_mbx_wq;
6682 }
6683 rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
6684 phba->sli4_hba.els_cq, LPFC_ELS);
6685 if (rc) {
6686 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6687 "0537 Failed setup of slow-path ELS WQ: "
6688 "rc = 0x%x\n", rc);
6689 goto out_destroy_mbx_wq;
6690 }
6691 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6692 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
6693 phba->sli4_hba.els_wq->queue_id,
6694 phba->sli4_hba.els_cq->queue_id);
6695
6696 /* Set up fast-path FCP Work Queue */
6697 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
6698 if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
6699 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6700 "0534 Fast-path FCP WQ (%d) not "
6701 "allocated\n", fcp_wqidx);
6702 goto out_destroy_fcp_wq;
6703 }
6704 rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
6705 phba->sli4_hba.fcp_cq[fcp_cq_index],
6706 LPFC_FCP);
6707 if (rc) {
6708 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6709 "0535 Failed setup of fast-path FCP "
6710 "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc);
6711 goto out_destroy_fcp_wq;
6712 }
6713 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6714 "2591 FCP WQ setup: wq[%d]-id=%d, "
6715 "parent cq[%d]-id=%d\n",
6716 fcp_wqidx,
6717 phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
6718 fcp_cq_index,
6719 phba->sli4_hba.fcp_cq[fcp_cq_index]->queue_id);
6720 /* Round robin FCP Work Queue's Completion Queue assignment */
James Smart05580562011-05-24 11:40:48 -04006721 if (phba->cfg_fcp_eq_count)
6722 fcp_cq_index = ((fcp_cq_index + 1) %
6723 phba->cfg_fcp_eq_count);
James Smartda0436e2009-05-22 14:51:39 -04006724 }
6725
6726 /*
6727 * Create Receive Queue (RQ)
6728 */
6729 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
6730 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6731 "0540 Receive Queue not allocated\n");
6732 goto out_destroy_fcp_wq;
6733 }
James Smart73d91e52011-10-10 21:32:10 -04006734
6735 lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
6736 lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
6737
James Smartda0436e2009-05-22 14:51:39 -04006738 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04006739 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04006740 if (rc) {
6741 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6742 "0541 Failed setup of Receive Queue: "
6743 "rc = 0x%x\n", rc);
6744 goto out_destroy_fcp_wq;
6745 }
James Smart73d91e52011-10-10 21:32:10 -04006746
James Smartda0436e2009-05-22 14:51:39 -04006747 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6748 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
6749 "parent cq-id=%d\n",
6750 phba->sli4_hba.hdr_rq->queue_id,
6751 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04006752 phba->sli4_hba.els_cq->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04006753 return 0;
6754
6755out_destroy_fcp_wq:
6756 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
6757 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
6758 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
6759out_destroy_mbx_wq:
6760 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
6761out_destroy_fcp_cq:
6762 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
6763 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
James Smartda0436e2009-05-22 14:51:39 -04006764 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
6765out_destroy_mbx_cq:
6766 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
6767out_destroy_fp_eq:
6768 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
6769 lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_eqidx]);
6770 lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
6771out_error:
6772 return rc;
6773}
6774
6775/**
6776 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
6777 * @phba: pointer to lpfc hba data structure.
6778 *
6779 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
6780 * operation.
6781 *
6782 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006783 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006784 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006785 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006786 **/
6787void
6788lpfc_sli4_queue_unset(struct lpfc_hba *phba)
6789{
6790 int fcp_qidx;
6791
6792 /* Unset mailbox command work queue */
6793 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
6794 /* Unset ELS work queue */
6795 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
6796 /* Unset unsolicited receive queue */
6797 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
6798 /* Unset FCP work queue */
6799 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
6800 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
6801 /* Unset mailbox command complete queue */
6802 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
6803 /* Unset ELS complete queue */
6804 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
James Smartda0436e2009-05-22 14:51:39 -04006805 /* Unset FCP response complete queue */
6806 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
6807 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
6808 /* Unset fast-path event queue */
6809 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
6810 lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_qidx]);
6811 /* Unset slow-path event queue */
6812 lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
6813}
6814
6815/**
6816 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
6817 * @phba: pointer to lpfc hba data structure.
6818 *
6819 * This routine is invoked to allocate and set up a pool of completion queue
6820 * events. The body of the completion queue event is a completion queue entry
6821 * CQE. For now, this pool is used for the interrupt service routine to queue
6822 * the following HBA completion queue events for the worker thread to process:
6823 * - Mailbox asynchronous events
6824 * - Receive queue completion unsolicited events
6825 * Later, this can be used for all the slow-path events.
6826 *
6827 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006828 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006829 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04006830 **/
6831static int
6832lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
6833{
6834 struct lpfc_cq_event *cq_event;
6835 int i;
6836
6837 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
6838 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
6839 if (!cq_event)
6840 goto out_pool_create_fail;
6841 list_add_tail(&cq_event->list,
6842 &phba->sli4_hba.sp_cqe_event_pool);
6843 }
6844 return 0;
6845
6846out_pool_create_fail:
6847 lpfc_sli4_cq_event_pool_destroy(phba);
6848 return -ENOMEM;
6849}
6850
6851/**
6852 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
6853 * @phba: pointer to lpfc hba data structure.
6854 *
6855 * This routine is invoked to free the pool of completion queue events at
6856 * driver unload time. Note that, it is the responsibility of the driver
6857 * cleanup routine to free all the outstanding completion-queue events
6858 * allocated from this pool back into the pool before invoking this routine
6859 * to destroy the pool.
6860 **/
6861static void
6862lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
6863{
6864 struct lpfc_cq_event *cq_event, *next_cq_event;
6865
6866 list_for_each_entry_safe(cq_event, next_cq_event,
6867 &phba->sli4_hba.sp_cqe_event_pool, list) {
6868 list_del(&cq_event->list);
6869 kfree(cq_event);
6870 }
6871}
6872
6873/**
6874 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
6875 * @phba: pointer to lpfc hba data structure.
6876 *
6877 * This routine is the lock free version of the API invoked to allocate a
6878 * completion-queue event from the free pool.
6879 *
6880 * Return: Pointer to the newly allocated completion-queue event if successful
6881 * NULL otherwise.
6882 **/
6883struct lpfc_cq_event *
6884__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
6885{
6886 struct lpfc_cq_event *cq_event = NULL;
6887
6888 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
6889 struct lpfc_cq_event, list);
6890 return cq_event;
6891}
6892
6893/**
6894 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
6895 * @phba: pointer to lpfc hba data structure.
6896 *
6897 * This routine is the lock version of the API invoked to allocate a
6898 * completion-queue event from the free pool.
6899 *
6900 * Return: Pointer to the newly allocated completion-queue event if successful
6901 * NULL otherwise.
6902 **/
6903struct lpfc_cq_event *
6904lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
6905{
6906 struct lpfc_cq_event *cq_event;
6907 unsigned long iflags;
6908
6909 spin_lock_irqsave(&phba->hbalock, iflags);
6910 cq_event = __lpfc_sli4_cq_event_alloc(phba);
6911 spin_unlock_irqrestore(&phba->hbalock, iflags);
6912 return cq_event;
6913}
6914
6915/**
6916 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
6917 * @phba: pointer to lpfc hba data structure.
6918 * @cq_event: pointer to the completion queue event to be freed.
6919 *
6920 * This routine is the lock free version of the API invoked to release a
6921 * completion-queue event back into the free pool.
6922 **/
6923void
6924__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
6925 struct lpfc_cq_event *cq_event)
6926{
6927 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
6928}
6929
6930/**
6931 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
6932 * @phba: pointer to lpfc hba data structure.
6933 * @cq_event: pointer to the completion queue event to be freed.
6934 *
6935 * This routine is the lock version of the API invoked to release a
6936 * completion-queue event back into the free pool.
6937 **/
6938void
6939lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
6940 struct lpfc_cq_event *cq_event)
6941{
6942 unsigned long iflags;
6943 spin_lock_irqsave(&phba->hbalock, iflags);
6944 __lpfc_sli4_cq_event_release(phba, cq_event);
6945 spin_unlock_irqrestore(&phba->hbalock, iflags);
6946}
6947
6948/**
6949 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
6950 * @phba: pointer to lpfc hba data structure.
6951 *
6952 * This routine is to free all the pending completion-queue events to the
6953 * back into the free pool for device reset.
6954 **/
6955static void
6956lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
6957{
6958 LIST_HEAD(cqelist);
6959 struct lpfc_cq_event *cqe;
6960 unsigned long iflags;
6961
6962 /* Retrieve all the pending WCQEs from pending WCQE lists */
6963 spin_lock_irqsave(&phba->hbalock, iflags);
6964 /* Pending FCP XRI abort events */
6965 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
6966 &cqelist);
6967 /* Pending ELS XRI abort events */
6968 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
6969 &cqelist);
6970 /* Pending asynnc events */
6971 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
6972 &cqelist);
6973 spin_unlock_irqrestore(&phba->hbalock, iflags);
6974
6975 while (!list_empty(&cqelist)) {
6976 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
6977 lpfc_sli4_cq_event_release(phba, cqe);
6978 }
6979}
6980
6981/**
6982 * lpfc_pci_function_reset - Reset pci function.
6983 * @phba: pointer to lpfc hba data structure.
6984 *
6985 * This routine is invoked to request a PCI function reset. It will destroys
6986 * all resources assigned to the PCI function which originates this request.
6987 *
6988 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006989 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006990 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006991 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006992 **/
6993int
6994lpfc_pci_function_reset(struct lpfc_hba *phba)
6995{
6996 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05006997 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04006998 uint32_t shdr_status, shdr_add_status;
James Smart2fcee4b2010-12-15 17:57:46 -05006999 uint32_t rdy_chk, num_resets = 0, reset_again = 0;
James Smartda0436e2009-05-22 14:51:39 -04007000 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05007001 struct lpfc_register reg_data;
James Smartda0436e2009-05-22 14:51:39 -04007002
James Smart2fcee4b2010-12-15 17:57:46 -05007003 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7004 switch (if_type) {
7005 case LPFC_SLI_INTF_IF_TYPE_0:
7006 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7007 GFP_KERNEL);
7008 if (!mboxq) {
7009 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7010 "0494 Unable to allocate memory for "
7011 "issuing SLI_FUNCTION_RESET mailbox "
7012 "command\n");
7013 return -ENOMEM;
7014 }
7015
7016 /* Setup PCI function reset mailbox-ioctl command */
7017 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
7018 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
7019 LPFC_SLI4_MBX_EMBED);
7020 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7021 shdr = (union lpfc_sli4_cfg_shdr *)
7022 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
7023 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7024 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
7025 &shdr->response);
7026 if (rc != MBX_TIMEOUT)
7027 mempool_free(mboxq, phba->mbox_mem_pool);
7028 if (shdr_status || shdr_add_status || rc) {
7029 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7030 "0495 SLI_FUNCTION_RESET mailbox "
7031 "failed with status x%x add_status x%x,"
7032 " mbx status x%x\n",
7033 shdr_status, shdr_add_status, rc);
7034 rc = -ENXIO;
7035 }
7036 break;
7037 case LPFC_SLI_INTF_IF_TYPE_2:
7038 for (num_resets = 0;
7039 num_resets < MAX_IF_TYPE_2_RESETS;
7040 num_resets++) {
7041 reg_data.word0 = 0;
7042 bf_set(lpfc_sliport_ctrl_end, &reg_data,
7043 LPFC_SLIPORT_LITTLE_ENDIAN);
7044 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
7045 LPFC_SLIPORT_INIT_PORT);
7046 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
7047 CTRLregaddr);
7048
7049 /*
7050 * Poll the Port Status Register and wait for RDY for
7051 * up to 10 seconds. If the port doesn't respond, treat
7052 * it as an error. If the port responds with RN, start
7053 * the loop again.
7054 */
7055 for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) {
James Smart73d91e52011-10-10 21:32:10 -04007056 msleep(10);
James Smart9940b972011-03-11 16:06:12 -05007057 if (lpfc_readl(phba->sli4_hba.u.if_type2.
7058 STATUSregaddr, &reg_data.word0)) {
7059 rc = -ENODEV;
James Smart73d91e52011-10-10 21:32:10 -04007060 goto out;
James Smart9940b972011-03-11 16:06:12 -05007061 }
James Smart2fcee4b2010-12-15 17:57:46 -05007062 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
7063 break;
7064 if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
7065 reset_again++;
7066 break;
7067 }
James Smart2fcee4b2010-12-15 17:57:46 -05007068 }
7069
7070 /*
7071 * If the port responds to the init request with
7072 * reset needed, delay for a bit and restart the loop.
7073 */
7074 if (reset_again) {
7075 msleep(10);
7076 reset_again = 0;
7077 continue;
7078 }
7079
7080 /* Detect any port errors. */
James Smart2fcee4b2010-12-15 17:57:46 -05007081 if ((bf_get(lpfc_sliport_status_err, &reg_data)) ||
7082 (rdy_chk >= 1000)) {
7083 phba->work_status[0] = readl(
7084 phba->sli4_hba.u.if_type2.ERR1regaddr);
7085 phba->work_status[1] = readl(
7086 phba->sli4_hba.u.if_type2.ERR2regaddr);
7087 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7088 "2890 Port Error Detected "
7089 "during Port Reset: "
7090 "port status reg 0x%x, "
7091 "error 1=0x%x, error 2=0x%x\n",
7092 reg_data.word0,
7093 phba->work_status[0],
7094 phba->work_status[1]);
7095 rc = -ENODEV;
7096 }
7097
7098 /*
7099 * Terminate the outer loop provided the Port indicated
7100 * ready within 10 seconds.
7101 */
7102 if (rdy_chk < 1000)
7103 break;
7104 }
James Smart05580562011-05-24 11:40:48 -04007105 /* delay driver action following IF_TYPE_2 function reset */
7106 msleep(100);
James Smart2fcee4b2010-12-15 17:57:46 -05007107 break;
7108 case LPFC_SLI_INTF_IF_TYPE_1:
7109 default:
7110 break;
James Smartda0436e2009-05-22 14:51:39 -04007111 }
7112
James Smart73d91e52011-10-10 21:32:10 -04007113out:
James Smart2fcee4b2010-12-15 17:57:46 -05007114 /* Catch the not-ready port failure after a port reset. */
7115 if (num_resets >= MAX_IF_TYPE_2_RESETS)
7116 rc = -ENODEV;
7117
James Smartda0436e2009-05-22 14:51:39 -04007118 return rc;
7119}
7120
7121/**
7122 * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands
7123 * @phba: pointer to lpfc hba data structure.
7124 * @cnt: number of nop mailbox commands to send.
7125 *
7126 * This routine is invoked to send a number @cnt of NOP mailbox command and
7127 * wait for each command to complete.
7128 *
7129 * Return: the number of NOP mailbox command completed.
7130 **/
7131static int
7132lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt)
7133{
7134 LPFC_MBOXQ_t *mboxq;
7135 int length, cmdsent;
7136 uint32_t mbox_tmo;
7137 uint32_t rc = 0;
7138 uint32_t shdr_status, shdr_add_status;
7139 union lpfc_sli4_cfg_shdr *shdr;
7140
7141 if (cnt == 0) {
7142 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7143 "2518 Requested to send 0 NOP mailbox cmd\n");
7144 return cnt;
7145 }
7146
7147 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7148 if (!mboxq) {
7149 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7150 "2519 Unable to allocate memory for issuing "
7151 "NOP mailbox command\n");
7152 return 0;
7153 }
7154
7155 /* Set up NOP SLI4_CONFIG mailbox-ioctl command */
7156 length = (sizeof(struct lpfc_mbx_nop) -
7157 sizeof(struct lpfc_sli4_cfg_mhdr));
7158 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
7159 LPFC_MBOX_OPCODE_NOP, length, LPFC_SLI4_MBX_EMBED);
7160
7161 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
7162 for (cmdsent = 0; cmdsent < cnt; cmdsent++) {
7163 if (!phba->sli4_hba.intr_enable)
7164 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7165 else
7166 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
7167 if (rc == MBX_TIMEOUT)
7168 break;
7169 /* Check return status */
7170 shdr = (union lpfc_sli4_cfg_shdr *)
7171 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
7172 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7173 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
7174 &shdr->response);
7175 if (shdr_status || shdr_add_status || rc) {
7176 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7177 "2520 NOP mailbox command failed "
7178 "status x%x add_status x%x mbx "
7179 "status x%x\n", shdr_status,
7180 shdr_add_status, rc);
7181 break;
7182 }
7183 }
7184
7185 if (rc != MBX_TIMEOUT)
7186 mempool_free(mboxq, phba->mbox_mem_pool);
7187
7188 return cmdsent;
7189}
7190
7191/**
James Smartda0436e2009-05-22 14:51:39 -04007192 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
7193 * @phba: pointer to lpfc hba data structure.
7194 *
7195 * This routine is invoked to set up the PCI device memory space for device
7196 * with SLI-4 interface spec.
7197 *
7198 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007199 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04007200 * other values - error
7201 **/
7202static int
7203lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
7204{
7205 struct pci_dev *pdev;
7206 unsigned long bar0map_len, bar1map_len, bar2map_len;
7207 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05007208 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04007209
7210 /* Obtain PCI device reference */
7211 if (!phba->pcidev)
7212 return error;
7213 else
7214 pdev = phba->pcidev;
7215
7216 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05007217 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
7218 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
7219 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
7220 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smartda0436e2009-05-22 14:51:39 -04007221 return error;
Michael Reed8e685972009-09-18 12:02:05 -05007222 }
7223 }
James Smartda0436e2009-05-22 14:51:39 -04007224
James Smart2fcee4b2010-12-15 17:57:46 -05007225 /*
7226 * The BARs and register set definitions and offset locations are
7227 * dependent on the if_type.
7228 */
7229 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
7230 &phba->sli4_hba.sli_intf.word0)) {
7231 return error;
7232 }
7233
7234 /* There is no SLI3 failback for SLI4 devices. */
7235 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
7236 LPFC_SLI_INTF_VALID) {
7237 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7238 "2894 SLI_INTF reg contents invalid "
7239 "sli_intf reg 0x%x\n",
7240 phba->sli4_hba.sli_intf.word0);
7241 return error;
7242 }
7243
7244 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7245 /*
7246 * Get the bus address of SLI4 device Bar regions and the
7247 * number of bytes required by each mapping. The mapping of the
7248 * particular PCI BARs regions is dependent on the type of
7249 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04007250 */
James Smart1dfb5a42010-02-12 14:40:50 -05007251 if (pci_resource_start(pdev, 0)) {
7252 phba->pci_bar0_map = pci_resource_start(pdev, 0);
7253 bar0map_len = pci_resource_len(pdev, 0);
James Smart2fcee4b2010-12-15 17:57:46 -05007254
7255 /*
7256 * Map SLI4 PCI Config Space Register base to a kernel virtual
7257 * addr
7258 */
7259 phba->sli4_hba.conf_regs_memmap_p =
7260 ioremap(phba->pci_bar0_map, bar0map_len);
7261 if (!phba->sli4_hba.conf_regs_memmap_p) {
7262 dev_printk(KERN_ERR, &pdev->dev,
7263 "ioremap failed for SLI4 PCI config "
7264 "registers.\n");
7265 goto out;
7266 }
7267 /* Set up BAR0 PCI config space register memory map */
7268 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05007269 } else {
7270 phba->pci_bar0_map = pci_resource_start(pdev, 1);
7271 bar0map_len = pci_resource_len(pdev, 1);
James Smart2fcee4b2010-12-15 17:57:46 -05007272 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
7273 dev_printk(KERN_ERR, &pdev->dev,
7274 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
7275 goto out;
7276 }
7277 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04007278 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05007279 if (!phba->sli4_hba.conf_regs_memmap_p) {
7280 dev_printk(KERN_ERR, &pdev->dev,
7281 "ioremap failed for SLI4 PCI config "
7282 "registers.\n");
7283 goto out;
7284 }
7285 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04007286 }
7287
James Smartc31098c2011-04-16 11:03:33 -04007288 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
7289 (pci_resource_start(pdev, 2))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007290 /*
7291 * Map SLI4 if type 0 HBA Control Register base to a kernel
7292 * virtual address and setup the registers.
7293 */
7294 phba->pci_bar1_map = pci_resource_start(pdev, 2);
7295 bar1map_len = pci_resource_len(pdev, 2);
7296 phba->sli4_hba.ctrl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04007297 ioremap(phba->pci_bar1_map, bar1map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05007298 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
7299 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04007300 "ioremap failed for SLI4 HBA control registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05007301 goto out_iounmap_conf;
7302 }
7303 lpfc_sli4_bar1_register_memmap(phba);
James Smartda0436e2009-05-22 14:51:39 -04007304 }
7305
James Smartc31098c2011-04-16 11:03:33 -04007306 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
7307 (pci_resource_start(pdev, 4))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007308 /*
7309 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
7310 * virtual address and setup the registers.
7311 */
7312 phba->pci_bar2_map = pci_resource_start(pdev, 4);
7313 bar2map_len = pci_resource_len(pdev, 4);
7314 phba->sli4_hba.drbl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04007315 ioremap(phba->pci_bar2_map, bar2map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05007316 if (!phba->sli4_hba.drbl_regs_memmap_p) {
7317 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04007318 "ioremap failed for SLI4 HBA doorbell registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05007319 goto out_iounmap_ctrl;
7320 }
7321 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
7322 if (error)
7323 goto out_iounmap_all;
James Smartda0436e2009-05-22 14:51:39 -04007324 }
7325
James Smartda0436e2009-05-22 14:51:39 -04007326 return 0;
7327
7328out_iounmap_all:
7329 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
7330out_iounmap_ctrl:
7331 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
7332out_iounmap_conf:
7333 iounmap(phba->sli4_hba.conf_regs_memmap_p);
7334out:
7335 return error;
7336}
7337
7338/**
7339 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
7340 * @phba: pointer to lpfc hba data structure.
7341 *
7342 * This routine is invoked to unset the PCI device memory space for device
7343 * with SLI-4 interface spec.
7344 **/
7345static void
7346lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
7347{
7348 struct pci_dev *pdev;
7349
7350 /* Obtain PCI device reference */
7351 if (!phba->pcidev)
7352 return;
7353 else
7354 pdev = phba->pcidev;
7355
7356 /* Free coherent DMA memory allocated */
7357
7358 /* Unmap I/O memory space */
7359 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
7360 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
7361 iounmap(phba->sli4_hba.conf_regs_memmap_p);
7362
7363 return;
7364}
7365
7366/**
James Smart3772a992009-05-22 14:50:54 -04007367 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
7368 * @phba: pointer to lpfc hba data structure.
7369 *
7370 * This routine is invoked to enable the MSI-X interrupt vectors to device
7371 * with SLI-3 interface specs. The kernel function pci_enable_msix() is
7372 * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
7373 * invoked, enables either all or nothing, depending on the current
7374 * availability of PCI vector resources. The device driver is responsible
7375 * for calling the individual request_irq() to register each MSI-X vector
7376 * with a interrupt handler, which is done in this function. Note that
7377 * later when device is unloading, the driver should always call free_irq()
7378 * on all MSI-X vectors it has done request_irq() on before calling
7379 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
7380 * will be left with MSI-X enabled and leaks its vectors.
7381 *
7382 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007383 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007384 * other values - error
7385 **/
7386static int
7387lpfc_sli_enable_msix(struct lpfc_hba *phba)
7388{
7389 int rc, i;
7390 LPFC_MBOXQ_t *pmb;
7391
7392 /* Set up MSI-X multi-message vectors */
7393 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
7394 phba->msix_entries[i].entry = i;
7395
7396 /* Configure MSI-X capability structure */
7397 rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
7398 ARRAY_SIZE(phba->msix_entries));
7399 if (rc) {
7400 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7401 "0420 PCI enable MSI-X failed (%d)\n", rc);
7402 goto msi_fail_out;
7403 }
7404 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
7405 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7406 "0477 MSI-X entry[%d]: vector=x%x "
7407 "message=%d\n", i,
7408 phba->msix_entries[i].vector,
7409 phba->msix_entries[i].entry);
7410 /*
7411 * Assign MSI-X vectors to interrupt handlers
7412 */
7413
7414 /* vector-0 is associated to slow-path handler */
7415 rc = request_irq(phba->msix_entries[0].vector,
7416 &lpfc_sli_sp_intr_handler, IRQF_SHARED,
7417 LPFC_SP_DRIVER_HANDLER_NAME, phba);
7418 if (rc) {
7419 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7420 "0421 MSI-X slow-path request_irq failed "
7421 "(%d)\n", rc);
7422 goto msi_fail_out;
7423 }
7424
7425 /* vector-1 is associated to fast-path handler */
7426 rc = request_irq(phba->msix_entries[1].vector,
7427 &lpfc_sli_fp_intr_handler, IRQF_SHARED,
7428 LPFC_FP_DRIVER_HANDLER_NAME, phba);
7429
7430 if (rc) {
7431 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7432 "0429 MSI-X fast-path request_irq failed "
7433 "(%d)\n", rc);
7434 goto irq_fail_out;
7435 }
7436
7437 /*
7438 * Configure HBA MSI-X attention conditions to messages
7439 */
7440 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7441
7442 if (!pmb) {
7443 rc = -ENOMEM;
7444 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7445 "0474 Unable to allocate memory for issuing "
7446 "MBOX_CONFIG_MSI command\n");
7447 goto mem_fail_out;
7448 }
7449 rc = lpfc_config_msi(phba, pmb);
7450 if (rc)
7451 goto mbx_fail_out;
7452 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
7453 if (rc != MBX_SUCCESS) {
7454 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
7455 "0351 Config MSI mailbox command failed, "
7456 "mbxCmd x%x, mbxStatus x%x\n",
7457 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
7458 goto mbx_fail_out;
7459 }
7460
7461 /* Free memory allocated for mailbox command */
7462 mempool_free(pmb, phba->mbox_mem_pool);
7463 return rc;
7464
7465mbx_fail_out:
7466 /* Free memory allocated for mailbox command */
7467 mempool_free(pmb, phba->mbox_mem_pool);
7468
7469mem_fail_out:
7470 /* free the irq already requested */
7471 free_irq(phba->msix_entries[1].vector, phba);
7472
7473irq_fail_out:
7474 /* free the irq already requested */
7475 free_irq(phba->msix_entries[0].vector, phba);
7476
7477msi_fail_out:
7478 /* Unconfigure MSI-X capability structure */
7479 pci_disable_msix(phba->pcidev);
7480 return rc;
7481}
7482
7483/**
7484 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
7485 * @phba: pointer to lpfc hba data structure.
7486 *
7487 * This routine is invoked to release the MSI-X vectors and then disable the
7488 * MSI-X interrupt mode to device with SLI-3 interface spec.
7489 **/
7490static void
7491lpfc_sli_disable_msix(struct lpfc_hba *phba)
7492{
7493 int i;
7494
7495 /* Free up MSI-X multi-message vectors */
7496 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
7497 free_irq(phba->msix_entries[i].vector, phba);
7498 /* Disable MSI-X */
7499 pci_disable_msix(phba->pcidev);
7500
7501 return;
7502}
7503
7504/**
7505 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
7506 * @phba: pointer to lpfc hba data structure.
7507 *
7508 * This routine is invoked to enable the MSI interrupt mode to device with
7509 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
7510 * enable the MSI vector. The device driver is responsible for calling the
7511 * request_irq() to register MSI vector with a interrupt the handler, which
7512 * is done in this function.
7513 *
7514 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007515 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007516 * other values - error
7517 */
7518static int
7519lpfc_sli_enable_msi(struct lpfc_hba *phba)
7520{
7521 int rc;
7522
7523 rc = pci_enable_msi(phba->pcidev);
7524 if (!rc)
7525 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7526 "0462 PCI enable MSI mode success.\n");
7527 else {
7528 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7529 "0471 PCI enable MSI mode failed (%d)\n", rc);
7530 return rc;
7531 }
7532
7533 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
7534 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
7535 if (rc) {
7536 pci_disable_msi(phba->pcidev);
7537 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7538 "0478 MSI request_irq failed (%d)\n", rc);
7539 }
7540 return rc;
7541}
7542
7543/**
7544 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
7545 * @phba: pointer to lpfc hba data structure.
7546 *
7547 * This routine is invoked to disable the MSI interrupt mode to device with
7548 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
7549 * done request_irq() on before calling pci_disable_msi(). Failure to do so
7550 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
7551 * its vector.
7552 */
7553static void
7554lpfc_sli_disable_msi(struct lpfc_hba *phba)
7555{
7556 free_irq(phba->pcidev->irq, phba);
7557 pci_disable_msi(phba->pcidev);
7558 return;
7559}
7560
7561/**
7562 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
7563 * @phba: pointer to lpfc hba data structure.
7564 *
7565 * This routine is invoked to enable device interrupt and associate driver's
7566 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
7567 * spec. Depends on the interrupt mode configured to the driver, the driver
7568 * will try to fallback from the configured interrupt mode to an interrupt
7569 * mode which is supported by the platform, kernel, and device in the order
7570 * of:
7571 * MSI-X -> MSI -> IRQ.
7572 *
7573 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007574 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007575 * other values - error
7576 **/
7577static uint32_t
7578lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
7579{
7580 uint32_t intr_mode = LPFC_INTR_ERROR;
7581 int retval;
7582
7583 if (cfg_mode == 2) {
7584 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
7585 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
7586 if (!retval) {
7587 /* Now, try to enable MSI-X interrupt mode */
7588 retval = lpfc_sli_enable_msix(phba);
7589 if (!retval) {
7590 /* Indicate initialization to MSI-X mode */
7591 phba->intr_type = MSIX;
7592 intr_mode = 2;
7593 }
7594 }
7595 }
7596
7597 /* Fallback to MSI if MSI-X initialization failed */
7598 if (cfg_mode >= 1 && phba->intr_type == NONE) {
7599 retval = lpfc_sli_enable_msi(phba);
7600 if (!retval) {
7601 /* Indicate initialization to MSI mode */
7602 phba->intr_type = MSI;
7603 intr_mode = 1;
7604 }
7605 }
7606
7607 /* Fallback to INTx if both MSI-X/MSI initalization failed */
7608 if (phba->intr_type == NONE) {
7609 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
7610 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
7611 if (!retval) {
7612 /* Indicate initialization to INTx mode */
7613 phba->intr_type = INTx;
7614 intr_mode = 0;
7615 }
7616 }
7617 return intr_mode;
7618}
7619
7620/**
7621 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
7622 * @phba: pointer to lpfc hba data structure.
7623 *
7624 * This routine is invoked to disable device interrupt and disassociate the
7625 * driver's interrupt handler(s) from interrupt vector(s) to device with
7626 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
7627 * release the interrupt vector(s) for the message signaled interrupt.
7628 **/
7629static void
7630lpfc_sli_disable_intr(struct lpfc_hba *phba)
7631{
7632 /* Disable the currently initialized interrupt mode */
7633 if (phba->intr_type == MSIX)
7634 lpfc_sli_disable_msix(phba);
7635 else if (phba->intr_type == MSI)
7636 lpfc_sli_disable_msi(phba);
7637 else if (phba->intr_type == INTx)
7638 free_irq(phba->pcidev->irq, phba);
7639
7640 /* Reset interrupt management states */
7641 phba->intr_type = NONE;
7642 phba->sli.slistat.sli_intr = 0;
7643
7644 return;
7645}
7646
7647/**
James Smartda0436e2009-05-22 14:51:39 -04007648 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
7649 * @phba: pointer to lpfc hba data structure.
7650 *
7651 * This routine is invoked to enable the MSI-X interrupt vectors to device
7652 * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
7653 * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
7654 * enables either all or nothing, depending on the current availability of
7655 * PCI vector resources. The device driver is responsible for calling the
7656 * individual request_irq() to register each MSI-X vector with a interrupt
7657 * handler, which is done in this function. Note that later when device is
7658 * unloading, the driver should always call free_irq() on all MSI-X vectors
7659 * it has done request_irq() on before calling pci_disable_msix(). Failure
7660 * to do so results in a BUG_ON() and a device will be left with MSI-X
7661 * enabled and leaks its vectors.
7662 *
7663 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007664 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04007665 * other values - error
7666 **/
7667static int
7668lpfc_sli4_enable_msix(struct lpfc_hba *phba)
7669{
James Smart75baf692010-06-08 18:31:21 -04007670 int vectors, rc, index;
James Smartda0436e2009-05-22 14:51:39 -04007671
7672 /* Set up MSI-X multi-message vectors */
7673 for (index = 0; index < phba->sli4_hba.cfg_eqn; index++)
7674 phba->sli4_hba.msix_entries[index].entry = index;
7675
7676 /* Configure MSI-X capability structure */
James Smart75baf692010-06-08 18:31:21 -04007677 vectors = phba->sli4_hba.cfg_eqn;
7678enable_msix_vectors:
James Smartda0436e2009-05-22 14:51:39 -04007679 rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries,
James Smart75baf692010-06-08 18:31:21 -04007680 vectors);
7681 if (rc > 1) {
7682 vectors = rc;
7683 goto enable_msix_vectors;
7684 } else if (rc) {
James Smartda0436e2009-05-22 14:51:39 -04007685 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7686 "0484 PCI enable MSI-X failed (%d)\n", rc);
7687 goto msi_fail_out;
7688 }
James Smart75baf692010-06-08 18:31:21 -04007689
James Smartda0436e2009-05-22 14:51:39 -04007690 /* Log MSI-X vector assignment */
James Smart75baf692010-06-08 18:31:21 -04007691 for (index = 0; index < vectors; index++)
James Smartda0436e2009-05-22 14:51:39 -04007692 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7693 "0489 MSI-X entry[%d]: vector=x%x "
7694 "message=%d\n", index,
7695 phba->sli4_hba.msix_entries[index].vector,
7696 phba->sli4_hba.msix_entries[index].entry);
7697 /*
7698 * Assign MSI-X vectors to interrupt handlers
7699 */
James Smart05580562011-05-24 11:40:48 -04007700 if (vectors > 1)
7701 rc = request_irq(phba->sli4_hba.msix_entries[0].vector,
7702 &lpfc_sli4_sp_intr_handler, IRQF_SHARED,
7703 LPFC_SP_DRIVER_HANDLER_NAME, phba);
7704 else
7705 /* All Interrupts need to be handled by one EQ */
7706 rc = request_irq(phba->sli4_hba.msix_entries[0].vector,
7707 &lpfc_sli4_intr_handler, IRQF_SHARED,
7708 LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -04007709 if (rc) {
7710 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7711 "0485 MSI-X slow-path request_irq failed "
7712 "(%d)\n", rc);
7713 goto msi_fail_out;
7714 }
7715
7716 /* The rest of the vector(s) are associated to fast-path handler(s) */
James Smart75baf692010-06-08 18:31:21 -04007717 for (index = 1; index < vectors; index++) {
James Smartda0436e2009-05-22 14:51:39 -04007718 phba->sli4_hba.fcp_eq_hdl[index - 1].idx = index - 1;
7719 phba->sli4_hba.fcp_eq_hdl[index - 1].phba = phba;
7720 rc = request_irq(phba->sli4_hba.msix_entries[index].vector,
7721 &lpfc_sli4_fp_intr_handler, IRQF_SHARED,
7722 LPFC_FP_DRIVER_HANDLER_NAME,
7723 &phba->sli4_hba.fcp_eq_hdl[index - 1]);
7724 if (rc) {
7725 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7726 "0486 MSI-X fast-path (%d) "
7727 "request_irq failed (%d)\n", index, rc);
7728 goto cfg_fail_out;
7729 }
7730 }
James Smart75baf692010-06-08 18:31:21 -04007731 phba->sli4_hba.msix_vec_nr = vectors;
James Smartda0436e2009-05-22 14:51:39 -04007732
7733 return rc;
7734
7735cfg_fail_out:
7736 /* free the irq already requested */
7737 for (--index; index >= 1; index--)
7738 free_irq(phba->sli4_hba.msix_entries[index - 1].vector,
7739 &phba->sli4_hba.fcp_eq_hdl[index - 1]);
7740
7741 /* free the irq already requested */
7742 free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
7743
7744msi_fail_out:
7745 /* Unconfigure MSI-X capability structure */
7746 pci_disable_msix(phba->pcidev);
7747 return rc;
7748}
7749
7750/**
7751 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
7752 * @phba: pointer to lpfc hba data structure.
7753 *
7754 * This routine is invoked to release the MSI-X vectors and then disable the
7755 * MSI-X interrupt mode to device with SLI-4 interface spec.
7756 **/
7757static void
7758lpfc_sli4_disable_msix(struct lpfc_hba *phba)
7759{
7760 int index;
7761
7762 /* Free up MSI-X multi-message vectors */
7763 free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
7764
James Smart75baf692010-06-08 18:31:21 -04007765 for (index = 1; index < phba->sli4_hba.msix_vec_nr; index++)
James Smartda0436e2009-05-22 14:51:39 -04007766 free_irq(phba->sli4_hba.msix_entries[index].vector,
7767 &phba->sli4_hba.fcp_eq_hdl[index - 1]);
James Smart75baf692010-06-08 18:31:21 -04007768
James Smartda0436e2009-05-22 14:51:39 -04007769 /* Disable MSI-X */
7770 pci_disable_msix(phba->pcidev);
7771
7772 return;
7773}
7774
7775/**
7776 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
7777 * @phba: pointer to lpfc hba data structure.
7778 *
7779 * This routine is invoked to enable the MSI interrupt mode to device with
7780 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
7781 * to enable the MSI vector. The device driver is responsible for calling
7782 * the request_irq() to register MSI vector with a interrupt the handler,
7783 * which is done in this function.
7784 *
7785 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007786 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04007787 * other values - error
7788 **/
7789static int
7790lpfc_sli4_enable_msi(struct lpfc_hba *phba)
7791{
7792 int rc, index;
7793
7794 rc = pci_enable_msi(phba->pcidev);
7795 if (!rc)
7796 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7797 "0487 PCI enable MSI mode success.\n");
7798 else {
7799 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7800 "0488 PCI enable MSI mode failed (%d)\n", rc);
7801 return rc;
7802 }
7803
7804 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
7805 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
7806 if (rc) {
7807 pci_disable_msi(phba->pcidev);
7808 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7809 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -04007810 return rc;
James Smartda0436e2009-05-22 14:51:39 -04007811 }
7812
7813 for (index = 0; index < phba->cfg_fcp_eq_count; index++) {
7814 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
7815 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
7816 }
7817
James Smart75baf692010-06-08 18:31:21 -04007818 return 0;
James Smartda0436e2009-05-22 14:51:39 -04007819}
7820
7821/**
7822 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
7823 * @phba: pointer to lpfc hba data structure.
7824 *
7825 * This routine is invoked to disable the MSI interrupt mode to device with
7826 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
7827 * done request_irq() on before calling pci_disable_msi(). Failure to do so
7828 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
7829 * its vector.
7830 **/
7831static void
7832lpfc_sli4_disable_msi(struct lpfc_hba *phba)
7833{
7834 free_irq(phba->pcidev->irq, phba);
7835 pci_disable_msi(phba->pcidev);
7836 return;
7837}
7838
7839/**
7840 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
7841 * @phba: pointer to lpfc hba data structure.
7842 *
7843 * This routine is invoked to enable device interrupt and associate driver's
7844 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
7845 * interface spec. Depends on the interrupt mode configured to the driver,
7846 * the driver will try to fallback from the configured interrupt mode to an
7847 * interrupt mode which is supported by the platform, kernel, and device in
7848 * the order of:
7849 * MSI-X -> MSI -> IRQ.
7850 *
7851 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007852 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04007853 * other values - error
7854 **/
7855static uint32_t
7856lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
7857{
7858 uint32_t intr_mode = LPFC_INTR_ERROR;
7859 int retval, index;
7860
7861 if (cfg_mode == 2) {
7862 /* Preparation before conf_msi mbox cmd */
7863 retval = 0;
7864 if (!retval) {
7865 /* Now, try to enable MSI-X interrupt mode */
7866 retval = lpfc_sli4_enable_msix(phba);
7867 if (!retval) {
7868 /* Indicate initialization to MSI-X mode */
7869 phba->intr_type = MSIX;
7870 intr_mode = 2;
7871 }
7872 }
7873 }
7874
7875 /* Fallback to MSI if MSI-X initialization failed */
7876 if (cfg_mode >= 1 && phba->intr_type == NONE) {
7877 retval = lpfc_sli4_enable_msi(phba);
7878 if (!retval) {
7879 /* Indicate initialization to MSI mode */
7880 phba->intr_type = MSI;
7881 intr_mode = 1;
7882 }
7883 }
7884
7885 /* Fallback to INTx if both MSI-X/MSI initalization failed */
7886 if (phba->intr_type == NONE) {
7887 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
7888 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
7889 if (!retval) {
7890 /* Indicate initialization to INTx mode */
7891 phba->intr_type = INTx;
7892 intr_mode = 0;
7893 for (index = 0; index < phba->cfg_fcp_eq_count;
7894 index++) {
7895 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
7896 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
7897 }
7898 }
7899 }
7900 return intr_mode;
7901}
7902
7903/**
7904 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
7905 * @phba: pointer to lpfc hba data structure.
7906 *
7907 * This routine is invoked to disable device interrupt and disassociate
7908 * the driver's interrupt handler(s) from interrupt vector(s) to device
7909 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
7910 * will release the interrupt vector(s) for the message signaled interrupt.
7911 **/
7912static void
7913lpfc_sli4_disable_intr(struct lpfc_hba *phba)
7914{
7915 /* Disable the currently initialized interrupt mode */
7916 if (phba->intr_type == MSIX)
7917 lpfc_sli4_disable_msix(phba);
7918 else if (phba->intr_type == MSI)
7919 lpfc_sli4_disable_msi(phba);
7920 else if (phba->intr_type == INTx)
7921 free_irq(phba->pcidev->irq, phba);
7922
7923 /* Reset interrupt management states */
7924 phba->intr_type = NONE;
7925 phba->sli.slistat.sli_intr = 0;
7926
7927 return;
7928}
7929
7930/**
James Smart3772a992009-05-22 14:50:54 -04007931 * lpfc_unset_hba - Unset SLI3 hba device initialization
7932 * @phba: pointer to lpfc hba data structure.
7933 *
7934 * This routine is invoked to unset the HBA device initialization steps to
7935 * a device with SLI-3 interface spec.
7936 **/
7937static void
7938lpfc_unset_hba(struct lpfc_hba *phba)
7939{
7940 struct lpfc_vport *vport = phba->pport;
7941 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7942
7943 spin_lock_irq(shost->host_lock);
7944 vport->load_flag |= FC_UNLOADING;
7945 spin_unlock_irq(shost->host_lock);
7946
7947 lpfc_stop_hba_timers(phba);
7948
7949 phba->pport->work_port_events = 0;
7950
7951 lpfc_sli_hba_down(phba);
7952
7953 lpfc_sli_brdrestart(phba);
7954
7955 lpfc_sli_disable_intr(phba);
7956
7957 return;
7958}
7959
7960/**
James Smartda0436e2009-05-22 14:51:39 -04007961 * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization.
7962 * @phba: pointer to lpfc hba data structure.
7963 *
7964 * This routine is invoked to unset the HBA device initialization steps to
7965 * a device with SLI-4 interface spec.
7966 **/
7967static void
7968lpfc_sli4_unset_hba(struct lpfc_hba *phba)
7969{
7970 struct lpfc_vport *vport = phba->pport;
7971 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7972
7973 spin_lock_irq(shost->host_lock);
7974 vport->load_flag |= FC_UNLOADING;
7975 spin_unlock_irq(shost->host_lock);
7976
7977 phba->pport->work_port_events = 0;
7978
James Smart3677a3a2010-09-29 11:19:14 -04007979 /* Stop the SLI4 device port */
7980 lpfc_stop_port(phba);
James Smartda0436e2009-05-22 14:51:39 -04007981
7982 lpfc_sli4_disable_intr(phba);
7983
James Smart3677a3a2010-09-29 11:19:14 -04007984 /* Reset SLI4 HBA FCoE function */
7985 lpfc_pci_function_reset(phba);
7986
James Smartda0436e2009-05-22 14:51:39 -04007987 return;
7988}
7989
7990/**
James Smart5af5eee2010-10-22 11:06:38 -04007991 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
7992 * @phba: Pointer to HBA context object.
7993 *
7994 * This function is called in the SLI4 code path to wait for completion
7995 * of device's XRIs exchange busy. It will check the XRI exchange busy
7996 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
7997 * that, it will check the XRI exchange busy on outstanding FCP and ELS
7998 * I/Os every 30 seconds, log error message, and wait forever. Only when
7999 * all XRI exchange busy complete, the driver unload shall proceed with
8000 * invoking the function reset ioctl mailbox command to the CNA and the
8001 * the rest of the driver unload resource release.
8002 **/
8003static void
8004lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
8005{
8006 int wait_time = 0;
8007 int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
8008 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
8009
8010 while (!fcp_xri_cmpl || !els_xri_cmpl) {
8011 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
8012 if (!fcp_xri_cmpl)
8013 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8014 "2877 FCP XRI exchange busy "
8015 "wait time: %d seconds.\n",
8016 wait_time/1000);
8017 if (!els_xri_cmpl)
8018 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8019 "2878 ELS XRI exchange busy "
8020 "wait time: %d seconds.\n",
8021 wait_time/1000);
8022 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
8023 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
8024 } else {
8025 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
8026 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
8027 }
8028 fcp_xri_cmpl =
8029 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
8030 els_xri_cmpl =
8031 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
8032 }
8033}
8034
8035/**
James Smartda0436e2009-05-22 14:51:39 -04008036 * lpfc_sli4_hba_unset - Unset the fcoe hba
8037 * @phba: Pointer to HBA context object.
8038 *
8039 * This function is called in the SLI4 code path to reset the HBA's FCoE
8040 * function. The caller is not required to hold any lock. This routine
8041 * issues PCI function reset mailbox command to reset the FCoE function.
8042 * At the end of the function, it calls lpfc_hba_down_post function to
8043 * free any pending commands.
8044 **/
8045static void
8046lpfc_sli4_hba_unset(struct lpfc_hba *phba)
8047{
8048 int wait_cnt = 0;
8049 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -04008050 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -04008051
8052 lpfc_stop_hba_timers(phba);
8053 phba->sli4_hba.intr_enable = 0;
8054
8055 /*
8056 * Gracefully wait out the potential current outstanding asynchronous
8057 * mailbox command.
8058 */
8059
8060 /* First, block any pending async mailbox command from posted */
8061 spin_lock_irq(&phba->hbalock);
8062 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
8063 spin_unlock_irq(&phba->hbalock);
8064 /* Now, trying to wait it out if we can */
8065 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
8066 msleep(10);
8067 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
8068 break;
8069 }
8070 /* Forcefully release the outstanding mailbox command if timed out */
8071 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
8072 spin_lock_irq(&phba->hbalock);
8073 mboxq = phba->sli.mbox_active;
8074 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
8075 __lpfc_mbox_cmpl_put(phba, mboxq);
8076 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8077 phba->sli.mbox_active = NULL;
8078 spin_unlock_irq(&phba->hbalock);
8079 }
8080
James Smart5af5eee2010-10-22 11:06:38 -04008081 /* Abort all iocbs associated with the hba */
8082 lpfc_sli_hba_iocb_abort(phba);
8083
8084 /* Wait for completion of device XRI exchange busy */
8085 lpfc_sli4_xri_exchange_busy_wait(phba);
8086
James Smartda0436e2009-05-22 14:51:39 -04008087 /* Disable PCI subsystem interrupt */
8088 lpfc_sli4_disable_intr(phba);
8089
James Smart912e3ac2011-05-24 11:42:11 -04008090 /* Disable SR-IOV if enabled */
8091 if (phba->cfg_sriov_nr_virtfn)
8092 pci_disable_sriov(pdev);
8093
James Smartda0436e2009-05-22 14:51:39 -04008094 /* Stop kthread signal shall trigger work_done one more time */
8095 kthread_stop(phba->worker_thread);
8096
James Smart3677a3a2010-09-29 11:19:14 -04008097 /* Reset SLI4 HBA FCoE function */
8098 lpfc_pci_function_reset(phba);
8099
James Smartda0436e2009-05-22 14:51:39 -04008100 /* Stop the SLI4 device port */
8101 phba->pport->work_port_events = 0;
8102}
8103
James Smart28baac72010-02-12 14:42:03 -05008104 /**
8105 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
8106 * @phba: Pointer to HBA context object.
8107 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
8108 *
8109 * This function is called in the SLI4 code path to read the port's
8110 * sli4 capabilities.
8111 *
8112 * This function may be be called from any context that can block-wait
8113 * for the completion. The expectation is that this routine is called
8114 * typically from probe_one or from the online routine.
8115 **/
8116int
8117lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
8118{
8119 int rc;
8120 struct lpfc_mqe *mqe;
8121 struct lpfc_pc_sli4_params *sli4_params;
8122 uint32_t mbox_tmo;
8123
8124 rc = 0;
8125 mqe = &mboxq->u.mqe;
8126
8127 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -05008128 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -05008129 if (!phba->sli4_hba.intr_enable)
8130 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8131 else {
8132 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_PORT_CAPABILITIES);
8133 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
8134 }
8135
8136 if (unlikely(rc))
8137 return 1;
8138
8139 sli4_params = &phba->sli4_hba.pc_sli4_params;
8140 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
8141 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
8142 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
8143 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
8144 &mqe->un.sli4_params);
8145 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
8146 &mqe->un.sli4_params);
8147 sli4_params->proto_types = mqe->un.sli4_params.word3;
8148 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
8149 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
8150 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
8151 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
8152 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
8153 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
8154 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
8155 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
8156 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
8157 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
8158 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
8159 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
8160 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
8161 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
8162 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
8163 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
8164 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
8165 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
8166 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
8167 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -04008168
8169 /* Make sure that sge_supp_len can be handled by the driver */
8170 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
8171 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
8172
James Smart28baac72010-02-12 14:42:03 -05008173 return rc;
8174}
8175
James Smartda0436e2009-05-22 14:51:39 -04008176/**
James Smartfedd3b72011-02-16 12:39:24 -05008177 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
8178 * @phba: Pointer to HBA context object.
8179 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
8180 *
8181 * This function is called in the SLI4 code path to read the port's
8182 * sli4 capabilities.
8183 *
8184 * This function may be be called from any context that can block-wait
8185 * for the completion. The expectation is that this routine is called
8186 * typically from probe_one or from the online routine.
8187 **/
8188int
8189lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
8190{
8191 int rc;
8192 struct lpfc_mqe *mqe = &mboxq->u.mqe;
8193 struct lpfc_pc_sli4_params *sli4_params;
8194 int length;
8195 struct lpfc_sli4_parameters *mbx_sli4_parameters;
8196
James Smart6d368e52011-05-24 11:44:12 -04008197 /*
8198 * By default, the driver assumes the SLI4 port requires RPI
8199 * header postings. The SLI4_PARAM response will correct this
8200 * assumption.
8201 */
8202 phba->sli4_hba.rpi_hdrs_in_use = 1;
8203
James Smartfedd3b72011-02-16 12:39:24 -05008204 /* Read the port's SLI4 Config Parameters */
8205 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
8206 sizeof(struct lpfc_sli4_cfg_mhdr));
8207 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8208 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
8209 length, LPFC_SLI4_MBX_EMBED);
8210 if (!phba->sli4_hba.intr_enable)
8211 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8212 else
8213 rc = lpfc_sli_issue_mbox_wait(phba, mboxq,
8214 lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG));
8215 if (unlikely(rc))
8216 return rc;
8217 sli4_params = &phba->sli4_hba.pc_sli4_params;
8218 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
8219 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
8220 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
8221 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
8222 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
8223 mbx_sli4_parameters);
8224 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
8225 mbx_sli4_parameters);
8226 if (bf_get(cfg_phwq, mbx_sli4_parameters))
8227 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
8228 else
8229 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
8230 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
8231 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
8232 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
8233 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
8234 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
8235 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
8236 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
8237 mbx_sli4_parameters);
8238 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
8239 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -04008240 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
8241 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart05580562011-05-24 11:40:48 -04008242
8243 /* Make sure that sge_supp_len can be handled by the driver */
8244 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
8245 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
8246
James Smartfedd3b72011-02-16 12:39:24 -05008247 return 0;
8248}
8249
8250/**
James Smart3772a992009-05-22 14:50:54 -04008251 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
8252 * @pdev: pointer to PCI device
8253 * @pid: pointer to PCI device identifier
8254 *
8255 * This routine is to be called to attach a device with SLI-3 interface spec
8256 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
8257 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
8258 * information of the device and driver to see if the driver state that it can
8259 * support this kind of device. If the match is successful, the driver core
8260 * invokes this routine. If this routine determines it can claim the HBA, it
8261 * does all the initialization that it needs to do to handle the HBA properly.
8262 *
8263 * Return code
8264 * 0 - driver can claim the device
8265 * negative value - driver can not claim the device
8266 **/
8267static int __devinit
8268lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
8269{
8270 struct lpfc_hba *phba;
8271 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -04008272 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -04008273 int error;
8274 uint32_t cfg_mode, intr_mode;
8275
8276 /* Allocate memory for HBA structure */
8277 phba = lpfc_hba_alloc(pdev);
8278 if (!phba)
8279 return -ENOMEM;
8280
8281 /* Perform generic PCI device enabling operation */
8282 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -04008283 if (error)
James Smart3772a992009-05-22 14:50:54 -04008284 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -04008285
8286 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
8287 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
8288 if (error)
8289 goto out_disable_pci_dev;
8290
8291 /* Set up SLI-3 specific device PCI memory space */
8292 error = lpfc_sli_pci_mem_setup(phba);
8293 if (error) {
8294 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8295 "1402 Failed to set up pci memory space.\n");
8296 goto out_disable_pci_dev;
8297 }
8298
8299 /* Set up phase-1 common device driver resources */
8300 error = lpfc_setup_driver_resource_phase1(phba);
8301 if (error) {
8302 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8303 "1403 Failed to set up driver resource.\n");
8304 goto out_unset_pci_mem_s3;
8305 }
8306
8307 /* Set up SLI-3 specific device driver resources */
8308 error = lpfc_sli_driver_resource_setup(phba);
8309 if (error) {
8310 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8311 "1404 Failed to set up driver resource.\n");
8312 goto out_unset_pci_mem_s3;
8313 }
8314
8315 /* Initialize and populate the iocb list per host */
8316 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
8317 if (error) {
8318 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8319 "1405 Failed to initialize iocb list.\n");
8320 goto out_unset_driver_resource_s3;
8321 }
8322
8323 /* Set up common device driver resources */
8324 error = lpfc_setup_driver_resource_phase2(phba);
8325 if (error) {
8326 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8327 "1406 Failed to set up driver resource.\n");
8328 goto out_free_iocb_list;
8329 }
8330
James Smart079b5c92011-08-21 21:48:49 -04008331 /* Get the default values for Model Name and Description */
8332 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
8333
James Smart3772a992009-05-22 14:50:54 -04008334 /* Create SCSI host to the physical port */
8335 error = lpfc_create_shost(phba);
8336 if (error) {
8337 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8338 "1407 Failed to create scsi host.\n");
8339 goto out_unset_driver_resource;
8340 }
8341
8342 /* Configure sysfs attributes */
8343 vport = phba->pport;
8344 error = lpfc_alloc_sysfs_attr(vport);
8345 if (error) {
8346 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8347 "1476 Failed to allocate sysfs attr\n");
8348 goto out_destroy_shost;
8349 }
8350
James Smart6669f9b2009-10-02 15:16:45 -04008351 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -04008352 /* Now, trying to enable interrupt and bring up the device */
8353 cfg_mode = phba->cfg_use_msi;
8354 while (true) {
8355 /* Put device to a known state before enabling interrupt */
8356 lpfc_stop_port(phba);
8357 /* Configure and enable interrupt */
8358 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
8359 if (intr_mode == LPFC_INTR_ERROR) {
8360 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8361 "0431 Failed to enable interrupt.\n");
8362 error = -ENODEV;
8363 goto out_free_sysfs_attr;
8364 }
8365 /* SLI-3 HBA setup */
8366 if (lpfc_sli_hba_setup(phba)) {
8367 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8368 "1477 Failed to set up hba\n");
8369 error = -ENODEV;
8370 goto out_remove_device;
8371 }
8372
8373 /* Wait 50ms for the interrupts of previous mailbox commands */
8374 msleep(50);
8375 /* Check active interrupts on message signaled interrupts */
8376 if (intr_mode == 0 ||
8377 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
8378 /* Log the current active interrupt mode */
8379 phba->intr_mode = intr_mode;
8380 lpfc_log_intr_mode(phba, intr_mode);
8381 break;
8382 } else {
8383 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8384 "0447 Configure interrupt mode (%d) "
8385 "failed active interrupt test.\n",
8386 intr_mode);
8387 /* Disable the current interrupt mode */
8388 lpfc_sli_disable_intr(phba);
8389 /* Try next level of interrupt mode */
8390 cfg_mode = --intr_mode;
8391 }
8392 }
8393
8394 /* Perform post initialization setup */
8395 lpfc_post_init_setup(phba);
8396
8397 /* Check if there are static vports to be created. */
8398 lpfc_create_static_vport(phba);
8399
8400 return 0;
8401
8402out_remove_device:
8403 lpfc_unset_hba(phba);
8404out_free_sysfs_attr:
8405 lpfc_free_sysfs_attr(vport);
8406out_destroy_shost:
8407 lpfc_destroy_shost(phba);
8408out_unset_driver_resource:
8409 lpfc_unset_driver_resource_phase2(phba);
8410out_free_iocb_list:
8411 lpfc_free_iocb_list(phba);
8412out_unset_driver_resource_s3:
8413 lpfc_sli_driver_resource_unset(phba);
8414out_unset_pci_mem_s3:
8415 lpfc_sli_pci_mem_unset(phba);
8416out_disable_pci_dev:
8417 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -04008418 if (shost)
8419 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -04008420out_free_phba:
8421 lpfc_hba_free(phba);
8422 return error;
8423}
8424
8425/**
8426 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -04008427 * @pdev: pointer to PCI device
8428 *
James Smart3772a992009-05-22 14:50:54 -04008429 * This routine is to be called to disattach a device with SLI-3 interface
8430 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
8431 * removed from PCI bus, it performs all the necessary cleanup for the HBA
8432 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -04008433 **/
dea31012005-04-17 16:05:31 -05008434static void __devexit
James Smart3772a992009-05-22 14:50:54 -04008435lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -05008436{
James Smart2e0fef82007-06-17 19:56:36 -05008437 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8438 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -05008439 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -05008440 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -05008441 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05008442 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
8443
James Smart549e55c2007-08-02 11:09:51 -04008444 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04008445 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04008446 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05008447
James Smart858c9f62007-06-17 19:56:39 -05008448 lpfc_free_sysfs_attr(vport);
8449
James Smarteada2722008-12-04 22:39:13 -05008450 /* Release all the vports against this physical port */
8451 vports = lpfc_create_vport_work_array(phba);
8452 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -04008453 for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
James Smarteada2722008-12-04 22:39:13 -05008454 fc_vport_terminate(vports[i]->fc_vport);
8455 lpfc_destroy_vport_work_array(phba, vports);
8456
8457 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -05008458 fc_remove_host(shost);
8459 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04008460 lpfc_cleanup(vport);
8461
James Smart2e0fef82007-06-17 19:56:36 -05008462 /*
8463 * Bring down the SLI Layer. This step disable all interrupts,
8464 * clears the rings, discards all mailbox commands, and resets
8465 * the HBA.
8466 */
James Smarta257bf92009-04-06 18:48:10 -04008467
Justin P. Mattock48e34d02010-12-30 15:07:58 -08008468 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -05008469 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -04008470 /* Stop kthread signal shall trigger work_done one more time */
8471 kthread_stop(phba->worker_thread);
8472 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -05008473 lpfc_sli_brdrestart(phba);
8474
James Smart3772a992009-05-22 14:50:54 -04008475 lpfc_stop_hba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05008476 spin_lock_irq(&phba->hbalock);
8477 list_del_init(&vport->listentry);
8478 spin_unlock_irq(&phba->hbalock);
8479
James Smart858c9f62007-06-17 19:56:39 -05008480 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05008481
James Smart912e3ac2011-05-24 11:42:11 -04008482 /* Disable SR-IOV if enabled */
8483 if (phba->cfg_sriov_nr_virtfn)
8484 pci_disable_sriov(pdev);
8485
James Smart5b75da22008-12-04 22:39:35 -05008486 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -04008487 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -05008488
8489 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05008490 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05008491
8492 /*
8493 * Call scsi_free before mem_free since scsi bufs are released to their
8494 * corresponding pools here.
8495 */
8496 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -04008497 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -05008498
James Smart34b02dc2008-08-24 21:49:55 -04008499 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
8500 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -05008501
James Smart2e0fef82007-06-17 19:56:36 -05008502 /* Free resources associated with SLI2 interface */
8503 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -04008504 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -05008505
8506 /* unmap adapter SLIM and Control Registers */
8507 iounmap(phba->ctrl_regs_memmap_p);
8508 iounmap(phba->slim_memmap_p);
8509
James Smart3772a992009-05-22 14:50:54 -04008510 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -05008511
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05008512 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05008513 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05008514}
8515
Linas Vepstas8d63f372007-02-14 14:28:36 -06008516/**
James Smart3772a992009-05-22 14:50:54 -04008517 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05008518 * @pdev: pointer to PCI device
8519 * @msg: power management message
8520 *
James Smart3772a992009-05-22 14:50:54 -04008521 * This routine is to be called from the kernel's PCI subsystem to support
8522 * system Power Management (PM) to device with SLI-3 interface spec. When
8523 * PM invokes this method, it quiesces the device by stopping the driver's
8524 * worker thread for the device, turning off device's interrupt and DMA,
8525 * and bring the device offline. Note that as the driver implements the
8526 * minimum PM requirements to a power-aware driver's PM support for the
8527 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
8528 * to the suspend() method call will be treated as SUSPEND and the driver will
8529 * fully reinitialize its device during resume() method call, the driver will
8530 * set device to PCI_D3hot state in PCI config space instead of setting it
8531 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -05008532 *
8533 * Return code
James Smart3772a992009-05-22 14:50:54 -04008534 * 0 - driver suspended the device
8535 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05008536 **/
8537static int
James Smart3772a992009-05-22 14:50:54 -04008538lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -05008539{
8540 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8541 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
8542
8543 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8544 "0473 PCI device Power Management suspend.\n");
8545
8546 /* Bring down the device */
8547 lpfc_offline_prep(phba);
8548 lpfc_offline(phba);
8549 kthread_stop(phba->worker_thread);
8550
8551 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -04008552 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -05008553
8554 /* Save device state to PCI config space */
8555 pci_save_state(pdev);
8556 pci_set_power_state(pdev, PCI_D3hot);
8557
8558 return 0;
8559}
8560
8561/**
James Smart3772a992009-05-22 14:50:54 -04008562 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05008563 * @pdev: pointer to PCI device
8564 *
James Smart3772a992009-05-22 14:50:54 -04008565 * This routine is to be called from the kernel's PCI subsystem to support
8566 * system Power Management (PM) to device with SLI-3 interface spec. When PM
8567 * invokes this method, it restores the device's PCI config space state and
8568 * fully reinitializes the device and brings it online. Note that as the
8569 * driver implements the minimum PM requirements to a power-aware driver's
8570 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
8571 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
8572 * driver will fully reinitialize its device during resume() method call,
8573 * the device will be set to PCI_D0 directly in PCI config space before
8574 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -05008575 *
8576 * Return code
James Smart3772a992009-05-22 14:50:54 -04008577 * 0 - driver suspended the device
8578 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05008579 **/
8580static int
James Smart3772a992009-05-22 14:50:54 -04008581lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -05008582{
8583 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8584 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -05008585 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05008586 int error;
8587
8588 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8589 "0452 PCI device Power Management resume.\n");
8590
8591 /* Restore device state from PCI config space */
8592 pci_set_power_state(pdev, PCI_D0);
8593 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -04008594
James Smart1dfb5a42010-02-12 14:40:50 -05008595 /*
8596 * As the new kernel behavior of pci_restore_state() API call clears
8597 * device saved_state flag, need to save the restored state again.
8598 */
8599 pci_save_state(pdev);
8600
James Smart3a55b532008-12-04 22:38:54 -05008601 if (pdev->is_busmaster)
8602 pci_set_master(pdev);
8603
8604 /* Startup the kernel thread for this host adapter. */
8605 phba->worker_thread = kthread_run(lpfc_do_work, phba,
8606 "lpfc_worker_%d", phba->brd_no);
8607 if (IS_ERR(phba->worker_thread)) {
8608 error = PTR_ERR(phba->worker_thread);
8609 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8610 "0434 PM resume failed to start worker "
8611 "thread: error=x%x.\n", error);
8612 return error;
8613 }
8614
James Smart5b75da22008-12-04 22:39:35 -05008615 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04008616 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05008617 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -05008618 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -05008619 "0430 PM resume Failed to enable interrupt\n");
8620 return -EIO;
8621 } else
8622 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05008623
8624 /* Restart HBA and bring it online */
8625 lpfc_sli_brdrestart(phba);
8626 lpfc_online(phba);
8627
James Smart5b75da22008-12-04 22:39:35 -05008628 /* Log the current active interrupt mode */
8629 lpfc_log_intr_mode(phba, phba->intr_mode);
8630
James Smart3a55b532008-12-04 22:38:54 -05008631 return 0;
8632}
8633
8634/**
James Smart891478a2009-11-18 15:40:23 -05008635 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
8636 * @phba: pointer to lpfc hba data structure.
8637 *
8638 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -04008639 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -05008640 **/
8641static void
8642lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
8643{
James Smarte2af0d22010-03-15 11:25:32 -04008644 struct lpfc_sli *psli = &phba->sli;
8645 struct lpfc_sli_ring *pring;
8646
James Smart891478a2009-11-18 15:40:23 -05008647 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8648 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -04008649
8650 /*
8651 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
8652 * and let the SCSI mid-layer to retry them to recover.
8653 */
8654 pring = &psli->ring[psli->fcp_ring];
8655 lpfc_sli_abort_iocb_ring(phba, pring);
James Smart891478a2009-11-18 15:40:23 -05008656}
8657
8658/**
James Smart0d878412009-10-02 15:16:56 -04008659 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
8660 * @phba: pointer to lpfc hba data structure.
8661 *
8662 * This routine is called to prepare the SLI3 device for PCI slot reset. It
8663 * disables the device interrupt and pci device, and aborts the internal FCP
8664 * pending I/Os.
8665 **/
8666static void
8667lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
8668{
James Smart0d878412009-10-02 15:16:56 -04008669 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -05008670 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -04008671
James Smart75baf692010-06-08 18:31:21 -04008672 /* Block any management I/Os to the device */
8673 lpfc_block_mgmt_io(phba);
8674
James Smarte2af0d22010-03-15 11:25:32 -04008675 /* Block all SCSI devices' I/Os on the host */
8676 lpfc_scsi_dev_block(phba);
8677
8678 /* stop all timers */
8679 lpfc_stop_hba_timers(phba);
8680
James Smart0d878412009-10-02 15:16:56 -04008681 /* Disable interrupt and pci device */
8682 lpfc_sli_disable_intr(phba);
8683 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -04008684
James Smarte2af0d22010-03-15 11:25:32 -04008685 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
8686 lpfc_sli_flush_fcp_rings(phba);
James Smart0d878412009-10-02 15:16:56 -04008687}
8688
8689/**
8690 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
8691 * @phba: pointer to lpfc hba data structure.
8692 *
8693 * This routine is called to prepare the SLI3 device for PCI slot permanently
8694 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
8695 * pending I/Os.
8696 **/
8697static void
James Smart75baf692010-06-08 18:31:21 -04008698lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -04008699{
8700 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -05008701 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -04008702 /* Block all SCSI devices' I/Os on the host */
8703 lpfc_scsi_dev_block(phba);
8704
8705 /* stop all timers */
8706 lpfc_stop_hba_timers(phba);
8707
James Smart0d878412009-10-02 15:16:56 -04008708 /* Clean up all driver's outstanding SCSI I/Os */
8709 lpfc_sli_flush_fcp_rings(phba);
8710}
8711
8712/**
James Smart3772a992009-05-22 14:50:54 -04008713 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -04008714 * @pdev: pointer to PCI device.
8715 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -06008716 *
James Smart3772a992009-05-22 14:50:54 -04008717 * This routine is called from the PCI subsystem for I/O error handling to
8718 * device with SLI-3 interface spec. This function is called by the PCI
8719 * subsystem after a PCI bus error affecting this device has been detected.
8720 * When this function is invoked, it will need to stop all the I/Os and
8721 * interrupt(s) to the device. Once that is done, it will return
8722 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
8723 * as desired.
James Smarte59058c2008-08-24 21:49:00 -04008724 *
8725 * Return codes
James Smart0d878412009-10-02 15:16:56 -04008726 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -04008727 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
8728 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -04008729 **/
James Smart3772a992009-05-22 14:50:54 -04008730static pci_ers_result_t
8731lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -06008732{
James Smart51ef4c22007-08-02 11:10:31 -04008733 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8734 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06008735
James Smart0d878412009-10-02 15:16:56 -04008736 switch (state) {
8737 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -05008738 /* Non-fatal error, prepare for recovery */
8739 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -04008740 return PCI_ERS_RESULT_CAN_RECOVER;
8741 case pci_channel_io_frozen:
8742 /* Fatal error, prepare for slot reset */
8743 lpfc_sli_prep_dev_for_reset(phba);
8744 return PCI_ERS_RESULT_NEED_RESET;
8745 case pci_channel_io_perm_failure:
8746 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -04008747 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06008748 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -04008749 default:
8750 /* Unknown state, prepare and request slot reset */
8751 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8752 "0472 Unknown PCI error state: x%x\n", state);
8753 lpfc_sli_prep_dev_for_reset(phba);
8754 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -04008755 }
Linas Vepstas8d63f372007-02-14 14:28:36 -06008756}
8757
8758/**
James Smart3772a992009-05-22 14:50:54 -04008759 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -04008760 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -06008761 *
James Smart3772a992009-05-22 14:50:54 -04008762 * This routine is called from the PCI subsystem for error handling to
8763 * device with SLI-3 interface spec. This is called after PCI bus has been
8764 * reset to restart the PCI card from scratch, as if from a cold-boot.
8765 * During the PCI subsystem error recovery, after driver returns
8766 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
8767 * recovery and then call this routine before calling the .resume method
8768 * to recover the device. This function will initialize the HBA device,
8769 * enable the interrupt, but it will just put the HBA to offline state
8770 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -04008771 *
8772 * Return codes
James Smart3772a992009-05-22 14:50:54 -04008773 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
8774 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -06008775 */
James Smart3772a992009-05-22 14:50:54 -04008776static pci_ers_result_t
8777lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -06008778{
James Smart51ef4c22007-08-02 11:10:31 -04008779 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8780 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06008781 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -05008782 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06008783
8784 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11008785 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -06008786 printk(KERN_ERR "lpfc: Cannot re-enable "
8787 "PCI device after reset.\n");
8788 return PCI_ERS_RESULT_DISCONNECT;
8789 }
8790
James Smart97207482008-12-04 22:39:19 -05008791 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -05008792
8793 /*
8794 * As the new kernel behavior of pci_restore_state() API call clears
8795 * device saved_state flag, need to save the restored state again.
8796 */
8797 pci_save_state(pdev);
8798
James Smart97207482008-12-04 22:39:19 -05008799 if (pdev->is_busmaster)
8800 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -06008801
James Smart92d7f7b2007-06-17 19:56:38 -05008802 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -04008803 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05008804 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06008805
James Smart5b75da22008-12-04 22:39:35 -05008806 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04008807 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05008808 if (intr_mode == LPFC_INTR_ERROR) {
8809 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8810 "0427 Cannot re-enable interrupt after "
8811 "slot reset.\n");
8812 return PCI_ERS_RESULT_DISCONNECT;
8813 } else
8814 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06008815
James Smart75baf692010-06-08 18:31:21 -04008816 /* Take device offline, it will perform cleanup */
8817 lpfc_offline_prep(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06008818 lpfc_offline(phba);
8819 lpfc_sli_brdrestart(phba);
8820
James Smart5b75da22008-12-04 22:39:35 -05008821 /* Log the current active interrupt mode */
8822 lpfc_log_intr_mode(phba, phba->intr_mode);
8823
Linas Vepstas8d63f372007-02-14 14:28:36 -06008824 return PCI_ERS_RESULT_RECOVERED;
8825}
8826
8827/**
James Smart3772a992009-05-22 14:50:54 -04008828 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -04008829 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -06008830 *
James Smart3772a992009-05-22 14:50:54 -04008831 * This routine is called from the PCI subsystem for error handling to device
8832 * with SLI-3 interface spec. It is called when kernel error recovery tells
8833 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
8834 * error recovery. After this call, traffic can start to flow from this device
8835 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -06008836 */
James Smart3772a992009-05-22 14:50:54 -04008837static void
8838lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -06008839{
James Smart51ef4c22007-08-02 11:10:31 -04008840 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8841 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06008842
James Smarte2af0d22010-03-15 11:25:32 -04008843 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -04008844 lpfc_online(phba);
James Smart0d878412009-10-02 15:16:56 -04008845
8846 /* Clean up Advanced Error Reporting (AER) if needed */
8847 if (phba->hba_flag & HBA_AER_ENABLED)
8848 pci_cleanup_aer_uncorrect_error_status(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -06008849}
8850
James Smart3772a992009-05-22 14:50:54 -04008851/**
James Smartda0436e2009-05-22 14:51:39 -04008852 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
8853 * @phba: pointer to lpfc hba data structure.
8854 *
8855 * returns the number of ELS/CT IOCBs to reserve
8856 **/
8857int
8858lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
8859{
8860 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
8861
James Smartf1126682009-06-10 17:22:44 -04008862 if (phba->sli_rev == LPFC_SLI_REV4) {
8863 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -04008864 return 10;
James Smartf1126682009-06-10 17:22:44 -04008865 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -04008866 return 25;
James Smartf1126682009-06-10 17:22:44 -04008867 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -04008868 return 50;
James Smartf1126682009-06-10 17:22:44 -04008869 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -04008870 return 100;
James Smartf1126682009-06-10 17:22:44 -04008871 else
James Smart6a9c52c2009-10-02 15:16:51 -04008872 return 150;
James Smartf1126682009-06-10 17:22:44 -04008873 } else
8874 return 0;
James Smartda0436e2009-05-22 14:51:39 -04008875}
8876
8877/**
James Smart52d52442011-05-24 11:42:45 -04008878 * lpfc_write_firmware - attempt to write a firmware image to the port
8879 * @phba: pointer to lpfc hba data structure.
8880 * @fw: pointer to firmware image returned from request_firmware.
8881 *
8882 * returns the number of bytes written if write is successful.
8883 * returns a negative error value if there were errors.
8884 * returns 0 if firmware matches currently active firmware on port.
8885 **/
8886int
8887lpfc_write_firmware(struct lpfc_hba *phba, const struct firmware *fw)
8888{
8889 char fwrev[32];
8890 struct lpfc_grp_hdr *image = (struct lpfc_grp_hdr *)fw->data;
8891 struct list_head dma_buffer_list;
8892 int i, rc = 0;
8893 struct lpfc_dmabuf *dmabuf, *next;
8894 uint32_t offset = 0, temp_offset = 0;
8895
8896 INIT_LIST_HEAD(&dma_buffer_list);
James Smart079b5c92011-08-21 21:48:49 -04008897 if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) ||
8898 (bf_get_be32(lpfc_grp_hdr_file_type, image) !=
8899 LPFC_FILE_TYPE_GROUP) ||
8900 (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) ||
8901 (be32_to_cpu(image->size) != fw->size)) {
James Smart52d52442011-05-24 11:42:45 -04008902 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8903 "3022 Invalid FW image found. "
James Smart079b5c92011-08-21 21:48:49 -04008904 "Magic:%x Type:%x ID:%x\n",
8905 be32_to_cpu(image->magic_number),
8906 bf_get_be32(lpfc_grp_hdr_file_type, image),
8907 bf_get_be32(lpfc_grp_hdr_id, image));
James Smart52d52442011-05-24 11:42:45 -04008908 return -EINVAL;
8909 }
8910 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -04008911 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -04008912 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8913 "3023 Updating Firmware. Current Version:%s "
8914 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -04008915 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -04008916 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
8917 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
8918 GFP_KERNEL);
8919 if (!dmabuf) {
8920 rc = -ENOMEM;
8921 goto out;
8922 }
8923 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
8924 SLI4_PAGE_SIZE,
8925 &dmabuf->phys,
8926 GFP_KERNEL);
8927 if (!dmabuf->virt) {
8928 kfree(dmabuf);
8929 rc = -ENOMEM;
8930 goto out;
8931 }
8932 list_add_tail(&dmabuf->list, &dma_buffer_list);
8933 }
8934 while (offset < fw->size) {
8935 temp_offset = offset;
8936 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -04008937 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -04008938 memcpy(dmabuf->virt,
8939 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -04008940 fw->size - temp_offset);
8941 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -04008942 break;
8943 }
James Smart52d52442011-05-24 11:42:45 -04008944 memcpy(dmabuf->virt, fw->data + temp_offset,
8945 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -04008946 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -04008947 }
8948 rc = lpfc_wr_object(phba, &dma_buffer_list,
8949 (fw->size - offset), &offset);
8950 if (rc) {
8951 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8952 "3024 Firmware update failed. "
8953 "%d\n", rc);
8954 goto out;
8955 }
8956 }
8957 rc = offset;
8958 }
8959out:
8960 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
8961 list_del(&dmabuf->list);
8962 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
8963 dmabuf->virt, dmabuf->phys);
8964 kfree(dmabuf);
8965 }
8966 return rc;
8967}
8968
8969/**
James Smartda0436e2009-05-22 14:51:39 -04008970 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
8971 * @pdev: pointer to PCI device
8972 * @pid: pointer to PCI device identifier
8973 *
8974 * This routine is called from the kernel's PCI subsystem to device with
8975 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
8976 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
8977 * information of the device and driver to see if the driver state that it
8978 * can support this kind of device. If the match is successful, the driver
8979 * core invokes this routine. If this routine determines it can claim the HBA,
8980 * it does all the initialization that it needs to do to handle the HBA
8981 * properly.
8982 *
8983 * Return code
8984 * 0 - driver can claim the device
8985 * negative value - driver can not claim the device
8986 **/
8987static int __devinit
8988lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
8989{
8990 struct lpfc_hba *phba;
8991 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -04008992 struct Scsi_Host *shost = NULL;
James Smartda0436e2009-05-22 14:51:39 -04008993 int error;
8994 uint32_t cfg_mode, intr_mode;
8995 int mcnt;
James Smart05580562011-05-24 11:40:48 -04008996 int adjusted_fcp_eq_count;
8997 int fcp_qidx;
James Smart52d52442011-05-24 11:42:45 -04008998 const struct firmware *fw;
8999 uint8_t file_name[16];
James Smartda0436e2009-05-22 14:51:39 -04009000
9001 /* Allocate memory for HBA structure */
9002 phba = lpfc_hba_alloc(pdev);
9003 if (!phba)
9004 return -ENOMEM;
9005
9006 /* Perform generic PCI device enabling operation */
9007 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -04009008 if (error)
James Smartda0436e2009-05-22 14:51:39 -04009009 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -04009010
9011 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
9012 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
9013 if (error)
9014 goto out_disable_pci_dev;
9015
9016 /* Set up SLI-4 specific device PCI memory space */
9017 error = lpfc_sli4_pci_mem_setup(phba);
9018 if (error) {
9019 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9020 "1410 Failed to set up pci memory space.\n");
9021 goto out_disable_pci_dev;
9022 }
9023
9024 /* Set up phase-1 common device driver resources */
9025 error = lpfc_setup_driver_resource_phase1(phba);
9026 if (error) {
9027 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9028 "1411 Failed to set up driver resource.\n");
9029 goto out_unset_pci_mem_s4;
9030 }
9031
9032 /* Set up SLI-4 Specific device driver resources */
9033 error = lpfc_sli4_driver_resource_setup(phba);
9034 if (error) {
9035 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9036 "1412 Failed to set up driver resource.\n");
9037 goto out_unset_pci_mem_s4;
9038 }
9039
9040 /* Initialize and populate the iocb list per host */
James Smart2a9bf3d2010-06-07 15:24:45 -04009041
9042 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9043 "2821 initialize iocb list %d.\n",
9044 phba->cfg_iocb_cnt*1024);
9045 error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
9046
James Smartda0436e2009-05-22 14:51:39 -04009047 if (error) {
9048 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9049 "1413 Failed to initialize iocb list.\n");
9050 goto out_unset_driver_resource_s4;
9051 }
9052
James Smart19ca7602010-11-20 23:11:55 -05009053 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -04009054 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -05009055
James Smartda0436e2009-05-22 14:51:39 -04009056 /* Set up common device driver resources */
9057 error = lpfc_setup_driver_resource_phase2(phba);
9058 if (error) {
9059 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9060 "1414 Failed to set up driver resource.\n");
9061 goto out_free_iocb_list;
9062 }
9063
James Smart079b5c92011-08-21 21:48:49 -04009064 /* Get the default values for Model Name and Description */
9065 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
9066
James Smartda0436e2009-05-22 14:51:39 -04009067 /* Create SCSI host to the physical port */
9068 error = lpfc_create_shost(phba);
9069 if (error) {
9070 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9071 "1415 Failed to create scsi host.\n");
9072 goto out_unset_driver_resource;
9073 }
9074
9075 /* Configure sysfs attributes */
9076 vport = phba->pport;
9077 error = lpfc_alloc_sysfs_attr(vport);
9078 if (error) {
9079 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9080 "1416 Failed to allocate sysfs attr\n");
9081 goto out_destroy_shost;
9082 }
9083
James Smart6669f9b2009-10-02 15:16:45 -04009084 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -04009085 /* Now, trying to enable interrupt and bring up the device */
9086 cfg_mode = phba->cfg_use_msi;
9087 while (true) {
9088 /* Put device to a known state before enabling interrupt */
9089 lpfc_stop_port(phba);
9090 /* Configure and enable interrupt */
9091 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
9092 if (intr_mode == LPFC_INTR_ERROR) {
9093 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9094 "0426 Failed to enable interrupt.\n");
9095 error = -ENODEV;
9096 goto out_free_sysfs_attr;
9097 }
James Smart05580562011-05-24 11:40:48 -04009098 /* Default to single EQ for non-MSI-X */
James Smartdef9c7a2009-12-21 17:02:28 -05009099 if (phba->intr_type != MSIX)
James Smart05580562011-05-24 11:40:48 -04009100 adjusted_fcp_eq_count = 0;
9101 else if (phba->sli4_hba.msix_vec_nr <
9102 phba->cfg_fcp_eq_count + 1)
9103 adjusted_fcp_eq_count = phba->sli4_hba.msix_vec_nr - 1;
9104 else
9105 adjusted_fcp_eq_count = phba->cfg_fcp_eq_count;
9106 /* Free unused EQs */
9107 for (fcp_qidx = adjusted_fcp_eq_count;
9108 fcp_qidx < phba->cfg_fcp_eq_count;
9109 fcp_qidx++) {
9110 lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]);
9111 /* do not delete the first fcp_cq */
9112 if (fcp_qidx)
9113 lpfc_sli4_queue_free(
9114 phba->sli4_hba.fcp_cq[fcp_qidx]);
9115 }
9116 phba->cfg_fcp_eq_count = adjusted_fcp_eq_count;
James Smartda0436e2009-05-22 14:51:39 -04009117 /* Set up SLI-4 HBA */
9118 if (lpfc_sli4_hba_setup(phba)) {
9119 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9120 "1421 Failed to set up hba\n");
9121 error = -ENODEV;
9122 goto out_disable_intr;
9123 }
9124
9125 /* Send NOP mbx cmds for non-INTx mode active interrupt test */
9126 if (intr_mode != 0)
9127 mcnt = lpfc_sli4_send_nop_mbox_cmds(phba,
9128 LPFC_ACT_INTR_CNT);
9129
9130 /* Check active interrupts received only for MSI/MSI-X */
9131 if (intr_mode == 0 ||
9132 phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) {
9133 /* Log the current active interrupt mode */
9134 phba->intr_mode = intr_mode;
9135 lpfc_log_intr_mode(phba, intr_mode);
9136 break;
9137 }
9138 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9139 "0451 Configure interrupt mode (%d) "
9140 "failed active interrupt test.\n",
9141 intr_mode);
James Smart2fcee4b2010-12-15 17:57:46 -05009142 /* Unset the previous SLI-4 HBA setup. */
9143 /*
9144 * TODO: Is this operation compatible with IF TYPE 2
9145 * devices? All port state is deleted and cleared.
9146 */
James Smartda0436e2009-05-22 14:51:39 -04009147 lpfc_sli4_unset_hba(phba);
9148 /* Try next level of interrupt mode */
9149 cfg_mode = --intr_mode;
9150 }
9151
9152 /* Perform post initialization setup */
9153 lpfc_post_init_setup(phba);
9154
James Smart52d52442011-05-24 11:42:45 -04009155 /* check for firmware upgrade or downgrade */
9156 snprintf(file_name, 16, "%s.grp", phba->ModelName);
9157 error = request_firmware(&fw, file_name, &phba->pcidev->dev);
9158 if (!error) {
9159 lpfc_write_firmware(phba, fw);
9160 release_firmware(fw);
9161 }
9162
James Smart1c6834a2009-07-19 10:01:26 -04009163 /* Check if there are static vports to be created. */
9164 lpfc_create_static_vport(phba);
James Smartda0436e2009-05-22 14:51:39 -04009165 return 0;
9166
9167out_disable_intr:
9168 lpfc_sli4_disable_intr(phba);
9169out_free_sysfs_attr:
9170 lpfc_free_sysfs_attr(vport);
9171out_destroy_shost:
9172 lpfc_destroy_shost(phba);
9173out_unset_driver_resource:
9174 lpfc_unset_driver_resource_phase2(phba);
9175out_free_iocb_list:
9176 lpfc_free_iocb_list(phba);
9177out_unset_driver_resource_s4:
9178 lpfc_sli4_driver_resource_unset(phba);
9179out_unset_pci_mem_s4:
9180 lpfc_sli4_pci_mem_unset(phba);
9181out_disable_pci_dev:
9182 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -04009183 if (shost)
9184 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -04009185out_free_phba:
9186 lpfc_hba_free(phba);
9187 return error;
9188}
9189
9190/**
9191 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
9192 * @pdev: pointer to PCI device
9193 *
9194 * This routine is called from the kernel's PCI subsystem to device with
9195 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
9196 * removed from PCI bus, it performs all the necessary cleanup for the HBA
9197 * device to be removed from the PCI subsystem properly.
9198 **/
9199static void __devexit
9200lpfc_pci_remove_one_s4(struct pci_dev *pdev)
9201{
9202 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9203 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
9204 struct lpfc_vport **vports;
9205 struct lpfc_hba *phba = vport->phba;
9206 int i;
9207
9208 /* Mark the device unloading flag */
9209 spin_lock_irq(&phba->hbalock);
9210 vport->load_flag |= FC_UNLOADING;
9211 spin_unlock_irq(&phba->hbalock);
9212
9213 /* Free the HBA sysfs attributes */
9214 lpfc_free_sysfs_attr(vport);
9215
9216 /* Release all the vports against this physical port */
9217 vports = lpfc_create_vport_work_array(phba);
9218 if (vports != NULL)
9219 for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
9220 fc_vport_terminate(vports[i]->fc_vport);
9221 lpfc_destroy_vport_work_array(phba, vports);
9222
9223 /* Remove FC host and then SCSI host with the physical port */
9224 fc_remove_host(shost);
9225 scsi_remove_host(shost);
9226
9227 /* Perform cleanup on the physical port */
9228 lpfc_cleanup(vport);
9229
9230 /*
9231 * Bring down the SLI Layer. This step disables all interrupts,
9232 * clears the rings, discards all mailbox commands, and resets
9233 * the HBA FCoE function.
9234 */
9235 lpfc_debugfs_terminate(vport);
9236 lpfc_sli4_hba_unset(phba);
9237
9238 spin_lock_irq(&phba->hbalock);
9239 list_del_init(&vport->listentry);
9240 spin_unlock_irq(&phba->hbalock);
9241
James Smart3677a3a2010-09-29 11:19:14 -04009242 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -04009243 * buffers are released to their corresponding pools here.
9244 */
9245 lpfc_scsi_free(phba);
9246 lpfc_sli4_driver_resource_unset(phba);
9247
9248 /* Unmap adapter Control and Doorbell registers */
9249 lpfc_sli4_pci_mem_unset(phba);
9250
9251 /* Release PCI resources and disable device's PCI function */
9252 scsi_host_put(shost);
9253 lpfc_disable_pci_dev(phba);
9254
9255 /* Finally, free the driver's device data structure */
9256 lpfc_hba_free(phba);
9257
9258 return;
9259}
9260
9261/**
9262 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
9263 * @pdev: pointer to PCI device
9264 * @msg: power management message
9265 *
9266 * This routine is called from the kernel's PCI subsystem to support system
9267 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
9268 * this method, it quiesces the device by stopping the driver's worker
9269 * thread for the device, turning off device's interrupt and DMA, and bring
9270 * the device offline. Note that as the driver implements the minimum PM
9271 * requirements to a power-aware driver's PM support for suspend/resume -- all
9272 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
9273 * method call will be treated as SUSPEND and the driver will fully
9274 * reinitialize its device during resume() method call, the driver will set
9275 * device to PCI_D3hot state in PCI config space instead of setting it
9276 * according to the @msg provided by the PM.
9277 *
9278 * Return code
9279 * 0 - driver suspended the device
9280 * Error otherwise
9281 **/
9282static int
9283lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
9284{
9285 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9286 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9287
9288 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -04009289 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -04009290
9291 /* Bring down the device */
9292 lpfc_offline_prep(phba);
9293 lpfc_offline(phba);
9294 kthread_stop(phba->worker_thread);
9295
9296 /* Disable interrupt from device */
9297 lpfc_sli4_disable_intr(phba);
9298
9299 /* Save device state to PCI config space */
9300 pci_save_state(pdev);
9301 pci_set_power_state(pdev, PCI_D3hot);
9302
9303 return 0;
9304}
9305
9306/**
9307 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
9308 * @pdev: pointer to PCI device
9309 *
9310 * This routine is called from the kernel's PCI subsystem to support system
9311 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
9312 * this method, it restores the device's PCI config space state and fully
9313 * reinitializes the device and brings it online. Note that as the driver
9314 * implements the minimum PM requirements to a power-aware driver's PM for
9315 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
9316 * to the suspend() method call will be treated as SUSPEND and the driver
9317 * will fully reinitialize its device during resume() method call, the device
9318 * will be set to PCI_D0 directly in PCI config space before restoring the
9319 * state.
9320 *
9321 * Return code
9322 * 0 - driver suspended the device
9323 * Error otherwise
9324 **/
9325static int
9326lpfc_pci_resume_one_s4(struct pci_dev *pdev)
9327{
9328 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9329 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9330 uint32_t intr_mode;
9331 int error;
9332
9333 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9334 "0292 PCI device Power Management resume.\n");
9335
9336 /* Restore device state from PCI config space */
9337 pci_set_power_state(pdev, PCI_D0);
9338 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -05009339
9340 /*
9341 * As the new kernel behavior of pci_restore_state() API call clears
9342 * device saved_state flag, need to save the restored state again.
9343 */
9344 pci_save_state(pdev);
9345
James Smartda0436e2009-05-22 14:51:39 -04009346 if (pdev->is_busmaster)
9347 pci_set_master(pdev);
9348
9349 /* Startup the kernel thread for this host adapter. */
9350 phba->worker_thread = kthread_run(lpfc_do_work, phba,
9351 "lpfc_worker_%d", phba->brd_no);
9352 if (IS_ERR(phba->worker_thread)) {
9353 error = PTR_ERR(phba->worker_thread);
9354 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9355 "0293 PM resume failed to start worker "
9356 "thread: error=x%x.\n", error);
9357 return error;
9358 }
9359
9360 /* Configure and enable interrupt */
9361 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
9362 if (intr_mode == LPFC_INTR_ERROR) {
9363 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9364 "0294 PM resume Failed to enable interrupt\n");
9365 return -EIO;
9366 } else
9367 phba->intr_mode = intr_mode;
9368
9369 /* Restart HBA and bring it online */
9370 lpfc_sli_brdrestart(phba);
9371 lpfc_online(phba);
9372
9373 /* Log the current active interrupt mode */
9374 lpfc_log_intr_mode(phba, phba->intr_mode);
9375
9376 return 0;
9377}
9378
9379/**
James Smart75baf692010-06-08 18:31:21 -04009380 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
9381 * @phba: pointer to lpfc hba data structure.
9382 *
9383 * This routine is called to prepare the SLI4 device for PCI slot recover. It
9384 * aborts all the outstanding SCSI I/Os to the pci device.
9385 **/
9386static void
9387lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
9388{
9389 struct lpfc_sli *psli = &phba->sli;
9390 struct lpfc_sli_ring *pring;
9391
9392 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9393 "2828 PCI channel I/O abort preparing for recovery\n");
9394 /*
9395 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
9396 * and let the SCSI mid-layer to retry them to recover.
9397 */
9398 pring = &psli->ring[psli->fcp_ring];
9399 lpfc_sli_abort_iocb_ring(phba, pring);
9400}
9401
9402/**
9403 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
9404 * @phba: pointer to lpfc hba data structure.
9405 *
9406 * This routine is called to prepare the SLI4 device for PCI slot reset. It
9407 * disables the device interrupt and pci device, and aborts the internal FCP
9408 * pending I/Os.
9409 **/
9410static void
9411lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
9412{
9413 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9414 "2826 PCI channel disable preparing for reset\n");
9415
9416 /* Block any management I/Os to the device */
9417 lpfc_block_mgmt_io(phba);
9418
9419 /* Block all SCSI devices' I/Os on the host */
9420 lpfc_scsi_dev_block(phba);
9421
9422 /* stop all timers */
9423 lpfc_stop_hba_timers(phba);
9424
9425 /* Disable interrupt and pci device */
9426 lpfc_sli4_disable_intr(phba);
9427 pci_disable_device(phba->pcidev);
9428
9429 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9430 lpfc_sli_flush_fcp_rings(phba);
9431}
9432
9433/**
9434 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
9435 * @phba: pointer to lpfc hba data structure.
9436 *
9437 * This routine is called to prepare the SLI4 device for PCI slot permanently
9438 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
9439 * pending I/Os.
9440 **/
9441static void
9442lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
9443{
9444 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9445 "2827 PCI channel permanent disable for failure\n");
9446
9447 /* Block all SCSI devices' I/Os on the host */
9448 lpfc_scsi_dev_block(phba);
9449
9450 /* stop all timers */
9451 lpfc_stop_hba_timers(phba);
9452
9453 /* Clean up all driver's outstanding SCSI I/Os */
9454 lpfc_sli_flush_fcp_rings(phba);
9455}
9456
9457/**
James Smartda0436e2009-05-22 14:51:39 -04009458 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
9459 * @pdev: pointer to PCI device.
9460 * @state: the current PCI connection state.
9461 *
9462 * This routine is called from the PCI subsystem for error handling to device
9463 * with SLI-4 interface spec. This function is called by the PCI subsystem
9464 * after a PCI bus error affecting this device has been detected. When this
9465 * function is invoked, it will need to stop all the I/Os and interrupt(s)
9466 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
9467 * for the PCI subsystem to perform proper recovery as desired.
9468 *
9469 * Return codes
9470 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
9471 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9472 **/
9473static pci_ers_result_t
9474lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
9475{
James Smart75baf692010-06-08 18:31:21 -04009476 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9477 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9478
9479 switch (state) {
9480 case pci_channel_io_normal:
9481 /* Non-fatal error, prepare for recovery */
9482 lpfc_sli4_prep_dev_for_recover(phba);
9483 return PCI_ERS_RESULT_CAN_RECOVER;
9484 case pci_channel_io_frozen:
9485 /* Fatal error, prepare for slot reset */
9486 lpfc_sli4_prep_dev_for_reset(phba);
9487 return PCI_ERS_RESULT_NEED_RESET;
9488 case pci_channel_io_perm_failure:
9489 /* Permanent failure, prepare for device down */
9490 lpfc_sli4_prep_dev_for_perm_failure(phba);
9491 return PCI_ERS_RESULT_DISCONNECT;
9492 default:
9493 /* Unknown state, prepare and request slot reset */
9494 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9495 "2825 Unknown PCI error state: x%x\n", state);
9496 lpfc_sli4_prep_dev_for_reset(phba);
9497 return PCI_ERS_RESULT_NEED_RESET;
9498 }
James Smartda0436e2009-05-22 14:51:39 -04009499}
9500
9501/**
9502 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
9503 * @pdev: pointer to PCI device.
9504 *
9505 * This routine is called from the PCI subsystem for error handling to device
9506 * with SLI-4 interface spec. It is called after PCI bus has been reset to
9507 * restart the PCI card from scratch, as if from a cold-boot. During the
9508 * PCI subsystem error recovery, after the driver returns
9509 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
9510 * recovery and then call this routine before calling the .resume method to
9511 * recover the device. This function will initialize the HBA device, enable
9512 * the interrupt, but it will just put the HBA to offline state without
9513 * passing any I/O traffic.
9514 *
9515 * Return codes
9516 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
9517 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9518 */
9519static pci_ers_result_t
9520lpfc_io_slot_reset_s4(struct pci_dev *pdev)
9521{
James Smart75baf692010-06-08 18:31:21 -04009522 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9523 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9524 struct lpfc_sli *psli = &phba->sli;
9525 uint32_t intr_mode;
9526
9527 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
9528 if (pci_enable_device_mem(pdev)) {
9529 printk(KERN_ERR "lpfc: Cannot re-enable "
9530 "PCI device after reset.\n");
9531 return PCI_ERS_RESULT_DISCONNECT;
9532 }
9533
9534 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -04009535
9536 /*
9537 * As the new kernel behavior of pci_restore_state() API call clears
9538 * device saved_state flag, need to save the restored state again.
9539 */
9540 pci_save_state(pdev);
9541
James Smart75baf692010-06-08 18:31:21 -04009542 if (pdev->is_busmaster)
9543 pci_set_master(pdev);
9544
9545 spin_lock_irq(&phba->hbalock);
9546 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
9547 spin_unlock_irq(&phba->hbalock);
9548
9549 /* Configure and enable interrupt */
9550 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
9551 if (intr_mode == LPFC_INTR_ERROR) {
9552 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9553 "2824 Cannot re-enable interrupt after "
9554 "slot reset.\n");
9555 return PCI_ERS_RESULT_DISCONNECT;
9556 } else
9557 phba->intr_mode = intr_mode;
9558
9559 /* Log the current active interrupt mode */
9560 lpfc_log_intr_mode(phba, phba->intr_mode);
9561
James Smartda0436e2009-05-22 14:51:39 -04009562 return PCI_ERS_RESULT_RECOVERED;
9563}
9564
9565/**
9566 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
9567 * @pdev: pointer to PCI device
9568 *
9569 * This routine is called from the PCI subsystem for error handling to device
9570 * with SLI-4 interface spec. It is called when kernel error recovery tells
9571 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
9572 * error recovery. After this call, traffic can start to flow from this device
9573 * again.
9574 **/
9575static void
9576lpfc_io_resume_s4(struct pci_dev *pdev)
9577{
James Smart75baf692010-06-08 18:31:21 -04009578 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9579 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9580
9581 /*
9582 * In case of slot reset, as function reset is performed through
9583 * mailbox command which needs DMA to be enabled, this operation
9584 * has to be moved to the io resume phase. Taking device offline
9585 * will perform the necessary cleanup.
9586 */
9587 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
9588 /* Perform device reset */
9589 lpfc_offline_prep(phba);
9590 lpfc_offline(phba);
9591 lpfc_sli_brdrestart(phba);
9592 /* Bring the device back online */
9593 lpfc_online(phba);
9594 }
9595
9596 /* Clean up Advanced Error Reporting (AER) if needed */
9597 if (phba->hba_flag & HBA_AER_ENABLED)
9598 pci_cleanup_aer_uncorrect_error_status(pdev);
James Smartda0436e2009-05-22 14:51:39 -04009599}
9600
9601/**
James Smart3772a992009-05-22 14:50:54 -04009602 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
9603 * @pdev: pointer to PCI device
9604 * @pid: pointer to PCI device identifier
9605 *
9606 * This routine is to be registered to the kernel's PCI subsystem. When an
9607 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
9608 * at PCI device-specific information of the device and driver to see if the
9609 * driver state that it can support this kind of device. If the match is
9610 * successful, the driver core invokes this routine. This routine dispatches
9611 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
9612 * do all the initialization that it needs to do to handle the HBA device
9613 * properly.
9614 *
9615 * Return code
9616 * 0 - driver can claim the device
9617 * negative value - driver can not claim the device
9618 **/
9619static int __devinit
9620lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
9621{
9622 int rc;
James Smart8fa38512009-07-19 10:01:03 -04009623 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -04009624
James Smart28baac72010-02-12 14:42:03 -05009625 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -04009626 return -ENODEV;
9627
James Smart8fa38512009-07-19 10:01:03 -04009628 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -05009629 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -04009630 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -04009631 else
James Smart3772a992009-05-22 14:50:54 -04009632 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -04009633
James Smart3772a992009-05-22 14:50:54 -04009634 return rc;
9635}
9636
9637/**
9638 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
9639 * @pdev: pointer to PCI device
9640 *
9641 * This routine is to be registered to the kernel's PCI subsystem. When an
9642 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
9643 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
9644 * remove routine, which will perform all the necessary cleanup for the
9645 * device to be removed from the PCI subsystem properly.
9646 **/
9647static void __devexit
9648lpfc_pci_remove_one(struct pci_dev *pdev)
9649{
9650 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9651 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9652
9653 switch (phba->pci_dev_grp) {
9654 case LPFC_PCI_DEV_LP:
9655 lpfc_pci_remove_one_s3(pdev);
9656 break;
James Smartda0436e2009-05-22 14:51:39 -04009657 case LPFC_PCI_DEV_OC:
9658 lpfc_pci_remove_one_s4(pdev);
9659 break;
James Smart3772a992009-05-22 14:50:54 -04009660 default:
9661 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9662 "1424 Invalid PCI device group: 0x%x\n",
9663 phba->pci_dev_grp);
9664 break;
9665 }
9666 return;
9667}
9668
9669/**
9670 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
9671 * @pdev: pointer to PCI device
9672 * @msg: power management message
9673 *
9674 * This routine is to be registered to the kernel's PCI subsystem to support
9675 * system Power Management (PM). When PM invokes this method, it dispatches
9676 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
9677 * suspend the device.
9678 *
9679 * Return code
9680 * 0 - driver suspended the device
9681 * Error otherwise
9682 **/
9683static int
9684lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
9685{
9686 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9687 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9688 int rc = -ENODEV;
9689
9690 switch (phba->pci_dev_grp) {
9691 case LPFC_PCI_DEV_LP:
9692 rc = lpfc_pci_suspend_one_s3(pdev, msg);
9693 break;
James Smartda0436e2009-05-22 14:51:39 -04009694 case LPFC_PCI_DEV_OC:
9695 rc = lpfc_pci_suspend_one_s4(pdev, msg);
9696 break;
James Smart3772a992009-05-22 14:50:54 -04009697 default:
9698 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9699 "1425 Invalid PCI device group: 0x%x\n",
9700 phba->pci_dev_grp);
9701 break;
9702 }
9703 return rc;
9704}
9705
9706/**
9707 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
9708 * @pdev: pointer to PCI device
9709 *
9710 * This routine is to be registered to the kernel's PCI subsystem to support
9711 * system Power Management (PM). When PM invokes this method, it dispatches
9712 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
9713 * resume the device.
9714 *
9715 * Return code
9716 * 0 - driver suspended the device
9717 * Error otherwise
9718 **/
9719static int
9720lpfc_pci_resume_one(struct pci_dev *pdev)
9721{
9722 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9723 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9724 int rc = -ENODEV;
9725
9726 switch (phba->pci_dev_grp) {
9727 case LPFC_PCI_DEV_LP:
9728 rc = lpfc_pci_resume_one_s3(pdev);
9729 break;
James Smartda0436e2009-05-22 14:51:39 -04009730 case LPFC_PCI_DEV_OC:
9731 rc = lpfc_pci_resume_one_s4(pdev);
9732 break;
James Smart3772a992009-05-22 14:50:54 -04009733 default:
9734 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9735 "1426 Invalid PCI device group: 0x%x\n",
9736 phba->pci_dev_grp);
9737 break;
9738 }
9739 return rc;
9740}
9741
9742/**
9743 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
9744 * @pdev: pointer to PCI device.
9745 * @state: the current PCI connection state.
9746 *
9747 * This routine is registered to the PCI subsystem for error handling. This
9748 * function is called by the PCI subsystem after a PCI bus error affecting
9749 * this device has been detected. When this routine is invoked, it dispatches
9750 * the action to the proper SLI-3 or SLI-4 device error detected handling
9751 * routine, which will perform the proper error detected operation.
9752 *
9753 * Return codes
9754 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
9755 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9756 **/
9757static pci_ers_result_t
9758lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
9759{
9760 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9761 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9762 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
9763
9764 switch (phba->pci_dev_grp) {
9765 case LPFC_PCI_DEV_LP:
9766 rc = lpfc_io_error_detected_s3(pdev, state);
9767 break;
James Smartda0436e2009-05-22 14:51:39 -04009768 case LPFC_PCI_DEV_OC:
9769 rc = lpfc_io_error_detected_s4(pdev, state);
9770 break;
James Smart3772a992009-05-22 14:50:54 -04009771 default:
9772 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9773 "1427 Invalid PCI device group: 0x%x\n",
9774 phba->pci_dev_grp);
9775 break;
9776 }
9777 return rc;
9778}
9779
9780/**
9781 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
9782 * @pdev: pointer to PCI device.
9783 *
9784 * This routine is registered to the PCI subsystem for error handling. This
9785 * function is called after PCI bus has been reset to restart the PCI card
9786 * from scratch, as if from a cold-boot. When this routine is invoked, it
9787 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
9788 * routine, which will perform the proper device reset.
9789 *
9790 * Return codes
9791 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
9792 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9793 **/
9794static pci_ers_result_t
9795lpfc_io_slot_reset(struct pci_dev *pdev)
9796{
9797 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9798 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9799 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
9800
9801 switch (phba->pci_dev_grp) {
9802 case LPFC_PCI_DEV_LP:
9803 rc = lpfc_io_slot_reset_s3(pdev);
9804 break;
James Smartda0436e2009-05-22 14:51:39 -04009805 case LPFC_PCI_DEV_OC:
9806 rc = lpfc_io_slot_reset_s4(pdev);
9807 break;
James Smart3772a992009-05-22 14:50:54 -04009808 default:
9809 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9810 "1428 Invalid PCI device group: 0x%x\n",
9811 phba->pci_dev_grp);
9812 break;
9813 }
9814 return rc;
9815}
9816
9817/**
9818 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
9819 * @pdev: pointer to PCI device
9820 *
9821 * This routine is registered to the PCI subsystem for error handling. It
9822 * is called when kernel error recovery tells the lpfc driver that it is
9823 * OK to resume normal PCI operation after PCI bus error recovery. When
9824 * this routine is invoked, it dispatches the action to the proper SLI-3
9825 * or SLI-4 device io_resume routine, which will resume the device operation.
9826 **/
9827static void
9828lpfc_io_resume(struct pci_dev *pdev)
9829{
9830 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9831 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9832
9833 switch (phba->pci_dev_grp) {
9834 case LPFC_PCI_DEV_LP:
9835 lpfc_io_resume_s3(pdev);
9836 break;
James Smartda0436e2009-05-22 14:51:39 -04009837 case LPFC_PCI_DEV_OC:
9838 lpfc_io_resume_s4(pdev);
9839 break;
James Smart3772a992009-05-22 14:50:54 -04009840 default:
9841 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9842 "1429 Invalid PCI device group: 0x%x\n",
9843 phba->pci_dev_grp);
9844 break;
9845 }
9846 return;
9847}
9848
dea31012005-04-17 16:05:31 -05009849static struct pci_device_id lpfc_id_table[] = {
9850 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
9851 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04009852 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
9853 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05009854 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
9855 PCI_ANY_ID, PCI_ANY_ID, },
9856 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
9857 PCI_ANY_ID, PCI_ANY_ID, },
9858 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
9859 PCI_ANY_ID, PCI_ANY_ID, },
9860 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
9861 PCI_ANY_ID, PCI_ANY_ID, },
9862 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
9863 PCI_ANY_ID, PCI_ANY_ID, },
9864 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
9865 PCI_ANY_ID, PCI_ANY_ID, },
9866 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
9867 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05009868 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
9869 PCI_ANY_ID, PCI_ANY_ID, },
9870 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
9871 PCI_ANY_ID, PCI_ANY_ID, },
9872 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
9873 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05009874 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
9875 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05009876 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
9877 PCI_ANY_ID, PCI_ANY_ID, },
9878 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
9879 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05009880 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
9881 PCI_ANY_ID, PCI_ANY_ID, },
9882 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
9883 PCI_ANY_ID, PCI_ANY_ID, },
9884 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
9885 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -04009886 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
9887 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05009888 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
9889 PCI_ANY_ID, PCI_ANY_ID, },
9890 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
9891 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05009892 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
9893 PCI_ANY_ID, PCI_ANY_ID, },
9894 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
9895 PCI_ANY_ID, PCI_ANY_ID, },
9896 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
9897 PCI_ANY_ID, PCI_ANY_ID, },
9898 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
9899 PCI_ANY_ID, PCI_ANY_ID, },
9900 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
9901 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05009902 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
9903 PCI_ANY_ID, PCI_ANY_ID, },
9904 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
9905 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -04009906 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
9907 PCI_ANY_ID, PCI_ANY_ID, },
9908 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
9909 PCI_ANY_ID, PCI_ANY_ID, },
9910 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
9911 PCI_ANY_ID, PCI_ANY_ID, },
9912 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
9913 PCI_ANY_ID, PCI_ANY_ID, },
9914 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
9915 PCI_ANY_ID, PCI_ANY_ID, },
9916 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
9917 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -04009918 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
9919 PCI_ANY_ID, PCI_ANY_ID, },
9920 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
9921 PCI_ANY_ID, PCI_ANY_ID, },
9922 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
9923 PCI_ANY_ID, PCI_ANY_ID, },
James Smart3772a992009-05-22 14:50:54 -04009924 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
9925 PCI_ANY_ID, PCI_ANY_ID, },
James Smarta747c9c2009-11-18 15:41:10 -05009926 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT,
9927 PCI_ANY_ID, PCI_ANY_ID, },
9928 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON,
James Smart6669f9b2009-10-02 15:16:45 -04009929 PCI_ANY_ID, PCI_ANY_ID, },
James Smart98fc5dd2010-06-07 15:24:29 -04009930 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS,
9931 PCI_ANY_ID, PCI_ANY_ID, },
James Smart085c6472010-11-20 23:11:37 -05009932 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC,
9933 PCI_ANY_ID, PCI_ANY_ID, },
9934 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE,
9935 PCI_ANY_ID, PCI_ANY_ID, },
James Smartc0c11512011-05-24 11:41:34 -04009936 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF,
9937 PCI_ANY_ID, PCI_ANY_ID, },
9938 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF,
9939 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05009940 { 0 }
9941};
9942
9943MODULE_DEVICE_TABLE(pci, lpfc_id_table);
9944
Linas Vepstas8d63f372007-02-14 14:28:36 -06009945static struct pci_error_handlers lpfc_err_handler = {
9946 .error_detected = lpfc_io_error_detected,
9947 .slot_reset = lpfc_io_slot_reset,
9948 .resume = lpfc_io_resume,
9949};
9950
dea31012005-04-17 16:05:31 -05009951static struct pci_driver lpfc_driver = {
9952 .name = LPFC_DRIVER_NAME,
9953 .id_table = lpfc_id_table,
9954 .probe = lpfc_pci_probe_one,
9955 .remove = __devexit_p(lpfc_pci_remove_one),
James Smart3a55b532008-12-04 22:38:54 -05009956 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -04009957 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -05009958 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -05009959};
9960
James Smarte59058c2008-08-24 21:49:00 -04009961/**
James Smart3621a712009-04-06 18:47:14 -04009962 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -04009963 *
9964 * This routine is to be invoked when the lpfc module is loaded into the
9965 * kernel. The special kernel macro module_init() is used to indicate the
9966 * role of this routine to the kernel as lpfc module entry point.
9967 *
9968 * Return codes
9969 * 0 - successful
9970 * -ENOMEM - FC attach transport failed
9971 * all others - failed
9972 */
dea31012005-04-17 16:05:31 -05009973static int __init
9974lpfc_init(void)
9975{
9976 int error = 0;
9977
9978 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04009979 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -05009980
James Smart7ee5d432007-10-27 13:37:17 -04009981 if (lpfc_enable_npiv) {
9982 lpfc_transport_functions.vport_create = lpfc_vport_create;
9983 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
9984 }
dea31012005-04-17 16:05:31 -05009985 lpfc_transport_template =
9986 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -04009987 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -05009988 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -04009989 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -04009990 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -04009991 fc_attach_transport(&lpfc_vport_transport_functions);
9992 if (lpfc_vport_transport_template == NULL) {
9993 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04009994 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -04009995 }
James Smart7ee5d432007-10-27 13:37:17 -04009996 }
dea31012005-04-17 16:05:31 -05009997 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -05009998 if (error) {
dea31012005-04-17 16:05:31 -05009999 fc_release_transport(lpfc_transport_template);
James Smartd7c255b2008-08-24 21:50:00 -040010000 if (lpfc_enable_npiv)
10001 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050010002 }
dea31012005-04-17 16:05:31 -050010003
10004 return error;
10005}
10006
James Smarte59058c2008-08-24 21:49:00 -040010007/**
James Smart3621a712009-04-06 18:47:14 -040010008 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040010009 *
10010 * This routine is invoked when the lpfc module is removed from the kernel.
10011 * The special kernel macro module_exit() is used to indicate the role of
10012 * this routine to the kernel as lpfc module exit point.
10013 */
dea31012005-04-17 16:05:31 -050010014static void __exit
10015lpfc_exit(void)
10016{
10017 pci_unregister_driver(&lpfc_driver);
10018 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040010019 if (lpfc_enable_npiv)
10020 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050010021 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040010022 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
10023 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050010024 (1L << _dump_buf_data_order), _dump_buf_data);
10025 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
10026 }
10027
10028 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040010029 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
10030 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050010031 (1L << _dump_buf_dif_order), _dump_buf_dif);
10032 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
10033 }
dea31012005-04-17 16:05:31 -050010034}
10035
10036module_init(lpfc_init);
10037module_exit(lpfc_exit);
10038MODULE_LICENSE("GPL");
10039MODULE_DESCRIPTION(LPFC_MODULE_DESC);
10040MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
10041MODULE_VERSION("0:" LPFC_DRIVER_VERSION);