blob: b9ff38fa7c2646a8a6edd2221debd9835af235c4 [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 Smartda0436e2009-05-22 14:51:39 -04001441
1442 /* If the pci channel is offline, ignore possible errors, since
1443 * we cannot communicate with the pci card anyway.
1444 */
1445 if (pci_channel_offline(phba->pcidev))
1446 return;
1447 /* If resets are disabled then leave the HBA alone and return */
1448 if (!phba->cfg_enable_hba_reset)
1449 return;
1450
1451 /* Send an internal error event to mgmt application */
1452 lpfc_board_errevt_to_mgmt(phba);
1453
1454 /* For now, the actual action for SLI4 device handling is not
1455 * specified yet, just treated it as adaptor hardware failure
1456 */
James Smartda0436e2009-05-22 14:51:39 -04001457 event_data = FC_REG_DUMP_EVENT;
1458 shost = lpfc_shost_from_vport(vport);
1459 fc_host_post_vendor_event(shost, fc_get_event_number(),
1460 sizeof(event_data), (char *) &event_data,
1461 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1462
James Smart2fcee4b2010-12-15 17:57:46 -05001463 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1464 switch (if_type) {
1465 case LPFC_SLI_INTF_IF_TYPE_0:
1466 lpfc_sli4_offline_eratt(phba);
1467 break;
1468 case LPFC_SLI_INTF_IF_TYPE_2:
1469 portstat_reg.word0 =
1470 readl(phba->sli4_hba.u.if_type2.STATUSregaddr);
1471
1472 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
1473 /* TODO: Register for Overtemp async events. */
1474 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1475 "2889 Port Overtemperature event, "
1476 "taking port\n");
1477 spin_lock_irq(&phba->hbalock);
1478 phba->over_temp_state = HBA_OVER_TEMP;
1479 spin_unlock_irq(&phba->hbalock);
1480 lpfc_sli4_offline_eratt(phba);
1481 return;
1482 }
1483 if (bf_get(lpfc_sliport_status_rn, &portstat_reg)) {
James Smart079b5c92011-08-21 21:48:49 -04001484 /* need reset: attempt for port recovery */
James Smart2fcee4b2010-12-15 17:57:46 -05001485 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1486 "2887 Port Error: Attempting "
1487 "Port Recovery\n");
James Smart079b5c92011-08-21 21:48:49 -04001488 lpfc_offline_prep(phba);
1489 lpfc_offline(phba);
1490 lpfc_sli_brdrestart(phba);
1491 if (lpfc_online(phba) == 0) {
1492 lpfc_unblock_mgmt_io(phba);
1493 return;
1494 }
1495 /* fall through for not able to recover */
James Smart2fcee4b2010-12-15 17:57:46 -05001496 }
1497 lpfc_sli4_offline_eratt(phba);
1498 break;
1499 case LPFC_SLI_INTF_IF_TYPE_1:
1500 default:
1501 break;
1502 }
James Smartda0436e2009-05-22 14:51:39 -04001503}
1504
1505/**
1506 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1507 * @phba: pointer to lpfc HBA data structure.
1508 *
1509 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1510 * routine from the API jump table function pointer from the lpfc_hba struct.
1511 *
1512 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001513 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001514 * Any other value - error.
1515 **/
1516void
1517lpfc_handle_eratt(struct lpfc_hba *phba)
1518{
1519 (*phba->lpfc_handle_eratt)(phba);
1520}
1521
1522/**
James Smart3621a712009-04-06 18:47:14 -04001523 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04001524 * @phba: pointer to lpfc hba data structure.
1525 *
1526 * This routine is invoked from the worker thread to handle a HBA host
1527 * attention link event.
1528 **/
dea31012005-04-17 16:05:31 -05001529void
James Smart2e0fef82007-06-17 19:56:36 -05001530lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001531{
James Smart2e0fef82007-06-17 19:56:36 -05001532 struct lpfc_vport *vport = phba->pport;
1533 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001534 LPFC_MBOXQ_t *pmb;
1535 volatile uint32_t control;
1536 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05001537 int rc = 0;
dea31012005-04-17 16:05:31 -05001538
1539 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001540 if (!pmb) {
1541 rc = 1;
dea31012005-04-17 16:05:31 -05001542 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05001543 }
dea31012005-04-17 16:05:31 -05001544
1545 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001546 if (!mp) {
1547 rc = 2;
dea31012005-04-17 16:05:31 -05001548 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05001549 }
dea31012005-04-17 16:05:31 -05001550
1551 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05001552 if (!mp->virt) {
1553 rc = 3;
dea31012005-04-17 16:05:31 -05001554 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05001555 }
dea31012005-04-17 16:05:31 -05001556
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001557 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04001558 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05001559
1560 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05001561 lpfc_read_topology(phba, pmb, mp);
1562 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05001563 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04001564 /* Block ELS IOCBs until we have processed this mbox command */
1565 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04001566 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05001567 if (rc == MBX_NOT_FINISHED) {
1568 rc = 4;
James Smart14691152006-12-02 13:34:28 -05001569 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05001570 }
dea31012005-04-17 16:05:31 -05001571
1572 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05001573 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001574 writel(HA_LATT, phba->HAregaddr);
1575 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001576 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001577
1578 return;
1579
James Smart14691152006-12-02 13:34:28 -05001580lpfc_handle_latt_free_mbuf:
James Smart0d2b6b82008-06-14 22:52:47 -04001581 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05001582 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05001583lpfc_handle_latt_free_mp:
1584 kfree(mp);
1585lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04001586 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001587lpfc_handle_latt_err_exit:
1588 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001589 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001590 psli->sli_flag |= LPFC_PROCESS_LA;
1591 control = readl(phba->HCregaddr);
1592 control |= HC_LAINT_ENA;
1593 writel(control, phba->HCregaddr);
1594 readl(phba->HCregaddr); /* flush */
1595
1596 /* Clear Link Attention in HA REG */
1597 writel(HA_LATT, phba->HAregaddr);
1598 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001599 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001600 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001601 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001602
James Smart09372822008-01-11 01:52:54 -05001603 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1604 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05001605
1606 return;
1607}
1608
James Smarte59058c2008-08-24 21:49:00 -04001609/**
James Smart3621a712009-04-06 18:47:14 -04001610 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04001611 * @phba: pointer to lpfc hba data structure.
1612 * @vpd: pointer to the vital product data.
1613 * @len: length of the vital product data in bytes.
1614 *
1615 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1616 * an array of characters. In this routine, the ModelName, ProgramType, and
1617 * ModelDesc, etc. fields of the phba data structure will be populated.
1618 *
1619 * Return codes
1620 * 0 - pointer to the VPD passed in is NULL
1621 * 1 - success
1622 **/
James Smart3772a992009-05-22 14:50:54 -04001623int
James Smart2e0fef82007-06-17 19:56:36 -05001624lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05001625{
1626 uint8_t lenlo, lenhi;
Anton Blanchard07da60c12007-03-21 08:41:47 -05001627 int Length;
dea31012005-04-17 16:05:31 -05001628 int i, j;
1629 int finished = 0;
1630 int index = 0;
1631
1632 if (!vpd)
1633 return 0;
1634
1635 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05001636 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001637 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001638 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
1639 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001640 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05001641 switch (vpd[index]) {
1642 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001643 case 0x91:
dea31012005-04-17 16:05:31 -05001644 index += 1;
1645 lenlo = vpd[index];
1646 index += 1;
1647 lenhi = vpd[index];
1648 index += 1;
1649 i = ((((unsigned short)lenhi) << 8) + lenlo);
1650 index += i;
1651 break;
1652 case 0x90:
1653 index += 1;
1654 lenlo = vpd[index];
1655 index += 1;
1656 lenhi = vpd[index];
1657 index += 1;
1658 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001659 if (Length > len - index)
1660 Length = len - index;
dea31012005-04-17 16:05:31 -05001661 while (Length > 0) {
1662 /* Look for Serial Number */
1663 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
1664 index += 2;
1665 i = vpd[index];
1666 index += 1;
1667 j = 0;
1668 Length -= (3+i);
1669 while(i--) {
1670 phba->SerialNumber[j++] = vpd[index++];
1671 if (j == 31)
1672 break;
1673 }
1674 phba->SerialNumber[j] = 0;
1675 continue;
1676 }
1677 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
1678 phba->vpd_flag |= VPD_MODEL_DESC;
1679 index += 2;
1680 i = vpd[index];
1681 index += 1;
1682 j = 0;
1683 Length -= (3+i);
1684 while(i--) {
1685 phba->ModelDesc[j++] = vpd[index++];
1686 if (j == 255)
1687 break;
1688 }
1689 phba->ModelDesc[j] = 0;
1690 continue;
1691 }
1692 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
1693 phba->vpd_flag |= VPD_MODEL_NAME;
1694 index += 2;
1695 i = vpd[index];
1696 index += 1;
1697 j = 0;
1698 Length -= (3+i);
1699 while(i--) {
1700 phba->ModelName[j++] = vpd[index++];
1701 if (j == 79)
1702 break;
1703 }
1704 phba->ModelName[j] = 0;
1705 continue;
1706 }
1707 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
1708 phba->vpd_flag |= VPD_PROGRAM_TYPE;
1709 index += 2;
1710 i = vpd[index];
1711 index += 1;
1712 j = 0;
1713 Length -= (3+i);
1714 while(i--) {
1715 phba->ProgramType[j++] = vpd[index++];
1716 if (j == 255)
1717 break;
1718 }
1719 phba->ProgramType[j] = 0;
1720 continue;
1721 }
1722 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1723 phba->vpd_flag |= VPD_PORT;
1724 index += 2;
1725 i = vpd[index];
1726 index += 1;
1727 j = 0;
1728 Length -= (3+i);
1729 while(i--) {
1730 phba->Port[j++] = vpd[index++];
1731 if (j == 19)
1732 break;
1733 }
1734 phba->Port[j] = 0;
1735 continue;
1736 }
1737 else {
1738 index += 2;
1739 i = vpd[index];
1740 index += 1;
1741 index += i;
1742 Length -= (3 + i);
1743 }
1744 }
1745 finished = 0;
1746 break;
1747 case 0x78:
1748 finished = 1;
1749 break;
1750 default:
1751 index ++;
1752 break;
1753 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001754 }
dea31012005-04-17 16:05:31 -05001755
1756 return(1);
1757}
1758
James Smarte59058c2008-08-24 21:49:00 -04001759/**
James Smart3621a712009-04-06 18:47:14 -04001760 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04001761 * @phba: pointer to lpfc hba data structure.
1762 * @mdp: pointer to the data structure to hold the derived model name.
1763 * @descp: pointer to the data structure to hold the derived description.
1764 *
1765 * This routine retrieves HBA's description based on its registered PCI device
1766 * ID. The @descp passed into this function points to an array of 256 chars. It
1767 * shall be returned with the model name, maximum speed, and the host bus type.
1768 * The @mdp passed into this function points to an array of 80 chars. When the
1769 * function returns, the @mdp will be filled with the model name.
1770 **/
dea31012005-04-17 16:05:31 -05001771static void
James Smart2e0fef82007-06-17 19:56:36 -05001772lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05001773{
1774 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05001775 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001776 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04001777 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04001778 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001779 struct {
James Smarta747c9c2009-11-18 15:41:10 -05001780 char *name;
1781 char *bus;
1782 char *function;
1783 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001784
1785 if (mdp && mdp[0] != '\0'
1786 && descp && descp[0] != '\0')
1787 return;
1788
James Smartc0c11512011-05-24 11:41:34 -04001789 if (phba->lmt & LMT_16Gb)
1790 max_speed = 16;
1791 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001792 max_speed = 10;
1793 else if (phba->lmt & LMT_8Gb)
1794 max_speed = 8;
1795 else if (phba->lmt & LMT_4Gb)
1796 max_speed = 4;
1797 else if (phba->lmt & LMT_2Gb)
1798 max_speed = 2;
1799 else
1800 max_speed = 1;
dea31012005-04-17 16:05:31 -05001801
1802 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05001803
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001804 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001805 case PCI_DEVICE_ID_FIREFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001806 m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001807 break;
dea31012005-04-17 16:05:31 -05001808 case PCI_DEVICE_ID_SUPERFLY:
1809 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smarta747c9c2009-11-18 15:41:10 -05001810 m = (typeof(m)){"LP7000", "PCI",
1811 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001812 else
James Smarta747c9c2009-11-18 15:41:10 -05001813 m = (typeof(m)){"LP7000E", "PCI",
1814 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001815 break;
1816 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001817 m = (typeof(m)){"LP8000", "PCI",
1818 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001819 break;
1820 case PCI_DEVICE_ID_CENTAUR:
1821 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smarta747c9c2009-11-18 15:41:10 -05001822 m = (typeof(m)){"LP9002", "PCI",
1823 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001824 else
James Smarta747c9c2009-11-18 15:41:10 -05001825 m = (typeof(m)){"LP9000", "PCI",
1826 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001827 break;
1828 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001829 m = (typeof(m)){"LP952", "PCI",
1830 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001831 break;
1832 case PCI_DEVICE_ID_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05001833 m = (typeof(m)){"LP9802", "PCI-X",
1834 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001835 break;
1836 case PCI_DEVICE_ID_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05001837 m = (typeof(m)){"LP10000", "PCI-X",
1838 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001839 break;
1840 case PCI_DEVICE_ID_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05001841 m = (typeof(m)){"LPX1000", "PCI-X",
1842 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001843 break;
1844 case PCI_DEVICE_ID_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001845 m = (typeof(m)){"LP982", "PCI-X",
1846 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001847 break;
1848 case PCI_DEVICE_ID_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05001849 m = (typeof(m)){"LP1050", "PCI-X",
1850 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001851 break;
1852 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05001853 m = (typeof(m)){"LP11000", "PCI-X2",
1854 "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001855 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001856 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001857 m = (typeof(m)){"LP11000-SP", "PCI-X2",
1858 "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001859 break;
1860 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001861 m = (typeof(m)){"LP11002-SP", "PCI-X2",
1862 "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001863 break;
1864 case PCI_DEVICE_ID_NEPTUNE:
James Smarta747c9c2009-11-18 15:41:10 -05001865 m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001866 break;
1867 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001868 m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001869 break;
1870 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001871 m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001872 break;
dea31012005-04-17 16:05:31 -05001873 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05001874 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001875 break;
1876 case PCI_DEVICE_ID_BSMB:
James Smarta747c9c2009-11-18 15:41:10 -05001877 m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001878 break;
1879 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05001880 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001881 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001882 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001883 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001884 break;
1885 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001886 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04001887 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001888 break;
dea31012005-04-17 16:05:31 -05001889 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05001890 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001891 break;
1892 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05001893 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001894 break;
1895 case PCI_DEVICE_ID_LP101:
James Smarta747c9c2009-11-18 15:41:10 -05001896 m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05001897 break;
1898 case PCI_DEVICE_ID_LP10000S:
James Smarta747c9c2009-11-18 15:41:10 -05001899 m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001900 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001901 case PCI_DEVICE_ID_LP11000S:
James Smarta747c9c2009-11-18 15:41:10 -05001902 m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05001903 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001904 case PCI_DEVICE_ID_LPE11000S:
James Smarta747c9c2009-11-18 15:41:10 -05001905 m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001906 break;
James Smartb87eab32007-04-25 09:53:28 -04001907 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05001908 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04001909 break;
1910 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05001911 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04001912 break;
1913 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05001914 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04001915 break;
1916 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001917 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04001918 break;
1919 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05001920 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04001921 break;
1922 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05001923 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04001924 break;
James Smart84774a42008-08-24 21:50:06 -04001925 case PCI_DEVICE_ID_HORNET:
James Smarta747c9c2009-11-18 15:41:10 -05001926 m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04001927 GE = 1;
1928 break;
1929 case PCI_DEVICE_ID_PROTEUS_VF:
James Smarta747c9c2009-11-18 15:41:10 -05001930 m = (typeof(m)){"LPev12000", "PCIe IOV",
1931 "Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04001932 break;
1933 case PCI_DEVICE_ID_PROTEUS_PF:
James Smarta747c9c2009-11-18 15:41:10 -05001934 m = (typeof(m)){"LPev12000", "PCIe IOV",
1935 "Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04001936 break;
1937 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05001938 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
1939 "Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04001940 break;
James Smartda0436e2009-05-22 14:51:39 -04001941 case PCI_DEVICE_ID_TIGERSHARK:
1942 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05001943 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04001944 break;
James Smarta747c9c2009-11-18 15:41:10 -05001945 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04001946 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05001947 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
1948 break;
1949 case PCI_DEVICE_ID_FALCON:
1950 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
1951 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04001952 break;
James Smart98fc5dd2010-06-07 15:24:29 -04001953 case PCI_DEVICE_ID_BALIUS:
1954 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
1955 "Fibre Channel Adapter"};
1956 break;
James Smart085c6472010-11-20 23:11:37 -05001957 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04001958 case PCI_DEVICE_ID_LANCER_FC_VF:
1959 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05001960 break;
1961 case PCI_DEVICE_ID_LANCER_FCOE:
James Smartc0c11512011-05-24 11:41:34 -04001962 case PCI_DEVICE_ID_LANCER_FCOE_VF:
James Smart085c6472010-11-20 23:11:37 -05001963 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04001964 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05001965 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001966 default:
James Smarta747c9c2009-11-18 15:41:10 -05001967 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001968 break;
dea31012005-04-17 16:05:31 -05001969 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001970
1971 if (mdp && mdp[0] == '\0')
1972 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04001973 /*
1974 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04001975 * and we put the port number on the end
1976 */
1977 if (descp && descp[0] == '\0') {
1978 if (oneConnect)
1979 snprintf(descp, 255,
James Smarta747c9c2009-11-18 15:41:10 -05001980 "Emulex OneConnect %s, %s Initiator, Port %s",
1981 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04001982 phba->Port);
1983 else
1984 snprintf(descp, 255,
1985 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05001986 m.name, max_speed, (GE) ? "GE" : "Gb",
1987 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04001988 }
dea31012005-04-17 16:05:31 -05001989}
1990
James Smarte59058c2008-08-24 21:49:00 -04001991/**
James Smart3621a712009-04-06 18:47:14 -04001992 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04001993 * @phba: pointer to lpfc hba data structure.
1994 * @pring: pointer to a IOCB ring.
1995 * @cnt: the number of IOCBs to be posted to the IOCB ring.
1996 *
1997 * This routine posts a given number of IOCBs with the associated DMA buffer
1998 * descriptors specified by the cnt argument to the given IOCB ring.
1999 *
2000 * Return codes
2001 * The number of IOCBs NOT able to be posted to the IOCB ring.
2002 **/
dea31012005-04-17 16:05:31 -05002003int
James Smart495a7142008-06-14 22:52:59 -04002004lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002005{
2006 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002007 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002008 struct lpfc_dmabuf *mp1, *mp2;
2009
2010 cnt += pring->missbufcnt;
2011
2012 /* While there are buffers to post */
2013 while (cnt > 0) {
2014 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002015 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002016 if (iocb == NULL) {
2017 pring->missbufcnt = cnt;
2018 return cnt;
2019 }
dea31012005-04-17 16:05:31 -05002020 icmd = &iocb->iocb;
2021
2022 /* 2 buffers can be posted per command */
2023 /* Allocate buffer to post */
2024 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2025 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002026 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2027 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002028 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002029 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002030 pring->missbufcnt = cnt;
2031 return cnt;
2032 }
2033
2034 INIT_LIST_HEAD(&mp1->list);
2035 /* Allocate buffer to post */
2036 if (cnt > 1) {
2037 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2038 if (mp2)
2039 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2040 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002041 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002042 kfree(mp2);
dea31012005-04-17 16:05:31 -05002043 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2044 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002045 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002046 pring->missbufcnt = cnt;
2047 return cnt;
2048 }
2049
2050 INIT_LIST_HEAD(&mp2->list);
2051 } else {
2052 mp2 = NULL;
2053 }
2054
2055 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2056 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2057 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2058 icmd->ulpBdeCount = 1;
2059 cnt--;
2060 if (mp2) {
2061 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2062 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2063 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2064 cnt--;
2065 icmd->ulpBdeCount = 2;
2066 }
2067
2068 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2069 icmd->ulpLe = 1;
2070
James Smart3772a992009-05-22 14:50:54 -04002071 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2072 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002073 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2074 kfree(mp1);
2075 cnt++;
2076 if (mp2) {
2077 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2078 kfree(mp2);
2079 cnt++;
2080 }
James Bottomley604a3e32005-10-29 10:28:33 -05002081 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002082 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002083 return cnt;
2084 }
dea31012005-04-17 16:05:31 -05002085 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002086 if (mp2)
dea31012005-04-17 16:05:31 -05002087 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002088 }
2089 pring->missbufcnt = 0;
2090 return 0;
2091}
2092
James Smarte59058c2008-08-24 21:49:00 -04002093/**
James Smart3621a712009-04-06 18:47:14 -04002094 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002095 * @phba: pointer to lpfc hba data structure.
2096 *
2097 * This routine posts initial receive IOCB buffers to the ELS ring. The
2098 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2099 * set to 64 IOCBs.
2100 *
2101 * Return codes
2102 * 0 - success (currently always success)
2103 **/
dea31012005-04-17 16:05:31 -05002104static int
James Smart2e0fef82007-06-17 19:56:36 -05002105lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002106{
2107 struct lpfc_sli *psli = &phba->sli;
2108
2109 /* Ring 0, ELS / CT buffers */
James Smart495a7142008-06-14 22:52:59 -04002110 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002111 /* Ring 2 - FCP no buffers needed */
2112
2113 return 0;
2114}
2115
2116#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2117
James Smarte59058c2008-08-24 21:49:00 -04002118/**
James Smart3621a712009-04-06 18:47:14 -04002119 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002120 * @HashResultPointer: pointer to an array as hash table.
2121 *
2122 * This routine sets up the initial values to the array of hash table entries
2123 * for the LC HBAs.
2124 **/
dea31012005-04-17 16:05:31 -05002125static void
2126lpfc_sha_init(uint32_t * HashResultPointer)
2127{
2128 HashResultPointer[0] = 0x67452301;
2129 HashResultPointer[1] = 0xEFCDAB89;
2130 HashResultPointer[2] = 0x98BADCFE;
2131 HashResultPointer[3] = 0x10325476;
2132 HashResultPointer[4] = 0xC3D2E1F0;
2133}
2134
James Smarte59058c2008-08-24 21:49:00 -04002135/**
James Smart3621a712009-04-06 18:47:14 -04002136 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002137 * @HashResultPointer: pointer to an initial/result hash table.
2138 * @HashWorkingPointer: pointer to an working hash table.
2139 *
2140 * This routine iterates an initial hash table pointed by @HashResultPointer
2141 * with the values from the working hash table pointeed by @HashWorkingPointer.
2142 * The results are putting back to the initial hash table, returned through
2143 * the @HashResultPointer as the result hash table.
2144 **/
dea31012005-04-17 16:05:31 -05002145static void
2146lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2147{
2148 int t;
2149 uint32_t TEMP;
2150 uint32_t A, B, C, D, E;
2151 t = 16;
2152 do {
2153 HashWorkingPointer[t] =
2154 S(1,
2155 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2156 8] ^
2157 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2158 } while (++t <= 79);
2159 t = 0;
2160 A = HashResultPointer[0];
2161 B = HashResultPointer[1];
2162 C = HashResultPointer[2];
2163 D = HashResultPointer[3];
2164 E = HashResultPointer[4];
2165
2166 do {
2167 if (t < 20) {
2168 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2169 } else if (t < 40) {
2170 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2171 } else if (t < 60) {
2172 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2173 } else {
2174 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2175 }
2176 TEMP += S(5, A) + E + HashWorkingPointer[t];
2177 E = D;
2178 D = C;
2179 C = S(30, B);
2180 B = A;
2181 A = TEMP;
2182 } while (++t <= 79);
2183
2184 HashResultPointer[0] += A;
2185 HashResultPointer[1] += B;
2186 HashResultPointer[2] += C;
2187 HashResultPointer[3] += D;
2188 HashResultPointer[4] += E;
2189
2190}
2191
James Smarte59058c2008-08-24 21:49:00 -04002192/**
James Smart3621a712009-04-06 18:47:14 -04002193 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002194 * @RandomChallenge: pointer to the entry of host challenge random number array.
2195 * @HashWorking: pointer to the entry of the working hash array.
2196 *
2197 * This routine calculates the working hash array referred by @HashWorking
2198 * from the challenge random numbers associated with the host, referred by
2199 * @RandomChallenge. The result is put into the entry of the working hash
2200 * array and returned by reference through @HashWorking.
2201 **/
dea31012005-04-17 16:05:31 -05002202static void
2203lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2204{
2205 *HashWorking = (*RandomChallenge ^ *HashWorking);
2206}
2207
James Smarte59058c2008-08-24 21:49:00 -04002208/**
James Smart3621a712009-04-06 18:47:14 -04002209 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002210 * @phba: pointer to lpfc hba data structure.
2211 * @hbainit: pointer to an array of unsigned 32-bit integers.
2212 *
2213 * This routine performs the special handling for LC HBA initialization.
2214 **/
dea31012005-04-17 16:05:31 -05002215void
2216lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2217{
2218 int t;
2219 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002220 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002221
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002222 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002223 if (!HashWorking)
2224 return;
2225
dea31012005-04-17 16:05:31 -05002226 HashWorking[0] = HashWorking[78] = *pwwnn++;
2227 HashWorking[1] = HashWorking[79] = *pwwnn;
2228
2229 for (t = 0; t < 7; t++)
2230 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2231
2232 lpfc_sha_init(hbainit);
2233 lpfc_sha_iterate(hbainit, HashWorking);
2234 kfree(HashWorking);
2235}
2236
James Smarte59058c2008-08-24 21:49:00 -04002237/**
James Smart3621a712009-04-06 18:47:14 -04002238 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002239 * @vport: pointer to a virtual N_Port data structure.
2240 *
2241 * This routine performs the necessary cleanups before deleting the @vport.
2242 * It invokes the discovery state machine to perform necessary state
2243 * transitions and to release the ndlps associated with the @vport. Note,
2244 * the physical port is treated as @vport 0.
2245 **/
James Smart87af33f2007-10-27 13:37:43 -04002246void
James Smart2e0fef82007-06-17 19:56:36 -05002247lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002248{
James Smart87af33f2007-10-27 13:37:43 -04002249 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002250 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002251 int i = 0;
dea31012005-04-17 16:05:31 -05002252
James Smart87af33f2007-10-27 13:37:43 -04002253 if (phba->link_state > LPFC_LINK_DOWN)
2254 lpfc_port_link_failure(vport);
2255
2256 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002257 if (!NLP_CHK_NODE_ACT(ndlp)) {
2258 ndlp = lpfc_enable_node(vport, ndlp,
2259 NLP_STE_UNUSED_NODE);
2260 if (!ndlp)
2261 continue;
2262 spin_lock_irq(&phba->ndlp_lock);
2263 NLP_SET_FREE_REQ(ndlp);
2264 spin_unlock_irq(&phba->ndlp_lock);
2265 /* Trigger the release of the ndlp memory */
2266 lpfc_nlp_put(ndlp);
2267 continue;
2268 }
2269 spin_lock_irq(&phba->ndlp_lock);
2270 if (NLP_CHK_FREE_REQ(ndlp)) {
2271 /* The ndlp should not be in memory free mode already */
2272 spin_unlock_irq(&phba->ndlp_lock);
2273 continue;
2274 } else
2275 /* Indicate request for freeing ndlp memory */
2276 NLP_SET_FREE_REQ(ndlp);
2277 spin_unlock_irq(&phba->ndlp_lock);
2278
James Smart58da1ff2008-04-07 10:15:56 -04002279 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2280 ndlp->nlp_DID == Fabric_DID) {
2281 /* Just free up ndlp with Fabric_DID for vports */
2282 lpfc_nlp_put(ndlp);
2283 continue;
2284 }
2285
James Smart87af33f2007-10-27 13:37:43 -04002286 if (ndlp->nlp_type & NLP_FABRIC)
2287 lpfc_disc_state_machine(vport, ndlp, NULL,
2288 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002289
James Smart87af33f2007-10-27 13:37:43 -04002290 lpfc_disc_state_machine(vport, ndlp, NULL,
2291 NLP_EVT_DEVICE_RM);
James Smart495a7142008-06-14 22:52:59 -04002292
James Smart87af33f2007-10-27 13:37:43 -04002293 }
2294
James Smarta8adb832007-10-27 13:37:53 -04002295 /* At this point, ALL ndlp's should be gone
2296 * because of the previous NLP_EVT_DEVICE_RM.
2297 * Lets wait for this to happen, if needed.
2298 */
James Smart87af33f2007-10-27 13:37:43 -04002299 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002300 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04002301 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04002302 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002303 list_for_each_entry_safe(ndlp, next_ndlp,
2304 &vport->fc_nodes, nlp_listp) {
2305 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2306 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04002307 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05002308 "usgmap:x%x refcnt:%d\n",
2309 ndlp->nlp_DID, (void *)ndlp,
2310 ndlp->nlp_usg_map,
2311 atomic_read(
2312 &ndlp->kref.refcount));
2313 }
James Smarta8adb832007-10-27 13:37:53 -04002314 break;
James Smart87af33f2007-10-27 13:37:43 -04002315 }
James Smarta8adb832007-10-27 13:37:53 -04002316
2317 /* Wait for any activity on ndlps to settle */
2318 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002319 }
James Smart1151e3e2011-02-16 12:39:35 -05002320 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002321}
2322
James Smarte59058c2008-08-24 21:49:00 -04002323/**
James Smart3621a712009-04-06 18:47:14 -04002324 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002325 * @vport: pointer to a virtual N_Port data structure.
2326 *
2327 * This routine stops all the timers associated with a @vport. This function
2328 * is invoked before disabling or deleting a @vport. Note that the physical
2329 * port is treated as @vport 0.
2330 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002331void
2332lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002333{
James Smart92d7f7b2007-06-17 19:56:38 -05002334 del_timer_sync(&vport->els_tmofunc);
2335 del_timer_sync(&vport->fc_fdmitmo);
James Smart92494142011-02-16 12:39:44 -05002336 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002337 lpfc_can_disctmo(vport);
2338 return;
dea31012005-04-17 16:05:31 -05002339}
2340
James Smarte59058c2008-08-24 21:49:00 -04002341/**
James Smartecfd03c2010-02-12 14:41:27 -05002342 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2343 * @phba: pointer to lpfc hba data structure.
2344 *
2345 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2346 * caller of this routine should already hold the host lock.
2347 **/
2348void
2349__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2350{
James Smart5ac6b302010-10-22 11:05:36 -04002351 /* Clear pending FCF rediscovery wait flag */
2352 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2353
James Smartecfd03c2010-02-12 14:41:27 -05002354 /* Now, try to stop the timer */
2355 del_timer(&phba->fcf.redisc_wait);
2356}
2357
2358/**
2359 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2360 * @phba: pointer to lpfc hba data structure.
2361 *
2362 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2363 * checks whether the FCF rediscovery wait timer is pending with the host
2364 * lock held before proceeding with disabling the timer and clearing the
2365 * wait timer pendig flag.
2366 **/
2367void
2368lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2369{
2370 spin_lock_irq(&phba->hbalock);
2371 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2372 /* FCF rediscovery timer already fired or stopped */
2373 spin_unlock_irq(&phba->hbalock);
2374 return;
2375 }
2376 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002377 /* Clear failover in progress flags */
2378 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002379 spin_unlock_irq(&phba->hbalock);
2380}
2381
2382/**
James Smart3772a992009-05-22 14:50:54 -04002383 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002384 * @phba: pointer to lpfc hba data structure.
2385 *
2386 * This routine stops all the timers associated with a HBA. This function is
2387 * invoked before either putting a HBA offline or unloading the driver.
2388 **/
James Smart3772a992009-05-22 14:50:54 -04002389void
2390lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002391{
James Smart51ef4c22007-08-02 11:10:31 -04002392 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05002393 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002394 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002395 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002396 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002397 if (phba->sli_rev == LPFC_SLI_REV4) {
2398 del_timer_sync(&phba->rrq_tmr);
2399 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2400 }
James Smart3772a992009-05-22 14:50:54 -04002401 phba->hb_outstanding = 0;
2402
2403 switch (phba->pci_dev_grp) {
2404 case LPFC_PCI_DEV_LP:
2405 /* Stop any LightPulse device specific driver timers */
2406 del_timer_sync(&phba->fcp_poll_timer);
2407 break;
2408 case LPFC_PCI_DEV_OC:
2409 /* Stop any OneConnect device sepcific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002410 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002411 break;
2412 default:
2413 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2414 "0297 Invalid device group (x%x)\n",
2415 phba->pci_dev_grp);
2416 break;
2417 }
James Smart2e0fef82007-06-17 19:56:36 -05002418 return;
dea31012005-04-17 16:05:31 -05002419}
2420
James Smarte59058c2008-08-24 21:49:00 -04002421/**
James Smart3621a712009-04-06 18:47:14 -04002422 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002423 * @phba: pointer to lpfc hba data structure.
2424 *
2425 * This routine marks a HBA's management interface as blocked. Once the HBA's
2426 * management interface is marked as blocked, all the user space access to
2427 * the HBA, whether they are from sysfs interface or libdfc interface will
2428 * all be blocked. The HBA is set to block the management interface when the
2429 * driver prepares the HBA interface for online or offline.
2430 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01002431static void
2432lpfc_block_mgmt_io(struct lpfc_hba * phba)
2433{
2434 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04002435 uint8_t actcmd = MBX_HEARTBEAT;
2436 unsigned long timeout;
2437
Adrian Bunka6ababd2007-11-05 18:07:33 +01002438
2439 spin_lock_irqsave(&phba->hbalock, iflag);
2440 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart6e7288d2010-06-07 15:23:35 -04002441 if (phba->sli.mbox_active)
2442 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
Adrian Bunka6ababd2007-11-05 18:07:33 +01002443 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart6e7288d2010-06-07 15:23:35 -04002444 /* Determine how long we might wait for the active mailbox
2445 * command to be gracefully completed by firmware.
2446 */
2447 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
2448 jiffies;
2449 /* Wait for the outstnading mailbox command to complete */
2450 while (phba->sli.mbox_active) {
2451 /* Check active mailbox complete status every 2ms */
2452 msleep(2);
2453 if (time_after(jiffies, timeout)) {
2454 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2455 "2813 Mgmt IO is Blocked %x "
2456 "- mbox cmd %x still active\n",
2457 phba->sli.sli_flag, actcmd);
2458 break;
2459 }
2460 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002461}
2462
James Smarte59058c2008-08-24 21:49:00 -04002463/**
James Smart3621a712009-04-06 18:47:14 -04002464 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04002465 * @phba: pointer to lpfc hba data structure.
2466 *
2467 * This routine initializes the HBA and brings a HBA online. During this
2468 * process, the management interface is blocked to prevent user space access
2469 * to the HBA interfering with the driver initialization.
2470 *
2471 * Return codes
2472 * 0 - successful
2473 * 1 - failed
2474 **/
dea31012005-04-17 16:05:31 -05002475int
James Smart2e0fef82007-06-17 19:56:36 -05002476lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002477{
Julia Lawall372bd282008-12-16 16:15:08 +01002478 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04002479 struct lpfc_vport **vports;
2480 int i;
James Smart2e0fef82007-06-17 19:56:36 -05002481
dea31012005-04-17 16:05:31 -05002482 if (!phba)
2483 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01002484 vport = phba->pport;
dea31012005-04-17 16:05:31 -05002485
James Smart2e0fef82007-06-17 19:56:36 -05002486 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05002487 return 0;
2488
James Smarted957682007-06-17 19:56:37 -05002489 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002490 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05002491
James Smart46fa3112007-04-25 09:51:45 -04002492 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002493
James Smart46fa3112007-04-25 09:51:45 -04002494 if (!lpfc_sli_queue_setup(phba)) {
2495 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002496 return 1;
James Smart46fa3112007-04-25 09:51:45 -04002497 }
2498
James Smartda0436e2009-05-22 14:51:39 -04002499 if (phba->sli_rev == LPFC_SLI_REV4) {
2500 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
2501 lpfc_unblock_mgmt_io(phba);
2502 return 1;
2503 }
2504 } else {
2505 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
2506 lpfc_unblock_mgmt_io(phba);
2507 return 1;
2508 }
James Smart46fa3112007-04-25 09:51:45 -04002509 }
dea31012005-04-17 16:05:31 -05002510
James Smart549e55c2007-08-02 11:09:51 -04002511 vports = lpfc_create_vport_work_array(phba);
2512 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002513 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002514 struct Scsi_Host *shost;
2515 shost = lpfc_shost_from_vport(vports[i]);
2516 spin_lock_irq(shost->host_lock);
2517 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
2518 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2519 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart1c6834a2009-07-19 10:01:26 -04002520 if (phba->sli_rev == LPFC_SLI_REV4)
2521 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart549e55c2007-08-02 11:09:51 -04002522 spin_unlock_irq(shost->host_lock);
2523 }
James Smart09372822008-01-11 01:52:54 -05002524 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002525
James Smart46fa3112007-04-25 09:51:45 -04002526 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002527 return 0;
2528}
2529
James Smarte59058c2008-08-24 21:49:00 -04002530/**
James Smart3621a712009-04-06 18:47:14 -04002531 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04002532 * @phba: pointer to lpfc hba data structure.
2533 *
2534 * This routine marks a HBA's management interface as not blocked. Once the
2535 * HBA's management interface is marked as not blocked, all the user space
2536 * access to the HBA, whether they are from sysfs interface or libdfc
2537 * interface will be allowed. The HBA is set to block the management interface
2538 * when the driver prepares the HBA interface for online or offline and then
2539 * set to unblock the management interface afterwards.
2540 **/
James Smart46fa3112007-04-25 09:51:45 -04002541void
James Smart46fa3112007-04-25 09:51:45 -04002542lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
2543{
2544 unsigned long iflag;
2545
James Smart2e0fef82007-06-17 19:56:36 -05002546 spin_lock_irqsave(&phba->hbalock, iflag);
2547 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
2548 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04002549}
2550
James Smarte59058c2008-08-24 21:49:00 -04002551/**
James Smart3621a712009-04-06 18:47:14 -04002552 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04002553 * @phba: pointer to lpfc hba data structure.
2554 *
2555 * This routine is invoked to prepare a HBA to be brought offline. It performs
2556 * unregistration login to all the nodes on all vports and flushes the mailbox
2557 * queue to make it ready to be brought offline.
2558 **/
James Smart46fa3112007-04-25 09:51:45 -04002559void
2560lpfc_offline_prep(struct lpfc_hba * phba)
2561{
James Smart2e0fef82007-06-17 19:56:36 -05002562 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04002563 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04002564 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05002565 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04002566 int i;
dea31012005-04-17 16:05:31 -05002567
James Smart2e0fef82007-06-17 19:56:36 -05002568 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002569 return;
dea31012005-04-17 16:05:31 -05002570
James Smart46fa3112007-04-25 09:51:45 -04002571 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002572
2573 lpfc_linkdown(phba);
2574
James Smart87af33f2007-10-27 13:37:43 -04002575 /* Issue an unreg_login to all nodes on all vports */
2576 vports = lpfc_create_vport_work_array(phba);
2577 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04002578 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04002579 if (vports[i]->load_flag & FC_UNLOADING)
2580 continue;
James Smart72100cc2010-02-12 14:43:01 -05002581 shost = lpfc_shost_from_vport(vports[i]);
2582 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05002583 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002584 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2585 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05002586 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05002587
James Smart87af33f2007-10-27 13:37:43 -04002588 shost = lpfc_shost_from_vport(vports[i]);
2589 list_for_each_entry_safe(ndlp, next_ndlp,
2590 &vports[i]->fc_nodes,
2591 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002592 if (!NLP_CHK_NODE_ACT(ndlp))
2593 continue;
James Smart87af33f2007-10-27 13:37:43 -04002594 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2595 continue;
2596 if (ndlp->nlp_type & NLP_FABRIC) {
2597 lpfc_disc_state_machine(vports[i], ndlp,
2598 NULL, NLP_EVT_DEVICE_RECOVERY);
2599 lpfc_disc_state_machine(vports[i], ndlp,
2600 NULL, NLP_EVT_DEVICE_RM);
2601 }
2602 spin_lock_irq(shost->host_lock);
2603 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2604 spin_unlock_irq(shost->host_lock);
2605 lpfc_unreg_rpi(vports[i], ndlp);
2606 }
2607 }
2608 }
James Smart09372822008-01-11 01:52:54 -05002609 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002610
James Smart04c68492009-05-22 14:52:52 -04002611 lpfc_sli_mbox_sys_shutdown(phba);
James Smart46fa3112007-04-25 09:51:45 -04002612}
2613
James Smarte59058c2008-08-24 21:49:00 -04002614/**
James Smart3621a712009-04-06 18:47:14 -04002615 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04002616 * @phba: pointer to lpfc hba data structure.
2617 *
2618 * This routine actually brings a HBA offline. It stops all the timers
2619 * associated with the HBA, brings down the SLI layer, and eventually
2620 * marks the HBA as in offline state for the upper layer protocol.
2621 **/
James Smart46fa3112007-04-25 09:51:45 -04002622void
James Smart2e0fef82007-06-17 19:56:36 -05002623lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04002624{
James Smart549e55c2007-08-02 11:09:51 -04002625 struct Scsi_Host *shost;
2626 struct lpfc_vport **vports;
2627 int i;
James Smart46fa3112007-04-25 09:51:45 -04002628
James Smart549e55c2007-08-02 11:09:51 -04002629 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002630 return;
James Smart688a8862006-07-06 15:49:56 -04002631
James Smartda0436e2009-05-22 14:51:39 -04002632 /* stop port and all timers associated with this hba */
2633 lpfc_stop_port(phba);
James Smart51ef4c22007-08-02 11:10:31 -04002634 vports = lpfc_create_vport_work_array(phba);
2635 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002636 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04002637 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05002638 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05002639 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002640 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05002641 /* Bring down the SLI Layer and cleanup. The HBA is offline
2642 now. */
2643 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002644 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04002645 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05002646 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04002647 vports = lpfc_create_vport_work_array(phba);
2648 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002649 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002650 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04002651 spin_lock_irq(shost->host_lock);
2652 vports[i]->work_port_events = 0;
2653 vports[i]->fc_flag |= FC_OFFLINE_MODE;
2654 spin_unlock_irq(shost->host_lock);
2655 }
James Smart09372822008-01-11 01:52:54 -05002656 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002657}
2658
James Smarte59058c2008-08-24 21:49:00 -04002659/**
James Smart3621a712009-04-06 18:47:14 -04002660 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04002661 * @phba: pointer to lpfc hba data structure.
2662 *
2663 * This routine is to free all the SCSI buffers and IOCBs from the driver
2664 * list back to kernel. It is called from lpfc_pci_remove_one to free
2665 * the internal resources before the device is removed from the system.
2666 *
2667 * Return codes
2668 * 0 - successful (for now, it always returns 0)
2669 **/
dea31012005-04-17 16:05:31 -05002670static int
James Smart2e0fef82007-06-17 19:56:36 -05002671lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002672{
2673 struct lpfc_scsi_buf *sb, *sb_next;
2674 struct lpfc_iocbq *io, *io_next;
2675
James Smart2e0fef82007-06-17 19:56:36 -05002676 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002677 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smart1c6f4ef52009-11-18 15:40:49 -05002678 spin_lock(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05002679 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
2680 list_del(&sb->list);
2681 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05002682 sb->dma_handle);
dea31012005-04-17 16:05:31 -05002683 kfree(sb);
2684 phba->total_scsi_bufs--;
2685 }
James Smart1c6f4ef52009-11-18 15:40:49 -05002686 spin_unlock(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05002687
2688 /* Release all the lpfc_iocbq entries maintained by this host. */
2689 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
2690 list_del(&io->list);
2691 kfree(io);
2692 phba->total_iocbq_bufs--;
2693 }
James Smart6d368e52011-05-24 11:44:12 -04002694
James Smart2e0fef82007-06-17 19:56:36 -05002695 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002696 return 0;
2697}
2698
James Smarte59058c2008-08-24 21:49:00 -04002699/**
James Smart3621a712009-04-06 18:47:14 -04002700 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04002701 * @phba: pointer to lpfc hba data structure.
2702 * @instance: a unique integer ID to this FC port.
2703 * @dev: pointer to the device data structure.
2704 *
2705 * This routine creates a FC port for the upper layer protocol. The FC port
2706 * can be created on top of either a physical port or a virtual port provided
2707 * by the HBA. This routine also allocates a SCSI host data structure (shost)
2708 * and associates the FC port created before adding the shost into the SCSI
2709 * layer.
2710 *
2711 * Return codes
2712 * @vport - pointer to the virtual N_Port data structure.
2713 * NULL - port create failed.
2714 **/
James Smart2e0fef82007-06-17 19:56:36 -05002715struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04002716lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04002717{
James Smart2e0fef82007-06-17 19:56:36 -05002718 struct lpfc_vport *vport;
2719 struct Scsi_Host *shost;
2720 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04002721
James Smart3de2a652007-08-02 11:09:59 -04002722 if (dev != &phba->pcidev->dev)
2723 shost = scsi_host_alloc(&lpfc_vport_template,
2724 sizeof(struct lpfc_vport));
2725 else
2726 shost = scsi_host_alloc(&lpfc_template,
2727 sizeof(struct lpfc_vport));
James Smart2e0fef82007-06-17 19:56:36 -05002728 if (!shost)
2729 goto out;
James Smart47a86172007-04-25 09:53:22 -04002730
James Smart2e0fef82007-06-17 19:56:36 -05002731 vport = (struct lpfc_vport *) shost->hostdata;
2732 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05002733 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05002734 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05002735 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04002736
James Smart3de2a652007-08-02 11:09:59 -04002737 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002738 shost->unique_id = instance;
2739 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04002740 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05002741 shost->this_id = -1;
2742 shost->max_cmd_len = 16;
James Smartda0436e2009-05-22 14:51:39 -04002743 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05002744 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04002745 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smartda0436e2009-05-22 14:51:39 -04002746 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
2747 }
James Smart81301a92008-12-04 22:39:46 -05002748
James Smart47a86172007-04-25 09:53:22 -04002749 /*
James Smart2e0fef82007-06-17 19:56:36 -05002750 * Set initial can_queue value since 0 is no longer supported and
2751 * scsi_add_host will fail. This will be adjusted later based on the
2752 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04002753 */
James Smart2e0fef82007-06-17 19:56:36 -05002754 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04002755 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05002756 shost->transportt = lpfc_vport_transport_template;
2757 vport->port_type = LPFC_NPIV_PORT;
2758 } else {
2759 shost->transportt = lpfc_transport_template;
2760 vport->port_type = LPFC_PHYSICAL_PORT;
2761 }
James Smart47a86172007-04-25 09:53:22 -04002762
James Smart2e0fef82007-06-17 19:56:36 -05002763 /* Initialize all internally managed lists. */
2764 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04002765 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05002766 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04002767
James Smart2e0fef82007-06-17 19:56:36 -05002768 init_timer(&vport->fc_disctmo);
2769 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05002770 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04002771
James Smart2e0fef82007-06-17 19:56:36 -05002772 init_timer(&vport->fc_fdmitmo);
2773 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
James Smart92d7f7b2007-06-17 19:56:38 -05002774 vport->fc_fdmitmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04002775
James Smart2e0fef82007-06-17 19:56:36 -05002776 init_timer(&vport->els_tmofunc);
2777 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05002778 vport->els_tmofunc.data = (unsigned long)vport;
James Smart92494142011-02-16 12:39:44 -05002779
2780 init_timer(&vport->delayed_disc_tmo);
2781 vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
2782 vport->delayed_disc_tmo.data = (unsigned long)vport;
2783
James Bottomleyd139b9b2009-11-05 13:33:12 -06002784 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05002785 if (error)
2786 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04002787
James Smart549e55c2007-08-02 11:09:51 -04002788 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05002789 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04002790 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05002791 return vport;
James Smart47a86172007-04-25 09:53:22 -04002792
James Smart2e0fef82007-06-17 19:56:36 -05002793out_put_shost:
2794 scsi_host_put(shost);
2795out:
2796 return NULL;
James Smart47a86172007-04-25 09:53:22 -04002797}
2798
James Smarte59058c2008-08-24 21:49:00 -04002799/**
James Smart3621a712009-04-06 18:47:14 -04002800 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04002801 * @vport: pointer to an lpfc virtual N_Port data structure.
2802 *
2803 * This routine destroys a FC port from the upper layer protocol. All the
2804 * resources associated with the port are released.
2805 **/
James Smart2e0fef82007-06-17 19:56:36 -05002806void
2807destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04002808{
James Smart92d7f7b2007-06-17 19:56:38 -05002809 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2810 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04002811
James Smart858c9f62007-06-17 19:56:39 -05002812 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05002813 fc_remove_host(shost);
2814 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04002815
James Smart92d7f7b2007-06-17 19:56:38 -05002816 spin_lock_irq(&phba->hbalock);
2817 list_del_init(&vport->listentry);
2818 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04002819
James Smart92d7f7b2007-06-17 19:56:38 -05002820 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04002821 return;
James Smart47a86172007-04-25 09:53:22 -04002822}
2823
James Smarte59058c2008-08-24 21:49:00 -04002824/**
James Smart3621a712009-04-06 18:47:14 -04002825 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04002826 *
2827 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
2828 * uses the kernel idr facility to perform the task.
2829 *
2830 * Return codes:
2831 * instance - a unique integer ID allocated as the new instance.
2832 * -1 - lpfc get instance failed.
2833 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002834int
2835lpfc_get_instance(void)
2836{
2837 int instance = 0;
2838
2839 /* Assign an unused number */
2840 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
2841 return -1;
2842 if (idr_get_new(&lpfc_hba_index, NULL, &instance))
2843 return -1;
2844 return instance;
2845}
2846
James Smarte59058c2008-08-24 21:49:00 -04002847/**
James Smart3621a712009-04-06 18:47:14 -04002848 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04002849 * @shost: pointer to SCSI host data structure.
2850 * @time: elapsed time of the scan in jiffies.
2851 *
2852 * This routine is called by the SCSI layer with a SCSI host to determine
2853 * whether the scan host is finished.
2854 *
2855 * Note: there is no scan_start function as adapter initialization will have
2856 * asynchronously kicked off the link initialization.
2857 *
2858 * Return codes
2859 * 0 - SCSI host scan is not over yet.
2860 * 1 - SCSI host scan is over.
2861 **/
James Smart47a86172007-04-25 09:53:22 -04002862int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
2863{
James Smart2e0fef82007-06-17 19:56:36 -05002864 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2865 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05002866 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04002867
James Smart858c9f62007-06-17 19:56:39 -05002868 spin_lock_irq(shost->host_lock);
2869
James Smart51ef4c22007-08-02 11:10:31 -04002870 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05002871 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002872 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05002873 }
James Smart2e0fef82007-06-17 19:56:36 -05002874 if (time >= 30 * HZ) {
2875 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002876 "0461 Scanning longer than 30 "
2877 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05002878 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002879 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002880 }
2881 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
2882 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002883 "0465 Link down longer than 15 "
2884 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05002885 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05002886 goto finished;
James Smart47a86172007-04-25 09:53:22 -04002887 }
2888
James Smart2e0fef82007-06-17 19:56:36 -05002889 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05002890 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002891 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05002892 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002893 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
James Smart858c9f62007-06-17 19:56:39 -05002894 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002895 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05002896 goto finished;
2897
2898 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002899
2900finished:
James Smart858c9f62007-06-17 19:56:39 -05002901 spin_unlock_irq(shost->host_lock);
2902 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05002903}
2904
James Smarte59058c2008-08-24 21:49:00 -04002905/**
James Smart3621a712009-04-06 18:47:14 -04002906 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04002907 * @shost: pointer to SCSI host data structure.
2908 *
2909 * This routine initializes a given SCSI host attributes on a FC port. The
2910 * SCSI host can be either on top of a physical port or a virtual port.
2911 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002912void lpfc_host_attrib_init(struct Scsi_Host *shost)
2913{
2914 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2915 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04002916 /*
James Smart2e0fef82007-06-17 19:56:36 -05002917 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04002918 */
2919
James Smart2e0fef82007-06-17 19:56:36 -05002920 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
2921 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04002922 fc_host_supported_classes(shost) = FC_COS_CLASS3;
2923
2924 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05002925 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04002926 fc_host_supported_fc4s(shost)[2] = 1;
2927 fc_host_supported_fc4s(shost)[7] = 1;
2928
James Smart92d7f7b2007-06-17 19:56:38 -05002929 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
2930 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04002931
2932 fc_host_supported_speeds(shost) = 0;
James Smart88a2cfb2011-07-22 18:36:33 -04002933 if (phba->lmt & LMT_16Gb)
2934 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
James Smart47a86172007-04-25 09:53:22 -04002935 if (phba->lmt & LMT_10Gb)
2936 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04002937 if (phba->lmt & LMT_8Gb)
2938 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04002939 if (phba->lmt & LMT_4Gb)
2940 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
2941 if (phba->lmt & LMT_2Gb)
2942 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
2943 if (phba->lmt & LMT_1Gb)
2944 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
2945
2946 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05002947 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
2948 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04002949
Mike Christie0af5d702010-09-15 16:52:31 -05002950 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
2951
James Smart47a86172007-04-25 09:53:22 -04002952 /* This value is also unchanging */
2953 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05002954 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04002955 fc_host_active_fc4s(shost)[2] = 1;
2956 fc_host_active_fc4s(shost)[7] = 1;
2957
James Smart92d7f7b2007-06-17 19:56:38 -05002958 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04002959 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04002960 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04002961 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04002962}
dea31012005-04-17 16:05:31 -05002963
James Smarte59058c2008-08-24 21:49:00 -04002964/**
James Smartda0436e2009-05-22 14:51:39 -04002965 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04002966 * @phba: pointer to lpfc hba data structure.
2967 *
James Smartda0436e2009-05-22 14:51:39 -04002968 * This routine is invoked to stop an SLI3 device port, it stops the device
2969 * from generating interrupts and stops the device driver's timers for the
2970 * device.
James Smarte59058c2008-08-24 21:49:00 -04002971 **/
James Smartdb2378e2008-02-08 18:49:51 -05002972static void
James Smartda0436e2009-05-22 14:51:39 -04002973lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05002974{
James Smartda0436e2009-05-22 14:51:39 -04002975 /* Clear all interrupt enable conditions */
2976 writel(0, phba->HCregaddr);
2977 readl(phba->HCregaddr); /* flush */
2978 /* Clear all pending interrupts */
2979 writel(0xffffffff, phba->HAregaddr);
2980 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04002981
James Smartda0436e2009-05-22 14:51:39 -04002982 /* Reset some HBA SLI setup states */
2983 lpfc_stop_hba_timers(phba);
2984 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05002985}
2986
James Smarte59058c2008-08-24 21:49:00 -04002987/**
James Smartda0436e2009-05-22 14:51:39 -04002988 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05002989 * @phba: pointer to lpfc hba data structure.
2990 *
James Smartda0436e2009-05-22 14:51:39 -04002991 * This routine is invoked to stop an SLI4 device port, it stops the device
2992 * from generating interrupts and stops the device driver's timers for the
2993 * device.
2994 **/
2995static void
2996lpfc_stop_port_s4(struct lpfc_hba *phba)
2997{
2998 /* Reset some HBA SLI4 setup states */
2999 lpfc_stop_hba_timers(phba);
3000 phba->pport->work_port_events = 0;
3001 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04003002}
3003
3004/**
3005 * lpfc_stop_port - Wrapper function for stopping hba port
3006 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05003007 *
James Smartda0436e2009-05-22 14:51:39 -04003008 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3009 * the API jump table function pointer from the lpfc_hba struct.
3010 **/
3011void
3012lpfc_stop_port(struct lpfc_hba *phba)
3013{
3014 phba->lpfc_stop_port(phba);
3015}
3016
3017/**
James Smartecfd03c2010-02-12 14:41:27 -05003018 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3019 * @phba: Pointer to hba for which this call is being executed.
3020 *
3021 * This routine starts the timer waiting for the FCF rediscovery to complete.
3022 **/
3023void
3024lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
3025{
3026 unsigned long fcf_redisc_wait_tmo =
3027 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
3028 /* Start fcf rediscovery wait period timer */
3029 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
3030 spin_lock_irq(&phba->hbalock);
3031 /* Allow action to new fcf asynchronous event */
3032 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
3033 /* Mark the FCF rediscovery pending state */
3034 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
3035 spin_unlock_irq(&phba->hbalock);
3036}
3037
3038/**
3039 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
3040 * @ptr: Map to lpfc_hba data structure pointer.
3041 *
3042 * This routine is invoked when waiting for FCF table rediscover has been
3043 * timed out. If new FCF record(s) has (have) been discovered during the
3044 * wait period, a new FCF event shall be added to the FCOE async event
3045 * list, and then worker thread shall be waked up for processing from the
3046 * worker thread context.
3047 **/
3048void
3049lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
3050{
3051 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
3052
3053 /* Don't send FCF rediscovery event if timer cancelled */
3054 spin_lock_irq(&phba->hbalock);
3055 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
3056 spin_unlock_irq(&phba->hbalock);
3057 return;
3058 }
3059 /* Clear FCF rediscovery timer pending flag */
3060 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
3061 /* FCF rediscovery event to worker thread */
3062 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
3063 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003064 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04003065 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05003066 /* wake up worker thread */
3067 lpfc_worker_wake_up(phba);
3068}
3069
3070/**
James Smartda0436e2009-05-22 14:51:39 -04003071 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
3072 * @phba: pointer to lpfc hba data structure.
3073 * @acqe_link: pointer to the async link completion queue entry.
3074 *
3075 * This routine is to parse the SLI4 link-attention link fault code and
3076 * translate it into the base driver's read link attention mailbox command
3077 * status.
3078 *
3079 * Return: Link-attention status in terms of base driver's coding.
3080 **/
3081static uint16_t
3082lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
3083 struct lpfc_acqe_link *acqe_link)
3084{
3085 uint16_t latt_fault;
3086
3087 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
3088 case LPFC_ASYNC_LINK_FAULT_NONE:
3089 case LPFC_ASYNC_LINK_FAULT_LOCAL:
3090 case LPFC_ASYNC_LINK_FAULT_REMOTE:
3091 latt_fault = 0;
3092 break;
3093 default:
3094 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3095 "0398 Invalid link fault code: x%x\n",
3096 bf_get(lpfc_acqe_link_fault, acqe_link));
3097 latt_fault = MBXERR_ERROR;
3098 break;
3099 }
3100 return latt_fault;
3101}
3102
3103/**
3104 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
3105 * @phba: pointer to lpfc hba data structure.
3106 * @acqe_link: pointer to the async link completion queue entry.
3107 *
3108 * This routine is to parse the SLI4 link attention type and translate it
3109 * into the base driver's link attention type coding.
3110 *
3111 * Return: Link attention type in terms of base driver's coding.
3112 **/
3113static uint8_t
3114lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
3115 struct lpfc_acqe_link *acqe_link)
3116{
3117 uint8_t att_type;
3118
3119 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
3120 case LPFC_ASYNC_LINK_STATUS_DOWN:
3121 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05003122 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04003123 break;
3124 case LPFC_ASYNC_LINK_STATUS_UP:
3125 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05003126 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003127 break;
3128 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05003129 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04003130 break;
3131 default:
3132 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3133 "0399 Invalid link attention type: x%x\n",
3134 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003135 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003136 break;
3137 }
3138 return att_type;
3139}
3140
3141/**
3142 * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
3143 * @phba: pointer to lpfc hba data structure.
3144 * @acqe_link: pointer to the async link completion queue entry.
3145 *
3146 * This routine is to parse the SLI4 link-attention link speed and translate
3147 * it into the base driver's link-attention link speed coding.
3148 *
3149 * Return: Link-attention link speed in terms of base driver's coding.
3150 **/
3151static uint8_t
3152lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba,
3153 struct lpfc_acqe_link *acqe_link)
3154{
3155 uint8_t link_speed;
3156
3157 switch (bf_get(lpfc_acqe_link_speed, acqe_link)) {
3158 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smartda0436e2009-05-22 14:51:39 -04003159 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smartda0436e2009-05-22 14:51:39 -04003160 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart76a95d72010-11-20 23:11:48 -05003161 link_speed = LPFC_LINK_SPEED_UNKNOWN;
James Smartda0436e2009-05-22 14:51:39 -04003162 break;
3163 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart76a95d72010-11-20 23:11:48 -05003164 link_speed = LPFC_LINK_SPEED_1GHZ;
James Smartda0436e2009-05-22 14:51:39 -04003165 break;
3166 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart76a95d72010-11-20 23:11:48 -05003167 link_speed = LPFC_LINK_SPEED_10GHZ;
James Smartda0436e2009-05-22 14:51:39 -04003168 break;
3169 default:
3170 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3171 "0483 Invalid link-attention link speed: x%x\n",
3172 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003173 link_speed = LPFC_LINK_SPEED_UNKNOWN;
James Smartda0436e2009-05-22 14:51:39 -04003174 break;
3175 }
3176 return link_speed;
3177}
3178
3179/**
James Smart70f3c072010-12-15 17:57:33 -05003180 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04003181 * @phba: pointer to lpfc hba data structure.
3182 * @acqe_link: pointer to the async link completion queue entry.
3183 *
James Smart70f3c072010-12-15 17:57:33 -05003184 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04003185 **/
3186static void
3187lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
3188 struct lpfc_acqe_link *acqe_link)
3189{
3190 struct lpfc_dmabuf *mp;
3191 LPFC_MBOXQ_t *pmb;
3192 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05003193 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04003194 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05003195 int rc;
James Smartda0436e2009-05-22 14:51:39 -04003196
3197 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05003198 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04003199 return;
James Smart32b97932009-07-19 10:01:21 -04003200 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04003201 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3202 if (!pmb) {
3203 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3204 "0395 The mboxq allocation failed\n");
3205 return;
3206 }
3207 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3208 if (!mp) {
3209 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3210 "0396 The lpfc_dmabuf allocation failed\n");
3211 goto out_free_pmb;
3212 }
3213 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
3214 if (!mp->virt) {
3215 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3216 "0397 The mbuf allocation failed\n");
3217 goto out_free_dmabuf;
3218 }
3219
3220 /* Cleanup any outstanding ELS commands */
3221 lpfc_els_flush_all_cmd(phba);
3222
3223 /* Block ELS IOCBs until we have done process link event */
3224 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
3225
3226 /* Update link event statistics */
3227 phba->sli.slistat.link_event++;
3228
James Smart76a95d72010-11-20 23:11:48 -05003229 /* Create lpfc_handle_latt mailbox command from link ACQE */
3230 lpfc_read_topology(phba, pmb, mp);
3231 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04003232 pmb->vport = phba->pport;
3233
James Smartda0436e2009-05-22 14:51:39 -04003234 /* Keep the link status for extra SLI4 state machine reference */
3235 phba->sli4_hba.link_state.speed =
3236 bf_get(lpfc_acqe_link_speed, acqe_link);
3237 phba->sli4_hba.link_state.duplex =
3238 bf_get(lpfc_acqe_link_duplex, acqe_link);
3239 phba->sli4_hba.link_state.status =
3240 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05003241 phba->sli4_hba.link_state.type =
3242 bf_get(lpfc_acqe_link_type, acqe_link);
3243 phba->sli4_hba.link_state.number =
3244 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04003245 phba->sli4_hba.link_state.fault =
3246 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05003247 phba->sli4_hba.link_state.logical_speed =
James Smart70f3c072010-12-15 17:57:33 -05003248 bf_get(lpfc_acqe_logical_link_speed, acqe_link);
3249 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04003250 "2900 Async FC/FCoE Link event - Speed:%dGBit "
3251 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
3252 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05003253 phba->sli4_hba.link_state.speed,
3254 phba->sli4_hba.link_state.topology,
3255 phba->sli4_hba.link_state.status,
3256 phba->sli4_hba.link_state.type,
3257 phba->sli4_hba.link_state.number,
3258 phba->sli4_hba.link_state.logical_speed * 10,
3259 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05003260 /*
3261 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
3262 * topology info. Note: Optional for non FC-AL ports.
3263 */
3264 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3265 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3266 if (rc == MBX_NOT_FINISHED)
3267 goto out_free_dmabuf;
3268 return;
3269 }
3270 /*
3271 * For FCoE Mode: fill in all the topology information we need and call
3272 * the READ_TOPOLOGY completion routine to continue without actually
3273 * sending the READ_TOPOLOGY mailbox command to the port.
3274 */
3275 /* Parse and translate status field */
3276 mb = &pmb->u.mb;
3277 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
3278
3279 /* Parse and translate link attention fields */
3280 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3281 la->eventTag = acqe_link->event_tag;
3282 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
3283 bf_set(lpfc_mbx_read_top_link_spd, la,
3284 lpfc_sli4_parse_latt_link_speed(phba, acqe_link));
3285
3286 /* Fake the the following irrelvant fields */
3287 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
3288 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
3289 bf_set(lpfc_mbx_read_top_il, la, 0);
3290 bf_set(lpfc_mbx_read_top_pb, la, 0);
3291 bf_set(lpfc_mbx_read_top_fa, la, 0);
3292 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04003293
3294 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05003295 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04003296
3297 return;
3298
3299out_free_dmabuf:
3300 kfree(mp);
3301out_free_pmb:
3302 mempool_free(pmb, phba->mbox_mem_pool);
3303}
3304
3305/**
James Smart70f3c072010-12-15 17:57:33 -05003306 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
3307 * @phba: pointer to lpfc hba data structure.
3308 * @acqe_fc: pointer to the async fc completion queue entry.
3309 *
3310 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
3311 * that the event was received and then issue a read_topology mailbox command so
3312 * that the rest of the driver will treat it the same as SLI3.
3313 **/
3314static void
3315lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
3316{
3317 struct lpfc_dmabuf *mp;
3318 LPFC_MBOXQ_t *pmb;
3319 int rc;
3320
3321 if (bf_get(lpfc_trailer_type, acqe_fc) !=
3322 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
3323 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3324 "2895 Non FC link Event detected.(%d)\n",
3325 bf_get(lpfc_trailer_type, acqe_fc));
3326 return;
3327 }
3328 /* Keep the link status for extra SLI4 state machine reference */
3329 phba->sli4_hba.link_state.speed =
3330 bf_get(lpfc_acqe_fc_la_speed, acqe_fc);
3331 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
3332 phba->sli4_hba.link_state.topology =
3333 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
3334 phba->sli4_hba.link_state.status =
3335 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
3336 phba->sli4_hba.link_state.type =
3337 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
3338 phba->sli4_hba.link_state.number =
3339 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
3340 phba->sli4_hba.link_state.fault =
3341 bf_get(lpfc_acqe_link_fault, acqe_fc);
3342 phba->sli4_hba.link_state.logical_speed =
3343 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc);
3344 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3345 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
3346 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
3347 "%dMbps Fault:%d\n",
3348 phba->sli4_hba.link_state.speed,
3349 phba->sli4_hba.link_state.topology,
3350 phba->sli4_hba.link_state.status,
3351 phba->sli4_hba.link_state.type,
3352 phba->sli4_hba.link_state.number,
3353 phba->sli4_hba.link_state.logical_speed * 10,
3354 phba->sli4_hba.link_state.fault);
3355 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3356 if (!pmb) {
3357 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3358 "2897 The mboxq allocation failed\n");
3359 return;
3360 }
3361 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3362 if (!mp) {
3363 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3364 "2898 The lpfc_dmabuf allocation failed\n");
3365 goto out_free_pmb;
3366 }
3367 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
3368 if (!mp->virt) {
3369 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3370 "2899 The mbuf allocation failed\n");
3371 goto out_free_dmabuf;
3372 }
3373
3374 /* Cleanup any outstanding ELS commands */
3375 lpfc_els_flush_all_cmd(phba);
3376
3377 /* Block ELS IOCBs until we have done process link event */
3378 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
3379
3380 /* Update link event statistics */
3381 phba->sli.slistat.link_event++;
3382
3383 /* Create lpfc_handle_latt mailbox command from link ACQE */
3384 lpfc_read_topology(phba, pmb, mp);
3385 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
3386 pmb->vport = phba->pport;
3387
3388 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3389 if (rc == MBX_NOT_FINISHED)
3390 goto out_free_dmabuf;
3391 return;
3392
3393out_free_dmabuf:
3394 kfree(mp);
3395out_free_pmb:
3396 mempool_free(pmb, phba->mbox_mem_pool);
3397}
3398
3399/**
3400 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
3401 * @phba: pointer to lpfc hba data structure.
3402 * @acqe_fc: pointer to the async SLI completion queue entry.
3403 *
3404 * This routine is to handle the SLI4 asynchronous SLI events.
3405 **/
3406static void
3407lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
3408{
3409 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3410 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
3411 "x%08x SLI Event Type:%d",
3412 acqe_sli->event_data1, acqe_sli->event_data2,
3413 bf_get(lpfc_trailer_type, acqe_sli));
3414 return;
3415}
3416
3417/**
James Smartfc2b9892010-02-26 14:15:29 -05003418 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
3419 * @vport: pointer to vport data structure.
3420 *
3421 * This routine is to perform Clear Virtual Link (CVL) on a vport in
3422 * response to a CVL event.
3423 *
3424 * Return the pointer to the ndlp with the vport if successful, otherwise
3425 * return NULL.
3426 **/
3427static struct lpfc_nodelist *
3428lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
3429{
3430 struct lpfc_nodelist *ndlp;
3431 struct Scsi_Host *shost;
3432 struct lpfc_hba *phba;
3433
3434 if (!vport)
3435 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05003436 phba = vport->phba;
3437 if (!phba)
3438 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04003439 ndlp = lpfc_findnode_did(vport, Fabric_DID);
3440 if (!ndlp) {
3441 /* Cannot find existing Fabric ndlp, so allocate a new one */
3442 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3443 if (!ndlp)
3444 return 0;
3445 lpfc_nlp_init(vport, ndlp, Fabric_DID);
3446 /* Set the node type */
3447 ndlp->nlp_type |= NLP_FABRIC;
3448 /* Put ndlp onto node list */
3449 lpfc_enqueue_node(vport, ndlp);
3450 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3451 /* re-setup ndlp without removing from node list */
3452 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3453 if (!ndlp)
3454 return 0;
3455 }
James Smart63e801c2010-11-20 23:14:19 -05003456 if ((phba->pport->port_state < LPFC_FLOGI) &&
3457 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05003458 return NULL;
3459 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05003460 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
3461 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05003462 return NULL;
3463 shost = lpfc_shost_from_vport(vport);
3464 if (!shost)
3465 return NULL;
3466 lpfc_linkdown_port(vport);
3467 lpfc_cleanup_pending_mbox(vport);
3468 spin_lock_irq(shost->host_lock);
3469 vport->fc_flag |= FC_VPORT_CVL_RCVD;
3470 spin_unlock_irq(shost->host_lock);
3471
3472 return ndlp;
3473}
3474
3475/**
3476 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
3477 * @vport: pointer to lpfc hba data structure.
3478 *
3479 * This routine is to perform Clear Virtual Link (CVL) on all vports in
3480 * response to a FCF dead event.
3481 **/
3482static void
3483lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
3484{
3485 struct lpfc_vport **vports;
3486 int i;
3487
3488 vports = lpfc_create_vport_work_array(phba);
3489 if (vports)
3490 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
3491 lpfc_sli4_perform_vport_cvl(vports[i]);
3492 lpfc_destroy_vport_work_array(phba, vports);
3493}
3494
3495/**
James Smart76a95d72010-11-20 23:11:48 -05003496 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04003497 * @phba: pointer to lpfc hba data structure.
3498 * @acqe_link: pointer to the async fcoe completion queue entry.
3499 *
3500 * This routine is to handle the SLI4 asynchronous fcoe event.
3501 **/
3502static void
James Smart76a95d72010-11-20 23:11:48 -05003503lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05003504 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04003505{
James Smart70f3c072010-12-15 17:57:33 -05003506 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04003507 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04003508 struct lpfc_vport *vport;
3509 struct lpfc_nodelist *ndlp;
3510 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05003511 int active_vlink_present;
3512 struct lpfc_vport **vports;
3513 int i;
James Smartda0436e2009-05-22 14:51:39 -04003514
James Smart70f3c072010-12-15 17:57:33 -05003515 phba->fc_eventTag = acqe_fip->event_tag;
3516 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04003517 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05003518 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
3519 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
3520 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04003521 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
3522 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04003523 "2546 New FCF event, evt_tag:x%x, "
3524 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05003525 acqe_fip->event_tag,
3526 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04003527 else
3528 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
3529 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04003530 "2788 FCF param modified event, "
3531 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05003532 acqe_fip->event_tag,
3533 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04003534 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05003535 /*
3536 * During period of FCF discovery, read the FCF
3537 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04003538 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05003539 */
3540 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
3541 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04003542 "2779 Read FCF (x%x) for updating "
3543 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05003544 acqe_fip->index);
3545 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05003546 }
James Smart38b92ef2010-08-04 16:11:39 -04003547
3548 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04003549 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04003550 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04003551 spin_unlock_irq(&phba->hbalock);
3552 break;
3553 }
3554 /* If fast FCF failover rescan event is pending, do nothing */
3555 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
3556 spin_unlock_irq(&phba->hbalock);
3557 break;
3558 }
3559
3560 /* If the FCF has been in discovered state, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04003561 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
3562 spin_unlock_irq(&phba->hbalock);
3563 break;
3564 }
3565 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04003566
James Smart0c9ab6f2010-02-26 14:15:57 -05003567 /* Otherwise, scan the entire FCF table and re-discover SAN */
3568 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04003569 "2770 Start FCF table scan per async FCF "
3570 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05003571 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05003572 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3573 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04003574 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05003575 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
3576 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04003577 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04003578 break;
3579
James Smart70f3c072010-12-15 17:57:33 -05003580 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04003581 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04003582 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05003583 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
3584 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04003585 break;
3586
James Smart70f3c072010-12-15 17:57:33 -05003587 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart0c9ab6f2010-02-26 14:15:57 -05003588 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04003589 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05003590 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04003591 /*
3592 * If we are in the middle of FCF failover process, clear
3593 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04003594 */
James Smartfc2b9892010-02-26 14:15:29 -05003595 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003596 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05003597 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003598 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05003599 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05003600 break;
3601 }
James Smart38b92ef2010-08-04 16:11:39 -04003602 spin_unlock_irq(&phba->hbalock);
3603
3604 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05003605 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04003606 break;
3607
3608 /*
3609 * Otherwise, request the port to rediscover the entire FCF
3610 * table for a fast recovery from case that the current FCF
3611 * is no longer valid as we are not in the middle of FCF
3612 * failover process already.
3613 */
3614 spin_lock_irq(&phba->hbalock);
James Smartfc2b9892010-02-26 14:15:29 -05003615 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05003616 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05003617 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04003618
James Smart0c9ab6f2010-02-26 14:15:57 -05003619 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3620 "2771 Start FCF fast failover process due to "
3621 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
James Smart70f3c072010-12-15 17:57:33 -05003622 "\n", acqe_fip->event_tag, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05003623 rc = lpfc_sli4_redisc_fcf_table(phba);
3624 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05003625 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
3626 LOG_DISCOVERY,
3627 "2772 Issue FCF rediscover mabilbox "
3628 "command failed, fail through to FCF "
3629 "dead event\n");
James Smartfc2b9892010-02-26 14:15:29 -05003630 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003631 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05003632 spin_unlock_irq(&phba->hbalock);
3633 /*
3634 * Last resort will fail over by treating this
3635 * as a link down to FCF registration.
3636 */
3637 lpfc_sli4_fcf_dead_failthrough(phba);
James Smart38b92ef2010-08-04 16:11:39 -04003638 } else {
3639 /* Reset FCF roundrobin bmask for new discovery */
James Smart7d791df2011-07-22 18:37:52 -04003640 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart38b92ef2010-08-04 16:11:39 -04003641 /*
3642 * Handling fast FCF failover to a DEAD FCF event is
3643 * considered equalivant to receiving CVL to all vports.
James Smartfc2b9892010-02-26 14:15:29 -05003644 */
3645 lpfc_sli4_perform_all_vport_cvl(phba);
James Smart38b92ef2010-08-04 16:11:39 -04003646 }
James Smartda0436e2009-05-22 14:51:39 -04003647 break;
James Smart70f3c072010-12-15 17:57:33 -05003648 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart0c9ab6f2010-02-26 14:15:57 -05003649 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04003650 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05003651 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04003652
James Smart6669f9b2009-10-02 15:16:45 -04003653 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04003654 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05003655 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04003656 if (!ndlp)
3657 break;
James Smart695a8142010-01-26 23:08:03 -05003658 active_vlink_present = 0;
3659
3660 vports = lpfc_create_vport_work_array(phba);
3661 if (vports) {
3662 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
3663 i++) {
3664 if ((!(vports[i]->fc_flag &
3665 FC_VPORT_CVL_RCVD)) &&
3666 (vports[i]->port_state > LPFC_FDISC)) {
3667 active_vlink_present = 1;
3668 break;
3669 }
3670 }
3671 lpfc_destroy_vport_work_array(phba, vports);
3672 }
3673
3674 if (active_vlink_present) {
3675 /*
3676 * If there are other active VLinks present,
3677 * re-instantiate the Vlink using FDISC.
3678 */
James Smart6669f9b2009-10-02 15:16:45 -04003679 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
James Smartfc2b9892010-02-26 14:15:29 -05003680 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04003681 spin_lock_irq(shost->host_lock);
3682 ndlp->nlp_flag |= NLP_DELAY_TMO;
3683 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05003684 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
3685 vport->port_state = LPFC_FDISC;
3686 } else {
James Smartecfd03c2010-02-12 14:41:27 -05003687 /*
3688 * Otherwise, we request port to rediscover
3689 * the entire FCF table for a fast recovery
3690 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05003691 * is no longer valid if we are not already
3692 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05003693 */
James Smartfc2b9892010-02-26 14:15:29 -05003694 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003695 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05003696 spin_unlock_irq(&phba->hbalock);
3697 break;
3698 }
3699 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05003700 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05003701 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003702 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
3703 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04003704 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05003705 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05003706 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05003707 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05003708 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
3709 LOG_DISCOVERY,
3710 "2774 Issue FCF rediscover "
3711 "mabilbox command failed, "
3712 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05003713 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003714 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05003715 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05003716 /*
3717 * Last resort will be re-try on the
3718 * the current registered FCF entry.
3719 */
3720 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04003721 } else
3722 /*
3723 * Reset FCF roundrobin bmask for new
3724 * discovery.
3725 */
James Smart7d791df2011-07-22 18:37:52 -04003726 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04003727 }
3728 break;
James Smartda0436e2009-05-22 14:51:39 -04003729 default:
3730 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3731 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05003732 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04003733 break;
3734 }
3735}
3736
3737/**
3738 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
3739 * @phba: pointer to lpfc hba data structure.
3740 * @acqe_link: pointer to the async dcbx completion queue entry.
3741 *
3742 * This routine is to handle the SLI4 asynchronous dcbx event.
3743 **/
3744static void
3745lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
3746 struct lpfc_acqe_dcbx *acqe_dcbx)
3747{
James Smart4d9ab992009-10-02 15:16:39 -04003748 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04003749 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3750 "0290 The SLI4 DCBX asynchronous event is not "
3751 "handled yet\n");
3752}
3753
3754/**
James Smartb19a0612010-04-06 14:48:51 -04003755 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
3756 * @phba: pointer to lpfc hba data structure.
3757 * @acqe_link: pointer to the async grp5 completion queue entry.
3758 *
3759 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
3760 * is an asynchronous notified of a logical link speed change. The Port
3761 * reports the logical link speed in units of 10Mbps.
3762 **/
3763static void
3764lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
3765 struct lpfc_acqe_grp5 *acqe_grp5)
3766{
3767 uint16_t prev_ll_spd;
3768
3769 phba->fc_eventTag = acqe_grp5->event_tag;
3770 phba->fcoe_eventtag = acqe_grp5->event_tag;
3771 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
3772 phba->sli4_hba.link_state.logical_speed =
3773 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5));
3774 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3775 "2789 GRP5 Async Event: Updating logical link speed "
3776 "from %dMbps to %dMbps\n", (prev_ll_spd * 10),
3777 (phba->sli4_hba.link_state.logical_speed*10));
3778}
3779
3780/**
James Smartda0436e2009-05-22 14:51:39 -04003781 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
3782 * @phba: pointer to lpfc hba data structure.
3783 *
3784 * This routine is invoked by the worker thread to process all the pending
3785 * SLI4 asynchronous events.
3786 **/
3787void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
3788{
3789 struct lpfc_cq_event *cq_event;
3790
3791 /* First, declare the async event has been handled */
3792 spin_lock_irq(&phba->hbalock);
3793 phba->hba_flag &= ~ASYNC_EVENT;
3794 spin_unlock_irq(&phba->hbalock);
3795 /* Now, handle all the async events */
3796 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
3797 /* Get the first event from the head of the event queue */
3798 spin_lock_irq(&phba->hbalock);
3799 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
3800 cq_event, struct lpfc_cq_event, list);
3801 spin_unlock_irq(&phba->hbalock);
3802 /* Process the asynchronous event */
3803 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
3804 case LPFC_TRAILER_CODE_LINK:
3805 lpfc_sli4_async_link_evt(phba,
3806 &cq_event->cqe.acqe_link);
3807 break;
3808 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05003809 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04003810 break;
3811 case LPFC_TRAILER_CODE_DCBX:
3812 lpfc_sli4_async_dcbx_evt(phba,
3813 &cq_event->cqe.acqe_dcbx);
3814 break;
James Smartb19a0612010-04-06 14:48:51 -04003815 case LPFC_TRAILER_CODE_GRP5:
3816 lpfc_sli4_async_grp5_evt(phba,
3817 &cq_event->cqe.acqe_grp5);
3818 break;
James Smart70f3c072010-12-15 17:57:33 -05003819 case LPFC_TRAILER_CODE_FC:
3820 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
3821 break;
3822 case LPFC_TRAILER_CODE_SLI:
3823 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
3824 break;
James Smartda0436e2009-05-22 14:51:39 -04003825 default:
3826 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3827 "1804 Invalid asynchrous event code: "
3828 "x%x\n", bf_get(lpfc_trailer_code,
3829 &cq_event->cqe.mcqe_cmpl));
3830 break;
3831 }
3832 /* Free the completion event processed to the free pool */
3833 lpfc_sli4_cq_event_release(phba, cq_event);
3834 }
3835}
3836
3837/**
James Smartecfd03c2010-02-12 14:41:27 -05003838 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
3839 * @phba: pointer to lpfc hba data structure.
3840 *
3841 * This routine is invoked by the worker thread to process FCF table
3842 * rediscovery pending completion event.
3843 **/
3844void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
3845{
3846 int rc;
3847
3848 spin_lock_irq(&phba->hbalock);
3849 /* Clear FCF rediscovery timeout event */
3850 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
3851 /* Clear driver fast failover FCF record flag */
3852 phba->fcf.failover_rec.flag = 0;
3853 /* Set state for FCF fast failover */
3854 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
3855 spin_unlock_irq(&phba->hbalock);
3856
3857 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05003858 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04003859 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05003860 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05003861 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05003862 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
3863 "2747 Issue FCF scan read FCF mailbox "
3864 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05003865}
3866
3867/**
James Smartda0436e2009-05-22 14:51:39 -04003868 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
3869 * @phba: pointer to lpfc hba data structure.
3870 * @dev_grp: The HBA PCI-Device group number.
3871 *
3872 * This routine is invoked to set up the per HBA PCI-Device group function
3873 * API jump table entries.
3874 *
3875 * Return: 0 if success, otherwise -ENODEV
3876 **/
3877int
3878lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05003879{
3880 int rc;
3881
James Smartda0436e2009-05-22 14:51:39 -04003882 /* Set up lpfc PCI-device group */
3883 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05003884
James Smartda0436e2009-05-22 14:51:39 -04003885 /* The LPFC_PCI_DEV_OC uses SLI4 */
3886 if (dev_grp == LPFC_PCI_DEV_OC)
3887 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05003888
James Smartda0436e2009-05-22 14:51:39 -04003889 /* Set up device INIT API function jump table */
3890 rc = lpfc_init_api_table_setup(phba, dev_grp);
3891 if (rc)
3892 return -ENODEV;
3893 /* Set up SCSI API function jump table */
3894 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
3895 if (rc)
3896 return -ENODEV;
3897 /* Set up SLI API function jump table */
3898 rc = lpfc_sli_api_table_setup(phba, dev_grp);
3899 if (rc)
3900 return -ENODEV;
3901 /* Set up MBOX API function jump table */
3902 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
3903 if (rc)
3904 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05003905
James Smartda0436e2009-05-22 14:51:39 -04003906 return 0;
James Smart5b75da22008-12-04 22:39:35 -05003907}
3908
3909/**
James Smart3621a712009-04-06 18:47:14 -04003910 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05003911 * @phba: pointer to lpfc hba data structure.
3912 * @intr_mode: active interrupt mode adopted.
3913 *
3914 * This routine it invoked to log the currently used active interrupt mode
3915 * to the device.
James Smart3772a992009-05-22 14:50:54 -04003916 **/
3917static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05003918{
3919 switch (intr_mode) {
3920 case 0:
3921 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3922 "0470 Enable INTx interrupt mode.\n");
3923 break;
3924 case 1:
3925 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3926 "0481 Enabled MSI interrupt mode.\n");
3927 break;
3928 case 2:
3929 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3930 "0480 Enabled MSI-X interrupt mode.\n");
3931 break;
3932 default:
3933 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3934 "0482 Illegal interrupt mode.\n");
3935 break;
3936 }
3937 return;
3938}
3939
James Smart5b75da22008-12-04 22:39:35 -05003940/**
James Smart3772a992009-05-22 14:50:54 -04003941 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05003942 * @phba: pointer to lpfc hba data structure.
3943 *
James Smart3772a992009-05-22 14:50:54 -04003944 * This routine is invoked to enable the PCI device that is common to all
3945 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05003946 *
3947 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02003948 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04003949 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05003950 **/
James Smart3772a992009-05-22 14:50:54 -04003951static int
3952lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05003953{
James Smart3772a992009-05-22 14:50:54 -04003954 struct pci_dev *pdev;
James Smart079b5c92011-08-21 21:48:49 -04003955 int bars = 0;
James Smart5b75da22008-12-04 22:39:35 -05003956
James Smart3772a992009-05-22 14:50:54 -04003957 /* Obtain PCI device reference */
3958 if (!phba->pcidev)
3959 goto out_error;
3960 else
3961 pdev = phba->pcidev;
3962 /* Select PCI BARs */
3963 bars = pci_select_bars(pdev, IORESOURCE_MEM);
3964 /* Enable PCI device */
3965 if (pci_enable_device_mem(pdev))
3966 goto out_error;
3967 /* Request PCI resource for the device */
3968 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
3969 goto out_disable_device;
3970 /* Set up device as PCI master and save state for EEH */
3971 pci_set_master(pdev);
3972 pci_try_set_mwi(pdev);
3973 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05003974
James Smart05580562011-05-24 11:40:48 -04003975 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
3976 if (pci_find_capability(pdev, PCI_CAP_ID_EXP))
3977 pdev->needs_freset = 1;
3978
James Smart3772a992009-05-22 14:50:54 -04003979 return 0;
James Smart5b75da22008-12-04 22:39:35 -05003980
James Smart3772a992009-05-22 14:50:54 -04003981out_disable_device:
3982 pci_disable_device(pdev);
3983out_error:
James Smart079b5c92011-08-21 21:48:49 -04003984 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3985 "1401 Failed to enable pci device, bars:x%x\n", bars);
James Smart3772a992009-05-22 14:50:54 -04003986 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05003987}
3988
3989/**
James Smart3772a992009-05-22 14:50:54 -04003990 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05003991 * @phba: pointer to lpfc hba data structure.
3992 *
James Smart3772a992009-05-22 14:50:54 -04003993 * This routine is invoked to disable the PCI device that is common to all
3994 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05003995 **/
3996static void
James Smart3772a992009-05-22 14:50:54 -04003997lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05003998{
James Smart3772a992009-05-22 14:50:54 -04003999 struct pci_dev *pdev;
4000 int bars;
James Smart5b75da22008-12-04 22:39:35 -05004001
James Smart3772a992009-05-22 14:50:54 -04004002 /* Obtain PCI device reference */
4003 if (!phba->pcidev)
4004 return;
4005 else
4006 pdev = phba->pcidev;
4007 /* Select PCI BARs */
4008 bars = pci_select_bars(pdev, IORESOURCE_MEM);
4009 /* Release PCI resource and disable PCI device */
4010 pci_release_selected_regions(pdev, bars);
4011 pci_disable_device(pdev);
4012 /* Null out PCI private reference to driver */
4013 pci_set_drvdata(pdev, NULL);
James Smart5b75da22008-12-04 22:39:35 -05004014
4015 return;
4016}
4017
4018/**
James Smart3772a992009-05-22 14:50:54 -04004019 * lpfc_reset_hba - Reset a hba
4020 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04004021 *
James Smart3772a992009-05-22 14:50:54 -04004022 * This routine is invoked to reset a hba device. It brings the HBA
4023 * offline, performs a board restart, and then brings the board back
4024 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
4025 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04004026 **/
James Smart3772a992009-05-22 14:50:54 -04004027void
4028lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05004029{
James Smart3772a992009-05-22 14:50:54 -04004030 /* If resets are disabled then set error state and return. */
4031 if (!phba->cfg_enable_hba_reset) {
4032 phba->link_state = LPFC_HBA_ERROR;
4033 return;
4034 }
4035 lpfc_offline_prep(phba);
4036 lpfc_offline(phba);
4037 lpfc_sli_brdrestart(phba);
4038 lpfc_online(phba);
4039 lpfc_unblock_mgmt_io(phba);
4040}
dea31012005-04-17 16:05:31 -05004041
James Smart3772a992009-05-22 14:50:54 -04004042/**
James Smart0a96e972011-07-22 18:37:28 -04004043 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
4044 * @phba: pointer to lpfc hba data structure.
4045 *
4046 * This function enables the PCI SR-IOV virtual functions to a physical
4047 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4048 * enable the number of virtual functions to the physical function. As
4049 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4050 * API call does not considered as an error condition for most of the device.
4051 **/
4052uint16_t
4053lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
4054{
4055 struct pci_dev *pdev = phba->pcidev;
4056 uint16_t nr_virtfn;
4057 int pos;
4058
4059 if (!pdev->is_physfn)
4060 return 0;
4061
4062 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4063 if (pos == 0)
4064 return 0;
4065
4066 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
4067 return nr_virtfn;
4068}
4069
4070/**
James Smart912e3ac2011-05-24 11:42:11 -04004071 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
4072 * @phba: pointer to lpfc hba data structure.
4073 * @nr_vfn: number of virtual functions to be enabled.
4074 *
4075 * This function enables the PCI SR-IOV virtual functions to a physical
4076 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4077 * enable the number of virtual functions to the physical function. As
4078 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4079 * API call does not considered as an error condition for most of the device.
4080 **/
4081int
4082lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
4083{
4084 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04004085 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04004086 int rc;
4087
James Smart0a96e972011-07-22 18:37:28 -04004088 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
4089 if (nr_vfn > max_nr_vfn) {
4090 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4091 "3057 Requested vfs (%d) greater than "
4092 "supported vfs (%d)", nr_vfn, max_nr_vfn);
4093 return -EINVAL;
4094 }
4095
James Smart912e3ac2011-05-24 11:42:11 -04004096 rc = pci_enable_sriov(pdev, nr_vfn);
4097 if (rc) {
4098 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4099 "2806 Failed to enable sriov on this device "
4100 "with vfn number nr_vf:%d, rc:%d\n",
4101 nr_vfn, rc);
4102 } else
4103 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4104 "2807 Successful enable sriov on this device "
4105 "with vfn number nr_vf:%d\n", nr_vfn);
4106 return rc;
4107}
4108
4109/**
James Smart3772a992009-05-22 14:50:54 -04004110 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
4111 * @phba: pointer to lpfc hba data structure.
4112 *
4113 * This routine is invoked to set up the driver internal resources specific to
4114 * support the SLI-3 HBA device it attached to.
4115 *
4116 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004117 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004118 * other values - error
4119 **/
4120static int
4121lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
4122{
4123 struct lpfc_sli *psli;
James Smart912e3ac2011-05-24 11:42:11 -04004124 int rc;
dea31012005-04-17 16:05:31 -05004125
James Smart3772a992009-05-22 14:50:54 -04004126 /*
4127 * Initialize timers used by driver
4128 */
dea31012005-04-17 16:05:31 -05004129
James Smart3772a992009-05-22 14:50:54 -04004130 /* Heartbeat timer */
4131 init_timer(&phba->hb_tmofunc);
4132 phba->hb_tmofunc.function = lpfc_hb_timeout;
4133 phba->hb_tmofunc.data = (unsigned long)phba;
4134
4135 psli = &phba->sli;
4136 /* MBOX heartbeat timer */
4137 init_timer(&psli->mbox_tmo);
4138 psli->mbox_tmo.function = lpfc_mbox_timeout;
4139 psli->mbox_tmo.data = (unsigned long) phba;
4140 /* FCP polling mode timer */
4141 init_timer(&phba->fcp_poll_timer);
4142 phba->fcp_poll_timer.function = lpfc_poll_timeout;
4143 phba->fcp_poll_timer.data = (unsigned long) phba;
4144 /* Fabric block timer */
4145 init_timer(&phba->fabric_block_timer);
4146 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
4147 phba->fabric_block_timer.data = (unsigned long) phba;
4148 /* EA polling mode timer */
4149 init_timer(&phba->eratt_poll);
4150 phba->eratt_poll.function = lpfc_poll_eratt;
4151 phba->eratt_poll.data = (unsigned long) phba;
4152
4153 /* Host attention work mask setup */
4154 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
4155 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
4156
4157 /* Get all the module params for configuring this host */
4158 lpfc_get_cfgparam(phba);
James Smart49198b32010-04-06 15:04:33 -04004159 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
4160 phba->menlo_flag |= HBA_MENLO_SUPPORT;
4161 /* check for menlo minimum sg count */
4162 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
4163 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
4164 }
4165
James Smart3772a992009-05-22 14:50:54 -04004166 /*
4167 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
4168 * used to create the sg_dma_buf_pool must be dynamically calculated.
4169 * 2 segments are added since the IOCB needs a command and response bde.
4170 */
4171 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
4172 sizeof(struct fcp_rsp) +
4173 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
4174
4175 if (phba->cfg_enable_bg) {
4176 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT;
4177 phba->cfg_sg_dma_buf_size +=
4178 phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64);
4179 }
4180
4181 /* Also reinitialize the host templates with new values. */
4182 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4183 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4184
4185 phba->max_vpi = LPFC_MAX_VPI;
4186 /* This will be set to correct value after config_port mbox */
4187 phba->max_vports = 0;
4188
4189 /*
4190 * Initialize the SLI Layer to run with lpfc HBAs.
4191 */
4192 lpfc_sli_setup(phba);
4193 lpfc_sli_queue_setup(phba);
4194
4195 /* Allocate device driver memory */
4196 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
4197 return -ENOMEM;
4198
James Smart912e3ac2011-05-24 11:42:11 -04004199 /*
4200 * Enable sr-iov virtual functions if supported and configured
4201 * through the module parameter.
4202 */
4203 if (phba->cfg_sriov_nr_virtfn > 0) {
4204 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
4205 phba->cfg_sriov_nr_virtfn);
4206 if (rc) {
4207 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4208 "2808 Requested number of SR-IOV "
4209 "virtual functions (%d) is not "
4210 "supported\n",
4211 phba->cfg_sriov_nr_virtfn);
4212 phba->cfg_sriov_nr_virtfn = 0;
4213 }
4214 }
4215
James Smart3772a992009-05-22 14:50:54 -04004216 return 0;
4217}
4218
4219/**
4220 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
4221 * @phba: pointer to lpfc hba data structure.
4222 *
4223 * This routine is invoked to unset the driver internal resources set up
4224 * specific for supporting the SLI-3 HBA device it attached to.
4225 **/
4226static void
4227lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
4228{
4229 /* Free device driver memory allocated */
4230 lpfc_mem_free_all(phba);
4231
4232 return;
4233}
4234
4235/**
James Smartda0436e2009-05-22 14:51:39 -04004236 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
4237 * @phba: pointer to lpfc hba data structure.
4238 *
4239 * This routine is invoked to set up the driver internal resources specific to
4240 * support the SLI-4 HBA device it attached to.
4241 *
4242 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004243 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04004244 * other values - error
4245 **/
4246static int
4247lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
4248{
4249 struct lpfc_sli *psli;
James Smart28baac72010-02-12 14:42:03 -05004250 LPFC_MBOXQ_t *mboxq;
4251 int rc, i, hbq_count, buf_size, dma_buf_size, max_buf_size;
4252 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
4253 struct lpfc_mqe *mqe;
James Smart085c6472010-11-20 23:11:37 -05004254 int longs, sli_family;
James Smartda0436e2009-05-22 14:51:39 -04004255
4256 /* Before proceed, wait for POST done and device ready */
4257 rc = lpfc_sli4_post_status_check(phba);
4258 if (rc)
4259 return -ENODEV;
4260
4261 /*
4262 * Initialize timers used by driver
4263 */
4264
4265 /* Heartbeat timer */
4266 init_timer(&phba->hb_tmofunc);
4267 phba->hb_tmofunc.function = lpfc_hb_timeout;
4268 phba->hb_tmofunc.data = (unsigned long)phba;
James Smart19ca7602010-11-20 23:11:55 -05004269 init_timer(&phba->rrq_tmr);
4270 phba->rrq_tmr.function = lpfc_rrq_timeout;
4271 phba->rrq_tmr.data = (unsigned long)phba;
James Smartda0436e2009-05-22 14:51:39 -04004272
4273 psli = &phba->sli;
4274 /* MBOX heartbeat timer */
4275 init_timer(&psli->mbox_tmo);
4276 psli->mbox_tmo.function = lpfc_mbox_timeout;
4277 psli->mbox_tmo.data = (unsigned long) phba;
4278 /* Fabric block timer */
4279 init_timer(&phba->fabric_block_timer);
4280 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
4281 phba->fabric_block_timer.data = (unsigned long) phba;
4282 /* EA polling mode timer */
4283 init_timer(&phba->eratt_poll);
4284 phba->eratt_poll.function = lpfc_poll_eratt;
4285 phba->eratt_poll.data = (unsigned long) phba;
James Smartecfd03c2010-02-12 14:41:27 -05004286 /* FCF rediscover timer */
4287 init_timer(&phba->fcf.redisc_wait);
4288 phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
4289 phba->fcf.redisc_wait.data = (unsigned long)phba;
4290
James Smartda0436e2009-05-22 14:51:39 -04004291 /*
James Smart7ad20aa2011-05-24 11:44:28 -04004292 * Control structure for handling external multi-buffer mailbox
4293 * command pass-through.
4294 */
4295 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
4296 sizeof(struct lpfc_mbox_ext_buf_ctx));
4297 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
4298
4299 /*
James Smartda0436e2009-05-22 14:51:39 -04004300 * We need to do a READ_CONFIG mailbox command here before
4301 * calling lpfc_get_cfgparam. For VFs this will report the
4302 * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings.
4303 * All of the resources allocated
4304 * for this Port are tied to these values.
4305 */
4306 /* Get all the module params for configuring this host */
4307 lpfc_get_cfgparam(phba);
4308 phba->max_vpi = LPFC_MAX_VPI;
4309 /* This will be set to correct value after the read_config mbox */
4310 phba->max_vports = 0;
4311
4312 /* Program the default value of vlan_id and fc_map */
4313 phba->valid_vlan = 0;
4314 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
4315 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
4316 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
4317
4318 /*
4319 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
4320 * used to create the sg_dma_buf_pool must be dynamically calculated.
4321 * 2 segments are added since the IOCB needs a command and response bde.
4322 * To insure that the scsi sgl does not cross a 4k page boundary only
James Smart28baac72010-02-12 14:42:03 -05004323 * sgl sizes of must be a power of 2.
James Smartda0436e2009-05-22 14:51:39 -04004324 */
James Smart28baac72010-02-12 14:42:03 -05004325 buf_size = (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp) +
4326 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge)));
James Smart085c6472010-11-20 23:11:37 -05004327
4328 sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf);
4329 max_buf_size = LPFC_SLI4_MAX_BUF_SIZE;
4330 switch (sli_family) {
4331 case LPFC_SLI_INTF_FAMILY_BE2:
4332 case LPFC_SLI_INTF_FAMILY_BE3:
4333 /* There is a single hint for BE - 2 pages per BPL. */
4334 if (bf_get(lpfc_sli_intf_sli_hint1, &phba->sli4_hba.sli_intf) ==
4335 LPFC_SLI_INTF_SLI_HINT1_1)
4336 max_buf_size = LPFC_SLI4_FL1_MAX_BUF_SIZE;
4337 break;
4338 case LPFC_SLI_INTF_FAMILY_LNCR_A0:
4339 case LPFC_SLI_INTF_FAMILY_LNCR_B0:
4340 default:
4341 break;
4342 }
James Smart28baac72010-02-12 14:42:03 -05004343 for (dma_buf_size = LPFC_SLI4_MIN_BUF_SIZE;
4344 dma_buf_size < max_buf_size && buf_size > dma_buf_size;
4345 dma_buf_size = dma_buf_size << 1)
4346 ;
4347 if (dma_buf_size == max_buf_size)
4348 phba->cfg_sg_seg_cnt = (dma_buf_size -
4349 sizeof(struct fcp_cmnd) - sizeof(struct fcp_rsp) -
4350 (2 * sizeof(struct sli4_sge))) /
4351 sizeof(struct sli4_sge);
4352 phba->cfg_sg_dma_buf_size = dma_buf_size;
James Smartda0436e2009-05-22 14:51:39 -04004353
4354 /* Initialize buffer queue management fields */
4355 hbq_count = lpfc_sli_hbq_count();
4356 for (i = 0; i < hbq_count; ++i)
4357 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
4358 INIT_LIST_HEAD(&phba->rb_pend_list);
4359 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
4360 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
4361
4362 /*
4363 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
4364 */
4365 /* Initialize the Abort scsi buffer list used by driver */
4366 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
4367 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
4368 /* This abort list used by worker thread */
4369 spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
4370
4371 /*
James Smart6d368e52011-05-24 11:44:12 -04004372 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04004373 */
4374
4375 /* Driver internel slow-path CQ Event pool */
4376 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
4377 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04004378 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04004379 /* Asynchronous event CQ Event work queue list */
4380 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
4381 /* Fast-path XRI aborted CQ Event work queue list */
4382 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
4383 /* Slow-path XRI aborted CQ Event work queue list */
4384 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
4385 /* Receive queue CQ Event work queue list */
4386 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
4387
James Smart6d368e52011-05-24 11:44:12 -04004388 /* Initialize extent block lists. */
4389 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
4390 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
4391 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
4392 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
4393
James Smartda0436e2009-05-22 14:51:39 -04004394 /* Initialize the driver internal SLI layer lists. */
4395 lpfc_sli_setup(phba);
4396 lpfc_sli_queue_setup(phba);
4397
4398 /* Allocate device driver memory */
4399 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
4400 if (rc)
4401 return -ENOMEM;
4402
James Smart2fcee4b2010-12-15 17:57:46 -05004403 /* IF Type 2 ports get initialized now. */
4404 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
4405 LPFC_SLI_INTF_IF_TYPE_2) {
4406 rc = lpfc_pci_function_reset(phba);
4407 if (unlikely(rc))
4408 return -ENODEV;
4409 }
4410
James Smartda0436e2009-05-22 14:51:39 -04004411 /* Create the bootstrap mailbox command */
4412 rc = lpfc_create_bootstrap_mbox(phba);
4413 if (unlikely(rc))
4414 goto out_free_mem;
4415
4416 /* Set up the host's endian order with the device. */
4417 rc = lpfc_setup_endian_order(phba);
4418 if (unlikely(rc))
4419 goto out_free_bsmbx;
4420
4421 /* Set up the hba's configuration parameters. */
4422 rc = lpfc_sli4_read_config(phba);
4423 if (unlikely(rc))
4424 goto out_free_bsmbx;
4425
James Smart2fcee4b2010-12-15 17:57:46 -05004426 /* IF Type 0 ports get initialized now. */
4427 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
4428 LPFC_SLI_INTF_IF_TYPE_0) {
4429 rc = lpfc_pci_function_reset(phba);
4430 if (unlikely(rc))
4431 goto out_free_bsmbx;
4432 }
James Smartda0436e2009-05-22 14:51:39 -04004433
James Smartcb5172e2010-03-15 11:25:07 -04004434 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
4435 GFP_KERNEL);
4436 if (!mboxq) {
4437 rc = -ENOMEM;
4438 goto out_free_bsmbx;
4439 }
4440
James Smartfedd3b72011-02-16 12:39:24 -05004441 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04004442 lpfc_supported_pages(mboxq);
4443 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05004444 if (!rc) {
4445 mqe = &mboxq->u.mqe;
4446 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
4447 LPFC_MAX_SUPPORTED_PAGES);
4448 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
4449 switch (pn_page[i]) {
4450 case LPFC_SLI4_PARAMETERS:
4451 phba->sli4_hba.pc_sli4_params.supported = 1;
4452 break;
4453 default:
4454 break;
4455 }
4456 }
4457 /* Read the port's SLI4 Parameters capabilities if supported. */
4458 if (phba->sli4_hba.pc_sli4_params.supported)
4459 rc = lpfc_pc_sli4_params_get(phba, mboxq);
4460 if (rc) {
4461 mempool_free(mboxq, phba->mbox_mem_pool);
4462 rc = -EIO;
4463 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04004464 }
4465 }
James Smartfedd3b72011-02-16 12:39:24 -05004466 /*
4467 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04004468 * If this call fails, it isn't critical unless the SLI4 parameters come
4469 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05004470 */
James Smart6d368e52011-05-24 11:44:12 -04004471 rc = lpfc_get_sli4_parameters(phba, mboxq);
4472 if (rc) {
4473 if (phba->sli4_hba.extents_in_use &&
4474 phba->sli4_hba.rpi_hdrs_in_use) {
4475 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4476 "2999 Unsupported SLI4 Parameters "
4477 "Extents and RPI headers enabled.\n");
4478 goto out_free_bsmbx;
4479 }
4480 }
James Smartcb5172e2010-03-15 11:25:07 -04004481 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04004482 /* Create all the SLI4 queues */
4483 rc = lpfc_sli4_queue_create(phba);
4484 if (rc)
4485 goto out_free_bsmbx;
4486
4487 /* Create driver internal CQE event pool */
4488 rc = lpfc_sli4_cq_event_pool_create(phba);
4489 if (rc)
4490 goto out_destroy_queue;
4491
4492 /* Initialize and populate the iocb list per host */
4493 rc = lpfc_init_sgl_list(phba);
4494 if (rc) {
4495 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4496 "1400 Failed to initialize sgl list.\n");
4497 goto out_destroy_cq_event_pool;
4498 }
4499 rc = lpfc_init_active_sgl_array(phba);
4500 if (rc) {
4501 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4502 "1430 Failed to initialize sgl list.\n");
4503 goto out_free_sgl_list;
4504 }
James Smartda0436e2009-05-22 14:51:39 -04004505 rc = lpfc_sli4_init_rpi_hdrs(phba);
4506 if (rc) {
4507 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4508 "1432 Failed to initialize rpi headers.\n");
4509 goto out_free_active_sgl;
4510 }
4511
James Smarta93ff372010-10-22 11:06:08 -04004512 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05004513 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
4514 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
4515 GFP_KERNEL);
4516 if (!phba->fcf.fcf_rr_bmask) {
4517 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4518 "2759 Failed allocate memory for FCF round "
4519 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04004520 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05004521 goto out_remove_rpi_hdrs;
4522 }
4523
James Smartda0436e2009-05-22 14:51:39 -04004524 phba->sli4_hba.fcp_eq_hdl = kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
4525 phba->cfg_fcp_eq_count), GFP_KERNEL);
4526 if (!phba->sli4_hba.fcp_eq_hdl) {
4527 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4528 "2572 Failed allocate memory for fast-path "
4529 "per-EQ handle array\n");
James Smart05580562011-05-24 11:40:48 -04004530 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05004531 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04004532 }
4533
4534 phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
4535 phba->sli4_hba.cfg_eqn), GFP_KERNEL);
4536 if (!phba->sli4_hba.msix_entries) {
4537 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4538 "2573 Failed allocate memory for msi-x "
4539 "interrupt vector entries\n");
James Smart05580562011-05-24 11:40:48 -04004540 rc = -ENOMEM;
James Smartda0436e2009-05-22 14:51:39 -04004541 goto out_free_fcp_eq_hdl;
4542 }
4543
James Smart912e3ac2011-05-24 11:42:11 -04004544 /*
4545 * Enable sr-iov virtual functions if supported and configured
4546 * through the module parameter.
4547 */
4548 if (phba->cfg_sriov_nr_virtfn > 0) {
4549 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
4550 phba->cfg_sriov_nr_virtfn);
4551 if (rc) {
4552 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4553 "3020 Requested number of SR-IOV "
4554 "virtual functions (%d) is not "
4555 "supported\n",
4556 phba->cfg_sriov_nr_virtfn);
4557 phba->cfg_sriov_nr_virtfn = 0;
4558 }
4559 }
4560
James Smart5248a742011-07-22 18:37:06 -04004561 return 0;
James Smartda0436e2009-05-22 14:51:39 -04004562
4563out_free_fcp_eq_hdl:
4564 kfree(phba->sli4_hba.fcp_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05004565out_free_fcf_rr_bmask:
4566 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04004567out_remove_rpi_hdrs:
4568 lpfc_sli4_remove_rpi_hdrs(phba);
4569out_free_active_sgl:
4570 lpfc_free_active_sgl(phba);
4571out_free_sgl_list:
4572 lpfc_free_sgl_list(phba);
4573out_destroy_cq_event_pool:
4574 lpfc_sli4_cq_event_pool_destroy(phba);
4575out_destroy_queue:
4576 lpfc_sli4_queue_destroy(phba);
4577out_free_bsmbx:
4578 lpfc_destroy_bootstrap_mbox(phba);
4579out_free_mem:
4580 lpfc_mem_free(phba);
4581 return rc;
4582}
4583
4584/**
4585 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
4586 * @phba: pointer to lpfc hba data structure.
4587 *
4588 * This routine is invoked to unset the driver internal resources set up
4589 * specific for supporting the SLI-4 HBA device it attached to.
4590 **/
4591static void
4592lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
4593{
4594 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
4595
James Smartda0436e2009-05-22 14:51:39 -04004596 /* Free memory allocated for msi-x interrupt vector entries */
4597 kfree(phba->sli4_hba.msix_entries);
4598
4599 /* Free memory allocated for fast-path work queue handles */
4600 kfree(phba->sli4_hba.fcp_eq_hdl);
4601
4602 /* Free the allocated rpi headers. */
4603 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04004604 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04004605
James Smart0c9ab6f2010-02-26 14:15:57 -05004606 /* Free eligible FCF index bmask */
4607 kfree(phba->fcf.fcf_rr_bmask);
4608
James Smartda0436e2009-05-22 14:51:39 -04004609 /* Free the ELS sgl list */
4610 lpfc_free_active_sgl(phba);
4611 lpfc_free_sgl_list(phba);
4612
4613 /* Free the SCSI sgl management array */
4614 kfree(phba->sli4_hba.lpfc_scsi_psb_array);
4615
4616 /* Free the SLI4 queues */
4617 lpfc_sli4_queue_destroy(phba);
4618
4619 /* Free the completion queue EQ event pool */
4620 lpfc_sli4_cq_event_release_all(phba);
4621 lpfc_sli4_cq_event_pool_destroy(phba);
4622
James Smart6d368e52011-05-24 11:44:12 -04004623 /* Release resource identifiers. */
4624 lpfc_sli4_dealloc_resource_identifiers(phba);
4625
James Smartda0436e2009-05-22 14:51:39 -04004626 /* Free the bsmbx region. */
4627 lpfc_destroy_bootstrap_mbox(phba);
4628
4629 /* Free the SLI Layer memory with SLI4 HBAs */
4630 lpfc_mem_free_all(phba);
4631
4632 /* Free the current connect table */
4633 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04004634 &phba->fcf_conn_rec_list, list) {
4635 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04004636 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04004637 }
James Smartda0436e2009-05-22 14:51:39 -04004638
4639 return;
4640}
4641
4642/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004643 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04004644 * @phba: The hba struct for which this call is being executed.
4645 * @dev_grp: The HBA PCI-Device group number.
4646 *
4647 * This routine sets up the device INIT interface API function jump table
4648 * in @phba struct.
4649 *
4650 * Returns: 0 - success, -ENODEV - failure.
4651 **/
4652int
4653lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
4654{
James Smart84d1b002010-02-12 14:42:33 -05004655 phba->lpfc_hba_init_link = lpfc_hba_init_link;
4656 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05004657 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04004658 switch (dev_grp) {
4659 case LPFC_PCI_DEV_LP:
4660 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
4661 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
4662 phba->lpfc_stop_port = lpfc_stop_port_s3;
4663 break;
James Smartda0436e2009-05-22 14:51:39 -04004664 case LPFC_PCI_DEV_OC:
4665 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
4666 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
4667 phba->lpfc_stop_port = lpfc_stop_port_s4;
4668 break;
James Smart3772a992009-05-22 14:50:54 -04004669 default:
4670 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4671 "1431 Invalid HBA PCI-device group: 0x%x\n",
4672 dev_grp);
4673 return -ENODEV;
4674 break;
4675 }
4676 return 0;
4677}
4678
4679/**
4680 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
4681 * @phba: pointer to lpfc hba data structure.
4682 *
4683 * This routine is invoked to set up the driver internal resources before the
4684 * device specific resource setup to support the HBA device it attached to.
4685 *
4686 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004687 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004688 * other values - error
4689 **/
4690static int
4691lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
4692{
4693 /*
4694 * Driver resources common to all SLI revisions
4695 */
James Smartea2151b2008-09-07 11:52:10 -04004696 atomic_set(&phba->fast_event_count, 0);
James Smart2e0fef82007-06-17 19:56:36 -05004697 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004698
James Smarte47c9092008-02-08 18:49:26 -05004699 /* Initialize ndlp management spinlock */
4700 spin_lock_init(&phba->ndlp_lock);
4701
James Smart2e0fef82007-06-17 19:56:36 -05004702 INIT_LIST_HEAD(&phba->port_list);
James Smart3772a992009-05-22 14:50:54 -04004703 INIT_LIST_HEAD(&phba->work_list);
James Smart84774a42008-08-24 21:50:06 -04004704 init_waitqueue_head(&phba->wait_4_mlo_m_q);
dea31012005-04-17 16:05:31 -05004705
James Smart3772a992009-05-22 14:50:54 -04004706 /* Initialize the wait queue head for the kernel thread */
4707 init_waitqueue_head(&phba->work_waitq);
James Smart858c9f62007-06-17 19:56:39 -05004708
James Smart3772a992009-05-22 14:50:54 -04004709 /* Initialize the scsi buffer list used by driver for scsi IO */
4710 spin_lock_init(&phba->scsi_buf_list_lock);
4711 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
dea31012005-04-17 16:05:31 -05004712
James Smart3772a992009-05-22 14:50:54 -04004713 /* Initialize the fabric iocb list */
4714 INIT_LIST_HEAD(&phba->fabric_iocb_list);
dea31012005-04-17 16:05:31 -05004715
James Smart3772a992009-05-22 14:50:54 -04004716 /* Initialize list to save ELS buffers */
4717 INIT_LIST_HEAD(&phba->elsbuf);
dea31012005-04-17 16:05:31 -05004718
James Smart3772a992009-05-22 14:50:54 -04004719 /* Initialize FCF connection rec list */
4720 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
dea31012005-04-17 16:05:31 -05004721
James Smart3772a992009-05-22 14:50:54 -04004722 return 0;
4723}
dea31012005-04-17 16:05:31 -05004724
James Smart3772a992009-05-22 14:50:54 -04004725/**
4726 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
4727 * @phba: pointer to lpfc hba data structure.
4728 *
4729 * This routine is invoked to set up the driver internal resources after the
4730 * device specific resource setup to support the HBA device it attached to.
4731 *
4732 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004733 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004734 * other values - error
4735 **/
4736static int
4737lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
4738{
4739 int error;
4740
4741 /* Startup the kernel thread for this host adapter. */
4742 phba->worker_thread = kthread_run(lpfc_do_work, phba,
4743 "lpfc_worker_%d", phba->brd_no);
4744 if (IS_ERR(phba->worker_thread)) {
4745 error = PTR_ERR(phba->worker_thread);
4746 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05004747 }
4748
James Smart3772a992009-05-22 14:50:54 -04004749 return 0;
4750}
4751
4752/**
4753 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
4754 * @phba: pointer to lpfc hba data structure.
4755 *
4756 * This routine is invoked to unset the driver internal resources set up after
4757 * the device specific resource setup for supporting the HBA device it
4758 * attached to.
4759 **/
4760static void
4761lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
4762{
4763 /* Stop kernel worker thread */
4764 kthread_stop(phba->worker_thread);
4765}
4766
4767/**
4768 * lpfc_free_iocb_list - Free iocb list.
4769 * @phba: pointer to lpfc hba data structure.
4770 *
4771 * This routine is invoked to free the driver's IOCB list and memory.
4772 **/
4773static void
4774lpfc_free_iocb_list(struct lpfc_hba *phba)
4775{
4776 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
4777
4778 spin_lock_irq(&phba->hbalock);
4779 list_for_each_entry_safe(iocbq_entry, iocbq_next,
4780 &phba->lpfc_iocb_list, list) {
4781 list_del(&iocbq_entry->list);
4782 kfree(iocbq_entry);
4783 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05004784 }
James Smart3772a992009-05-22 14:50:54 -04004785 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004786
James Smart3772a992009-05-22 14:50:54 -04004787 return;
4788}
dea31012005-04-17 16:05:31 -05004789
James Smart3772a992009-05-22 14:50:54 -04004790/**
4791 * lpfc_init_iocb_list - Allocate and initialize iocb list.
4792 * @phba: pointer to lpfc hba data structure.
4793 *
4794 * This routine is invoked to allocate and initizlize the driver's IOCB
4795 * list and set up the IOCB tag array accordingly.
4796 *
4797 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004798 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04004799 * other values - error
4800 **/
4801static int
4802lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
4803{
4804 struct lpfc_iocbq *iocbq_entry = NULL;
4805 uint16_t iotag;
4806 int i;
dea31012005-04-17 16:05:31 -05004807
4808 /* Initialize and populate the iocb list per host. */
4809 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04004810 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07004811 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05004812 if (iocbq_entry == NULL) {
4813 printk(KERN_ERR "%s: only allocated %d iocbs of "
4814 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07004815 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05004816 goto out_free_iocbq;
4817 }
4818
James Bottomley604a3e32005-10-29 10:28:33 -05004819 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
4820 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04004821 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05004822 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04004823 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05004824 goto out_free_iocbq;
4825 }
James Smart6d368e52011-05-24 11:44:12 -04004826 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04004827 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05004828
4829 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004830 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
4831 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05004832 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004833 }
4834
James Smart3772a992009-05-22 14:50:54 -04004835 return 0;
4836
4837out_free_iocbq:
4838 lpfc_free_iocb_list(phba);
4839
4840 return -ENOMEM;
4841}
4842
4843/**
James Smartda0436e2009-05-22 14:51:39 -04004844 * lpfc_free_sgl_list - Free sgl list.
4845 * @phba: pointer to lpfc hba data structure.
4846 *
4847 * This routine is invoked to free the driver's sgl list and memory.
4848 **/
4849static void
4850lpfc_free_sgl_list(struct lpfc_hba *phba)
4851{
4852 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
4853 LIST_HEAD(sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04004854
4855 spin_lock_irq(&phba->hbalock);
4856 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
4857 spin_unlock_irq(&phba->hbalock);
4858
4859 list_for_each_entry_safe(sglq_entry, sglq_next,
4860 &sglq_list, list) {
4861 list_del(&sglq_entry->list);
4862 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
4863 kfree(sglq_entry);
4864 phba->sli4_hba.total_sglq_bufs--;
4865 }
James Smartda0436e2009-05-22 14:51:39 -04004866 kfree(phba->sli4_hba.lpfc_els_sgl_array);
4867}
4868
4869/**
4870 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
4871 * @phba: pointer to lpfc hba data structure.
4872 *
4873 * This routine is invoked to allocate the driver's active sgl memory.
4874 * This array will hold the sglq_entry's for active IOs.
4875 **/
4876static int
4877lpfc_init_active_sgl_array(struct lpfc_hba *phba)
4878{
4879 int size;
4880 size = sizeof(struct lpfc_sglq *);
4881 size *= phba->sli4_hba.max_cfg_param.max_xri;
4882
4883 phba->sli4_hba.lpfc_sglq_active_list =
4884 kzalloc(size, GFP_KERNEL);
4885 if (!phba->sli4_hba.lpfc_sglq_active_list)
4886 return -ENOMEM;
4887 return 0;
4888}
4889
4890/**
4891 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
4892 * @phba: pointer to lpfc hba data structure.
4893 *
4894 * This routine is invoked to walk through the array of active sglq entries
4895 * and free all of the resources.
4896 * This is just a place holder for now.
4897 **/
4898static void
4899lpfc_free_active_sgl(struct lpfc_hba *phba)
4900{
4901 kfree(phba->sli4_hba.lpfc_sglq_active_list);
4902}
4903
4904/**
4905 * lpfc_init_sgl_list - Allocate and initialize sgl list.
4906 * @phba: pointer to lpfc hba data structure.
4907 *
4908 * This routine is invoked to allocate and initizlize the driver's sgl
4909 * list and set up the sgl xritag tag array accordingly.
4910 *
4911 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004912 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04004913 * other values - error
4914 **/
4915static int
4916lpfc_init_sgl_list(struct lpfc_hba *phba)
4917{
4918 struct lpfc_sglq *sglq_entry = NULL;
4919 int i;
4920 int els_xri_cnt;
4921
4922 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
4923 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04004924 "2400 ELS XRI count %d.\n",
James Smartda0436e2009-05-22 14:51:39 -04004925 els_xri_cnt);
4926 /* Initialize and populate the sglq list per host/VF. */
4927 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
4928 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
4929
4930 /* Sanity check on XRI management */
4931 if (phba->sli4_hba.max_cfg_param.max_xri <= els_xri_cnt) {
4932 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4933 "2562 No room left for SCSI XRI allocation: "
4934 "max_xri=%d, els_xri=%d\n",
4935 phba->sli4_hba.max_cfg_param.max_xri,
4936 els_xri_cnt);
4937 return -ENOMEM;
4938 }
4939
4940 /* Allocate memory for the ELS XRI management array */
4941 phba->sli4_hba.lpfc_els_sgl_array =
4942 kzalloc((sizeof(struct lpfc_sglq *) * els_xri_cnt),
4943 GFP_KERNEL);
4944
4945 if (!phba->sli4_hba.lpfc_els_sgl_array) {
4946 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4947 "2401 Failed to allocate memory for ELS "
4948 "XRI management array of size %d.\n",
4949 els_xri_cnt);
4950 return -ENOMEM;
4951 }
4952
4953 /* Keep the SCSI XRI into the XRI management array */
4954 phba->sli4_hba.scsi_xri_max =
4955 phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
4956 phba->sli4_hba.scsi_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04004957 phba->sli4_hba.lpfc_scsi_psb_array =
4958 kzalloc((sizeof(struct lpfc_scsi_buf *) *
4959 phba->sli4_hba.scsi_xri_max), GFP_KERNEL);
4960
4961 if (!phba->sli4_hba.lpfc_scsi_psb_array) {
4962 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4963 "2563 Failed to allocate memory for SCSI "
4964 "XRI management array of size %d.\n",
4965 phba->sli4_hba.scsi_xri_max);
4966 kfree(phba->sli4_hba.lpfc_els_sgl_array);
4967 return -ENOMEM;
4968 }
4969
4970 for (i = 0; i < els_xri_cnt; i++) {
4971 sglq_entry = kzalloc(sizeof(struct lpfc_sglq), GFP_KERNEL);
4972 if (sglq_entry == NULL) {
4973 printk(KERN_ERR "%s: only allocated %d sgls of "
4974 "expected %d count. Unloading driver.\n",
4975 __func__, i, els_xri_cnt);
4976 goto out_free_mem;
4977 }
4978
James Smartda0436e2009-05-22 14:51:39 -04004979 sglq_entry->buff_type = GEN_BUFF_TYPE;
4980 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, &sglq_entry->phys);
4981 if (sglq_entry->virt == NULL) {
4982 kfree(sglq_entry);
4983 printk(KERN_ERR "%s: failed to allocate mbuf.\n"
4984 "Unloading driver.\n", __func__);
4985 goto out_free_mem;
4986 }
4987 sglq_entry->sgl = sglq_entry->virt;
4988 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
4989
4990 /* The list order is used by later block SGL registraton */
4991 spin_lock_irq(&phba->hbalock);
James Smart0f65ff62010-02-26 14:14:23 -05004992 sglq_entry->state = SGL_FREED;
James Smartda0436e2009-05-22 14:51:39 -04004993 list_add_tail(&sglq_entry->list, &phba->sli4_hba.lpfc_sgl_list);
4994 phba->sli4_hba.lpfc_els_sgl_array[i] = sglq_entry;
4995 phba->sli4_hba.total_sglq_bufs++;
4996 spin_unlock_irq(&phba->hbalock);
4997 }
4998 return 0;
4999
5000out_free_mem:
5001 kfree(phba->sli4_hba.lpfc_scsi_psb_array);
5002 lpfc_free_sgl_list(phba);
5003 return -ENOMEM;
5004}
5005
5006/**
5007 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
5008 * @phba: pointer to lpfc hba data structure.
5009 *
5010 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04005011 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04005012 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04005013 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
5014 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04005015 *
5016 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005017 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04005018 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04005019 **/
5020int
5021lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
5022{
5023 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04005024 struct lpfc_rpi_hdr *rpi_hdr;
5025
5026 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartda0436e2009-05-22 14:51:39 -04005027 /*
James Smart6d368e52011-05-24 11:44:12 -04005028 * If the SLI4 port supports extents, posting the rpi header isn't
5029 * required. Set the expected maximum count and let the actual value
5030 * get set when extents are fully allocated.
James Smartda0436e2009-05-22 14:51:39 -04005031 */
James Smart6d368e52011-05-24 11:44:12 -04005032 if (!phba->sli4_hba.rpi_hdrs_in_use) {
5033 phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
5034 return rc;
5035 }
5036 if (phba->sli4_hba.extents_in_use)
5037 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04005038
5039 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
5040 if (!rpi_hdr) {
5041 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
5042 "0391 Error during rpi post operation\n");
5043 lpfc_sli4_remove_rpis(phba);
5044 rc = -ENODEV;
5045 }
5046
5047 return rc;
5048}
5049
5050/**
5051 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
5052 * @phba: pointer to lpfc hba data structure.
5053 *
5054 * This routine is invoked to allocate a single 4KB memory region to
5055 * support rpis and stores them in the phba. This single region
5056 * provides support for up to 64 rpis. The region is used globally
5057 * by the device.
5058 *
5059 * Returns:
5060 * A valid rpi hdr on success.
5061 * A NULL pointer on any failure.
5062 **/
5063struct lpfc_rpi_hdr *
5064lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
5065{
5066 uint16_t rpi_limit, curr_rpi_range;
5067 struct lpfc_dmabuf *dmabuf;
5068 struct lpfc_rpi_hdr *rpi_hdr;
James Smart9589b062011-04-16 11:03:17 -04005069 uint32_t rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04005070
James Smart6d368e52011-05-24 11:44:12 -04005071 /*
5072 * If the SLI4 port supports extents, posting the rpi header isn't
5073 * required. Set the expected maximum count and let the actual value
5074 * get set when extents are fully allocated.
5075 */
5076 if (!phba->sli4_hba.rpi_hdrs_in_use)
5077 return NULL;
5078 if (phba->sli4_hba.extents_in_use)
5079 return NULL;
5080
5081 /* The limit on the logical index is just the max_rpi count. */
James Smartda0436e2009-05-22 14:51:39 -04005082 rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
James Smart6d368e52011-05-24 11:44:12 -04005083 phba->sli4_hba.max_cfg_param.max_rpi - 1;
James Smartda0436e2009-05-22 14:51:39 -04005084
5085 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04005086 /*
5087 * Establish the starting RPI in this header block. The starting
5088 * rpi is normalized to a zero base because the physical rpi is
5089 * port based.
5090 */
5091 curr_rpi_range = phba->sli4_hba.next_rpi -
5092 phba->sli4_hba.max_cfg_param.rpi_base;
James Smartda0436e2009-05-22 14:51:39 -04005093 spin_unlock_irq(&phba->hbalock);
5094
5095 /*
5096 * The port has a limited number of rpis. The increment here
5097 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
5098 * and to allow the full max_rpi range per port.
5099 */
5100 if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
James Smart9589b062011-04-16 11:03:17 -04005101 rpi_count = rpi_limit - curr_rpi_range;
5102 else
5103 rpi_count = LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04005104
James Smart6d368e52011-05-24 11:44:12 -04005105 if (!rpi_count)
5106 return NULL;
James Smartda0436e2009-05-22 14:51:39 -04005107 /*
5108 * First allocate the protocol header region for the port. The
5109 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
5110 */
5111 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5112 if (!dmabuf)
5113 return NULL;
5114
5115 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
5116 LPFC_HDR_TEMPLATE_SIZE,
5117 &dmabuf->phys,
5118 GFP_KERNEL);
5119 if (!dmabuf->virt) {
5120 rpi_hdr = NULL;
5121 goto err_free_dmabuf;
5122 }
5123
5124 memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE);
5125 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
5126 rpi_hdr = NULL;
5127 goto err_free_coherent;
5128 }
5129
5130 /* Save the rpi header data for cleanup later. */
5131 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
5132 if (!rpi_hdr)
5133 goto err_free_coherent;
5134
5135 rpi_hdr->dmabuf = dmabuf;
5136 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
5137 rpi_hdr->page_count = 1;
5138 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04005139
5140 /* The rpi_hdr stores the logical index only. */
5141 rpi_hdr->start_rpi = curr_rpi_range;
James Smartda0436e2009-05-22 14:51:39 -04005142 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
5143
5144 /*
James Smart6d368e52011-05-24 11:44:12 -04005145 * The next_rpi stores the next logical module-64 rpi value used
5146 * to post physical rpis in subsequent rpi postings.
James Smartda0436e2009-05-22 14:51:39 -04005147 */
James Smart9589b062011-04-16 11:03:17 -04005148 phba->sli4_hba.next_rpi += rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04005149 spin_unlock_irq(&phba->hbalock);
5150 return rpi_hdr;
5151
5152 err_free_coherent:
5153 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
5154 dmabuf->virt, dmabuf->phys);
5155 err_free_dmabuf:
5156 kfree(dmabuf);
5157 return NULL;
5158}
5159
5160/**
5161 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
5162 * @phba: pointer to lpfc hba data structure.
5163 *
5164 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04005165 * to support rpis for SLI4 ports not supporting extents. This routine
5166 * presumes the caller has released all rpis consumed by fabric or port
5167 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04005168 **/
5169void
5170lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
5171{
5172 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
5173
James Smart6d368e52011-05-24 11:44:12 -04005174 if (!phba->sli4_hba.rpi_hdrs_in_use)
5175 goto exit;
5176
James Smartda0436e2009-05-22 14:51:39 -04005177 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
5178 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
5179 list_del(&rpi_hdr->list);
5180 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
5181 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
5182 kfree(rpi_hdr->dmabuf);
5183 kfree(rpi_hdr);
5184 }
James Smart6d368e52011-05-24 11:44:12 -04005185 exit:
5186 /* There are no rpis available to the port now. */
5187 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04005188}
5189
5190/**
James Smart3772a992009-05-22 14:50:54 -04005191 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
5192 * @pdev: pointer to pci device data structure.
5193 *
5194 * This routine is invoked to allocate the driver hba data structure for an
5195 * HBA device. If the allocation is successful, the phba reference to the
5196 * PCI device data structure is set.
5197 *
5198 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005199 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04005200 * NULL - error
5201 **/
5202static struct lpfc_hba *
5203lpfc_hba_alloc(struct pci_dev *pdev)
5204{
5205 struct lpfc_hba *phba;
5206
5207 /* Allocate memory for HBA structure */
5208 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
5209 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02005210 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04005211 return NULL;
5212 }
5213
5214 /* Set reference to PCI device in HBA structure */
5215 phba->pcidev = pdev;
5216
5217 /* Assign an unused board number */
5218 phba->brd_no = lpfc_get_instance();
5219 if (phba->brd_no < 0) {
5220 kfree(phba);
5221 return NULL;
5222 }
5223
James Smart4fede782010-01-26 23:08:55 -05005224 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04005225 INIT_LIST_HEAD(&phba->ct_ev_waiters);
5226
James Smart3772a992009-05-22 14:50:54 -04005227 return phba;
5228}
5229
5230/**
5231 * lpfc_hba_free - Free driver hba data structure with a device.
5232 * @phba: pointer to lpfc hba data structure.
5233 *
5234 * This routine is invoked to free the driver hba data structure with an
5235 * HBA device.
5236 **/
5237static void
5238lpfc_hba_free(struct lpfc_hba *phba)
5239{
5240 /* Release the driver assigned board number */
5241 idr_remove(&lpfc_hba_index, phba->brd_no);
5242
5243 kfree(phba);
5244 return;
5245}
5246
5247/**
5248 * lpfc_create_shost - Create hba physical port with associated scsi host.
5249 * @phba: pointer to lpfc hba data structure.
5250 *
5251 * This routine is invoked to create HBA physical port and associate a SCSI
5252 * host with it.
5253 *
5254 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005255 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005256 * other values - error
5257 **/
5258static int
5259lpfc_create_shost(struct lpfc_hba *phba)
5260{
5261 struct lpfc_vport *vport;
5262 struct Scsi_Host *shost;
5263
5264 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05005265 phba->fc_edtov = FF_DEF_EDTOV;
5266 phba->fc_ratov = FF_DEF_RATOV;
5267 phba->fc_altov = FF_DEF_ALTOV;
5268 phba->fc_arbtov = FF_DEF_ARBTOV;
5269
James Smartd7c47992010-06-08 18:31:54 -04005270 atomic_set(&phba->sdev_cnt, 0);
James Smart3de2a652007-08-02 11:09:59 -04005271 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05005272 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04005273 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05005274
5275 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05005276 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05005277 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04005278 /* Put reference to SCSI host to driver's device private data */
5279 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05005280
James Smart3772a992009-05-22 14:50:54 -04005281 return 0;
5282}
dea31012005-04-17 16:05:31 -05005283
James Smart3772a992009-05-22 14:50:54 -04005284/**
5285 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
5286 * @phba: pointer to lpfc hba data structure.
5287 *
5288 * This routine is invoked to destroy HBA physical port and the associated
5289 * SCSI host.
5290 **/
5291static void
5292lpfc_destroy_shost(struct lpfc_hba *phba)
5293{
5294 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04005295
James Smart3772a992009-05-22 14:50:54 -04005296 /* Destroy physical port that associated with the SCSI host */
5297 destroy_port(vport);
5298
5299 return;
5300}
5301
5302/**
5303 * lpfc_setup_bg - Setup Block guard structures and debug areas.
5304 * @phba: pointer to lpfc hba data structure.
5305 * @shost: the shost to be used to detect Block guard settings.
5306 *
5307 * This routine sets up the local Block guard protocol settings for @shost.
5308 * This routine also allocates memory for debugging bg buffers.
5309 **/
5310static void
5311lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
5312{
5313 int pagecnt = 10;
5314 if (lpfc_prot_mask && lpfc_prot_guard) {
5315 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5316 "1478 Registering BlockGuard with the "
5317 "SCSI layer\n");
5318 scsi_host_set_prot(shost, lpfc_prot_mask);
5319 scsi_host_set_guard(shost, lpfc_prot_guard);
James Smart98c9ea52007-10-27 13:37:33 -04005320 }
James Smart81301a92008-12-04 22:39:46 -05005321 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05005322 while (pagecnt) {
5323 spin_lock_init(&_dump_buf_lock);
5324 _dump_buf_data =
5325 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
5326 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04005327 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5328 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04005329 "_dump_buf_data at 0x%p\n",
5330 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05005331 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04005332 memset(_dump_buf_data, 0,
5333 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05005334 break;
James Smart3772a992009-05-22 14:50:54 -04005335 } else
James Smart81301a92008-12-04 22:39:46 -05005336 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05005337 }
James Smart81301a92008-12-04 22:39:46 -05005338 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04005339 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5340 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04005341 "memory for hexdump\n");
5342 } else
James Smart6a9c52c2009-10-02 15:16:51 -04005343 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5344 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05005345 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05005346 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05005347 while (pagecnt) {
5348 _dump_buf_dif =
5349 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
5350 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04005351 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5352 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04005353 "_dump_buf_dif at 0x%p\n",
5354 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05005355 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04005356 memset(_dump_buf_dif, 0,
5357 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05005358 break;
James Smart3772a992009-05-22 14:50:54 -04005359 } else
James Smart81301a92008-12-04 22:39:46 -05005360 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05005361 }
James Smart81301a92008-12-04 22:39:46 -05005362 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04005363 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5364 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04005365 "memory for hexdump\n");
5366 } else
James Smart6a9c52c2009-10-02 15:16:51 -04005367 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
5368 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04005369 _dump_buf_dif);
5370}
5371
5372/**
5373 * lpfc_post_init_setup - Perform necessary device post initialization setup.
5374 * @phba: pointer to lpfc hba data structure.
5375 *
5376 * This routine is invoked to perform all the necessary post initialization
5377 * setup for the device.
5378 **/
5379static void
5380lpfc_post_init_setup(struct lpfc_hba *phba)
5381{
5382 struct Scsi_Host *shost;
5383 struct lpfc_adapter_event_header adapter_event;
5384
5385 /* Get the default values for Model Name and Description */
5386 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
5387
5388 /*
5389 * hba setup may have changed the hba_queue_depth so we need to
5390 * adjust the value of can_queue.
5391 */
5392 shost = pci_get_drvdata(phba->pcidev);
5393 shost->can_queue = phba->cfg_hba_queue_depth - 10;
5394 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
5395 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05005396
5397 lpfc_host_attrib_init(shost);
5398
James Smart2e0fef82007-06-17 19:56:36 -05005399 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
5400 spin_lock_irq(shost->host_lock);
5401 lpfc_poll_start_timer(phba);
5402 spin_unlock_irq(shost->host_lock);
5403 }
James Smart8f6d98d2006-08-01 07:34:00 -04005404
James Smart93996272008-08-24 21:50:30 -04005405 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5406 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04005407 /* Send board arrival event to upper layer */
5408 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
5409 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
5410 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04005411 sizeof(adapter_event),
5412 (char *) &adapter_event,
5413 LPFC_NL_VENDOR_ID);
5414 return;
5415}
5416
5417/**
5418 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
5419 * @phba: pointer to lpfc hba data structure.
5420 *
5421 * This routine is invoked to set up the PCI device memory space for device
5422 * with SLI-3 interface spec.
5423 *
5424 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005425 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005426 * other values - error
5427 **/
5428static int
5429lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
5430{
5431 struct pci_dev *pdev;
5432 unsigned long bar0map_len, bar2map_len;
5433 int i, hbq_count;
5434 void *ptr;
5435 int error = -ENODEV;
5436
5437 /* Obtain PCI device reference */
5438 if (!phba->pcidev)
5439 return error;
5440 else
5441 pdev = phba->pcidev;
5442
5443 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05005444 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
5445 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
5446 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
5447 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smart3772a992009-05-22 14:50:54 -04005448 return error;
Michael Reed8e685972009-09-18 12:02:05 -05005449 }
5450 }
James Smart3772a992009-05-22 14:50:54 -04005451
5452 /* Get the bus address of Bar0 and Bar2 and the number of bytes
5453 * required by each mapping.
5454 */
5455 phba->pci_bar0_map = pci_resource_start(pdev, 0);
5456 bar0map_len = pci_resource_len(pdev, 0);
5457
5458 phba->pci_bar2_map = pci_resource_start(pdev, 2);
5459 bar2map_len = pci_resource_len(pdev, 2);
5460
5461 /* Map HBA SLIM to a kernel virtual address. */
5462 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
5463 if (!phba->slim_memmap_p) {
5464 dev_printk(KERN_ERR, &pdev->dev,
5465 "ioremap failed for SLIM memory.\n");
5466 goto out;
5467 }
5468
5469 /* Map HBA Control Registers to a kernel virtual address. */
5470 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
5471 if (!phba->ctrl_regs_memmap_p) {
5472 dev_printk(KERN_ERR, &pdev->dev,
5473 "ioremap failed for HBA control registers.\n");
5474 goto out_iounmap_slim;
5475 }
5476
5477 /* Allocate memory for SLI-2 structures */
5478 phba->slim2p.virt = dma_alloc_coherent(&pdev->dev,
5479 SLI2_SLIM_SIZE,
5480 &phba->slim2p.phys,
5481 GFP_KERNEL);
5482 if (!phba->slim2p.virt)
5483 goto out_iounmap;
5484
5485 memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
5486 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04005487 phba->mbox_ext = (phba->slim2p.virt +
5488 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04005489 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
5490 phba->IOCBs = (phba->slim2p.virt +
5491 offsetof(struct lpfc_sli2_slim, IOCBs));
5492
5493 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
5494 lpfc_sli_hbq_size(),
5495 &phba->hbqslimp.phys,
5496 GFP_KERNEL);
5497 if (!phba->hbqslimp.virt)
5498 goto out_free_slim;
5499
5500 hbq_count = lpfc_sli_hbq_count();
5501 ptr = phba->hbqslimp.virt;
5502 for (i = 0; i < hbq_count; ++i) {
5503 phba->hbqs[i].hbq_virt = ptr;
5504 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
5505 ptr += (lpfc_hbq_defs[i]->entry_count *
5506 sizeof(struct lpfc_hbq_entry));
5507 }
5508 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
5509 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
5510
5511 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
5512
5513 INIT_LIST_HEAD(&phba->rb_pend_list);
5514
5515 phba->MBslimaddr = phba->slim_memmap_p;
5516 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
5517 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
5518 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
5519 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04005520
dea31012005-04-17 16:05:31 -05005521 return 0;
5522
dea31012005-04-17 16:05:31 -05005523out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04005524 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
5525 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05005526out_iounmap:
5527 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005528out_iounmap_slim:
dea31012005-04-17 16:05:31 -05005529 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05005530out:
5531 return error;
5532}
5533
James Smarte59058c2008-08-24 21:49:00 -04005534/**
James Smart3772a992009-05-22 14:50:54 -04005535 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
5536 * @phba: pointer to lpfc hba data structure.
5537 *
5538 * This routine is invoked to unset the PCI device memory space for device
5539 * with SLI-3 interface spec.
5540 **/
5541static void
5542lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
5543{
5544 struct pci_dev *pdev;
5545
5546 /* Obtain PCI device reference */
5547 if (!phba->pcidev)
5548 return;
5549 else
5550 pdev = phba->pcidev;
5551
5552 /* Free coherent DMA memory allocated */
5553 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
5554 phba->hbqslimp.virt, phba->hbqslimp.phys);
5555 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
5556 phba->slim2p.virt, phba->slim2p.phys);
5557
5558 /* I/O memory unmap */
5559 iounmap(phba->ctrl_regs_memmap_p);
5560 iounmap(phba->slim_memmap_p);
5561
5562 return;
5563}
5564
5565/**
James Smartda0436e2009-05-22 14:51:39 -04005566 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
5567 * @phba: pointer to lpfc hba data structure.
5568 *
5569 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
5570 * done and check status.
5571 *
5572 * Return 0 if successful, otherwise -ENODEV.
5573 **/
5574int
5575lpfc_sli4_post_status_check(struct lpfc_hba *phba)
5576{
James Smart2fcee4b2010-12-15 17:57:46 -05005577 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
5578 struct lpfc_register reg_data;
5579 int i, port_error = 0;
5580 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04005581
James Smart9940b972011-03-11 16:06:12 -05005582 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
5583 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05005584 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04005585 return -ENODEV;
5586
James Smartda0436e2009-05-22 14:51:39 -04005587 /* Wait up to 30 seconds for the SLI Port POST done and ready */
5588 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05005589 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
5590 &portsmphr_reg.word0) ||
5591 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05005592 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04005593 port_error = -ENODEV;
5594 break;
5595 }
James Smart2fcee4b2010-12-15 17:57:46 -05005596 if (LPFC_POST_STAGE_PORT_READY ==
5597 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04005598 break;
James Smartda0436e2009-05-22 14:51:39 -04005599 msleep(10);
5600 }
5601
James Smart2fcee4b2010-12-15 17:57:46 -05005602 /*
5603 * If there was a port error during POST, then don't proceed with
5604 * other register reads as the data may not be valid. Just exit.
5605 */
5606 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04005607 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05005608 "1408 Port Failed POST - portsmphr=0x%x, "
5609 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
5610 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
5611 portsmphr_reg.word0,
5612 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
5613 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
5614 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
5615 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
5616 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
5617 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
5618 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
5619 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
5620 } else {
James Smart28baac72010-02-12 14:42:03 -05005621 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05005622 "2534 Device Info: SLIFamily=0x%x, "
5623 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
5624 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05005625 bf_get(lpfc_sli_intf_sli_family,
5626 &phba->sli4_hba.sli_intf),
5627 bf_get(lpfc_sli_intf_slirev,
5628 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05005629 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05005630 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05005631 bf_get(lpfc_sli_intf_sli_hint1,
5632 &phba->sli4_hba.sli_intf),
5633 bf_get(lpfc_sli_intf_sli_hint2,
5634 &phba->sli4_hba.sli_intf),
5635 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05005636 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05005637 /*
5638 * Check for other Port errors during the initialization
5639 * process. Fail the load if the port did not come up
5640 * correctly.
5641 */
5642 if_type = bf_get(lpfc_sli_intf_if_type,
5643 &phba->sli4_hba.sli_intf);
5644 switch (if_type) {
5645 case LPFC_SLI_INTF_IF_TYPE_0:
5646 phba->sli4_hba.ue_mask_lo =
5647 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
5648 phba->sli4_hba.ue_mask_hi =
5649 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
5650 uerrlo_reg.word0 =
5651 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
5652 uerrhi_reg.word0 =
5653 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
5654 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
5655 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
5656 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5657 "1422 Unrecoverable Error "
5658 "Detected during POST "
5659 "uerr_lo_reg=0x%x, "
5660 "uerr_hi_reg=0x%x, "
5661 "ue_mask_lo_reg=0x%x, "
5662 "ue_mask_hi_reg=0x%x\n",
5663 uerrlo_reg.word0,
5664 uerrhi_reg.word0,
5665 phba->sli4_hba.ue_mask_lo,
5666 phba->sli4_hba.ue_mask_hi);
5667 port_error = -ENODEV;
5668 }
5669 break;
5670 case LPFC_SLI_INTF_IF_TYPE_2:
5671 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05005672 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
5673 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04005674 (bf_get(lpfc_sliport_status_err, &reg_data) &&
5675 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05005676 phba->work_status[0] =
5677 readl(phba->sli4_hba.u.if_type2.
5678 ERR1regaddr);
5679 phba->work_status[1] =
5680 readl(phba->sli4_hba.u.if_type2.
5681 ERR2regaddr);
5682 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5683 "2888 Port Error Detected "
5684 "during POST: "
5685 "port status reg 0x%x, "
5686 "port_smphr reg 0x%x, "
5687 "error 1=0x%x, error 2=0x%x\n",
5688 reg_data.word0,
5689 portsmphr_reg.word0,
5690 phba->work_status[0],
5691 phba->work_status[1]);
5692 port_error = -ENODEV;
5693 }
5694 break;
5695 case LPFC_SLI_INTF_IF_TYPE_1:
5696 default:
5697 break;
5698 }
James Smart28baac72010-02-12 14:42:03 -05005699 }
James Smartda0436e2009-05-22 14:51:39 -04005700 return port_error;
5701}
5702
5703/**
5704 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
5705 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05005706 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04005707 *
5708 * This routine is invoked to set up SLI4 BAR0 PCI config space register
5709 * memory map.
5710 **/
5711static void
James Smart2fcee4b2010-12-15 17:57:46 -05005712lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04005713{
James Smart2fcee4b2010-12-15 17:57:46 -05005714 switch (if_type) {
5715 case LPFC_SLI_INTF_IF_TYPE_0:
5716 phba->sli4_hba.u.if_type0.UERRLOregaddr =
5717 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
5718 phba->sli4_hba.u.if_type0.UERRHIregaddr =
5719 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
5720 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
5721 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
5722 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
5723 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
5724 phba->sli4_hba.SLIINTFregaddr =
5725 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
5726 break;
5727 case LPFC_SLI_INTF_IF_TYPE_2:
5728 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04005729 phba->sli4_hba.conf_regs_memmap_p +
5730 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05005731 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04005732 phba->sli4_hba.conf_regs_memmap_p +
5733 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05005734 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04005735 phba->sli4_hba.conf_regs_memmap_p +
5736 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05005737 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04005738 phba->sli4_hba.conf_regs_memmap_p +
5739 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05005740 phba->sli4_hba.SLIINTFregaddr =
5741 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
5742 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04005743 phba->sli4_hba.conf_regs_memmap_p +
5744 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05005745 phba->sli4_hba.RQDBregaddr =
5746 phba->sli4_hba.conf_regs_memmap_p + LPFC_RQ_DOORBELL;
5747 phba->sli4_hba.WQDBregaddr =
5748 phba->sli4_hba.conf_regs_memmap_p + LPFC_WQ_DOORBELL;
5749 phba->sli4_hba.EQCQDBregaddr =
5750 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
5751 phba->sli4_hba.MQDBregaddr =
5752 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
5753 phba->sli4_hba.BMBXregaddr =
5754 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
5755 break;
5756 case LPFC_SLI_INTF_IF_TYPE_1:
5757 default:
5758 dev_printk(KERN_ERR, &phba->pcidev->dev,
5759 "FATAL - unsupported SLI4 interface type - %d\n",
5760 if_type);
5761 break;
5762 }
James Smartda0436e2009-05-22 14:51:39 -04005763}
5764
5765/**
5766 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
5767 * @phba: pointer to lpfc hba data structure.
5768 *
5769 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
5770 * memory map.
5771 **/
5772static void
5773lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
5774{
James Smart2fcee4b2010-12-15 17:57:46 -05005775 phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
5776 LPFC_SLIPORT_IF0_SMPHR;
James Smartda0436e2009-05-22 14:51:39 -04005777 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05005778 LPFC_HST_ISR0;
James Smartda0436e2009-05-22 14:51:39 -04005779 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05005780 LPFC_HST_IMR0;
James Smartda0436e2009-05-22 14:51:39 -04005781 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05005782 LPFC_HST_ISCR0;
James Smartda0436e2009-05-22 14:51:39 -04005783}
5784
5785/**
5786 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
5787 * @phba: pointer to lpfc hba data structure.
5788 * @vf: virtual function number
5789 *
5790 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
5791 * based on the given viftual function number, @vf.
5792 *
5793 * Return 0 if successful, otherwise -ENODEV.
5794 **/
5795static int
5796lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
5797{
5798 if (vf > LPFC_VIR_FUNC_MAX)
5799 return -ENODEV;
5800
5801 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
5802 vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL);
5803 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
5804 vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL);
5805 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
5806 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
5807 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
5808 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
5809 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
5810 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
5811 return 0;
5812}
5813
5814/**
5815 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
5816 * @phba: pointer to lpfc hba data structure.
5817 *
5818 * This routine is invoked to create the bootstrap mailbox
5819 * region consistent with the SLI-4 interface spec. This
5820 * routine allocates all memory necessary to communicate
5821 * mailbox commands to the port and sets up all alignment
5822 * needs. No locks are expected to be held when calling
5823 * this routine.
5824 *
5825 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005826 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04005827 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04005828 **/
5829static int
5830lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
5831{
5832 uint32_t bmbx_size;
5833 struct lpfc_dmabuf *dmabuf;
5834 struct dma_address *dma_address;
5835 uint32_t pa_addr;
5836 uint64_t phys_addr;
5837
5838 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5839 if (!dmabuf)
5840 return -ENOMEM;
5841
5842 /*
5843 * The bootstrap mailbox region is comprised of 2 parts
5844 * plus an alignment restriction of 16 bytes.
5845 */
5846 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
5847 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
5848 bmbx_size,
5849 &dmabuf->phys,
5850 GFP_KERNEL);
5851 if (!dmabuf->virt) {
5852 kfree(dmabuf);
5853 return -ENOMEM;
5854 }
5855 memset(dmabuf->virt, 0, bmbx_size);
5856
5857 /*
5858 * Initialize the bootstrap mailbox pointers now so that the register
5859 * operations are simple later. The mailbox dma address is required
5860 * to be 16-byte aligned. Also align the virtual memory as each
5861 * maibox is copied into the bmbx mailbox region before issuing the
5862 * command to the port.
5863 */
5864 phba->sli4_hba.bmbx.dmabuf = dmabuf;
5865 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
5866
5867 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
5868 LPFC_ALIGN_16_BYTE);
5869 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
5870 LPFC_ALIGN_16_BYTE);
5871
5872 /*
5873 * Set the high and low physical addresses now. The SLI4 alignment
5874 * requirement is 16 bytes and the mailbox is posted to the port
5875 * as two 30-bit addresses. The other data is a bit marking whether
5876 * the 30-bit address is the high or low address.
5877 * Upcast bmbx aphys to 64bits so shift instruction compiles
5878 * clean on 32 bit machines.
5879 */
5880 dma_address = &phba->sli4_hba.bmbx.dma_address;
5881 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
5882 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
5883 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
5884 LPFC_BMBX_BIT1_ADDR_HI);
5885
5886 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
5887 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
5888 LPFC_BMBX_BIT1_ADDR_LO);
5889 return 0;
5890}
5891
5892/**
5893 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
5894 * @phba: pointer to lpfc hba data structure.
5895 *
5896 * This routine is invoked to teardown the bootstrap mailbox
5897 * region and release all host resources. This routine requires
5898 * the caller to ensure all mailbox commands recovered, no
5899 * additional mailbox comands are sent, and interrupts are disabled
5900 * before calling this routine.
5901 *
5902 **/
5903static void
5904lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
5905{
5906 dma_free_coherent(&phba->pcidev->dev,
5907 phba->sli4_hba.bmbx.bmbx_size,
5908 phba->sli4_hba.bmbx.dmabuf->virt,
5909 phba->sli4_hba.bmbx.dmabuf->phys);
5910
5911 kfree(phba->sli4_hba.bmbx.dmabuf);
5912 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
5913}
5914
5915/**
5916 * lpfc_sli4_read_config - Get the config parameters.
5917 * @phba: pointer to lpfc hba data structure.
5918 *
5919 * This routine is invoked to read the configuration parameters from the HBA.
5920 * The configuration parameters are used to set the base and maximum values
5921 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
5922 * allocation for the port.
5923 *
5924 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005925 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005926 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04005927 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04005928 **/
5929static int
5930lpfc_sli4_read_config(struct lpfc_hba *phba)
5931{
5932 LPFC_MBOXQ_t *pmb;
5933 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04005934 union lpfc_sli4_cfg_shdr *shdr;
5935 uint32_t shdr_status, shdr_add_status;
5936 struct lpfc_mbx_get_func_cfg *get_func_cfg;
5937 struct lpfc_rsrc_desc_fcfcoe *desc;
5938 uint32_t desc_count;
5939 int length, i, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04005940
5941 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5942 if (!pmb) {
5943 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5944 "2011 Unable to allocate memory for issuing "
5945 "SLI_CONFIG_SPECIAL mailbox command\n");
5946 return -ENOMEM;
5947 }
5948
5949 lpfc_read_config(phba, pmb);
5950
5951 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
5952 if (rc != MBX_SUCCESS) {
5953 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5954 "2012 Mailbox failed , mbxCmd x%x "
5955 "READ_CONFIG, mbxStatus x%x\n",
5956 bf_get(lpfc_mqe_command, &pmb->u.mqe),
5957 bf_get(lpfc_mqe_status, &pmb->u.mqe));
5958 rc = -EIO;
5959 } else {
5960 rd_config = &pmb->u.mqe.un.rd_config;
James Smart6d368e52011-05-24 11:44:12 -04005961 phba->sli4_hba.extents_in_use =
5962 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04005963 phba->sli4_hba.max_cfg_param.max_xri =
5964 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
5965 phba->sli4_hba.max_cfg_param.xri_base =
5966 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
5967 phba->sli4_hba.max_cfg_param.max_vpi =
5968 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
5969 phba->sli4_hba.max_cfg_param.vpi_base =
5970 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
5971 phba->sli4_hba.max_cfg_param.max_rpi =
5972 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
5973 phba->sli4_hba.max_cfg_param.rpi_base =
5974 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
5975 phba->sli4_hba.max_cfg_param.max_vfi =
5976 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
5977 phba->sli4_hba.max_cfg_param.vfi_base =
5978 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
5979 phba->sli4_hba.max_cfg_param.max_fcfi =
5980 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04005981 phba->sli4_hba.max_cfg_param.max_eq =
5982 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
5983 phba->sli4_hba.max_cfg_param.max_rq =
5984 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
5985 phba->sli4_hba.max_cfg_param.max_wq =
5986 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
5987 phba->sli4_hba.max_cfg_param.max_cq =
5988 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
5989 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
5990 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
5991 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
5992 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
5993 phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base;
James Smart5ffc2662009-11-18 15:39:44 -05005994 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
5995 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04005996 phba->max_vports = phba->max_vpi;
5997 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04005998 "2003 cfg params Extents? %d "
5999 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04006000 "VPI(B:%d M:%d) "
6001 "VFI(B:%d M:%d) "
6002 "RPI(B:%d M:%d) "
James Smart6d368e52011-05-24 11:44:12 -04006003 "FCFI(Count:%d)\n",
6004 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04006005 phba->sli4_hba.max_cfg_param.xri_base,
6006 phba->sli4_hba.max_cfg_param.max_xri,
6007 phba->sli4_hba.max_cfg_param.vpi_base,
6008 phba->sli4_hba.max_cfg_param.max_vpi,
6009 phba->sli4_hba.max_cfg_param.vfi_base,
6010 phba->sli4_hba.max_cfg_param.max_vfi,
6011 phba->sli4_hba.max_cfg_param.rpi_base,
6012 phba->sli4_hba.max_cfg_param.max_rpi,
James Smartda0436e2009-05-22 14:51:39 -04006013 phba->sli4_hba.max_cfg_param.max_fcfi);
6014 }
James Smart912e3ac2011-05-24 11:42:11 -04006015
6016 if (rc)
6017 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04006018
6019 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smartb92938b2010-06-07 15:24:12 -04006020 if (phba->cfg_hba_queue_depth >
6021 (phba->sli4_hba.max_cfg_param.max_xri -
6022 lpfc_sli4_get_els_iocb_cnt(phba)))
James Smartda0436e2009-05-22 14:51:39 -04006023 phba->cfg_hba_queue_depth =
James Smartb92938b2010-06-07 15:24:12 -04006024 phba->sli4_hba.max_cfg_param.max_xri -
6025 lpfc_sli4_get_els_iocb_cnt(phba);
James Smart912e3ac2011-05-24 11:42:11 -04006026
6027 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
6028 LPFC_SLI_INTF_IF_TYPE_2)
6029 goto read_cfg_out;
6030
6031 /* get the pf# and vf# for SLI4 if_type 2 port */
6032 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
6033 sizeof(struct lpfc_sli4_cfg_mhdr));
6034 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
6035 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
6036 length, LPFC_SLI4_MBX_EMBED);
6037
6038 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
6039 shdr = (union lpfc_sli4_cfg_shdr *)
6040 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
6041 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6042 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6043 if (rc || shdr_status || shdr_add_status) {
6044 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6045 "3026 Mailbox failed , mbxCmd x%x "
6046 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
6047 bf_get(lpfc_mqe_command, &pmb->u.mqe),
6048 bf_get(lpfc_mqe_status, &pmb->u.mqe));
6049 rc = -EIO;
6050 goto read_cfg_out;
6051 }
6052
6053 /* search for fc_fcoe resrouce descriptor */
6054 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
6055 desc_count = get_func_cfg->func_cfg.rsrc_desc_count;
6056
6057 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
6058 desc = (struct lpfc_rsrc_desc_fcfcoe *)
6059 &get_func_cfg->func_cfg.desc[i];
6060 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
6061 bf_get(lpfc_rsrc_desc_pcie_type, desc)) {
6062 phba->sli4_hba.iov.pf_number =
6063 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
6064 phba->sli4_hba.iov.vf_number =
6065 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
6066 break;
6067 }
6068 }
6069
6070 if (i < LPFC_RSRC_DESC_MAX_NUM)
6071 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6072 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
6073 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
6074 phba->sli4_hba.iov.vf_number);
6075 else {
6076 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6077 "3028 GET_FUNCTION_CONFIG: failed to find "
6078 "Resrouce Descriptor:x%x\n",
6079 LPFC_RSRC_DESC_TYPE_FCFCOE);
6080 rc = -EIO;
6081 }
6082
6083read_cfg_out:
6084 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04006085 return rc;
6086}
6087
6088/**
James Smart2fcee4b2010-12-15 17:57:46 -05006089 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04006090 * @phba: pointer to lpfc hba data structure.
6091 *
James Smart2fcee4b2010-12-15 17:57:46 -05006092 * This routine is invoked to setup the port-side endian order when
6093 * the port if_type is 0. This routine has no function for other
6094 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04006095 *
6096 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006097 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006098 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006099 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006100 **/
6101static int
6102lpfc_setup_endian_order(struct lpfc_hba *phba)
6103{
6104 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05006105 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04006106 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
6107 HOST_ENDIAN_HIGH_WORD1};
6108
James Smart2fcee4b2010-12-15 17:57:46 -05006109 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
6110 switch (if_type) {
6111 case LPFC_SLI_INTF_IF_TYPE_0:
6112 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
6113 GFP_KERNEL);
6114 if (!mboxq) {
6115 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6116 "0492 Unable to allocate memory for "
6117 "issuing SLI_CONFIG_SPECIAL mailbox "
6118 "command\n");
6119 return -ENOMEM;
6120 }
James Smartda0436e2009-05-22 14:51:39 -04006121
James Smart2fcee4b2010-12-15 17:57:46 -05006122 /*
6123 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
6124 * two words to contain special data values and no other data.
6125 */
6126 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
6127 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
6128 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6129 if (rc != MBX_SUCCESS) {
6130 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6131 "0493 SLI_CONFIG_SPECIAL mailbox "
6132 "failed with status x%x\n",
6133 rc);
6134 rc = -EIO;
6135 }
6136 mempool_free(mboxq, phba->mbox_mem_pool);
6137 break;
6138 case LPFC_SLI_INTF_IF_TYPE_2:
6139 case LPFC_SLI_INTF_IF_TYPE_1:
6140 default:
6141 break;
James Smartda0436e2009-05-22 14:51:39 -04006142 }
James Smartda0436e2009-05-22 14:51:39 -04006143 return rc;
6144}
6145
6146/**
6147 * lpfc_sli4_queue_create - Create all the SLI4 queues
6148 * @phba: pointer to lpfc hba data structure.
6149 *
6150 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
6151 * operation. For each SLI4 queue type, the parameters such as queue entry
6152 * count (queue depth) shall be taken from the module parameter. For now,
6153 * we just use some constant number as place holder.
6154 *
6155 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006156 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006157 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006158 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006159 **/
6160static int
6161lpfc_sli4_queue_create(struct lpfc_hba *phba)
6162{
6163 struct lpfc_queue *qdesc;
6164 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
6165 int cfg_fcp_wq_count;
6166 int cfg_fcp_eq_count;
6167
6168 /*
6169 * Sanity check for confiugred queue parameters against the run-time
6170 * device parameters
6171 */
6172
6173 /* Sanity check on FCP fast-path WQ parameters */
6174 cfg_fcp_wq_count = phba->cfg_fcp_wq_count;
6175 if (cfg_fcp_wq_count >
6176 (phba->sli4_hba.max_cfg_param.max_wq - LPFC_SP_WQN_DEF)) {
6177 cfg_fcp_wq_count = phba->sli4_hba.max_cfg_param.max_wq -
6178 LPFC_SP_WQN_DEF;
6179 if (cfg_fcp_wq_count < LPFC_FP_WQN_MIN) {
6180 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6181 "2581 Not enough WQs (%d) from "
6182 "the pci function for supporting "
6183 "FCP WQs (%d)\n",
6184 phba->sli4_hba.max_cfg_param.max_wq,
6185 phba->cfg_fcp_wq_count);
6186 goto out_error;
6187 }
6188 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6189 "2582 Not enough WQs (%d) from the pci "
6190 "function for supporting the requested "
6191 "FCP WQs (%d), the actual FCP WQs can "
6192 "be supported: %d\n",
6193 phba->sli4_hba.max_cfg_param.max_wq,
6194 phba->cfg_fcp_wq_count, cfg_fcp_wq_count);
6195 }
6196 /* The actual number of FCP work queues adopted */
6197 phba->cfg_fcp_wq_count = cfg_fcp_wq_count;
6198
6199 /* Sanity check on FCP fast-path EQ parameters */
6200 cfg_fcp_eq_count = phba->cfg_fcp_eq_count;
6201 if (cfg_fcp_eq_count >
6202 (phba->sli4_hba.max_cfg_param.max_eq - LPFC_SP_EQN_DEF)) {
6203 cfg_fcp_eq_count = phba->sli4_hba.max_cfg_param.max_eq -
6204 LPFC_SP_EQN_DEF;
6205 if (cfg_fcp_eq_count < LPFC_FP_EQN_MIN) {
6206 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6207 "2574 Not enough EQs (%d) from the "
6208 "pci function for supporting FCP "
6209 "EQs (%d)\n",
6210 phba->sli4_hba.max_cfg_param.max_eq,
6211 phba->cfg_fcp_eq_count);
6212 goto out_error;
6213 }
6214 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6215 "2575 Not enough EQs (%d) from the pci "
6216 "function for supporting the requested "
6217 "FCP EQs (%d), the actual FCP EQs can "
6218 "be supported: %d\n",
6219 phba->sli4_hba.max_cfg_param.max_eq,
6220 phba->cfg_fcp_eq_count, cfg_fcp_eq_count);
6221 }
6222 /* It does not make sense to have more EQs than WQs */
6223 if (cfg_fcp_eq_count > phba->cfg_fcp_wq_count) {
6224 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smart6a9c52c2009-10-02 15:16:51 -04006225 "2593 The FCP EQ count(%d) cannot be greater "
6226 "than the FCP WQ count(%d), limiting the "
6227 "FCP EQ count to %d\n", cfg_fcp_eq_count,
James Smartda0436e2009-05-22 14:51:39 -04006228 phba->cfg_fcp_wq_count,
6229 phba->cfg_fcp_wq_count);
6230 cfg_fcp_eq_count = phba->cfg_fcp_wq_count;
6231 }
6232 /* The actual number of FCP event queues adopted */
6233 phba->cfg_fcp_eq_count = cfg_fcp_eq_count;
6234 /* The overall number of event queues used */
6235 phba->sli4_hba.cfg_eqn = phba->cfg_fcp_eq_count + LPFC_SP_EQN_DEF;
6236
6237 /*
6238 * Create Event Queues (EQs)
6239 */
6240
6241 /* Get EQ depth from module parameter, fake the default for now */
6242 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
6243 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
6244
6245 /* Create slow path event queue */
6246 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
6247 phba->sli4_hba.eq_ecount);
6248 if (!qdesc) {
6249 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6250 "0496 Failed allocate slow-path EQ\n");
6251 goto out_error;
6252 }
6253 phba->sli4_hba.sp_eq = qdesc;
6254
6255 /* Create fast-path FCP Event Queue(s) */
6256 phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) *
6257 phba->cfg_fcp_eq_count), GFP_KERNEL);
6258 if (!phba->sli4_hba.fp_eq) {
6259 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6260 "2576 Failed allocate memory for fast-path "
6261 "EQ record array\n");
6262 goto out_free_sp_eq;
6263 }
6264 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
6265 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
6266 phba->sli4_hba.eq_ecount);
6267 if (!qdesc) {
6268 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6269 "0497 Failed allocate fast-path EQ\n");
6270 goto out_free_fp_eq;
6271 }
6272 phba->sli4_hba.fp_eq[fcp_eqidx] = qdesc;
6273 }
6274
6275 /*
6276 * Create Complete Queues (CQs)
6277 */
6278
6279 /* Get CQ depth from module parameter, fake the default for now */
6280 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
6281 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
6282
6283 /* Create slow-path Mailbox Command Complete Queue */
6284 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
6285 phba->sli4_hba.cq_ecount);
6286 if (!qdesc) {
6287 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6288 "0500 Failed allocate slow-path mailbox CQ\n");
6289 goto out_free_fp_eq;
6290 }
6291 phba->sli4_hba.mbx_cq = qdesc;
6292
6293 /* Create slow-path ELS Complete Queue */
6294 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
6295 phba->sli4_hba.cq_ecount);
6296 if (!qdesc) {
6297 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6298 "0501 Failed allocate slow-path ELS CQ\n");
6299 goto out_free_mbx_cq;
6300 }
6301 phba->sli4_hba.els_cq = qdesc;
6302
James Smartda0436e2009-05-22 14:51:39 -04006303
6304 /* Create fast-path FCP Completion Queue(s), one-to-one with EQs */
6305 phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
6306 phba->cfg_fcp_eq_count), GFP_KERNEL);
6307 if (!phba->sli4_hba.fcp_cq) {
6308 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6309 "2577 Failed allocate memory for fast-path "
6310 "CQ record array\n");
James Smart4d9ab992009-10-02 15:16:39 -04006311 goto out_free_els_cq;
James Smartda0436e2009-05-22 14:51:39 -04006312 }
6313 for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) {
6314 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
6315 phba->sli4_hba.cq_ecount);
6316 if (!qdesc) {
6317 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6318 "0499 Failed allocate fast-path FCP "
6319 "CQ (%d)\n", fcp_cqidx);
6320 goto out_free_fcp_cq;
6321 }
6322 phba->sli4_hba.fcp_cq[fcp_cqidx] = qdesc;
6323 }
6324
6325 /* Create Mailbox Command Queue */
6326 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
6327 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
6328
6329 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
6330 phba->sli4_hba.mq_ecount);
6331 if (!qdesc) {
6332 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6333 "0505 Failed allocate slow-path MQ\n");
6334 goto out_free_fcp_cq;
6335 }
6336 phba->sli4_hba.mbx_wq = qdesc;
6337
6338 /*
6339 * Create all the Work Queues (WQs)
6340 */
6341 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
6342 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
6343
6344 /* Create slow-path ELS Work Queue */
6345 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
6346 phba->sli4_hba.wq_ecount);
6347 if (!qdesc) {
6348 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6349 "0504 Failed allocate slow-path ELS WQ\n");
6350 goto out_free_mbx_wq;
6351 }
6352 phba->sli4_hba.els_wq = qdesc;
6353
6354 /* Create fast-path FCP Work Queue(s) */
6355 phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
6356 phba->cfg_fcp_wq_count), GFP_KERNEL);
6357 if (!phba->sli4_hba.fcp_wq) {
6358 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6359 "2578 Failed allocate memory for fast-path "
6360 "WQ record array\n");
6361 goto out_free_els_wq;
6362 }
6363 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
6364 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
6365 phba->sli4_hba.wq_ecount);
6366 if (!qdesc) {
6367 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6368 "0503 Failed allocate fast-path FCP "
6369 "WQ (%d)\n", fcp_wqidx);
6370 goto out_free_fcp_wq;
6371 }
6372 phba->sli4_hba.fcp_wq[fcp_wqidx] = qdesc;
6373 }
6374
6375 /*
6376 * Create Receive Queue (RQ)
6377 */
6378 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
6379 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
6380
6381 /* Create Receive Queue for header */
6382 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
6383 phba->sli4_hba.rq_ecount);
6384 if (!qdesc) {
6385 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6386 "0506 Failed allocate receive HRQ\n");
6387 goto out_free_fcp_wq;
6388 }
6389 phba->sli4_hba.hdr_rq = qdesc;
6390
6391 /* Create Receive Queue for data */
6392 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
6393 phba->sli4_hba.rq_ecount);
6394 if (!qdesc) {
6395 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6396 "0507 Failed allocate receive DRQ\n");
6397 goto out_free_hdr_rq;
6398 }
6399 phba->sli4_hba.dat_rq = qdesc;
6400
6401 return 0;
6402
6403out_free_hdr_rq:
6404 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
6405 phba->sli4_hba.hdr_rq = NULL;
6406out_free_fcp_wq:
6407 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) {
6408 lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_wqidx]);
6409 phba->sli4_hba.fcp_wq[fcp_wqidx] = NULL;
6410 }
6411 kfree(phba->sli4_hba.fcp_wq);
6412out_free_els_wq:
6413 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
6414 phba->sli4_hba.els_wq = NULL;
6415out_free_mbx_wq:
6416 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
6417 phba->sli4_hba.mbx_wq = NULL;
6418out_free_fcp_cq:
6419 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) {
6420 lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_cqidx]);
6421 phba->sli4_hba.fcp_cq[fcp_cqidx] = NULL;
6422 }
6423 kfree(phba->sli4_hba.fcp_cq);
James Smartda0436e2009-05-22 14:51:39 -04006424out_free_els_cq:
6425 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
6426 phba->sli4_hba.els_cq = NULL;
6427out_free_mbx_cq:
6428 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
6429 phba->sli4_hba.mbx_cq = NULL;
6430out_free_fp_eq:
6431 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) {
6432 lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_eqidx]);
6433 phba->sli4_hba.fp_eq[fcp_eqidx] = NULL;
6434 }
6435 kfree(phba->sli4_hba.fp_eq);
6436out_free_sp_eq:
6437 lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
6438 phba->sli4_hba.sp_eq = NULL;
6439out_error:
6440 return -ENOMEM;
6441}
6442
6443/**
6444 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
6445 * @phba: pointer to lpfc hba data structure.
6446 *
6447 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
6448 * operation.
6449 *
6450 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006451 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006452 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006453 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006454 **/
6455static void
6456lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
6457{
6458 int fcp_qidx;
6459
6460 /* Release mailbox command work queue */
6461 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
6462 phba->sli4_hba.mbx_wq = NULL;
6463
6464 /* Release ELS work queue */
6465 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
6466 phba->sli4_hba.els_wq = NULL;
6467
6468 /* Release FCP work queue */
6469 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
6470 lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_qidx]);
6471 kfree(phba->sli4_hba.fcp_wq);
6472 phba->sli4_hba.fcp_wq = NULL;
6473
6474 /* Release unsolicited receive queue */
6475 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
6476 phba->sli4_hba.hdr_rq = NULL;
6477 lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
6478 phba->sli4_hba.dat_rq = NULL;
6479
James Smartda0436e2009-05-22 14:51:39 -04006480 /* Release ELS complete queue */
6481 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
6482 phba->sli4_hba.els_cq = NULL;
6483
6484 /* Release mailbox command complete queue */
6485 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
6486 phba->sli4_hba.mbx_cq = NULL;
6487
6488 /* Release FCP response complete queue */
James Smart05580562011-05-24 11:40:48 -04006489 fcp_qidx = 0;
6490 do
James Smartda0436e2009-05-22 14:51:39 -04006491 lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_qidx]);
James Smart05580562011-05-24 11:40:48 -04006492 while (++fcp_qidx < phba->cfg_fcp_eq_count);
James Smartda0436e2009-05-22 14:51:39 -04006493 kfree(phba->sli4_hba.fcp_cq);
6494 phba->sli4_hba.fcp_cq = NULL;
6495
6496 /* Release fast-path event queue */
6497 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
6498 lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]);
6499 kfree(phba->sli4_hba.fp_eq);
6500 phba->sli4_hba.fp_eq = NULL;
6501
6502 /* Release slow-path event queue */
6503 lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
6504 phba->sli4_hba.sp_eq = NULL;
6505
6506 return;
6507}
6508
6509/**
6510 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
6511 * @phba: pointer to lpfc hba data structure.
6512 *
6513 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
6514 * operation.
6515 *
6516 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006517 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006518 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006519 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006520 **/
6521int
6522lpfc_sli4_queue_setup(struct lpfc_hba *phba)
6523{
6524 int rc = -ENOMEM;
6525 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
6526 int fcp_cq_index = 0;
6527
6528 /*
6529 * Set up Event Queues (EQs)
6530 */
6531
6532 /* Set up slow-path event queue */
6533 if (!phba->sli4_hba.sp_eq) {
6534 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6535 "0520 Slow-path EQ not allocated\n");
6536 goto out_error;
6537 }
6538 rc = lpfc_eq_create(phba, phba->sli4_hba.sp_eq,
6539 LPFC_SP_DEF_IMAX);
6540 if (rc) {
6541 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6542 "0521 Failed setup of slow-path EQ: "
6543 "rc = 0x%x\n", rc);
6544 goto out_error;
6545 }
6546 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6547 "2583 Slow-path EQ setup: queue-id=%d\n",
6548 phba->sli4_hba.sp_eq->queue_id);
6549
6550 /* Set up fast-path event queue */
6551 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
6552 if (!phba->sli4_hba.fp_eq[fcp_eqidx]) {
6553 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6554 "0522 Fast-path EQ (%d) not "
6555 "allocated\n", fcp_eqidx);
6556 goto out_destroy_fp_eq;
6557 }
6558 rc = lpfc_eq_create(phba, phba->sli4_hba.fp_eq[fcp_eqidx],
6559 phba->cfg_fcp_imax);
6560 if (rc) {
6561 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6562 "0523 Failed setup of fast-path EQ "
6563 "(%d), rc = 0x%x\n", fcp_eqidx, rc);
6564 goto out_destroy_fp_eq;
6565 }
6566 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6567 "2584 Fast-path EQ setup: "
6568 "queue[%d]-id=%d\n", fcp_eqidx,
6569 phba->sli4_hba.fp_eq[fcp_eqidx]->queue_id);
6570 }
6571
6572 /*
6573 * Set up Complete Queues (CQs)
6574 */
6575
6576 /* Set up slow-path MBOX Complete Queue as the first CQ */
6577 if (!phba->sli4_hba.mbx_cq) {
6578 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6579 "0528 Mailbox CQ not allocated\n");
6580 goto out_destroy_fp_eq;
6581 }
6582 rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, phba->sli4_hba.sp_eq,
6583 LPFC_MCQ, LPFC_MBOX);
6584 if (rc) {
6585 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6586 "0529 Failed setup of slow-path mailbox CQ: "
6587 "rc = 0x%x\n", rc);
6588 goto out_destroy_fp_eq;
6589 }
6590 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6591 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
6592 phba->sli4_hba.mbx_cq->queue_id,
6593 phba->sli4_hba.sp_eq->queue_id);
6594
6595 /* Set up slow-path ELS Complete Queue */
6596 if (!phba->sli4_hba.els_cq) {
6597 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6598 "0530 ELS CQ not allocated\n");
6599 goto out_destroy_mbx_cq;
6600 }
6601 rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, phba->sli4_hba.sp_eq,
6602 LPFC_WCQ, LPFC_ELS);
6603 if (rc) {
6604 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6605 "0531 Failed setup of slow-path ELS CQ: "
6606 "rc = 0x%x\n", rc);
6607 goto out_destroy_mbx_cq;
6608 }
6609 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6610 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
6611 phba->sli4_hba.els_cq->queue_id,
6612 phba->sli4_hba.sp_eq->queue_id);
6613
James Smartda0436e2009-05-22 14:51:39 -04006614 /* Set up fast-path FCP Response Complete Queue */
James Smart05580562011-05-24 11:40:48 -04006615 fcp_cqidx = 0;
6616 do {
James Smartda0436e2009-05-22 14:51:39 -04006617 if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
6618 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6619 "0526 Fast-path FCP CQ (%d) not "
6620 "allocated\n", fcp_cqidx);
6621 goto out_destroy_fcp_cq;
6622 }
James Smart05580562011-05-24 11:40:48 -04006623 if (phba->cfg_fcp_eq_count)
6624 rc = lpfc_cq_create(phba,
6625 phba->sli4_hba.fcp_cq[fcp_cqidx],
6626 phba->sli4_hba.fp_eq[fcp_cqidx],
6627 LPFC_WCQ, LPFC_FCP);
6628 else
6629 rc = lpfc_cq_create(phba,
6630 phba->sli4_hba.fcp_cq[fcp_cqidx],
6631 phba->sli4_hba.sp_eq,
6632 LPFC_WCQ, LPFC_FCP);
James Smartda0436e2009-05-22 14:51:39 -04006633 if (rc) {
6634 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6635 "0527 Failed setup of fast-path FCP "
6636 "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc);
6637 goto out_destroy_fcp_cq;
6638 }
6639 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6640 "2588 FCP CQ setup: cq[%d]-id=%d, "
James Smart05580562011-05-24 11:40:48 -04006641 "parent %seq[%d]-id=%d\n",
James Smartda0436e2009-05-22 14:51:39 -04006642 fcp_cqidx,
6643 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
James Smart05580562011-05-24 11:40:48 -04006644 (phba->cfg_fcp_eq_count) ? "" : "sp_",
James Smartda0436e2009-05-22 14:51:39 -04006645 fcp_cqidx,
James Smart05580562011-05-24 11:40:48 -04006646 (phba->cfg_fcp_eq_count) ?
6647 phba->sli4_hba.fp_eq[fcp_cqidx]->queue_id :
6648 phba->sli4_hba.sp_eq->queue_id);
6649 } while (++fcp_cqidx < phba->cfg_fcp_eq_count);
James Smartda0436e2009-05-22 14:51:39 -04006650
6651 /*
6652 * Set up all the Work Queues (WQs)
6653 */
6654
6655 /* Set up Mailbox Command Queue */
6656 if (!phba->sli4_hba.mbx_wq) {
6657 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6658 "0538 Slow-path MQ not allocated\n");
6659 goto out_destroy_fcp_cq;
6660 }
6661 rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
6662 phba->sli4_hba.mbx_cq, LPFC_MBOX);
6663 if (rc) {
6664 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6665 "0539 Failed setup of slow-path MQ: "
6666 "rc = 0x%x\n", rc);
6667 goto out_destroy_fcp_cq;
6668 }
6669 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6670 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
6671 phba->sli4_hba.mbx_wq->queue_id,
6672 phba->sli4_hba.mbx_cq->queue_id);
6673
6674 /* Set up slow-path ELS Work Queue */
6675 if (!phba->sli4_hba.els_wq) {
6676 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6677 "0536 Slow-path ELS WQ not allocated\n");
6678 goto out_destroy_mbx_wq;
6679 }
6680 rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
6681 phba->sli4_hba.els_cq, LPFC_ELS);
6682 if (rc) {
6683 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6684 "0537 Failed setup of slow-path ELS WQ: "
6685 "rc = 0x%x\n", rc);
6686 goto out_destroy_mbx_wq;
6687 }
6688 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6689 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
6690 phba->sli4_hba.els_wq->queue_id,
6691 phba->sli4_hba.els_cq->queue_id);
6692
6693 /* Set up fast-path FCP Work Queue */
6694 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
6695 if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
6696 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6697 "0534 Fast-path FCP WQ (%d) not "
6698 "allocated\n", fcp_wqidx);
6699 goto out_destroy_fcp_wq;
6700 }
6701 rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
6702 phba->sli4_hba.fcp_cq[fcp_cq_index],
6703 LPFC_FCP);
6704 if (rc) {
6705 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6706 "0535 Failed setup of fast-path FCP "
6707 "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc);
6708 goto out_destroy_fcp_wq;
6709 }
6710 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6711 "2591 FCP WQ setup: wq[%d]-id=%d, "
6712 "parent cq[%d]-id=%d\n",
6713 fcp_wqidx,
6714 phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
6715 fcp_cq_index,
6716 phba->sli4_hba.fcp_cq[fcp_cq_index]->queue_id);
6717 /* Round robin FCP Work Queue's Completion Queue assignment */
James Smart05580562011-05-24 11:40:48 -04006718 if (phba->cfg_fcp_eq_count)
6719 fcp_cq_index = ((fcp_cq_index + 1) %
6720 phba->cfg_fcp_eq_count);
James Smartda0436e2009-05-22 14:51:39 -04006721 }
6722
6723 /*
6724 * Create Receive Queue (RQ)
6725 */
6726 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
6727 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6728 "0540 Receive Queue not allocated\n");
6729 goto out_destroy_fcp_wq;
6730 }
6731 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04006732 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04006733 if (rc) {
6734 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6735 "0541 Failed setup of Receive Queue: "
6736 "rc = 0x%x\n", rc);
6737 goto out_destroy_fcp_wq;
6738 }
6739 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6740 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
6741 "parent cq-id=%d\n",
6742 phba->sli4_hba.hdr_rq->queue_id,
6743 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04006744 phba->sli4_hba.els_cq->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04006745 return 0;
6746
6747out_destroy_fcp_wq:
6748 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
6749 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
6750 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
6751out_destroy_mbx_wq:
6752 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
6753out_destroy_fcp_cq:
6754 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
6755 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
James Smartda0436e2009-05-22 14:51:39 -04006756 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
6757out_destroy_mbx_cq:
6758 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
6759out_destroy_fp_eq:
6760 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
6761 lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_eqidx]);
6762 lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
6763out_error:
6764 return rc;
6765}
6766
6767/**
6768 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
6769 * @phba: pointer to lpfc hba data structure.
6770 *
6771 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
6772 * operation.
6773 *
6774 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006775 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006776 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006777 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006778 **/
6779void
6780lpfc_sli4_queue_unset(struct lpfc_hba *phba)
6781{
6782 int fcp_qidx;
6783
6784 /* Unset mailbox command work queue */
6785 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
6786 /* Unset ELS work queue */
6787 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
6788 /* Unset unsolicited receive queue */
6789 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
6790 /* Unset FCP work queue */
6791 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
6792 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
6793 /* Unset mailbox command complete queue */
6794 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
6795 /* Unset ELS complete queue */
6796 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
James Smartda0436e2009-05-22 14:51:39 -04006797 /* Unset FCP response complete queue */
6798 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
6799 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
6800 /* Unset fast-path event queue */
6801 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
6802 lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_qidx]);
6803 /* Unset slow-path event queue */
6804 lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
6805}
6806
6807/**
6808 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
6809 * @phba: pointer to lpfc hba data structure.
6810 *
6811 * This routine is invoked to allocate and set up a pool of completion queue
6812 * events. The body of the completion queue event is a completion queue entry
6813 * CQE. For now, this pool is used for the interrupt service routine to queue
6814 * the following HBA completion queue events for the worker thread to process:
6815 * - Mailbox asynchronous events
6816 * - Receive queue completion unsolicited events
6817 * Later, this can be used for all the slow-path events.
6818 *
6819 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006820 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006821 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04006822 **/
6823static int
6824lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
6825{
6826 struct lpfc_cq_event *cq_event;
6827 int i;
6828
6829 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
6830 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
6831 if (!cq_event)
6832 goto out_pool_create_fail;
6833 list_add_tail(&cq_event->list,
6834 &phba->sli4_hba.sp_cqe_event_pool);
6835 }
6836 return 0;
6837
6838out_pool_create_fail:
6839 lpfc_sli4_cq_event_pool_destroy(phba);
6840 return -ENOMEM;
6841}
6842
6843/**
6844 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
6845 * @phba: pointer to lpfc hba data structure.
6846 *
6847 * This routine is invoked to free the pool of completion queue events at
6848 * driver unload time. Note that, it is the responsibility of the driver
6849 * cleanup routine to free all the outstanding completion-queue events
6850 * allocated from this pool back into the pool before invoking this routine
6851 * to destroy the pool.
6852 **/
6853static void
6854lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
6855{
6856 struct lpfc_cq_event *cq_event, *next_cq_event;
6857
6858 list_for_each_entry_safe(cq_event, next_cq_event,
6859 &phba->sli4_hba.sp_cqe_event_pool, list) {
6860 list_del(&cq_event->list);
6861 kfree(cq_event);
6862 }
6863}
6864
6865/**
6866 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
6867 * @phba: pointer to lpfc hba data structure.
6868 *
6869 * This routine is the lock free version of the API invoked to allocate a
6870 * completion-queue event from the free pool.
6871 *
6872 * Return: Pointer to the newly allocated completion-queue event if successful
6873 * NULL otherwise.
6874 **/
6875struct lpfc_cq_event *
6876__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
6877{
6878 struct lpfc_cq_event *cq_event = NULL;
6879
6880 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
6881 struct lpfc_cq_event, list);
6882 return cq_event;
6883}
6884
6885/**
6886 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
6887 * @phba: pointer to lpfc hba data structure.
6888 *
6889 * This routine is the lock version of the API invoked to allocate a
6890 * completion-queue event from the free pool.
6891 *
6892 * Return: Pointer to the newly allocated completion-queue event if successful
6893 * NULL otherwise.
6894 **/
6895struct lpfc_cq_event *
6896lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
6897{
6898 struct lpfc_cq_event *cq_event;
6899 unsigned long iflags;
6900
6901 spin_lock_irqsave(&phba->hbalock, iflags);
6902 cq_event = __lpfc_sli4_cq_event_alloc(phba);
6903 spin_unlock_irqrestore(&phba->hbalock, iflags);
6904 return cq_event;
6905}
6906
6907/**
6908 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
6909 * @phba: pointer to lpfc hba data structure.
6910 * @cq_event: pointer to the completion queue event to be freed.
6911 *
6912 * This routine is the lock free version of the API invoked to release a
6913 * completion-queue event back into the free pool.
6914 **/
6915void
6916__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
6917 struct lpfc_cq_event *cq_event)
6918{
6919 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
6920}
6921
6922/**
6923 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
6924 * @phba: pointer to lpfc hba data structure.
6925 * @cq_event: pointer to the completion queue event to be freed.
6926 *
6927 * This routine is the lock version of the API invoked to release a
6928 * completion-queue event back into the free pool.
6929 **/
6930void
6931lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
6932 struct lpfc_cq_event *cq_event)
6933{
6934 unsigned long iflags;
6935 spin_lock_irqsave(&phba->hbalock, iflags);
6936 __lpfc_sli4_cq_event_release(phba, cq_event);
6937 spin_unlock_irqrestore(&phba->hbalock, iflags);
6938}
6939
6940/**
6941 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
6942 * @phba: pointer to lpfc hba data structure.
6943 *
6944 * This routine is to free all the pending completion-queue events to the
6945 * back into the free pool for device reset.
6946 **/
6947static void
6948lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
6949{
6950 LIST_HEAD(cqelist);
6951 struct lpfc_cq_event *cqe;
6952 unsigned long iflags;
6953
6954 /* Retrieve all the pending WCQEs from pending WCQE lists */
6955 spin_lock_irqsave(&phba->hbalock, iflags);
6956 /* Pending FCP XRI abort events */
6957 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
6958 &cqelist);
6959 /* Pending ELS XRI abort events */
6960 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
6961 &cqelist);
6962 /* Pending asynnc events */
6963 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
6964 &cqelist);
6965 spin_unlock_irqrestore(&phba->hbalock, iflags);
6966
6967 while (!list_empty(&cqelist)) {
6968 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
6969 lpfc_sli4_cq_event_release(phba, cqe);
6970 }
6971}
6972
6973/**
6974 * lpfc_pci_function_reset - Reset pci function.
6975 * @phba: pointer to lpfc hba data structure.
6976 *
6977 * This routine is invoked to request a PCI function reset. It will destroys
6978 * all resources assigned to the PCI function which originates this request.
6979 *
6980 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006981 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006982 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04006983 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04006984 **/
6985int
6986lpfc_pci_function_reset(struct lpfc_hba *phba)
6987{
6988 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05006989 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04006990 uint32_t shdr_status, shdr_add_status;
James Smart2fcee4b2010-12-15 17:57:46 -05006991 uint32_t rdy_chk, num_resets = 0, reset_again = 0;
James Smartda0436e2009-05-22 14:51:39 -04006992 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05006993 struct lpfc_register reg_data;
James Smartda0436e2009-05-22 14:51:39 -04006994
James Smart2fcee4b2010-12-15 17:57:46 -05006995 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
6996 switch (if_type) {
6997 case LPFC_SLI_INTF_IF_TYPE_0:
6998 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
6999 GFP_KERNEL);
7000 if (!mboxq) {
7001 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7002 "0494 Unable to allocate memory for "
7003 "issuing SLI_FUNCTION_RESET mailbox "
7004 "command\n");
7005 return -ENOMEM;
7006 }
7007
7008 /* Setup PCI function reset mailbox-ioctl command */
7009 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
7010 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
7011 LPFC_SLI4_MBX_EMBED);
7012 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7013 shdr = (union lpfc_sli4_cfg_shdr *)
7014 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
7015 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7016 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
7017 &shdr->response);
7018 if (rc != MBX_TIMEOUT)
7019 mempool_free(mboxq, phba->mbox_mem_pool);
7020 if (shdr_status || shdr_add_status || rc) {
7021 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7022 "0495 SLI_FUNCTION_RESET mailbox "
7023 "failed with status x%x add_status x%x,"
7024 " mbx status x%x\n",
7025 shdr_status, shdr_add_status, rc);
7026 rc = -ENXIO;
7027 }
7028 break;
7029 case LPFC_SLI_INTF_IF_TYPE_2:
7030 for (num_resets = 0;
7031 num_resets < MAX_IF_TYPE_2_RESETS;
7032 num_resets++) {
7033 reg_data.word0 = 0;
7034 bf_set(lpfc_sliport_ctrl_end, &reg_data,
7035 LPFC_SLIPORT_LITTLE_ENDIAN);
7036 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
7037 LPFC_SLIPORT_INIT_PORT);
7038 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
7039 CTRLregaddr);
7040
7041 /*
7042 * Poll the Port Status Register and wait for RDY for
7043 * up to 10 seconds. If the port doesn't respond, treat
7044 * it as an error. If the port responds with RN, start
7045 * the loop again.
7046 */
7047 for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) {
James Smart9940b972011-03-11 16:06:12 -05007048 if (lpfc_readl(phba->sli4_hba.u.if_type2.
7049 STATUSregaddr, &reg_data.word0)) {
7050 rc = -ENODEV;
7051 break;
7052 }
James Smart2fcee4b2010-12-15 17:57:46 -05007053 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
7054 break;
7055 if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
7056 reset_again++;
7057 break;
7058 }
7059 msleep(10);
7060 }
7061
7062 /*
7063 * If the port responds to the init request with
7064 * reset needed, delay for a bit and restart the loop.
7065 */
7066 if (reset_again) {
7067 msleep(10);
7068 reset_again = 0;
7069 continue;
7070 }
7071
7072 /* Detect any port errors. */
James Smart9940b972011-03-11 16:06:12 -05007073 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
7074 &reg_data.word0)) {
7075 rc = -ENODEV;
7076 break;
7077 }
James Smart2fcee4b2010-12-15 17:57:46 -05007078 if ((bf_get(lpfc_sliport_status_err, &reg_data)) ||
7079 (rdy_chk >= 1000)) {
7080 phba->work_status[0] = readl(
7081 phba->sli4_hba.u.if_type2.ERR1regaddr);
7082 phba->work_status[1] = readl(
7083 phba->sli4_hba.u.if_type2.ERR2regaddr);
7084 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7085 "2890 Port Error Detected "
7086 "during Port Reset: "
7087 "port status reg 0x%x, "
7088 "error 1=0x%x, error 2=0x%x\n",
7089 reg_data.word0,
7090 phba->work_status[0],
7091 phba->work_status[1]);
7092 rc = -ENODEV;
7093 }
7094
7095 /*
7096 * Terminate the outer loop provided the Port indicated
7097 * ready within 10 seconds.
7098 */
7099 if (rdy_chk < 1000)
7100 break;
7101 }
James Smart05580562011-05-24 11:40:48 -04007102 /* delay driver action following IF_TYPE_2 function reset */
7103 msleep(100);
James Smart2fcee4b2010-12-15 17:57:46 -05007104 break;
7105 case LPFC_SLI_INTF_IF_TYPE_1:
7106 default:
7107 break;
James Smartda0436e2009-05-22 14:51:39 -04007108 }
7109
James Smart2fcee4b2010-12-15 17:57:46 -05007110 /* Catch the not-ready port failure after a port reset. */
7111 if (num_resets >= MAX_IF_TYPE_2_RESETS)
7112 rc = -ENODEV;
7113
James Smartda0436e2009-05-22 14:51:39 -04007114 return rc;
7115}
7116
7117/**
7118 * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands
7119 * @phba: pointer to lpfc hba data structure.
7120 * @cnt: number of nop mailbox commands to send.
7121 *
7122 * This routine is invoked to send a number @cnt of NOP mailbox command and
7123 * wait for each command to complete.
7124 *
7125 * Return: the number of NOP mailbox command completed.
7126 **/
7127static int
7128lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt)
7129{
7130 LPFC_MBOXQ_t *mboxq;
7131 int length, cmdsent;
7132 uint32_t mbox_tmo;
7133 uint32_t rc = 0;
7134 uint32_t shdr_status, shdr_add_status;
7135 union lpfc_sli4_cfg_shdr *shdr;
7136
7137 if (cnt == 0) {
7138 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7139 "2518 Requested to send 0 NOP mailbox cmd\n");
7140 return cnt;
7141 }
7142
7143 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7144 if (!mboxq) {
7145 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7146 "2519 Unable to allocate memory for issuing "
7147 "NOP mailbox command\n");
7148 return 0;
7149 }
7150
7151 /* Set up NOP SLI4_CONFIG mailbox-ioctl command */
7152 length = (sizeof(struct lpfc_mbx_nop) -
7153 sizeof(struct lpfc_sli4_cfg_mhdr));
7154 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
7155 LPFC_MBOX_OPCODE_NOP, length, LPFC_SLI4_MBX_EMBED);
7156
7157 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
7158 for (cmdsent = 0; cmdsent < cnt; cmdsent++) {
7159 if (!phba->sli4_hba.intr_enable)
7160 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7161 else
7162 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
7163 if (rc == MBX_TIMEOUT)
7164 break;
7165 /* Check return status */
7166 shdr = (union lpfc_sli4_cfg_shdr *)
7167 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
7168 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7169 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
7170 &shdr->response);
7171 if (shdr_status || shdr_add_status || rc) {
7172 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7173 "2520 NOP mailbox command failed "
7174 "status x%x add_status x%x mbx "
7175 "status x%x\n", shdr_status,
7176 shdr_add_status, rc);
7177 break;
7178 }
7179 }
7180
7181 if (rc != MBX_TIMEOUT)
7182 mempool_free(mboxq, phba->mbox_mem_pool);
7183
7184 return cmdsent;
7185}
7186
7187/**
James Smartda0436e2009-05-22 14:51:39 -04007188 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
7189 * @phba: pointer to lpfc hba data structure.
7190 *
7191 * This routine is invoked to set up the PCI device memory space for device
7192 * with SLI-4 interface spec.
7193 *
7194 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007195 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04007196 * other values - error
7197 **/
7198static int
7199lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
7200{
7201 struct pci_dev *pdev;
7202 unsigned long bar0map_len, bar1map_len, bar2map_len;
7203 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05007204 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04007205
7206 /* Obtain PCI device reference */
7207 if (!phba->pcidev)
7208 return error;
7209 else
7210 pdev = phba->pcidev;
7211
7212 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05007213 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
7214 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
7215 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
7216 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smartda0436e2009-05-22 14:51:39 -04007217 return error;
Michael Reed8e685972009-09-18 12:02:05 -05007218 }
7219 }
James Smartda0436e2009-05-22 14:51:39 -04007220
James Smart2fcee4b2010-12-15 17:57:46 -05007221 /*
7222 * The BARs and register set definitions and offset locations are
7223 * dependent on the if_type.
7224 */
7225 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
7226 &phba->sli4_hba.sli_intf.word0)) {
7227 return error;
7228 }
7229
7230 /* There is no SLI3 failback for SLI4 devices. */
7231 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
7232 LPFC_SLI_INTF_VALID) {
7233 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7234 "2894 SLI_INTF reg contents invalid "
7235 "sli_intf reg 0x%x\n",
7236 phba->sli4_hba.sli_intf.word0);
7237 return error;
7238 }
7239
7240 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7241 /*
7242 * Get the bus address of SLI4 device Bar regions and the
7243 * number of bytes required by each mapping. The mapping of the
7244 * particular PCI BARs regions is dependent on the type of
7245 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04007246 */
James Smart1dfb5a42010-02-12 14:40:50 -05007247 if (pci_resource_start(pdev, 0)) {
7248 phba->pci_bar0_map = pci_resource_start(pdev, 0);
7249 bar0map_len = pci_resource_len(pdev, 0);
James Smart2fcee4b2010-12-15 17:57:46 -05007250
7251 /*
7252 * Map SLI4 PCI Config Space Register base to a kernel virtual
7253 * addr
7254 */
7255 phba->sli4_hba.conf_regs_memmap_p =
7256 ioremap(phba->pci_bar0_map, bar0map_len);
7257 if (!phba->sli4_hba.conf_regs_memmap_p) {
7258 dev_printk(KERN_ERR, &pdev->dev,
7259 "ioremap failed for SLI4 PCI config "
7260 "registers.\n");
7261 goto out;
7262 }
7263 /* Set up BAR0 PCI config space register memory map */
7264 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05007265 } else {
7266 phba->pci_bar0_map = pci_resource_start(pdev, 1);
7267 bar0map_len = pci_resource_len(pdev, 1);
James Smart2fcee4b2010-12-15 17:57:46 -05007268 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
7269 dev_printk(KERN_ERR, &pdev->dev,
7270 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
7271 goto out;
7272 }
7273 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04007274 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05007275 if (!phba->sli4_hba.conf_regs_memmap_p) {
7276 dev_printk(KERN_ERR, &pdev->dev,
7277 "ioremap failed for SLI4 PCI config "
7278 "registers.\n");
7279 goto out;
7280 }
7281 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04007282 }
7283
James Smartc31098c2011-04-16 11:03:33 -04007284 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
7285 (pci_resource_start(pdev, 2))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007286 /*
7287 * Map SLI4 if type 0 HBA Control Register base to a kernel
7288 * virtual address and setup the registers.
7289 */
7290 phba->pci_bar1_map = pci_resource_start(pdev, 2);
7291 bar1map_len = pci_resource_len(pdev, 2);
7292 phba->sli4_hba.ctrl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04007293 ioremap(phba->pci_bar1_map, bar1map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05007294 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
7295 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04007296 "ioremap failed for SLI4 HBA control registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05007297 goto out_iounmap_conf;
7298 }
7299 lpfc_sli4_bar1_register_memmap(phba);
James Smartda0436e2009-05-22 14:51:39 -04007300 }
7301
James Smartc31098c2011-04-16 11:03:33 -04007302 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
7303 (pci_resource_start(pdev, 4))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007304 /*
7305 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
7306 * virtual address and setup the registers.
7307 */
7308 phba->pci_bar2_map = pci_resource_start(pdev, 4);
7309 bar2map_len = pci_resource_len(pdev, 4);
7310 phba->sli4_hba.drbl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04007311 ioremap(phba->pci_bar2_map, bar2map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05007312 if (!phba->sli4_hba.drbl_regs_memmap_p) {
7313 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04007314 "ioremap failed for SLI4 HBA doorbell registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05007315 goto out_iounmap_ctrl;
7316 }
7317 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
7318 if (error)
7319 goto out_iounmap_all;
James Smartda0436e2009-05-22 14:51:39 -04007320 }
7321
James Smartda0436e2009-05-22 14:51:39 -04007322 return 0;
7323
7324out_iounmap_all:
7325 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
7326out_iounmap_ctrl:
7327 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
7328out_iounmap_conf:
7329 iounmap(phba->sli4_hba.conf_regs_memmap_p);
7330out:
7331 return error;
7332}
7333
7334/**
7335 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
7336 * @phba: pointer to lpfc hba data structure.
7337 *
7338 * This routine is invoked to unset the PCI device memory space for device
7339 * with SLI-4 interface spec.
7340 **/
7341static void
7342lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
7343{
7344 struct pci_dev *pdev;
7345
7346 /* Obtain PCI device reference */
7347 if (!phba->pcidev)
7348 return;
7349 else
7350 pdev = phba->pcidev;
7351
7352 /* Free coherent DMA memory allocated */
7353
7354 /* Unmap I/O memory space */
7355 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
7356 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
7357 iounmap(phba->sli4_hba.conf_regs_memmap_p);
7358
7359 return;
7360}
7361
7362/**
James Smart3772a992009-05-22 14:50:54 -04007363 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
7364 * @phba: pointer to lpfc hba data structure.
7365 *
7366 * This routine is invoked to enable the MSI-X interrupt vectors to device
7367 * with SLI-3 interface specs. The kernel function pci_enable_msix() is
7368 * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
7369 * invoked, enables either all or nothing, depending on the current
7370 * availability of PCI vector resources. The device driver is responsible
7371 * for calling the individual request_irq() to register each MSI-X vector
7372 * with a interrupt handler, which is done in this function. Note that
7373 * later when device is unloading, the driver should always call free_irq()
7374 * on all MSI-X vectors it has done request_irq() on before calling
7375 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
7376 * will be left with MSI-X enabled and leaks its vectors.
7377 *
7378 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007379 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007380 * other values - error
7381 **/
7382static int
7383lpfc_sli_enable_msix(struct lpfc_hba *phba)
7384{
7385 int rc, i;
7386 LPFC_MBOXQ_t *pmb;
7387
7388 /* Set up MSI-X multi-message vectors */
7389 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
7390 phba->msix_entries[i].entry = i;
7391
7392 /* Configure MSI-X capability structure */
7393 rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
7394 ARRAY_SIZE(phba->msix_entries));
7395 if (rc) {
7396 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7397 "0420 PCI enable MSI-X failed (%d)\n", rc);
7398 goto msi_fail_out;
7399 }
7400 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
7401 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7402 "0477 MSI-X entry[%d]: vector=x%x "
7403 "message=%d\n", i,
7404 phba->msix_entries[i].vector,
7405 phba->msix_entries[i].entry);
7406 /*
7407 * Assign MSI-X vectors to interrupt handlers
7408 */
7409
7410 /* vector-0 is associated to slow-path handler */
7411 rc = request_irq(phba->msix_entries[0].vector,
7412 &lpfc_sli_sp_intr_handler, IRQF_SHARED,
7413 LPFC_SP_DRIVER_HANDLER_NAME, phba);
7414 if (rc) {
7415 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7416 "0421 MSI-X slow-path request_irq failed "
7417 "(%d)\n", rc);
7418 goto msi_fail_out;
7419 }
7420
7421 /* vector-1 is associated to fast-path handler */
7422 rc = request_irq(phba->msix_entries[1].vector,
7423 &lpfc_sli_fp_intr_handler, IRQF_SHARED,
7424 LPFC_FP_DRIVER_HANDLER_NAME, phba);
7425
7426 if (rc) {
7427 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7428 "0429 MSI-X fast-path request_irq failed "
7429 "(%d)\n", rc);
7430 goto irq_fail_out;
7431 }
7432
7433 /*
7434 * Configure HBA MSI-X attention conditions to messages
7435 */
7436 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7437
7438 if (!pmb) {
7439 rc = -ENOMEM;
7440 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7441 "0474 Unable to allocate memory for issuing "
7442 "MBOX_CONFIG_MSI command\n");
7443 goto mem_fail_out;
7444 }
7445 rc = lpfc_config_msi(phba, pmb);
7446 if (rc)
7447 goto mbx_fail_out;
7448 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
7449 if (rc != MBX_SUCCESS) {
7450 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
7451 "0351 Config MSI mailbox command failed, "
7452 "mbxCmd x%x, mbxStatus x%x\n",
7453 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
7454 goto mbx_fail_out;
7455 }
7456
7457 /* Free memory allocated for mailbox command */
7458 mempool_free(pmb, phba->mbox_mem_pool);
7459 return rc;
7460
7461mbx_fail_out:
7462 /* Free memory allocated for mailbox command */
7463 mempool_free(pmb, phba->mbox_mem_pool);
7464
7465mem_fail_out:
7466 /* free the irq already requested */
7467 free_irq(phba->msix_entries[1].vector, phba);
7468
7469irq_fail_out:
7470 /* free the irq already requested */
7471 free_irq(phba->msix_entries[0].vector, phba);
7472
7473msi_fail_out:
7474 /* Unconfigure MSI-X capability structure */
7475 pci_disable_msix(phba->pcidev);
7476 return rc;
7477}
7478
7479/**
7480 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
7481 * @phba: pointer to lpfc hba data structure.
7482 *
7483 * This routine is invoked to release the MSI-X vectors and then disable the
7484 * MSI-X interrupt mode to device with SLI-3 interface spec.
7485 **/
7486static void
7487lpfc_sli_disable_msix(struct lpfc_hba *phba)
7488{
7489 int i;
7490
7491 /* Free up MSI-X multi-message vectors */
7492 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
7493 free_irq(phba->msix_entries[i].vector, phba);
7494 /* Disable MSI-X */
7495 pci_disable_msix(phba->pcidev);
7496
7497 return;
7498}
7499
7500/**
7501 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
7502 * @phba: pointer to lpfc hba data structure.
7503 *
7504 * This routine is invoked to enable the MSI interrupt mode to device with
7505 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
7506 * enable the MSI vector. The device driver is responsible for calling the
7507 * request_irq() to register MSI vector with a interrupt the handler, which
7508 * is done in this function.
7509 *
7510 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007511 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007512 * other values - error
7513 */
7514static int
7515lpfc_sli_enable_msi(struct lpfc_hba *phba)
7516{
7517 int rc;
7518
7519 rc = pci_enable_msi(phba->pcidev);
7520 if (!rc)
7521 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7522 "0462 PCI enable MSI mode success.\n");
7523 else {
7524 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7525 "0471 PCI enable MSI mode failed (%d)\n", rc);
7526 return rc;
7527 }
7528
7529 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
7530 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
7531 if (rc) {
7532 pci_disable_msi(phba->pcidev);
7533 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7534 "0478 MSI request_irq failed (%d)\n", rc);
7535 }
7536 return rc;
7537}
7538
7539/**
7540 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
7541 * @phba: pointer to lpfc hba data structure.
7542 *
7543 * This routine is invoked to disable the MSI interrupt mode to device with
7544 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
7545 * done request_irq() on before calling pci_disable_msi(). Failure to do so
7546 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
7547 * its vector.
7548 */
7549static void
7550lpfc_sli_disable_msi(struct lpfc_hba *phba)
7551{
7552 free_irq(phba->pcidev->irq, phba);
7553 pci_disable_msi(phba->pcidev);
7554 return;
7555}
7556
7557/**
7558 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
7559 * @phba: pointer to lpfc hba data structure.
7560 *
7561 * This routine is invoked to enable device interrupt and associate driver's
7562 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
7563 * spec. Depends on the interrupt mode configured to the driver, the driver
7564 * will try to fallback from the configured interrupt mode to an interrupt
7565 * mode which is supported by the platform, kernel, and device in the order
7566 * of:
7567 * MSI-X -> MSI -> IRQ.
7568 *
7569 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007570 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007571 * other values - error
7572 **/
7573static uint32_t
7574lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
7575{
7576 uint32_t intr_mode = LPFC_INTR_ERROR;
7577 int retval;
7578
7579 if (cfg_mode == 2) {
7580 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
7581 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
7582 if (!retval) {
7583 /* Now, try to enable MSI-X interrupt mode */
7584 retval = lpfc_sli_enable_msix(phba);
7585 if (!retval) {
7586 /* Indicate initialization to MSI-X mode */
7587 phba->intr_type = MSIX;
7588 intr_mode = 2;
7589 }
7590 }
7591 }
7592
7593 /* Fallback to MSI if MSI-X initialization failed */
7594 if (cfg_mode >= 1 && phba->intr_type == NONE) {
7595 retval = lpfc_sli_enable_msi(phba);
7596 if (!retval) {
7597 /* Indicate initialization to MSI mode */
7598 phba->intr_type = MSI;
7599 intr_mode = 1;
7600 }
7601 }
7602
7603 /* Fallback to INTx if both MSI-X/MSI initalization failed */
7604 if (phba->intr_type == NONE) {
7605 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
7606 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
7607 if (!retval) {
7608 /* Indicate initialization to INTx mode */
7609 phba->intr_type = INTx;
7610 intr_mode = 0;
7611 }
7612 }
7613 return intr_mode;
7614}
7615
7616/**
7617 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
7618 * @phba: pointer to lpfc hba data structure.
7619 *
7620 * This routine is invoked to disable device interrupt and disassociate the
7621 * driver's interrupt handler(s) from interrupt vector(s) to device with
7622 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
7623 * release the interrupt vector(s) for the message signaled interrupt.
7624 **/
7625static void
7626lpfc_sli_disable_intr(struct lpfc_hba *phba)
7627{
7628 /* Disable the currently initialized interrupt mode */
7629 if (phba->intr_type == MSIX)
7630 lpfc_sli_disable_msix(phba);
7631 else if (phba->intr_type == MSI)
7632 lpfc_sli_disable_msi(phba);
7633 else if (phba->intr_type == INTx)
7634 free_irq(phba->pcidev->irq, phba);
7635
7636 /* Reset interrupt management states */
7637 phba->intr_type = NONE;
7638 phba->sli.slistat.sli_intr = 0;
7639
7640 return;
7641}
7642
7643/**
James Smartda0436e2009-05-22 14:51:39 -04007644 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
7645 * @phba: pointer to lpfc hba data structure.
7646 *
7647 * This routine is invoked to enable the MSI-X interrupt vectors to device
7648 * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
7649 * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
7650 * enables either all or nothing, depending on the current availability of
7651 * PCI vector resources. The device driver is responsible for calling the
7652 * individual request_irq() to register each MSI-X vector with a interrupt
7653 * handler, which is done in this function. Note that later when device is
7654 * unloading, the driver should always call free_irq() on all MSI-X vectors
7655 * it has done request_irq() on before calling pci_disable_msix(). Failure
7656 * to do so results in a BUG_ON() and a device will be left with MSI-X
7657 * enabled and leaks its vectors.
7658 *
7659 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007660 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04007661 * other values - error
7662 **/
7663static int
7664lpfc_sli4_enable_msix(struct lpfc_hba *phba)
7665{
James Smart75baf692010-06-08 18:31:21 -04007666 int vectors, rc, index;
James Smartda0436e2009-05-22 14:51:39 -04007667
7668 /* Set up MSI-X multi-message vectors */
7669 for (index = 0; index < phba->sli4_hba.cfg_eqn; index++)
7670 phba->sli4_hba.msix_entries[index].entry = index;
7671
7672 /* Configure MSI-X capability structure */
James Smart75baf692010-06-08 18:31:21 -04007673 vectors = phba->sli4_hba.cfg_eqn;
7674enable_msix_vectors:
James Smartda0436e2009-05-22 14:51:39 -04007675 rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries,
James Smart75baf692010-06-08 18:31:21 -04007676 vectors);
7677 if (rc > 1) {
7678 vectors = rc;
7679 goto enable_msix_vectors;
7680 } else if (rc) {
James Smartda0436e2009-05-22 14:51:39 -04007681 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7682 "0484 PCI enable MSI-X failed (%d)\n", rc);
7683 goto msi_fail_out;
7684 }
James Smart75baf692010-06-08 18:31:21 -04007685
James Smartda0436e2009-05-22 14:51:39 -04007686 /* Log MSI-X vector assignment */
James Smart75baf692010-06-08 18:31:21 -04007687 for (index = 0; index < vectors; index++)
James Smartda0436e2009-05-22 14:51:39 -04007688 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7689 "0489 MSI-X entry[%d]: vector=x%x "
7690 "message=%d\n", index,
7691 phba->sli4_hba.msix_entries[index].vector,
7692 phba->sli4_hba.msix_entries[index].entry);
7693 /*
7694 * Assign MSI-X vectors to interrupt handlers
7695 */
James Smart05580562011-05-24 11:40:48 -04007696 if (vectors > 1)
7697 rc = request_irq(phba->sli4_hba.msix_entries[0].vector,
7698 &lpfc_sli4_sp_intr_handler, IRQF_SHARED,
7699 LPFC_SP_DRIVER_HANDLER_NAME, phba);
7700 else
7701 /* All Interrupts need to be handled by one EQ */
7702 rc = request_irq(phba->sli4_hba.msix_entries[0].vector,
7703 &lpfc_sli4_intr_handler, IRQF_SHARED,
7704 LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -04007705 if (rc) {
7706 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7707 "0485 MSI-X slow-path request_irq failed "
7708 "(%d)\n", rc);
7709 goto msi_fail_out;
7710 }
7711
7712 /* The rest of the vector(s) are associated to fast-path handler(s) */
James Smart75baf692010-06-08 18:31:21 -04007713 for (index = 1; index < vectors; index++) {
James Smartda0436e2009-05-22 14:51:39 -04007714 phba->sli4_hba.fcp_eq_hdl[index - 1].idx = index - 1;
7715 phba->sli4_hba.fcp_eq_hdl[index - 1].phba = phba;
7716 rc = request_irq(phba->sli4_hba.msix_entries[index].vector,
7717 &lpfc_sli4_fp_intr_handler, IRQF_SHARED,
7718 LPFC_FP_DRIVER_HANDLER_NAME,
7719 &phba->sli4_hba.fcp_eq_hdl[index - 1]);
7720 if (rc) {
7721 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7722 "0486 MSI-X fast-path (%d) "
7723 "request_irq failed (%d)\n", index, rc);
7724 goto cfg_fail_out;
7725 }
7726 }
James Smart75baf692010-06-08 18:31:21 -04007727 phba->sli4_hba.msix_vec_nr = vectors;
James Smartda0436e2009-05-22 14:51:39 -04007728
7729 return rc;
7730
7731cfg_fail_out:
7732 /* free the irq already requested */
7733 for (--index; index >= 1; index--)
7734 free_irq(phba->sli4_hba.msix_entries[index - 1].vector,
7735 &phba->sli4_hba.fcp_eq_hdl[index - 1]);
7736
7737 /* free the irq already requested */
7738 free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
7739
7740msi_fail_out:
7741 /* Unconfigure MSI-X capability structure */
7742 pci_disable_msix(phba->pcidev);
7743 return rc;
7744}
7745
7746/**
7747 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
7748 * @phba: pointer to lpfc hba data structure.
7749 *
7750 * This routine is invoked to release the MSI-X vectors and then disable the
7751 * MSI-X interrupt mode to device with SLI-4 interface spec.
7752 **/
7753static void
7754lpfc_sli4_disable_msix(struct lpfc_hba *phba)
7755{
7756 int index;
7757
7758 /* Free up MSI-X multi-message vectors */
7759 free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
7760
James Smart75baf692010-06-08 18:31:21 -04007761 for (index = 1; index < phba->sli4_hba.msix_vec_nr; index++)
James Smartda0436e2009-05-22 14:51:39 -04007762 free_irq(phba->sli4_hba.msix_entries[index].vector,
7763 &phba->sli4_hba.fcp_eq_hdl[index - 1]);
James Smart75baf692010-06-08 18:31:21 -04007764
James Smartda0436e2009-05-22 14:51:39 -04007765 /* Disable MSI-X */
7766 pci_disable_msix(phba->pcidev);
7767
7768 return;
7769}
7770
7771/**
7772 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
7773 * @phba: pointer to lpfc hba data structure.
7774 *
7775 * This routine is invoked to enable the MSI interrupt mode to device with
7776 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
7777 * to enable the MSI vector. The device driver is responsible for calling
7778 * the request_irq() to register MSI vector with a interrupt the handler,
7779 * which is done in this function.
7780 *
7781 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007782 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04007783 * other values - error
7784 **/
7785static int
7786lpfc_sli4_enable_msi(struct lpfc_hba *phba)
7787{
7788 int rc, index;
7789
7790 rc = pci_enable_msi(phba->pcidev);
7791 if (!rc)
7792 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7793 "0487 PCI enable MSI mode success.\n");
7794 else {
7795 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7796 "0488 PCI enable MSI mode failed (%d)\n", rc);
7797 return rc;
7798 }
7799
7800 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
7801 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
7802 if (rc) {
7803 pci_disable_msi(phba->pcidev);
7804 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7805 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -04007806 return rc;
James Smartda0436e2009-05-22 14:51:39 -04007807 }
7808
7809 for (index = 0; index < phba->cfg_fcp_eq_count; index++) {
7810 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
7811 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
7812 }
7813
James Smart75baf692010-06-08 18:31:21 -04007814 return 0;
James Smartda0436e2009-05-22 14:51:39 -04007815}
7816
7817/**
7818 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
7819 * @phba: pointer to lpfc hba data structure.
7820 *
7821 * This routine is invoked to disable the MSI interrupt mode to device with
7822 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
7823 * done request_irq() on before calling pci_disable_msi(). Failure to do so
7824 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
7825 * its vector.
7826 **/
7827static void
7828lpfc_sli4_disable_msi(struct lpfc_hba *phba)
7829{
7830 free_irq(phba->pcidev->irq, phba);
7831 pci_disable_msi(phba->pcidev);
7832 return;
7833}
7834
7835/**
7836 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
7837 * @phba: pointer to lpfc hba data structure.
7838 *
7839 * This routine is invoked to enable device interrupt and associate driver's
7840 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
7841 * interface spec. Depends on the interrupt mode configured to the driver,
7842 * the driver will try to fallback from the configured interrupt mode to an
7843 * interrupt mode which is supported by the platform, kernel, and device in
7844 * the order of:
7845 * MSI-X -> MSI -> IRQ.
7846 *
7847 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007848 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04007849 * other values - error
7850 **/
7851static uint32_t
7852lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
7853{
7854 uint32_t intr_mode = LPFC_INTR_ERROR;
7855 int retval, index;
7856
7857 if (cfg_mode == 2) {
7858 /* Preparation before conf_msi mbox cmd */
7859 retval = 0;
7860 if (!retval) {
7861 /* Now, try to enable MSI-X interrupt mode */
7862 retval = lpfc_sli4_enable_msix(phba);
7863 if (!retval) {
7864 /* Indicate initialization to MSI-X mode */
7865 phba->intr_type = MSIX;
7866 intr_mode = 2;
7867 }
7868 }
7869 }
7870
7871 /* Fallback to MSI if MSI-X initialization failed */
7872 if (cfg_mode >= 1 && phba->intr_type == NONE) {
7873 retval = lpfc_sli4_enable_msi(phba);
7874 if (!retval) {
7875 /* Indicate initialization to MSI mode */
7876 phba->intr_type = MSI;
7877 intr_mode = 1;
7878 }
7879 }
7880
7881 /* Fallback to INTx if both MSI-X/MSI initalization failed */
7882 if (phba->intr_type == NONE) {
7883 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
7884 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
7885 if (!retval) {
7886 /* Indicate initialization to INTx mode */
7887 phba->intr_type = INTx;
7888 intr_mode = 0;
7889 for (index = 0; index < phba->cfg_fcp_eq_count;
7890 index++) {
7891 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
7892 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
7893 }
7894 }
7895 }
7896 return intr_mode;
7897}
7898
7899/**
7900 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
7901 * @phba: pointer to lpfc hba data structure.
7902 *
7903 * This routine is invoked to disable device interrupt and disassociate
7904 * the driver's interrupt handler(s) from interrupt vector(s) to device
7905 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
7906 * will release the interrupt vector(s) for the message signaled interrupt.
7907 **/
7908static void
7909lpfc_sli4_disable_intr(struct lpfc_hba *phba)
7910{
7911 /* Disable the currently initialized interrupt mode */
7912 if (phba->intr_type == MSIX)
7913 lpfc_sli4_disable_msix(phba);
7914 else if (phba->intr_type == MSI)
7915 lpfc_sli4_disable_msi(phba);
7916 else if (phba->intr_type == INTx)
7917 free_irq(phba->pcidev->irq, phba);
7918
7919 /* Reset interrupt management states */
7920 phba->intr_type = NONE;
7921 phba->sli.slistat.sli_intr = 0;
7922
7923 return;
7924}
7925
7926/**
James Smart3772a992009-05-22 14:50:54 -04007927 * lpfc_unset_hba - Unset SLI3 hba device initialization
7928 * @phba: pointer to lpfc hba data structure.
7929 *
7930 * This routine is invoked to unset the HBA device initialization steps to
7931 * a device with SLI-3 interface spec.
7932 **/
7933static void
7934lpfc_unset_hba(struct lpfc_hba *phba)
7935{
7936 struct lpfc_vport *vport = phba->pport;
7937 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7938
7939 spin_lock_irq(shost->host_lock);
7940 vport->load_flag |= FC_UNLOADING;
7941 spin_unlock_irq(shost->host_lock);
7942
7943 lpfc_stop_hba_timers(phba);
7944
7945 phba->pport->work_port_events = 0;
7946
7947 lpfc_sli_hba_down(phba);
7948
7949 lpfc_sli_brdrestart(phba);
7950
7951 lpfc_sli_disable_intr(phba);
7952
7953 return;
7954}
7955
7956/**
James Smartda0436e2009-05-22 14:51:39 -04007957 * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization.
7958 * @phba: pointer to lpfc hba data structure.
7959 *
7960 * This routine is invoked to unset the HBA device initialization steps to
7961 * a device with SLI-4 interface spec.
7962 **/
7963static void
7964lpfc_sli4_unset_hba(struct lpfc_hba *phba)
7965{
7966 struct lpfc_vport *vport = phba->pport;
7967 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7968
7969 spin_lock_irq(shost->host_lock);
7970 vport->load_flag |= FC_UNLOADING;
7971 spin_unlock_irq(shost->host_lock);
7972
7973 phba->pport->work_port_events = 0;
7974
James Smart3677a3a2010-09-29 11:19:14 -04007975 /* Stop the SLI4 device port */
7976 lpfc_stop_port(phba);
James Smartda0436e2009-05-22 14:51:39 -04007977
7978 lpfc_sli4_disable_intr(phba);
7979
James Smart3677a3a2010-09-29 11:19:14 -04007980 /* Reset SLI4 HBA FCoE function */
7981 lpfc_pci_function_reset(phba);
7982
James Smartda0436e2009-05-22 14:51:39 -04007983 return;
7984}
7985
7986/**
James Smart5af5eee2010-10-22 11:06:38 -04007987 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
7988 * @phba: Pointer to HBA context object.
7989 *
7990 * This function is called in the SLI4 code path to wait for completion
7991 * of device's XRIs exchange busy. It will check the XRI exchange busy
7992 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
7993 * that, it will check the XRI exchange busy on outstanding FCP and ELS
7994 * I/Os every 30 seconds, log error message, and wait forever. Only when
7995 * all XRI exchange busy complete, the driver unload shall proceed with
7996 * invoking the function reset ioctl mailbox command to the CNA and the
7997 * the rest of the driver unload resource release.
7998 **/
7999static void
8000lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
8001{
8002 int wait_time = 0;
8003 int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
8004 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
8005
8006 while (!fcp_xri_cmpl || !els_xri_cmpl) {
8007 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
8008 if (!fcp_xri_cmpl)
8009 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8010 "2877 FCP XRI exchange busy "
8011 "wait time: %d seconds.\n",
8012 wait_time/1000);
8013 if (!els_xri_cmpl)
8014 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8015 "2878 ELS XRI exchange busy "
8016 "wait time: %d seconds.\n",
8017 wait_time/1000);
8018 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
8019 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
8020 } else {
8021 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
8022 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
8023 }
8024 fcp_xri_cmpl =
8025 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
8026 els_xri_cmpl =
8027 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
8028 }
8029}
8030
8031/**
James Smartda0436e2009-05-22 14:51:39 -04008032 * lpfc_sli4_hba_unset - Unset the fcoe hba
8033 * @phba: Pointer to HBA context object.
8034 *
8035 * This function is called in the SLI4 code path to reset the HBA's FCoE
8036 * function. The caller is not required to hold any lock. This routine
8037 * issues PCI function reset mailbox command to reset the FCoE function.
8038 * At the end of the function, it calls lpfc_hba_down_post function to
8039 * free any pending commands.
8040 **/
8041static void
8042lpfc_sli4_hba_unset(struct lpfc_hba *phba)
8043{
8044 int wait_cnt = 0;
8045 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -04008046 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -04008047
8048 lpfc_stop_hba_timers(phba);
8049 phba->sli4_hba.intr_enable = 0;
8050
8051 /*
8052 * Gracefully wait out the potential current outstanding asynchronous
8053 * mailbox command.
8054 */
8055
8056 /* First, block any pending async mailbox command from posted */
8057 spin_lock_irq(&phba->hbalock);
8058 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
8059 spin_unlock_irq(&phba->hbalock);
8060 /* Now, trying to wait it out if we can */
8061 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
8062 msleep(10);
8063 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
8064 break;
8065 }
8066 /* Forcefully release the outstanding mailbox command if timed out */
8067 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
8068 spin_lock_irq(&phba->hbalock);
8069 mboxq = phba->sli.mbox_active;
8070 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
8071 __lpfc_mbox_cmpl_put(phba, mboxq);
8072 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8073 phba->sli.mbox_active = NULL;
8074 spin_unlock_irq(&phba->hbalock);
8075 }
8076
James Smart5af5eee2010-10-22 11:06:38 -04008077 /* Abort all iocbs associated with the hba */
8078 lpfc_sli_hba_iocb_abort(phba);
8079
8080 /* Wait for completion of device XRI exchange busy */
8081 lpfc_sli4_xri_exchange_busy_wait(phba);
8082
James Smartda0436e2009-05-22 14:51:39 -04008083 /* Disable PCI subsystem interrupt */
8084 lpfc_sli4_disable_intr(phba);
8085
James Smart912e3ac2011-05-24 11:42:11 -04008086 /* Disable SR-IOV if enabled */
8087 if (phba->cfg_sriov_nr_virtfn)
8088 pci_disable_sriov(pdev);
8089
James Smartda0436e2009-05-22 14:51:39 -04008090 /* Stop kthread signal shall trigger work_done one more time */
8091 kthread_stop(phba->worker_thread);
8092
James Smart3677a3a2010-09-29 11:19:14 -04008093 /* Reset SLI4 HBA FCoE function */
8094 lpfc_pci_function_reset(phba);
8095
James Smartda0436e2009-05-22 14:51:39 -04008096 /* Stop the SLI4 device port */
8097 phba->pport->work_port_events = 0;
8098}
8099
James Smart28baac72010-02-12 14:42:03 -05008100 /**
8101 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
8102 * @phba: Pointer to HBA context object.
8103 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
8104 *
8105 * This function is called in the SLI4 code path to read the port's
8106 * sli4 capabilities.
8107 *
8108 * This function may be be called from any context that can block-wait
8109 * for the completion. The expectation is that this routine is called
8110 * typically from probe_one or from the online routine.
8111 **/
8112int
8113lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
8114{
8115 int rc;
8116 struct lpfc_mqe *mqe;
8117 struct lpfc_pc_sli4_params *sli4_params;
8118 uint32_t mbox_tmo;
8119
8120 rc = 0;
8121 mqe = &mboxq->u.mqe;
8122
8123 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -05008124 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -05008125 if (!phba->sli4_hba.intr_enable)
8126 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8127 else {
8128 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_PORT_CAPABILITIES);
8129 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
8130 }
8131
8132 if (unlikely(rc))
8133 return 1;
8134
8135 sli4_params = &phba->sli4_hba.pc_sli4_params;
8136 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
8137 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
8138 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
8139 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
8140 &mqe->un.sli4_params);
8141 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
8142 &mqe->un.sli4_params);
8143 sli4_params->proto_types = mqe->un.sli4_params.word3;
8144 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
8145 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
8146 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
8147 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
8148 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
8149 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
8150 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
8151 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
8152 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
8153 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
8154 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
8155 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
8156 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
8157 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
8158 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
8159 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
8160 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
8161 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
8162 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
8163 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -04008164
8165 /* Make sure that sge_supp_len can be handled by the driver */
8166 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
8167 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
8168
James Smart28baac72010-02-12 14:42:03 -05008169 return rc;
8170}
8171
James Smartda0436e2009-05-22 14:51:39 -04008172/**
James Smartfedd3b72011-02-16 12:39:24 -05008173 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
8174 * @phba: Pointer to HBA context object.
8175 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
8176 *
8177 * This function is called in the SLI4 code path to read the port's
8178 * sli4 capabilities.
8179 *
8180 * This function may be be called from any context that can block-wait
8181 * for the completion. The expectation is that this routine is called
8182 * typically from probe_one or from the online routine.
8183 **/
8184int
8185lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
8186{
8187 int rc;
8188 struct lpfc_mqe *mqe = &mboxq->u.mqe;
8189 struct lpfc_pc_sli4_params *sli4_params;
8190 int length;
8191 struct lpfc_sli4_parameters *mbx_sli4_parameters;
8192
James Smart6d368e52011-05-24 11:44:12 -04008193 /*
8194 * By default, the driver assumes the SLI4 port requires RPI
8195 * header postings. The SLI4_PARAM response will correct this
8196 * assumption.
8197 */
8198 phba->sli4_hba.rpi_hdrs_in_use = 1;
8199
James Smartfedd3b72011-02-16 12:39:24 -05008200 /* Read the port's SLI4 Config Parameters */
8201 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
8202 sizeof(struct lpfc_sli4_cfg_mhdr));
8203 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8204 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
8205 length, LPFC_SLI4_MBX_EMBED);
8206 if (!phba->sli4_hba.intr_enable)
8207 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8208 else
8209 rc = lpfc_sli_issue_mbox_wait(phba, mboxq,
8210 lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG));
8211 if (unlikely(rc))
8212 return rc;
8213 sli4_params = &phba->sli4_hba.pc_sli4_params;
8214 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
8215 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
8216 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
8217 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
8218 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
8219 mbx_sli4_parameters);
8220 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
8221 mbx_sli4_parameters);
8222 if (bf_get(cfg_phwq, mbx_sli4_parameters))
8223 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
8224 else
8225 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
8226 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
8227 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
8228 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
8229 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
8230 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
8231 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
8232 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
8233 mbx_sli4_parameters);
8234 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
8235 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -04008236 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
8237 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart05580562011-05-24 11:40:48 -04008238
8239 /* Make sure that sge_supp_len can be handled by the driver */
8240 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
8241 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
8242
James Smartfedd3b72011-02-16 12:39:24 -05008243 return 0;
8244}
8245
8246/**
James Smart3772a992009-05-22 14:50:54 -04008247 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
8248 * @pdev: pointer to PCI device
8249 * @pid: pointer to PCI device identifier
8250 *
8251 * This routine is to be called to attach a device with SLI-3 interface spec
8252 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
8253 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
8254 * information of the device and driver to see if the driver state that it can
8255 * support this kind of device. If the match is successful, the driver core
8256 * invokes this routine. If this routine determines it can claim the HBA, it
8257 * does all the initialization that it needs to do to handle the HBA properly.
8258 *
8259 * Return code
8260 * 0 - driver can claim the device
8261 * negative value - driver can not claim the device
8262 **/
8263static int __devinit
8264lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
8265{
8266 struct lpfc_hba *phba;
8267 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -04008268 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -04008269 int error;
8270 uint32_t cfg_mode, intr_mode;
8271
8272 /* Allocate memory for HBA structure */
8273 phba = lpfc_hba_alloc(pdev);
8274 if (!phba)
8275 return -ENOMEM;
8276
8277 /* Perform generic PCI device enabling operation */
8278 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -04008279 if (error)
James Smart3772a992009-05-22 14:50:54 -04008280 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -04008281
8282 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
8283 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
8284 if (error)
8285 goto out_disable_pci_dev;
8286
8287 /* Set up SLI-3 specific device PCI memory space */
8288 error = lpfc_sli_pci_mem_setup(phba);
8289 if (error) {
8290 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8291 "1402 Failed to set up pci memory space.\n");
8292 goto out_disable_pci_dev;
8293 }
8294
8295 /* Set up phase-1 common device driver resources */
8296 error = lpfc_setup_driver_resource_phase1(phba);
8297 if (error) {
8298 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8299 "1403 Failed to set up driver resource.\n");
8300 goto out_unset_pci_mem_s3;
8301 }
8302
8303 /* Set up SLI-3 specific device driver resources */
8304 error = lpfc_sli_driver_resource_setup(phba);
8305 if (error) {
8306 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8307 "1404 Failed to set up driver resource.\n");
8308 goto out_unset_pci_mem_s3;
8309 }
8310
8311 /* Initialize and populate the iocb list per host */
8312 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
8313 if (error) {
8314 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8315 "1405 Failed to initialize iocb list.\n");
8316 goto out_unset_driver_resource_s3;
8317 }
8318
8319 /* Set up common device driver resources */
8320 error = lpfc_setup_driver_resource_phase2(phba);
8321 if (error) {
8322 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8323 "1406 Failed to set up driver resource.\n");
8324 goto out_free_iocb_list;
8325 }
8326
James Smart079b5c92011-08-21 21:48:49 -04008327 /* Get the default values for Model Name and Description */
8328 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
8329
James Smart3772a992009-05-22 14:50:54 -04008330 /* Create SCSI host to the physical port */
8331 error = lpfc_create_shost(phba);
8332 if (error) {
8333 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8334 "1407 Failed to create scsi host.\n");
8335 goto out_unset_driver_resource;
8336 }
8337
8338 /* Configure sysfs attributes */
8339 vport = phba->pport;
8340 error = lpfc_alloc_sysfs_attr(vport);
8341 if (error) {
8342 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8343 "1476 Failed to allocate sysfs attr\n");
8344 goto out_destroy_shost;
8345 }
8346
James Smart6669f9b2009-10-02 15:16:45 -04008347 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -04008348 /* Now, trying to enable interrupt and bring up the device */
8349 cfg_mode = phba->cfg_use_msi;
8350 while (true) {
8351 /* Put device to a known state before enabling interrupt */
8352 lpfc_stop_port(phba);
8353 /* Configure and enable interrupt */
8354 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
8355 if (intr_mode == LPFC_INTR_ERROR) {
8356 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8357 "0431 Failed to enable interrupt.\n");
8358 error = -ENODEV;
8359 goto out_free_sysfs_attr;
8360 }
8361 /* SLI-3 HBA setup */
8362 if (lpfc_sli_hba_setup(phba)) {
8363 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8364 "1477 Failed to set up hba\n");
8365 error = -ENODEV;
8366 goto out_remove_device;
8367 }
8368
8369 /* Wait 50ms for the interrupts of previous mailbox commands */
8370 msleep(50);
8371 /* Check active interrupts on message signaled interrupts */
8372 if (intr_mode == 0 ||
8373 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
8374 /* Log the current active interrupt mode */
8375 phba->intr_mode = intr_mode;
8376 lpfc_log_intr_mode(phba, intr_mode);
8377 break;
8378 } else {
8379 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8380 "0447 Configure interrupt mode (%d) "
8381 "failed active interrupt test.\n",
8382 intr_mode);
8383 /* Disable the current interrupt mode */
8384 lpfc_sli_disable_intr(phba);
8385 /* Try next level of interrupt mode */
8386 cfg_mode = --intr_mode;
8387 }
8388 }
8389
8390 /* Perform post initialization setup */
8391 lpfc_post_init_setup(phba);
8392
8393 /* Check if there are static vports to be created. */
8394 lpfc_create_static_vport(phba);
8395
8396 return 0;
8397
8398out_remove_device:
8399 lpfc_unset_hba(phba);
8400out_free_sysfs_attr:
8401 lpfc_free_sysfs_attr(vport);
8402out_destroy_shost:
8403 lpfc_destroy_shost(phba);
8404out_unset_driver_resource:
8405 lpfc_unset_driver_resource_phase2(phba);
8406out_free_iocb_list:
8407 lpfc_free_iocb_list(phba);
8408out_unset_driver_resource_s3:
8409 lpfc_sli_driver_resource_unset(phba);
8410out_unset_pci_mem_s3:
8411 lpfc_sli_pci_mem_unset(phba);
8412out_disable_pci_dev:
8413 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -04008414 if (shost)
8415 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -04008416out_free_phba:
8417 lpfc_hba_free(phba);
8418 return error;
8419}
8420
8421/**
8422 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -04008423 * @pdev: pointer to PCI device
8424 *
James Smart3772a992009-05-22 14:50:54 -04008425 * This routine is to be called to disattach a device with SLI-3 interface
8426 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
8427 * removed from PCI bus, it performs all the necessary cleanup for the HBA
8428 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -04008429 **/
dea31012005-04-17 16:05:31 -05008430static void __devexit
James Smart3772a992009-05-22 14:50:54 -04008431lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -05008432{
James Smart2e0fef82007-06-17 19:56:36 -05008433 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8434 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -05008435 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -05008436 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -05008437 int i;
Tomohiro Kusumi8a4df122008-01-11 01:53:00 -05008438 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
8439
James Smart549e55c2007-08-02 11:09:51 -04008440 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04008441 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04008442 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05008443
James Smart858c9f62007-06-17 19:56:39 -05008444 lpfc_free_sysfs_attr(vport);
8445
James Smarteada2722008-12-04 22:39:13 -05008446 /* Release all the vports against this physical port */
8447 vports = lpfc_create_vport_work_array(phba);
8448 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -04008449 for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
James Smarteada2722008-12-04 22:39:13 -05008450 fc_vport_terminate(vports[i]->fc_vport);
8451 lpfc_destroy_vport_work_array(phba, vports);
8452
8453 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -05008454 fc_remove_host(shost);
8455 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04008456 lpfc_cleanup(vport);
8457
James Smart2e0fef82007-06-17 19:56:36 -05008458 /*
8459 * Bring down the SLI Layer. This step disable all interrupts,
8460 * clears the rings, discards all mailbox commands, and resets
8461 * the HBA.
8462 */
James Smarta257bf92009-04-06 18:48:10 -04008463
Justin P. Mattock48e34d02010-12-30 15:07:58 -08008464 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -05008465 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -04008466 /* Stop kthread signal shall trigger work_done one more time */
8467 kthread_stop(phba->worker_thread);
8468 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -05008469 lpfc_sli_brdrestart(phba);
8470
James Smart3772a992009-05-22 14:50:54 -04008471 lpfc_stop_hba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05008472 spin_lock_irq(&phba->hbalock);
8473 list_del_init(&vport->listentry);
8474 spin_unlock_irq(&phba->hbalock);
8475
James Smart858c9f62007-06-17 19:56:39 -05008476 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05008477
James Smart912e3ac2011-05-24 11:42:11 -04008478 /* Disable SR-IOV if enabled */
8479 if (phba->cfg_sriov_nr_virtfn)
8480 pci_disable_sriov(pdev);
8481
James Smart5b75da22008-12-04 22:39:35 -05008482 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -04008483 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -05008484
8485 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05008486 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05008487
8488 /*
8489 * Call scsi_free before mem_free since scsi bufs are released to their
8490 * corresponding pools here.
8491 */
8492 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -04008493 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -05008494
James Smart34b02dc2008-08-24 21:49:55 -04008495 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
8496 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -05008497
James Smart2e0fef82007-06-17 19:56:36 -05008498 /* Free resources associated with SLI2 interface */
8499 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -04008500 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -05008501
8502 /* unmap adapter SLIM and Control Registers */
8503 iounmap(phba->ctrl_regs_memmap_p);
8504 iounmap(phba->slim_memmap_p);
8505
James Smart3772a992009-05-22 14:50:54 -04008506 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -05008507
Tomohiro Kusumi8a4df122008-01-11 01:53:00 -05008508 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05008509 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05008510}
8511
Linas Vepstas8d63f372007-02-14 14:28:36 -06008512/**
James Smart3772a992009-05-22 14:50:54 -04008513 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05008514 * @pdev: pointer to PCI device
8515 * @msg: power management message
8516 *
James Smart3772a992009-05-22 14:50:54 -04008517 * This routine is to be called from the kernel's PCI subsystem to support
8518 * system Power Management (PM) to device with SLI-3 interface spec. When
8519 * PM invokes this method, it quiesces the device by stopping the driver's
8520 * worker thread for the device, turning off device's interrupt and DMA,
8521 * and bring the device offline. Note that as the driver implements the
8522 * minimum PM requirements to a power-aware driver's PM support for the
8523 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
8524 * to the suspend() method call will be treated as SUSPEND and the driver will
8525 * fully reinitialize its device during resume() method call, the driver will
8526 * set device to PCI_D3hot state in PCI config space instead of setting it
8527 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -05008528 *
8529 * Return code
James Smart3772a992009-05-22 14:50:54 -04008530 * 0 - driver suspended the device
8531 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05008532 **/
8533static int
James Smart3772a992009-05-22 14:50:54 -04008534lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -05008535{
8536 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8537 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
8538
8539 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8540 "0473 PCI device Power Management suspend.\n");
8541
8542 /* Bring down the device */
8543 lpfc_offline_prep(phba);
8544 lpfc_offline(phba);
8545 kthread_stop(phba->worker_thread);
8546
8547 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -04008548 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -05008549
8550 /* Save device state to PCI config space */
8551 pci_save_state(pdev);
8552 pci_set_power_state(pdev, PCI_D3hot);
8553
8554 return 0;
8555}
8556
8557/**
James Smart3772a992009-05-22 14:50:54 -04008558 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05008559 * @pdev: pointer to PCI device
8560 *
James Smart3772a992009-05-22 14:50:54 -04008561 * This routine is to be called from the kernel's PCI subsystem to support
8562 * system Power Management (PM) to device with SLI-3 interface spec. When PM
8563 * invokes this method, it restores the device's PCI config space state and
8564 * fully reinitializes the device and brings it online. Note that as the
8565 * driver implements the minimum PM requirements to a power-aware driver's
8566 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
8567 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
8568 * driver will fully reinitialize its device during resume() method call,
8569 * the device will be set to PCI_D0 directly in PCI config space before
8570 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -05008571 *
8572 * Return code
James Smart3772a992009-05-22 14:50:54 -04008573 * 0 - driver suspended the device
8574 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05008575 **/
8576static int
James Smart3772a992009-05-22 14:50:54 -04008577lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -05008578{
8579 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8580 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -05008581 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05008582 int error;
8583
8584 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8585 "0452 PCI device Power Management resume.\n");
8586
8587 /* Restore device state from PCI config space */
8588 pci_set_power_state(pdev, PCI_D0);
8589 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -04008590
James Smart1dfb5a42010-02-12 14:40:50 -05008591 /*
8592 * As the new kernel behavior of pci_restore_state() API call clears
8593 * device saved_state flag, need to save the restored state again.
8594 */
8595 pci_save_state(pdev);
8596
James Smart3a55b532008-12-04 22:38:54 -05008597 if (pdev->is_busmaster)
8598 pci_set_master(pdev);
8599
8600 /* Startup the kernel thread for this host adapter. */
8601 phba->worker_thread = kthread_run(lpfc_do_work, phba,
8602 "lpfc_worker_%d", phba->brd_no);
8603 if (IS_ERR(phba->worker_thread)) {
8604 error = PTR_ERR(phba->worker_thread);
8605 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8606 "0434 PM resume failed to start worker "
8607 "thread: error=x%x.\n", error);
8608 return error;
8609 }
8610
James Smart5b75da22008-12-04 22:39:35 -05008611 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04008612 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05008613 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -05008614 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -05008615 "0430 PM resume Failed to enable interrupt\n");
8616 return -EIO;
8617 } else
8618 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05008619
8620 /* Restart HBA and bring it online */
8621 lpfc_sli_brdrestart(phba);
8622 lpfc_online(phba);
8623
James Smart5b75da22008-12-04 22:39:35 -05008624 /* Log the current active interrupt mode */
8625 lpfc_log_intr_mode(phba, phba->intr_mode);
8626
James Smart3a55b532008-12-04 22:38:54 -05008627 return 0;
8628}
8629
8630/**
James Smart891478a2009-11-18 15:40:23 -05008631 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
8632 * @phba: pointer to lpfc hba data structure.
8633 *
8634 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -04008635 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -05008636 **/
8637static void
8638lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
8639{
James Smarte2af0d22010-03-15 11:25:32 -04008640 struct lpfc_sli *psli = &phba->sli;
8641 struct lpfc_sli_ring *pring;
8642
James Smart891478a2009-11-18 15:40:23 -05008643 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8644 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -04008645
8646 /*
8647 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
8648 * and let the SCSI mid-layer to retry them to recover.
8649 */
8650 pring = &psli->ring[psli->fcp_ring];
8651 lpfc_sli_abort_iocb_ring(phba, pring);
James Smart891478a2009-11-18 15:40:23 -05008652}
8653
8654/**
James Smart0d878412009-10-02 15:16:56 -04008655 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
8656 * @phba: pointer to lpfc hba data structure.
8657 *
8658 * This routine is called to prepare the SLI3 device for PCI slot reset. It
8659 * disables the device interrupt and pci device, and aborts the internal FCP
8660 * pending I/Os.
8661 **/
8662static void
8663lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
8664{
James Smart0d878412009-10-02 15:16:56 -04008665 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -05008666 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -04008667
James Smart75baf692010-06-08 18:31:21 -04008668 /* Block any management I/Os to the device */
8669 lpfc_block_mgmt_io(phba);
8670
James Smarte2af0d22010-03-15 11:25:32 -04008671 /* Block all SCSI devices' I/Os on the host */
8672 lpfc_scsi_dev_block(phba);
8673
8674 /* stop all timers */
8675 lpfc_stop_hba_timers(phba);
8676
James Smart0d878412009-10-02 15:16:56 -04008677 /* Disable interrupt and pci device */
8678 lpfc_sli_disable_intr(phba);
8679 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -04008680
James Smarte2af0d22010-03-15 11:25:32 -04008681 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
8682 lpfc_sli_flush_fcp_rings(phba);
James Smart0d878412009-10-02 15:16:56 -04008683}
8684
8685/**
8686 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
8687 * @phba: pointer to lpfc hba data structure.
8688 *
8689 * This routine is called to prepare the SLI3 device for PCI slot permanently
8690 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
8691 * pending I/Os.
8692 **/
8693static void
James Smart75baf692010-06-08 18:31:21 -04008694lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -04008695{
8696 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -05008697 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -04008698 /* Block all SCSI devices' I/Os on the host */
8699 lpfc_scsi_dev_block(phba);
8700
8701 /* stop all timers */
8702 lpfc_stop_hba_timers(phba);
8703
James Smart0d878412009-10-02 15:16:56 -04008704 /* Clean up all driver's outstanding SCSI I/Os */
8705 lpfc_sli_flush_fcp_rings(phba);
8706}
8707
8708/**
James Smart3772a992009-05-22 14:50:54 -04008709 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -04008710 * @pdev: pointer to PCI device.
8711 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -06008712 *
James Smart3772a992009-05-22 14:50:54 -04008713 * This routine is called from the PCI subsystem for I/O error handling to
8714 * device with SLI-3 interface spec. This function is called by the PCI
8715 * subsystem after a PCI bus error affecting this device has been detected.
8716 * When this function is invoked, it will need to stop all the I/Os and
8717 * interrupt(s) to the device. Once that is done, it will return
8718 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
8719 * as desired.
James Smarte59058c2008-08-24 21:49:00 -04008720 *
8721 * Return codes
James Smart0d878412009-10-02 15:16:56 -04008722 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -04008723 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
8724 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -04008725 **/
James Smart3772a992009-05-22 14:50:54 -04008726static pci_ers_result_t
8727lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -06008728{
James Smart51ef4c22007-08-02 11:10:31 -04008729 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8730 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06008731
James Smart0d878412009-10-02 15:16:56 -04008732 switch (state) {
8733 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -05008734 /* Non-fatal error, prepare for recovery */
8735 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -04008736 return PCI_ERS_RESULT_CAN_RECOVER;
8737 case pci_channel_io_frozen:
8738 /* Fatal error, prepare for slot reset */
8739 lpfc_sli_prep_dev_for_reset(phba);
8740 return PCI_ERS_RESULT_NEED_RESET;
8741 case pci_channel_io_perm_failure:
8742 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -04008743 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06008744 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -04008745 default:
8746 /* Unknown state, prepare and request slot reset */
8747 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8748 "0472 Unknown PCI error state: x%x\n", state);
8749 lpfc_sli_prep_dev_for_reset(phba);
8750 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -04008751 }
Linas Vepstas8d63f372007-02-14 14:28:36 -06008752}
8753
8754/**
James Smart3772a992009-05-22 14:50:54 -04008755 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -04008756 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -06008757 *
James Smart3772a992009-05-22 14:50:54 -04008758 * This routine is called from the PCI subsystem for error handling to
8759 * device with SLI-3 interface spec. This is called after PCI bus has been
8760 * reset to restart the PCI card from scratch, as if from a cold-boot.
8761 * During the PCI subsystem error recovery, after driver returns
8762 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
8763 * recovery and then call this routine before calling the .resume method
8764 * to recover the device. This function will initialize the HBA device,
8765 * enable the interrupt, but it will just put the HBA to offline state
8766 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -04008767 *
8768 * Return codes
James Smart3772a992009-05-22 14:50:54 -04008769 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
8770 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -06008771 */
James Smart3772a992009-05-22 14:50:54 -04008772static pci_ers_result_t
8773lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -06008774{
James Smart51ef4c22007-08-02 11:10:31 -04008775 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8776 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06008777 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -05008778 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06008779
8780 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11008781 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -06008782 printk(KERN_ERR "lpfc: Cannot re-enable "
8783 "PCI device after reset.\n");
8784 return PCI_ERS_RESULT_DISCONNECT;
8785 }
8786
James Smart97207482008-12-04 22:39:19 -05008787 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -05008788
8789 /*
8790 * As the new kernel behavior of pci_restore_state() API call clears
8791 * device saved_state flag, need to save the restored state again.
8792 */
8793 pci_save_state(pdev);
8794
James Smart97207482008-12-04 22:39:19 -05008795 if (pdev->is_busmaster)
8796 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -06008797
James Smart92d7f7b2007-06-17 19:56:38 -05008798 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -04008799 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05008800 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06008801
James Smart5b75da22008-12-04 22:39:35 -05008802 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04008803 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05008804 if (intr_mode == LPFC_INTR_ERROR) {
8805 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8806 "0427 Cannot re-enable interrupt after "
8807 "slot reset.\n");
8808 return PCI_ERS_RESULT_DISCONNECT;
8809 } else
8810 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06008811
James Smart75baf692010-06-08 18:31:21 -04008812 /* Take device offline, it will perform cleanup */
8813 lpfc_offline_prep(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06008814 lpfc_offline(phba);
8815 lpfc_sli_brdrestart(phba);
8816
James Smart5b75da22008-12-04 22:39:35 -05008817 /* Log the current active interrupt mode */
8818 lpfc_log_intr_mode(phba, phba->intr_mode);
8819
Linas Vepstas8d63f372007-02-14 14:28:36 -06008820 return PCI_ERS_RESULT_RECOVERED;
8821}
8822
8823/**
James Smart3772a992009-05-22 14:50:54 -04008824 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -04008825 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -06008826 *
James Smart3772a992009-05-22 14:50:54 -04008827 * This routine is called from the PCI subsystem for error handling to device
8828 * with SLI-3 interface spec. It is called when kernel error recovery tells
8829 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
8830 * error recovery. After this call, traffic can start to flow from this device
8831 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -06008832 */
James Smart3772a992009-05-22 14:50:54 -04008833static void
8834lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -06008835{
James Smart51ef4c22007-08-02 11:10:31 -04008836 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8837 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06008838
James Smarte2af0d22010-03-15 11:25:32 -04008839 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -04008840 lpfc_online(phba);
James Smart0d878412009-10-02 15:16:56 -04008841
8842 /* Clean up Advanced Error Reporting (AER) if needed */
8843 if (phba->hba_flag & HBA_AER_ENABLED)
8844 pci_cleanup_aer_uncorrect_error_status(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -06008845}
8846
James Smart3772a992009-05-22 14:50:54 -04008847/**
James Smartda0436e2009-05-22 14:51:39 -04008848 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
8849 * @phba: pointer to lpfc hba data structure.
8850 *
8851 * returns the number of ELS/CT IOCBs to reserve
8852 **/
8853int
8854lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
8855{
8856 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
8857
James Smartf1126682009-06-10 17:22:44 -04008858 if (phba->sli_rev == LPFC_SLI_REV4) {
8859 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -04008860 return 10;
James Smartf1126682009-06-10 17:22:44 -04008861 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -04008862 return 25;
James Smartf1126682009-06-10 17:22:44 -04008863 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -04008864 return 50;
James Smartf1126682009-06-10 17:22:44 -04008865 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -04008866 return 100;
James Smartf1126682009-06-10 17:22:44 -04008867 else
James Smart6a9c52c2009-10-02 15:16:51 -04008868 return 150;
James Smartf1126682009-06-10 17:22:44 -04008869 } else
8870 return 0;
James Smartda0436e2009-05-22 14:51:39 -04008871}
8872
8873/**
James Smart52d52442011-05-24 11:42:45 -04008874 * lpfc_write_firmware - attempt to write a firmware image to the port
8875 * @phba: pointer to lpfc hba data structure.
8876 * @fw: pointer to firmware image returned from request_firmware.
8877 *
8878 * returns the number of bytes written if write is successful.
8879 * returns a negative error value if there were errors.
8880 * returns 0 if firmware matches currently active firmware on port.
8881 **/
8882int
8883lpfc_write_firmware(struct lpfc_hba *phba, const struct firmware *fw)
8884{
8885 char fwrev[32];
8886 struct lpfc_grp_hdr *image = (struct lpfc_grp_hdr *)fw->data;
8887 struct list_head dma_buffer_list;
8888 int i, rc = 0;
8889 struct lpfc_dmabuf *dmabuf, *next;
8890 uint32_t offset = 0, temp_offset = 0;
8891
8892 INIT_LIST_HEAD(&dma_buffer_list);
James Smart079b5c92011-08-21 21:48:49 -04008893 if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) ||
8894 (bf_get_be32(lpfc_grp_hdr_file_type, image) !=
8895 LPFC_FILE_TYPE_GROUP) ||
8896 (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) ||
8897 (be32_to_cpu(image->size) != fw->size)) {
James Smart52d52442011-05-24 11:42:45 -04008898 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8899 "3022 Invalid FW image found. "
James Smart079b5c92011-08-21 21:48:49 -04008900 "Magic:%x Type:%x ID:%x\n",
8901 be32_to_cpu(image->magic_number),
8902 bf_get_be32(lpfc_grp_hdr_file_type, image),
8903 bf_get_be32(lpfc_grp_hdr_id, image));
James Smart52d52442011-05-24 11:42:45 -04008904 return -EINVAL;
8905 }
8906 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -04008907 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -04008908 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8909 "3023 Updating Firmware. Current Version:%s "
8910 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -04008911 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -04008912 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
8913 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
8914 GFP_KERNEL);
8915 if (!dmabuf) {
8916 rc = -ENOMEM;
8917 goto out;
8918 }
8919 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
8920 SLI4_PAGE_SIZE,
8921 &dmabuf->phys,
8922 GFP_KERNEL);
8923 if (!dmabuf->virt) {
8924 kfree(dmabuf);
8925 rc = -ENOMEM;
8926 goto out;
8927 }
8928 list_add_tail(&dmabuf->list, &dma_buffer_list);
8929 }
8930 while (offset < fw->size) {
8931 temp_offset = offset;
8932 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -04008933 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -04008934 memcpy(dmabuf->virt,
8935 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -04008936 fw->size - temp_offset);
8937 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -04008938 break;
8939 }
James Smart52d52442011-05-24 11:42:45 -04008940 memcpy(dmabuf->virt, fw->data + temp_offset,
8941 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -04008942 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -04008943 }
8944 rc = lpfc_wr_object(phba, &dma_buffer_list,
8945 (fw->size - offset), &offset);
8946 if (rc) {
8947 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8948 "3024 Firmware update failed. "
8949 "%d\n", rc);
8950 goto out;
8951 }
8952 }
8953 rc = offset;
8954 }
8955out:
8956 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
8957 list_del(&dmabuf->list);
8958 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
8959 dmabuf->virt, dmabuf->phys);
8960 kfree(dmabuf);
8961 }
8962 return rc;
8963}
8964
8965/**
James Smartda0436e2009-05-22 14:51:39 -04008966 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
8967 * @pdev: pointer to PCI device
8968 * @pid: pointer to PCI device identifier
8969 *
8970 * This routine is called from the kernel's PCI subsystem to device with
8971 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
8972 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
8973 * information of the device and driver to see if the driver state that it
8974 * can support this kind of device. If the match is successful, the driver
8975 * core invokes this routine. If this routine determines it can claim the HBA,
8976 * it does all the initialization that it needs to do to handle the HBA
8977 * properly.
8978 *
8979 * Return code
8980 * 0 - driver can claim the device
8981 * negative value - driver can not claim the device
8982 **/
8983static int __devinit
8984lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
8985{
8986 struct lpfc_hba *phba;
8987 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -04008988 struct Scsi_Host *shost = NULL;
James Smartda0436e2009-05-22 14:51:39 -04008989 int error;
8990 uint32_t cfg_mode, intr_mode;
8991 int mcnt;
James Smart05580562011-05-24 11:40:48 -04008992 int adjusted_fcp_eq_count;
8993 int fcp_qidx;
James Smart52d52442011-05-24 11:42:45 -04008994 const struct firmware *fw;
8995 uint8_t file_name[16];
James Smartda0436e2009-05-22 14:51:39 -04008996
8997 /* Allocate memory for HBA structure */
8998 phba = lpfc_hba_alloc(pdev);
8999 if (!phba)
9000 return -ENOMEM;
9001
9002 /* Perform generic PCI device enabling operation */
9003 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -04009004 if (error)
James Smartda0436e2009-05-22 14:51:39 -04009005 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -04009006
9007 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
9008 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
9009 if (error)
9010 goto out_disable_pci_dev;
9011
9012 /* Set up SLI-4 specific device PCI memory space */
9013 error = lpfc_sli4_pci_mem_setup(phba);
9014 if (error) {
9015 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9016 "1410 Failed to set up pci memory space.\n");
9017 goto out_disable_pci_dev;
9018 }
9019
9020 /* Set up phase-1 common device driver resources */
9021 error = lpfc_setup_driver_resource_phase1(phba);
9022 if (error) {
9023 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9024 "1411 Failed to set up driver resource.\n");
9025 goto out_unset_pci_mem_s4;
9026 }
9027
9028 /* Set up SLI-4 Specific device driver resources */
9029 error = lpfc_sli4_driver_resource_setup(phba);
9030 if (error) {
9031 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9032 "1412 Failed to set up driver resource.\n");
9033 goto out_unset_pci_mem_s4;
9034 }
9035
9036 /* Initialize and populate the iocb list per host */
James Smart2a9bf3d2010-06-07 15:24:45 -04009037
9038 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9039 "2821 initialize iocb list %d.\n",
9040 phba->cfg_iocb_cnt*1024);
9041 error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
9042
James Smartda0436e2009-05-22 14:51:39 -04009043 if (error) {
9044 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9045 "1413 Failed to initialize iocb list.\n");
9046 goto out_unset_driver_resource_s4;
9047 }
9048
James Smart19ca7602010-11-20 23:11:55 -05009049 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -04009050 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -05009051
James Smartda0436e2009-05-22 14:51:39 -04009052 /* Set up common device driver resources */
9053 error = lpfc_setup_driver_resource_phase2(phba);
9054 if (error) {
9055 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9056 "1414 Failed to set up driver resource.\n");
9057 goto out_free_iocb_list;
9058 }
9059
James Smart079b5c92011-08-21 21:48:49 -04009060 /* Get the default values for Model Name and Description */
9061 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
9062
James Smartda0436e2009-05-22 14:51:39 -04009063 /* Create SCSI host to the physical port */
9064 error = lpfc_create_shost(phba);
9065 if (error) {
9066 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9067 "1415 Failed to create scsi host.\n");
9068 goto out_unset_driver_resource;
9069 }
9070
9071 /* Configure sysfs attributes */
9072 vport = phba->pport;
9073 error = lpfc_alloc_sysfs_attr(vport);
9074 if (error) {
9075 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9076 "1416 Failed to allocate sysfs attr\n");
9077 goto out_destroy_shost;
9078 }
9079
James Smart6669f9b2009-10-02 15:16:45 -04009080 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -04009081 /* Now, trying to enable interrupt and bring up the device */
9082 cfg_mode = phba->cfg_use_msi;
9083 while (true) {
9084 /* Put device to a known state before enabling interrupt */
9085 lpfc_stop_port(phba);
9086 /* Configure and enable interrupt */
9087 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
9088 if (intr_mode == LPFC_INTR_ERROR) {
9089 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9090 "0426 Failed to enable interrupt.\n");
9091 error = -ENODEV;
9092 goto out_free_sysfs_attr;
9093 }
James Smart05580562011-05-24 11:40:48 -04009094 /* Default to single EQ for non-MSI-X */
James Smartdef9c7a2009-12-21 17:02:28 -05009095 if (phba->intr_type != MSIX)
James Smart05580562011-05-24 11:40:48 -04009096 adjusted_fcp_eq_count = 0;
9097 else if (phba->sli4_hba.msix_vec_nr <
9098 phba->cfg_fcp_eq_count + 1)
9099 adjusted_fcp_eq_count = phba->sli4_hba.msix_vec_nr - 1;
9100 else
9101 adjusted_fcp_eq_count = phba->cfg_fcp_eq_count;
9102 /* Free unused EQs */
9103 for (fcp_qidx = adjusted_fcp_eq_count;
9104 fcp_qidx < phba->cfg_fcp_eq_count;
9105 fcp_qidx++) {
9106 lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]);
9107 /* do not delete the first fcp_cq */
9108 if (fcp_qidx)
9109 lpfc_sli4_queue_free(
9110 phba->sli4_hba.fcp_cq[fcp_qidx]);
9111 }
9112 phba->cfg_fcp_eq_count = adjusted_fcp_eq_count;
James Smartda0436e2009-05-22 14:51:39 -04009113 /* Set up SLI-4 HBA */
9114 if (lpfc_sli4_hba_setup(phba)) {
9115 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9116 "1421 Failed to set up hba\n");
9117 error = -ENODEV;
9118 goto out_disable_intr;
9119 }
9120
9121 /* Send NOP mbx cmds for non-INTx mode active interrupt test */
9122 if (intr_mode != 0)
9123 mcnt = lpfc_sli4_send_nop_mbox_cmds(phba,
9124 LPFC_ACT_INTR_CNT);
9125
9126 /* Check active interrupts received only for MSI/MSI-X */
9127 if (intr_mode == 0 ||
9128 phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) {
9129 /* Log the current active interrupt mode */
9130 phba->intr_mode = intr_mode;
9131 lpfc_log_intr_mode(phba, intr_mode);
9132 break;
9133 }
9134 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9135 "0451 Configure interrupt mode (%d) "
9136 "failed active interrupt test.\n",
9137 intr_mode);
James Smart2fcee4b2010-12-15 17:57:46 -05009138 /* Unset the previous SLI-4 HBA setup. */
9139 /*
9140 * TODO: Is this operation compatible with IF TYPE 2
9141 * devices? All port state is deleted and cleared.
9142 */
James Smartda0436e2009-05-22 14:51:39 -04009143 lpfc_sli4_unset_hba(phba);
9144 /* Try next level of interrupt mode */
9145 cfg_mode = --intr_mode;
9146 }
9147
9148 /* Perform post initialization setup */
9149 lpfc_post_init_setup(phba);
9150
James Smart52d52442011-05-24 11:42:45 -04009151 /* check for firmware upgrade or downgrade */
9152 snprintf(file_name, 16, "%s.grp", phba->ModelName);
9153 error = request_firmware(&fw, file_name, &phba->pcidev->dev);
9154 if (!error) {
9155 lpfc_write_firmware(phba, fw);
9156 release_firmware(fw);
9157 }
9158
James Smart1c6834a2009-07-19 10:01:26 -04009159 /* Check if there are static vports to be created. */
9160 lpfc_create_static_vport(phba);
James Smartda0436e2009-05-22 14:51:39 -04009161 return 0;
9162
9163out_disable_intr:
9164 lpfc_sli4_disable_intr(phba);
9165out_free_sysfs_attr:
9166 lpfc_free_sysfs_attr(vport);
9167out_destroy_shost:
9168 lpfc_destroy_shost(phba);
9169out_unset_driver_resource:
9170 lpfc_unset_driver_resource_phase2(phba);
9171out_free_iocb_list:
9172 lpfc_free_iocb_list(phba);
9173out_unset_driver_resource_s4:
9174 lpfc_sli4_driver_resource_unset(phba);
9175out_unset_pci_mem_s4:
9176 lpfc_sli4_pci_mem_unset(phba);
9177out_disable_pci_dev:
9178 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -04009179 if (shost)
9180 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -04009181out_free_phba:
9182 lpfc_hba_free(phba);
9183 return error;
9184}
9185
9186/**
9187 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
9188 * @pdev: pointer to PCI device
9189 *
9190 * This routine is called from the kernel's PCI subsystem to device with
9191 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
9192 * removed from PCI bus, it performs all the necessary cleanup for the HBA
9193 * device to be removed from the PCI subsystem properly.
9194 **/
9195static void __devexit
9196lpfc_pci_remove_one_s4(struct pci_dev *pdev)
9197{
9198 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9199 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
9200 struct lpfc_vport **vports;
9201 struct lpfc_hba *phba = vport->phba;
9202 int i;
9203
9204 /* Mark the device unloading flag */
9205 spin_lock_irq(&phba->hbalock);
9206 vport->load_flag |= FC_UNLOADING;
9207 spin_unlock_irq(&phba->hbalock);
9208
9209 /* Free the HBA sysfs attributes */
9210 lpfc_free_sysfs_attr(vport);
9211
9212 /* Release all the vports against this physical port */
9213 vports = lpfc_create_vport_work_array(phba);
9214 if (vports != NULL)
9215 for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
9216 fc_vport_terminate(vports[i]->fc_vport);
9217 lpfc_destroy_vport_work_array(phba, vports);
9218
9219 /* Remove FC host and then SCSI host with the physical port */
9220 fc_remove_host(shost);
9221 scsi_remove_host(shost);
9222
9223 /* Perform cleanup on the physical port */
9224 lpfc_cleanup(vport);
9225
9226 /*
9227 * Bring down the SLI Layer. This step disables all interrupts,
9228 * clears the rings, discards all mailbox commands, and resets
9229 * the HBA FCoE function.
9230 */
9231 lpfc_debugfs_terminate(vport);
9232 lpfc_sli4_hba_unset(phba);
9233
9234 spin_lock_irq(&phba->hbalock);
9235 list_del_init(&vport->listentry);
9236 spin_unlock_irq(&phba->hbalock);
9237
James Smart3677a3a2010-09-29 11:19:14 -04009238 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -04009239 * buffers are released to their corresponding pools here.
9240 */
9241 lpfc_scsi_free(phba);
9242 lpfc_sli4_driver_resource_unset(phba);
9243
9244 /* Unmap adapter Control and Doorbell registers */
9245 lpfc_sli4_pci_mem_unset(phba);
9246
9247 /* Release PCI resources and disable device's PCI function */
9248 scsi_host_put(shost);
9249 lpfc_disable_pci_dev(phba);
9250
9251 /* Finally, free the driver's device data structure */
9252 lpfc_hba_free(phba);
9253
9254 return;
9255}
9256
9257/**
9258 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
9259 * @pdev: pointer to PCI device
9260 * @msg: power management message
9261 *
9262 * This routine is called from the kernel's PCI subsystem to support system
9263 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
9264 * this method, it quiesces the device by stopping the driver's worker
9265 * thread for the device, turning off device's interrupt and DMA, and bring
9266 * the device offline. Note that as the driver implements the minimum PM
9267 * requirements to a power-aware driver's PM support for suspend/resume -- all
9268 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
9269 * method call will be treated as SUSPEND and the driver will fully
9270 * reinitialize its device during resume() method call, the driver will set
9271 * device to PCI_D3hot state in PCI config space instead of setting it
9272 * according to the @msg provided by the PM.
9273 *
9274 * Return code
9275 * 0 - driver suspended the device
9276 * Error otherwise
9277 **/
9278static int
9279lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
9280{
9281 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9282 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9283
9284 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -04009285 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -04009286
9287 /* Bring down the device */
9288 lpfc_offline_prep(phba);
9289 lpfc_offline(phba);
9290 kthread_stop(phba->worker_thread);
9291
9292 /* Disable interrupt from device */
9293 lpfc_sli4_disable_intr(phba);
9294
9295 /* Save device state to PCI config space */
9296 pci_save_state(pdev);
9297 pci_set_power_state(pdev, PCI_D3hot);
9298
9299 return 0;
9300}
9301
9302/**
9303 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
9304 * @pdev: pointer to PCI device
9305 *
9306 * This routine is called from the kernel's PCI subsystem to support system
9307 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
9308 * this method, it restores the device's PCI config space state and fully
9309 * reinitializes the device and brings it online. Note that as the driver
9310 * implements the minimum PM requirements to a power-aware driver's PM for
9311 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
9312 * to the suspend() method call will be treated as SUSPEND and the driver
9313 * will fully reinitialize its device during resume() method call, the device
9314 * will be set to PCI_D0 directly in PCI config space before restoring the
9315 * state.
9316 *
9317 * Return code
9318 * 0 - driver suspended the device
9319 * Error otherwise
9320 **/
9321static int
9322lpfc_pci_resume_one_s4(struct pci_dev *pdev)
9323{
9324 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9325 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9326 uint32_t intr_mode;
9327 int error;
9328
9329 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9330 "0292 PCI device Power Management resume.\n");
9331
9332 /* Restore device state from PCI config space */
9333 pci_set_power_state(pdev, PCI_D0);
9334 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -05009335
9336 /*
9337 * As the new kernel behavior of pci_restore_state() API call clears
9338 * device saved_state flag, need to save the restored state again.
9339 */
9340 pci_save_state(pdev);
9341
James Smartda0436e2009-05-22 14:51:39 -04009342 if (pdev->is_busmaster)
9343 pci_set_master(pdev);
9344
9345 /* Startup the kernel thread for this host adapter. */
9346 phba->worker_thread = kthread_run(lpfc_do_work, phba,
9347 "lpfc_worker_%d", phba->brd_no);
9348 if (IS_ERR(phba->worker_thread)) {
9349 error = PTR_ERR(phba->worker_thread);
9350 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9351 "0293 PM resume failed to start worker "
9352 "thread: error=x%x.\n", error);
9353 return error;
9354 }
9355
9356 /* Configure and enable interrupt */
9357 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
9358 if (intr_mode == LPFC_INTR_ERROR) {
9359 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9360 "0294 PM resume Failed to enable interrupt\n");
9361 return -EIO;
9362 } else
9363 phba->intr_mode = intr_mode;
9364
9365 /* Restart HBA and bring it online */
9366 lpfc_sli_brdrestart(phba);
9367 lpfc_online(phba);
9368
9369 /* Log the current active interrupt mode */
9370 lpfc_log_intr_mode(phba, phba->intr_mode);
9371
9372 return 0;
9373}
9374
9375/**
James Smart75baf692010-06-08 18:31:21 -04009376 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
9377 * @phba: pointer to lpfc hba data structure.
9378 *
9379 * This routine is called to prepare the SLI4 device for PCI slot recover. It
9380 * aborts all the outstanding SCSI I/Os to the pci device.
9381 **/
9382static void
9383lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
9384{
9385 struct lpfc_sli *psli = &phba->sli;
9386 struct lpfc_sli_ring *pring;
9387
9388 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9389 "2828 PCI channel I/O abort preparing for recovery\n");
9390 /*
9391 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
9392 * and let the SCSI mid-layer to retry them to recover.
9393 */
9394 pring = &psli->ring[psli->fcp_ring];
9395 lpfc_sli_abort_iocb_ring(phba, pring);
9396}
9397
9398/**
9399 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
9400 * @phba: pointer to lpfc hba data structure.
9401 *
9402 * This routine is called to prepare the SLI4 device for PCI slot reset. It
9403 * disables the device interrupt and pci device, and aborts the internal FCP
9404 * pending I/Os.
9405 **/
9406static void
9407lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
9408{
9409 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9410 "2826 PCI channel disable preparing for reset\n");
9411
9412 /* Block any management I/Os to the device */
9413 lpfc_block_mgmt_io(phba);
9414
9415 /* Block all SCSI devices' I/Os on the host */
9416 lpfc_scsi_dev_block(phba);
9417
9418 /* stop all timers */
9419 lpfc_stop_hba_timers(phba);
9420
9421 /* Disable interrupt and pci device */
9422 lpfc_sli4_disable_intr(phba);
9423 pci_disable_device(phba->pcidev);
9424
9425 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9426 lpfc_sli_flush_fcp_rings(phba);
9427}
9428
9429/**
9430 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
9431 * @phba: pointer to lpfc hba data structure.
9432 *
9433 * This routine is called to prepare the SLI4 device for PCI slot permanently
9434 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
9435 * pending I/Os.
9436 **/
9437static void
9438lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
9439{
9440 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9441 "2827 PCI channel permanent disable for failure\n");
9442
9443 /* Block all SCSI devices' I/Os on the host */
9444 lpfc_scsi_dev_block(phba);
9445
9446 /* stop all timers */
9447 lpfc_stop_hba_timers(phba);
9448
9449 /* Clean up all driver's outstanding SCSI I/Os */
9450 lpfc_sli_flush_fcp_rings(phba);
9451}
9452
9453/**
James Smartda0436e2009-05-22 14:51:39 -04009454 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
9455 * @pdev: pointer to PCI device.
9456 * @state: the current PCI connection state.
9457 *
9458 * This routine is called from the PCI subsystem for error handling to device
9459 * with SLI-4 interface spec. This function is called by the PCI subsystem
9460 * after a PCI bus error affecting this device has been detected. When this
9461 * function is invoked, it will need to stop all the I/Os and interrupt(s)
9462 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
9463 * for the PCI subsystem to perform proper recovery as desired.
9464 *
9465 * Return codes
9466 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
9467 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9468 **/
9469static pci_ers_result_t
9470lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
9471{
James Smart75baf692010-06-08 18:31:21 -04009472 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9473 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9474
9475 switch (state) {
9476 case pci_channel_io_normal:
9477 /* Non-fatal error, prepare for recovery */
9478 lpfc_sli4_prep_dev_for_recover(phba);
9479 return PCI_ERS_RESULT_CAN_RECOVER;
9480 case pci_channel_io_frozen:
9481 /* Fatal error, prepare for slot reset */
9482 lpfc_sli4_prep_dev_for_reset(phba);
9483 return PCI_ERS_RESULT_NEED_RESET;
9484 case pci_channel_io_perm_failure:
9485 /* Permanent failure, prepare for device down */
9486 lpfc_sli4_prep_dev_for_perm_failure(phba);
9487 return PCI_ERS_RESULT_DISCONNECT;
9488 default:
9489 /* Unknown state, prepare and request slot reset */
9490 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9491 "2825 Unknown PCI error state: x%x\n", state);
9492 lpfc_sli4_prep_dev_for_reset(phba);
9493 return PCI_ERS_RESULT_NEED_RESET;
9494 }
James Smartda0436e2009-05-22 14:51:39 -04009495}
9496
9497/**
9498 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
9499 * @pdev: pointer to PCI device.
9500 *
9501 * This routine is called from the PCI subsystem for error handling to device
9502 * with SLI-4 interface spec. It is called after PCI bus has been reset to
9503 * restart the PCI card from scratch, as if from a cold-boot. During the
9504 * PCI subsystem error recovery, after the driver returns
9505 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
9506 * recovery and then call this routine before calling the .resume method to
9507 * recover the device. This function will initialize the HBA device, enable
9508 * the interrupt, but it will just put the HBA to offline state without
9509 * passing any I/O traffic.
9510 *
9511 * Return codes
9512 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
9513 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9514 */
9515static pci_ers_result_t
9516lpfc_io_slot_reset_s4(struct pci_dev *pdev)
9517{
James Smart75baf692010-06-08 18:31:21 -04009518 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9519 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9520 struct lpfc_sli *psli = &phba->sli;
9521 uint32_t intr_mode;
9522
9523 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
9524 if (pci_enable_device_mem(pdev)) {
9525 printk(KERN_ERR "lpfc: Cannot re-enable "
9526 "PCI device after reset.\n");
9527 return PCI_ERS_RESULT_DISCONNECT;
9528 }
9529
9530 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -04009531
9532 /*
9533 * As the new kernel behavior of pci_restore_state() API call clears
9534 * device saved_state flag, need to save the restored state again.
9535 */
9536 pci_save_state(pdev);
9537
James Smart75baf692010-06-08 18:31:21 -04009538 if (pdev->is_busmaster)
9539 pci_set_master(pdev);
9540
9541 spin_lock_irq(&phba->hbalock);
9542 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
9543 spin_unlock_irq(&phba->hbalock);
9544
9545 /* Configure and enable interrupt */
9546 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
9547 if (intr_mode == LPFC_INTR_ERROR) {
9548 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9549 "2824 Cannot re-enable interrupt after "
9550 "slot reset.\n");
9551 return PCI_ERS_RESULT_DISCONNECT;
9552 } else
9553 phba->intr_mode = intr_mode;
9554
9555 /* Log the current active interrupt mode */
9556 lpfc_log_intr_mode(phba, phba->intr_mode);
9557
James Smartda0436e2009-05-22 14:51:39 -04009558 return PCI_ERS_RESULT_RECOVERED;
9559}
9560
9561/**
9562 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
9563 * @pdev: pointer to PCI device
9564 *
9565 * This routine is called from the PCI subsystem for error handling to device
9566 * with SLI-4 interface spec. It is called when kernel error recovery tells
9567 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
9568 * error recovery. After this call, traffic can start to flow from this device
9569 * again.
9570 **/
9571static void
9572lpfc_io_resume_s4(struct pci_dev *pdev)
9573{
James Smart75baf692010-06-08 18:31:21 -04009574 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9575 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9576
9577 /*
9578 * In case of slot reset, as function reset is performed through
9579 * mailbox command which needs DMA to be enabled, this operation
9580 * has to be moved to the io resume phase. Taking device offline
9581 * will perform the necessary cleanup.
9582 */
9583 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
9584 /* Perform device reset */
9585 lpfc_offline_prep(phba);
9586 lpfc_offline(phba);
9587 lpfc_sli_brdrestart(phba);
9588 /* Bring the device back online */
9589 lpfc_online(phba);
9590 }
9591
9592 /* Clean up Advanced Error Reporting (AER) if needed */
9593 if (phba->hba_flag & HBA_AER_ENABLED)
9594 pci_cleanup_aer_uncorrect_error_status(pdev);
James Smartda0436e2009-05-22 14:51:39 -04009595}
9596
9597/**
James Smart3772a992009-05-22 14:50:54 -04009598 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
9599 * @pdev: pointer to PCI device
9600 * @pid: pointer to PCI device identifier
9601 *
9602 * This routine is to be registered to the kernel's PCI subsystem. When an
9603 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
9604 * at PCI device-specific information of the device and driver to see if the
9605 * driver state that it can support this kind of device. If the match is
9606 * successful, the driver core invokes this routine. This routine dispatches
9607 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
9608 * do all the initialization that it needs to do to handle the HBA device
9609 * properly.
9610 *
9611 * Return code
9612 * 0 - driver can claim the device
9613 * negative value - driver can not claim the device
9614 **/
9615static int __devinit
9616lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
9617{
9618 int rc;
James Smart8fa38512009-07-19 10:01:03 -04009619 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -04009620
James Smart28baac72010-02-12 14:42:03 -05009621 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -04009622 return -ENODEV;
9623
James Smart8fa38512009-07-19 10:01:03 -04009624 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -05009625 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -04009626 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -04009627 else
James Smart3772a992009-05-22 14:50:54 -04009628 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -04009629
James Smart3772a992009-05-22 14:50:54 -04009630 return rc;
9631}
9632
9633/**
9634 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
9635 * @pdev: pointer to PCI device
9636 *
9637 * This routine is to be registered to the kernel's PCI subsystem. When an
9638 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
9639 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
9640 * remove routine, which will perform all the necessary cleanup for the
9641 * device to be removed from the PCI subsystem properly.
9642 **/
9643static void __devexit
9644lpfc_pci_remove_one(struct pci_dev *pdev)
9645{
9646 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9647 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9648
9649 switch (phba->pci_dev_grp) {
9650 case LPFC_PCI_DEV_LP:
9651 lpfc_pci_remove_one_s3(pdev);
9652 break;
James Smartda0436e2009-05-22 14:51:39 -04009653 case LPFC_PCI_DEV_OC:
9654 lpfc_pci_remove_one_s4(pdev);
9655 break;
James Smart3772a992009-05-22 14:50:54 -04009656 default:
9657 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9658 "1424 Invalid PCI device group: 0x%x\n",
9659 phba->pci_dev_grp);
9660 break;
9661 }
9662 return;
9663}
9664
9665/**
9666 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
9667 * @pdev: pointer to PCI device
9668 * @msg: power management message
9669 *
9670 * This routine is to be registered to the kernel's PCI subsystem to support
9671 * system Power Management (PM). When PM invokes this method, it dispatches
9672 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
9673 * suspend the device.
9674 *
9675 * Return code
9676 * 0 - driver suspended the device
9677 * Error otherwise
9678 **/
9679static int
9680lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
9681{
9682 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9683 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9684 int rc = -ENODEV;
9685
9686 switch (phba->pci_dev_grp) {
9687 case LPFC_PCI_DEV_LP:
9688 rc = lpfc_pci_suspend_one_s3(pdev, msg);
9689 break;
James Smartda0436e2009-05-22 14:51:39 -04009690 case LPFC_PCI_DEV_OC:
9691 rc = lpfc_pci_suspend_one_s4(pdev, msg);
9692 break;
James Smart3772a992009-05-22 14:50:54 -04009693 default:
9694 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9695 "1425 Invalid PCI device group: 0x%x\n",
9696 phba->pci_dev_grp);
9697 break;
9698 }
9699 return rc;
9700}
9701
9702/**
9703 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
9704 * @pdev: pointer to PCI device
9705 *
9706 * This routine is to be registered to the kernel's PCI subsystem to support
9707 * system Power Management (PM). When PM invokes this method, it dispatches
9708 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
9709 * resume the device.
9710 *
9711 * Return code
9712 * 0 - driver suspended the device
9713 * Error otherwise
9714 **/
9715static int
9716lpfc_pci_resume_one(struct pci_dev *pdev)
9717{
9718 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9719 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9720 int rc = -ENODEV;
9721
9722 switch (phba->pci_dev_grp) {
9723 case LPFC_PCI_DEV_LP:
9724 rc = lpfc_pci_resume_one_s3(pdev);
9725 break;
James Smartda0436e2009-05-22 14:51:39 -04009726 case LPFC_PCI_DEV_OC:
9727 rc = lpfc_pci_resume_one_s4(pdev);
9728 break;
James Smart3772a992009-05-22 14:50:54 -04009729 default:
9730 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9731 "1426 Invalid PCI device group: 0x%x\n",
9732 phba->pci_dev_grp);
9733 break;
9734 }
9735 return rc;
9736}
9737
9738/**
9739 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
9740 * @pdev: pointer to PCI device.
9741 * @state: the current PCI connection state.
9742 *
9743 * This routine is registered to the PCI subsystem for error handling. This
9744 * function is called by the PCI subsystem after a PCI bus error affecting
9745 * this device has been detected. When this routine is invoked, it dispatches
9746 * the action to the proper SLI-3 or SLI-4 device error detected handling
9747 * routine, which will perform the proper error detected operation.
9748 *
9749 * Return codes
9750 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
9751 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9752 **/
9753static pci_ers_result_t
9754lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
9755{
9756 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9757 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9758 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
9759
9760 switch (phba->pci_dev_grp) {
9761 case LPFC_PCI_DEV_LP:
9762 rc = lpfc_io_error_detected_s3(pdev, state);
9763 break;
James Smartda0436e2009-05-22 14:51:39 -04009764 case LPFC_PCI_DEV_OC:
9765 rc = lpfc_io_error_detected_s4(pdev, state);
9766 break;
James Smart3772a992009-05-22 14:50:54 -04009767 default:
9768 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9769 "1427 Invalid PCI device group: 0x%x\n",
9770 phba->pci_dev_grp);
9771 break;
9772 }
9773 return rc;
9774}
9775
9776/**
9777 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
9778 * @pdev: pointer to PCI device.
9779 *
9780 * This routine is registered to the PCI subsystem for error handling. This
9781 * function is called after PCI bus has been reset to restart the PCI card
9782 * from scratch, as if from a cold-boot. When this routine is invoked, it
9783 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
9784 * routine, which will perform the proper device reset.
9785 *
9786 * Return codes
9787 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
9788 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9789 **/
9790static pci_ers_result_t
9791lpfc_io_slot_reset(struct pci_dev *pdev)
9792{
9793 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9794 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9795 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
9796
9797 switch (phba->pci_dev_grp) {
9798 case LPFC_PCI_DEV_LP:
9799 rc = lpfc_io_slot_reset_s3(pdev);
9800 break;
James Smartda0436e2009-05-22 14:51:39 -04009801 case LPFC_PCI_DEV_OC:
9802 rc = lpfc_io_slot_reset_s4(pdev);
9803 break;
James Smart3772a992009-05-22 14:50:54 -04009804 default:
9805 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9806 "1428 Invalid PCI device group: 0x%x\n",
9807 phba->pci_dev_grp);
9808 break;
9809 }
9810 return rc;
9811}
9812
9813/**
9814 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
9815 * @pdev: pointer to PCI device
9816 *
9817 * This routine is registered to the PCI subsystem for error handling. It
9818 * is called when kernel error recovery tells the lpfc driver that it is
9819 * OK to resume normal PCI operation after PCI bus error recovery. When
9820 * this routine is invoked, it dispatches the action to the proper SLI-3
9821 * or SLI-4 device io_resume routine, which will resume the device operation.
9822 **/
9823static void
9824lpfc_io_resume(struct pci_dev *pdev)
9825{
9826 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9827 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
9828
9829 switch (phba->pci_dev_grp) {
9830 case LPFC_PCI_DEV_LP:
9831 lpfc_io_resume_s3(pdev);
9832 break;
James Smartda0436e2009-05-22 14:51:39 -04009833 case LPFC_PCI_DEV_OC:
9834 lpfc_io_resume_s4(pdev);
9835 break;
James Smart3772a992009-05-22 14:50:54 -04009836 default:
9837 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9838 "1429 Invalid PCI device group: 0x%x\n",
9839 phba->pci_dev_grp);
9840 break;
9841 }
9842 return;
9843}
9844
dea31012005-04-17 16:05:31 -05009845static struct pci_device_id lpfc_id_table[] = {
9846 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
9847 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04009848 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
9849 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05009850 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
9851 PCI_ANY_ID, PCI_ANY_ID, },
9852 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
9853 PCI_ANY_ID, PCI_ANY_ID, },
9854 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
9855 PCI_ANY_ID, PCI_ANY_ID, },
9856 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
9857 PCI_ANY_ID, PCI_ANY_ID, },
9858 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
9859 PCI_ANY_ID, PCI_ANY_ID, },
9860 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
9861 PCI_ANY_ID, PCI_ANY_ID, },
9862 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
9863 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05009864 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
9865 PCI_ANY_ID, PCI_ANY_ID, },
9866 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
9867 PCI_ANY_ID, PCI_ANY_ID, },
9868 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
9869 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05009870 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
9871 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05009872 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
9873 PCI_ANY_ID, PCI_ANY_ID, },
9874 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
9875 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05009876 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
9877 PCI_ANY_ID, PCI_ANY_ID, },
9878 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
9879 PCI_ANY_ID, PCI_ANY_ID, },
9880 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
9881 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -04009882 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
9883 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05009884 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
9885 PCI_ANY_ID, PCI_ANY_ID, },
9886 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
9887 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05009888 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
9889 PCI_ANY_ID, PCI_ANY_ID, },
9890 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
9891 PCI_ANY_ID, PCI_ANY_ID, },
9892 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
9893 PCI_ANY_ID, PCI_ANY_ID, },
9894 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
9895 PCI_ANY_ID, PCI_ANY_ID, },
9896 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
9897 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05009898 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
9899 PCI_ANY_ID, PCI_ANY_ID, },
9900 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
9901 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -04009902 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
9903 PCI_ANY_ID, PCI_ANY_ID, },
9904 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
9905 PCI_ANY_ID, PCI_ANY_ID, },
9906 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
9907 PCI_ANY_ID, PCI_ANY_ID, },
9908 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
9909 PCI_ANY_ID, PCI_ANY_ID, },
9910 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
9911 PCI_ANY_ID, PCI_ANY_ID, },
9912 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
9913 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -04009914 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
9915 PCI_ANY_ID, PCI_ANY_ID, },
9916 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
9917 PCI_ANY_ID, PCI_ANY_ID, },
9918 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
9919 PCI_ANY_ID, PCI_ANY_ID, },
James Smart3772a992009-05-22 14:50:54 -04009920 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
9921 PCI_ANY_ID, PCI_ANY_ID, },
James Smarta747c9c2009-11-18 15:41:10 -05009922 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT,
9923 PCI_ANY_ID, PCI_ANY_ID, },
9924 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON,
James Smart6669f9b2009-10-02 15:16:45 -04009925 PCI_ANY_ID, PCI_ANY_ID, },
James Smart98fc5dd2010-06-07 15:24:29 -04009926 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS,
9927 PCI_ANY_ID, PCI_ANY_ID, },
James Smart085c6472010-11-20 23:11:37 -05009928 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC,
9929 PCI_ANY_ID, PCI_ANY_ID, },
9930 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE,
9931 PCI_ANY_ID, PCI_ANY_ID, },
James Smartc0c11512011-05-24 11:41:34 -04009932 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF,
9933 PCI_ANY_ID, PCI_ANY_ID, },
9934 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF,
9935 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05009936 { 0 }
9937};
9938
9939MODULE_DEVICE_TABLE(pci, lpfc_id_table);
9940
Linas Vepstas8d63f372007-02-14 14:28:36 -06009941static struct pci_error_handlers lpfc_err_handler = {
9942 .error_detected = lpfc_io_error_detected,
9943 .slot_reset = lpfc_io_slot_reset,
9944 .resume = lpfc_io_resume,
9945};
9946
dea31012005-04-17 16:05:31 -05009947static struct pci_driver lpfc_driver = {
9948 .name = LPFC_DRIVER_NAME,
9949 .id_table = lpfc_id_table,
9950 .probe = lpfc_pci_probe_one,
9951 .remove = __devexit_p(lpfc_pci_remove_one),
James Smart3a55b532008-12-04 22:38:54 -05009952 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -04009953 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -05009954 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -05009955};
9956
James Smarte59058c2008-08-24 21:49:00 -04009957/**
James Smart3621a712009-04-06 18:47:14 -04009958 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -04009959 *
9960 * This routine is to be invoked when the lpfc module is loaded into the
9961 * kernel. The special kernel macro module_init() is used to indicate the
9962 * role of this routine to the kernel as lpfc module entry point.
9963 *
9964 * Return codes
9965 * 0 - successful
9966 * -ENOMEM - FC attach transport failed
9967 * all others - failed
9968 */
dea31012005-04-17 16:05:31 -05009969static int __init
9970lpfc_init(void)
9971{
9972 int error = 0;
9973
9974 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04009975 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -05009976
James Smart7ee5d432007-10-27 13:37:17 -04009977 if (lpfc_enable_npiv) {
9978 lpfc_transport_functions.vport_create = lpfc_vport_create;
9979 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
9980 }
dea31012005-04-17 16:05:31 -05009981 lpfc_transport_template =
9982 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -04009983 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -05009984 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -04009985 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -04009986 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -04009987 fc_attach_transport(&lpfc_vport_transport_functions);
9988 if (lpfc_vport_transport_template == NULL) {
9989 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04009990 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -04009991 }
James Smart7ee5d432007-10-27 13:37:17 -04009992 }
dea31012005-04-17 16:05:31 -05009993 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -05009994 if (error) {
dea31012005-04-17 16:05:31 -05009995 fc_release_transport(lpfc_transport_template);
James Smartd7c255b2008-08-24 21:50:00 -04009996 if (lpfc_enable_npiv)
9997 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -05009998 }
dea31012005-04-17 16:05:31 -05009999
10000 return error;
10001}
10002
James Smarte59058c2008-08-24 21:49:00 -040010003/**
James Smart3621a712009-04-06 18:47:14 -040010004 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040010005 *
10006 * This routine is invoked when the lpfc module is removed from the kernel.
10007 * The special kernel macro module_exit() is used to indicate the role of
10008 * this routine to the kernel as lpfc module exit point.
10009 */
dea31012005-04-17 16:05:31 -050010010static void __exit
10011lpfc_exit(void)
10012{
10013 pci_unregister_driver(&lpfc_driver);
10014 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -040010015 if (lpfc_enable_npiv)
10016 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050010017 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040010018 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
10019 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050010020 (1L << _dump_buf_data_order), _dump_buf_data);
10021 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
10022 }
10023
10024 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040010025 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
10026 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050010027 (1L << _dump_buf_dif_order), _dump_buf_dif);
10028 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
10029 }
dea31012005-04-17 16:05:31 -050010030}
10031
10032module_init(lpfc_init);
10033module_exit(lpfc_exit);
10034MODULE_LICENSE("GPL");
10035MODULE_DESCRIPTION(LPFC_MODULE_DESC);
10036MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
10037MODULE_VERSION("0:" LPFC_DRIVER_VERSION);