blob: f8271a587aab964d2697c566bab287467ead256f [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 Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 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>
dea31012005-04-17 16:05:31 -050031
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040032#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050033#include <scsi/scsi_device.h>
34#include <scsi/scsi_host.h>
35#include <scsi/scsi_transport_fc.h>
36
James Smartda0436e2009-05-22 14:51:39 -040037#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050038#include "lpfc_hw.h"
39#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040040#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040041#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050042#include "lpfc_disc.h"
43#include "lpfc_scsi.h"
44#include "lpfc.h"
45#include "lpfc_logmsg.h"
46#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050047#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050048#include "lpfc_version.h"
49
James Smart81301a92008-12-04 22:39:46 -050050char *_dump_buf_data;
51unsigned long _dump_buf_data_order;
52char *_dump_buf_dif;
53unsigned long _dump_buf_dif_order;
54spinlock_t _dump_buf_lock;
55
dea31012005-04-17 16:05:31 -050056static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
57static int lpfc_post_rcv_buf(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040058static int lpfc_sli4_queue_create(struct lpfc_hba *);
59static void lpfc_sli4_queue_destroy(struct lpfc_hba *);
60static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
61static int lpfc_setup_endian_order(struct lpfc_hba *);
62static int lpfc_sli4_read_config(struct lpfc_hba *);
63static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
64static void lpfc_free_sgl_list(struct lpfc_hba *);
65static int lpfc_init_sgl_list(struct lpfc_hba *);
66static int lpfc_init_active_sgl_array(struct lpfc_hba *);
67static void lpfc_free_active_sgl(struct lpfc_hba *);
68static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
69static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
70static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
71static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
72static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
dea31012005-04-17 16:05:31 -050073
74static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050075static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -050076static DEFINE_IDR(lpfc_hba_index);
77
James Smarte59058c2008-08-24 21:49:00 -040078/**
James Smart3621a712009-04-06 18:47:14 -040079 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
James Smarte59058c2008-08-24 21:49:00 -040080 * @phba: pointer to lpfc hba data structure.
81 *
82 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
83 * mailbox command. It retrieves the revision information from the HBA and
84 * collects the Vital Product Data (VPD) about the HBA for preparing the
85 * configuration of the HBA.
86 *
87 * Return codes:
88 * 0 - success.
89 * -ERESTART - requests the SLI layer to reset the HBA and try again.
90 * Any other value - indicates an error.
91 **/
dea31012005-04-17 16:05:31 -050092int
James Smart2e0fef82007-06-17 19:56:36 -050093lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -050094{
95 lpfc_vpd_t *vp = &phba->vpd;
96 int i = 0, rc;
97 LPFC_MBOXQ_t *pmb;
98 MAILBOX_t *mb;
99 char *lpfc_vpd_data = NULL;
100 uint16_t offset = 0;
101 static char licensed[56] =
102 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -0400103 static int init_key = 1;
dea31012005-04-17 16:05:31 -0500104
105 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
106 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500107 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500108 return -ENOMEM;
109 }
110
James Smart04c68492009-05-22 14:52:52 -0400111 mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -0500112 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -0500113
114 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -0400115 if (init_key) {
116 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -0500117
James Smart65a29c12006-07-06 15:50:50 -0400118 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
119 *ptext = cpu_to_be32(*ptext);
120 init_key = 0;
121 }
dea31012005-04-17 16:05:31 -0500122
123 lpfc_read_nv(phba, pmb);
124 memset((char*)mb->un.varRDnvp.rsvd3, 0,
125 sizeof (mb->un.varRDnvp.rsvd3));
126 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
127 sizeof (licensed));
128
129 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
130
131 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500132 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400133 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500134 "error, mbxCmd x%x READ_NVPARM, "
135 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500136 mb->mbxCommand, mb->mbxStatus);
137 mempool_free(pmb, phba->mbox_mem_pool);
138 return -ERESTART;
139 }
140 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500141 sizeof(phba->wwnn));
142 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
143 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500144 }
145
James Smart92d7f7b2007-06-17 19:56:38 -0500146 phba->sli3_options = 0x0;
147
dea31012005-04-17 16:05:31 -0500148 /* Setup and issue mailbox READ REV command */
149 lpfc_read_rev(phba, pmb);
150 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
151 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500152 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400153 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500154 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500155 mb->mbxCommand, mb->mbxStatus);
156 mempool_free( pmb, phba->mbox_mem_pool);
157 return -ERESTART;
158 }
159
James Smart92d7f7b2007-06-17 19:56:38 -0500160
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500161 /*
162 * The value of rr must be 1 since the driver set the cv field to 1.
163 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500164 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500165 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500166 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500167 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400168 "0440 Adapter failed to init, READ_REV has "
169 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500170 mempool_free(pmb, phba->mbox_mem_pool);
171 return -ERESTART;
dea31012005-04-17 16:05:31 -0500172 }
173
James Smart495a7142008-06-14 22:52:59 -0400174 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
175 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500176 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400177 }
James Smarted957682007-06-17 19:56:37 -0500178
dea31012005-04-17 16:05:31 -0500179 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500180 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500181 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500182 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
183 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
184 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
185 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500186 vp->rev.biuRev = mb->un.varRdRev.biuRev;
187 vp->rev.smRev = mb->un.varRdRev.smRev;
188 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
189 vp->rev.endecRev = mb->un.varRdRev.endecRev;
190 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
191 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
192 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
193 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
194 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
195 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
196
James Smart92d7f7b2007-06-17 19:56:38 -0500197 /* If the sli feature level is less then 9, we must
198 * tear down all RPIs and VPIs on link down if NPIV
199 * is enabled.
200 */
201 if (vp->rev.feaLevelHigh < 9)
202 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
203
dea31012005-04-17 16:05:31 -0500204 if (lpfc_is_LC_HBA(phba->pcidev->device))
205 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
206 sizeof (phba->RandomData));
207
dea31012005-04-17 16:05:31 -0500208 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500209 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
210 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400211 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500212
213 do {
214 lpfc_dump_mem(phba, pmb, offset);
215 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
216
217 if (rc != MBX_SUCCESS) {
218 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400219 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500220 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500221 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500222 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500223 }
James Smart04c68492009-05-22 14:52:52 -0400224 /* dump mem may return a zero when finished or we got a
225 * mailbox error, either way we are done.
226 */
227 if (mb->un.varDmp.word_cnt == 0)
228 break;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500229 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
230 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400231 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
232 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500233 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500234 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500235 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
236 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500237
238 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500239out_free_mbox:
240 mempool_free(pmb, phba->mbox_mem_pool);
241 return 0;
242}
243
James Smarte59058c2008-08-24 21:49:00 -0400244/**
James Smart3621a712009-04-06 18:47:14 -0400245 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
James Smarte59058c2008-08-24 21:49:00 -0400246 * @phba: pointer to lpfc hba data structure.
247 * @pmboxq: pointer to the driver internal queue element for mailbox command.
248 *
249 * This is the completion handler for driver's configuring asynchronous event
250 * mailbox command to the device. If the mailbox command returns successfully,
251 * it will set internal async event support flag to 1; otherwise, it will
252 * set internal async event support flag to 0.
253 **/
James Smart57127f12007-10-27 13:37:05 -0400254static void
255lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
256{
James Smart04c68492009-05-22 14:52:52 -0400257 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
James Smart57127f12007-10-27 13:37:05 -0400258 phba->temp_sensor_support = 1;
259 else
260 phba->temp_sensor_support = 0;
261 mempool_free(pmboxq, phba->mbox_mem_pool);
262 return;
263}
264
James Smarte59058c2008-08-24 21:49:00 -0400265/**
James Smart3621a712009-04-06 18:47:14 -0400266 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
James Smart97207482008-12-04 22:39:19 -0500267 * @phba: pointer to lpfc hba data structure.
268 * @pmboxq: pointer to the driver internal queue element for mailbox command.
269 *
270 * This is the completion handler for dump mailbox command for getting
271 * wake up parameters. When this command complete, the response contain
272 * Option rom version of the HBA. This function translate the version number
273 * into a human readable string and store it in OptionROMVersion.
274 **/
275static void
276lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
277{
278 struct prog_id *prg;
279 uint32_t prog_id_word;
280 char dist = ' ';
281 /* character array used for decoding dist type. */
282 char dist_char[] = "nabx";
283
James Smart04c68492009-05-22 14:52:52 -0400284 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
James Smart9f1e1b52008-12-04 22:39:40 -0500285 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500286 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500287 }
James Smart97207482008-12-04 22:39:19 -0500288
289 prg = (struct prog_id *) &prog_id_word;
290
291 /* word 7 contain option rom version */
James Smart04c68492009-05-22 14:52:52 -0400292 prog_id_word = pmboxq->u.mb.un.varWords[7];
James Smart97207482008-12-04 22:39:19 -0500293
294 /* Decode the Option rom version word to a readable string */
295 if (prg->dist < 4)
296 dist = dist_char[prg->dist];
297
298 if ((prg->dist == 3) && (prg->num == 0))
299 sprintf(phba->OptionROMVersion, "%d.%d%d",
300 prg->ver, prg->rev, prg->lev);
301 else
302 sprintf(phba->OptionROMVersion, "%d.%d%d%c%d",
303 prg->ver, prg->rev, prg->lev,
304 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500305 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500306 return;
307}
308
309/**
James Smart3621a712009-04-06 18:47:14 -0400310 * lpfc_config_port_post - Perform lpfc initialization after config port
James Smarte59058c2008-08-24 21:49:00 -0400311 * @phba: pointer to lpfc hba data structure.
312 *
313 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
314 * command call. It performs all internal resource and state setups on the
315 * port: post IOCB buffers, enable appropriate host interrupt attentions,
316 * ELS ring timers, etc.
317 *
318 * Return codes
319 * 0 - success.
320 * Any other value - error.
321 **/
dea31012005-04-17 16:05:31 -0500322int
James Smart2e0fef82007-06-17 19:56:36 -0500323lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500324{
James Smart2e0fef82007-06-17 19:56:36 -0500325 struct lpfc_vport *vport = phba->pport;
James Smarta257bf92009-04-06 18:48:10 -0400326 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500327 LPFC_MBOXQ_t *pmb;
328 MAILBOX_t *mb;
329 struct lpfc_dmabuf *mp;
330 struct lpfc_sli *psli = &phba->sli;
331 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500332 int i, j;
333 int rc;
dea31012005-04-17 16:05:31 -0500334
James Smart7af67052007-10-27 13:38:11 -0400335 spin_lock_irq(&phba->hbalock);
336 /*
337 * If the Config port completed correctly the HBA is not
338 * over heated any more.
339 */
340 if (phba->over_temp_state == HBA_OVER_TEMP)
341 phba->over_temp_state = HBA_NORMAL_TEMP;
342 spin_unlock_irq(&phba->hbalock);
343
dea31012005-04-17 16:05:31 -0500344 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
345 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500346 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500347 return -ENOMEM;
348 }
James Smart04c68492009-05-22 14:52:52 -0400349 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500350
dea31012005-04-17 16:05:31 -0500351 /* Get login parameters for NID. */
James Smart92d7f7b2007-06-17 19:56:38 -0500352 lpfc_read_sparam(phba, pmb, 0);
James Smarted957682007-06-17 19:56:37 -0500353 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500354 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500355 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400356 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500357 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500358 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500359 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500360 mp = (struct lpfc_dmabuf *) pmb->context1;
361 mempool_free( pmb, phba->mbox_mem_pool);
362 lpfc_mbuf_free(phba, mp->virt, mp->phys);
363 kfree(mp);
364 return -EIO;
365 }
366
367 mp = (struct lpfc_dmabuf *) pmb->context1;
368
James Smart2e0fef82007-06-17 19:56:36 -0500369 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500370 lpfc_mbuf_free(phba, mp->virt, mp->phys);
371 kfree(mp);
372 pmb->context1 = NULL;
373
James Smarta12e07b2006-12-02 13:35:30 -0500374 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -0500375 u64_to_wwn(phba->cfg_soft_wwnn,
376 vport->fc_sparam.nodeName.u.wwn);
James Smartc3f28af2006-08-18 17:47:18 -0400377 if (phba->cfg_soft_wwpn)
James Smart2e0fef82007-06-17 19:56:36 -0500378 u64_to_wwn(phba->cfg_soft_wwpn,
379 vport->fc_sparam.portName.u.wwn);
380 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -0500381 sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -0500382 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -0500383 sizeof (struct lpfc_name));
James Smarta257bf92009-04-06 18:48:10 -0400384
385 /* Update the fc_host data structures with new wwn. */
386 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
387 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart21e9a0a2009-05-22 14:53:21 -0400388 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smarta257bf92009-04-06 18:48:10 -0400389
dea31012005-04-17 16:05:31 -0500390 /* If no serial number in VPD data, use low 6 bytes of WWNN */
391 /* This should be consolidated into parse_vpd ? - mr */
392 if (phba->SerialNumber[0] == 0) {
393 uint8_t *outptr;
394
James Smart2e0fef82007-06-17 19:56:36 -0500395 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500396 for (i = 0; i < 12; i++) {
397 status = *outptr++;
398 j = ((status & 0xf0) >> 4);
399 if (j <= 9)
400 phba->SerialNumber[i] =
401 (char)((uint8_t) 0x30 + (uint8_t) j);
402 else
403 phba->SerialNumber[i] =
404 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
405 i++;
406 j = (status & 0xf);
407 if (j <= 9)
408 phba->SerialNumber[i] =
409 (char)((uint8_t) 0x30 + (uint8_t) j);
410 else
411 phba->SerialNumber[i] =
412 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
413 }
414 }
415
dea31012005-04-17 16:05:31 -0500416 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500417 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500418 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500419 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400420 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500421 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500422 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500423 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500424 mempool_free( pmb, phba->mbox_mem_pool);
425 return -EIO;
426 }
427
428 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
429 if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
430 phba->cfg_hba_queue_depth =
James Smartf1126682009-06-10 17:22:44 -0400431 (mb->un.varRdConfig.max_xri + 1) -
432 lpfc_sli4_get_els_iocb_cnt(phba);
dea31012005-04-17 16:05:31 -0500433
434 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500435
436 /* Get the default values for Model Name and Description */
437 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
438
439 if ((phba->cfg_link_speed > LINK_SPEED_10G)
440 || ((phba->cfg_link_speed == LINK_SPEED_1G)
441 && !(phba->lmt & LMT_1Gb))
442 || ((phba->cfg_link_speed == LINK_SPEED_2G)
443 && !(phba->lmt & LMT_2Gb))
444 || ((phba->cfg_link_speed == LINK_SPEED_4G)
445 && !(phba->lmt & LMT_4Gb))
446 || ((phba->cfg_link_speed == LINK_SPEED_8G)
447 && !(phba->lmt & LMT_8Gb))
448 || ((phba->cfg_link_speed == LINK_SPEED_10G)
449 && !(phba->lmt & LMT_10Gb))) {
450 /* Reset link speed to auto */
James Smarted957682007-06-17 19:56:37 -0500451 lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400452 "1302 Invalid speed for this board: "
dea31012005-04-17 16:05:31 -0500453 "Reset link speed to auto: x%x\n",
dea31012005-04-17 16:05:31 -0500454 phba->cfg_link_speed);
455 phba->cfg_link_speed = LINK_SPEED_AUTO;
456 }
457
James Smart2e0fef82007-06-17 19:56:36 -0500458 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500459
James Smart0b727fe2007-10-27 13:37:25 -0400460 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smarta4bc3372006-12-02 13:34:16 -0500461 if (psli->ring[psli->extra_ring].cmdringaddr)
462 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500463 if (psli->ring[psli->fcp_ring].cmdringaddr)
464 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
465 if (psli->ring[psli->next_ring].cmdringaddr)
466 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
467
468 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500469 if (phba->sli_rev != 3)
470 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500471
James Smart93996272008-08-24 21:50:30 -0400472 /*
473 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
474 */
475 if (phba->intr_type == MSIX) {
476 rc = lpfc_config_msi(phba, pmb);
477 if (rc) {
478 mempool_free(pmb, phba->mbox_mem_pool);
479 return -EIO;
480 }
481 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
482 if (rc != MBX_SUCCESS) {
483 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
484 "0352 Config MSI mailbox command "
485 "failed, mbxCmd x%x, mbxStatus x%x\n",
James Smart04c68492009-05-22 14:52:52 -0400486 pmb->u.mb.mbxCommand,
487 pmb->u.mb.mbxStatus);
James Smart93996272008-08-24 21:50:30 -0400488 mempool_free(pmb, phba->mbox_mem_pool);
489 return -EIO;
490 }
491 }
492
James Smart04c68492009-05-22 14:52:52 -0400493 spin_lock_irq(&phba->hbalock);
James Smart93996272008-08-24 21:50:30 -0400494 /* Initialize ERATT handling flag */
495 phba->hba_flag &= ~HBA_ERATT_HANDLED;
496
dea31012005-04-17 16:05:31 -0500497 /* Enable appropriate host interrupts */
dea31012005-04-17 16:05:31 -0500498 status = readl(phba->HCregaddr);
499 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
500 if (psli->num_rings > 0)
501 status |= HC_R0INT_ENA;
502 if (psli->num_rings > 1)
503 status |= HC_R1INT_ENA;
504 if (psli->num_rings > 2)
505 status |= HC_R2INT_ENA;
506 if (psli->num_rings > 3)
507 status |= HC_R3INT_ENA;
508
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500509 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
510 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400511 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500512
dea31012005-04-17 16:05:31 -0500513 writel(status, phba->HCregaddr);
514 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500515 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500516
James Smart93996272008-08-24 21:50:30 -0400517 /* Set up ring-0 (ELS) timer */
518 timeout = phba->fc_ratov * 2;
James Smart2e0fef82007-06-17 19:56:36 -0500519 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
James Smart93996272008-08-24 21:50:30 -0400520 /* Set up heart beat (HB) timer */
James Smart858c9f62007-06-17 19:56:39 -0500521 mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
522 phba->hb_outstanding = 0;
523 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400524 /* Set up error attention (ERATT) polling timer */
525 mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
dea31012005-04-17 16:05:31 -0500526
527 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
528 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart5b8bd0c2007-04-25 09:52:49 -0400529 lpfc_set_loopback_flag(phba);
James Smartd7c255b2008-08-24 21:50:00 -0400530 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
James Smart8aee9182006-08-31 12:27:57 -0400531 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500532 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400533 "0454 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500534 "INIT_LINK, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500535 mb->mbxCommand, mb->mbxStatus);
536
537 /* Clear all interrupt enable conditions */
538 writel(0, phba->HCregaddr);
539 readl(phba->HCregaddr); /* flush */
540 /* Clear all pending interrupts */
541 writel(0xffffffff, phba->HAregaddr);
542 readl(phba->HAregaddr); /* flush */
543
James Smart2e0fef82007-06-17 19:56:36 -0500544 phba->link_state = LPFC_HBA_ERROR;
James Smart8aee9182006-08-31 12:27:57 -0400545 if (rc != MBX_BUSY)
546 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500547 return -EIO;
548 }
549 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400550 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
551 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
552 pmb->mbox_cmpl = lpfc_config_async_cmpl;
553 pmb->vport = phba->pport;
554 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500555
James Smart57127f12007-10-27 13:37:05 -0400556 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
557 lpfc_printf_log(phba,
558 KERN_ERR,
559 LOG_INIT,
560 "0456 Adapter failed to issue "
561 "ASYNCEVT_ENABLE mbox status x%x \n.",
562 rc);
563 mempool_free(pmb, phba->mbox_mem_pool);
564 }
James Smart97207482008-12-04 22:39:19 -0500565
566 /* Get Option rom version */
567 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
568 lpfc_dump_wakeup_param(phba, pmb);
569 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
570 pmb->vport = phba->pport;
571 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
572
573 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
574 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
575 "to get Option ROM version status x%x\n.", rc);
576 mempool_free(pmb, phba->mbox_mem_pool);
577 }
578
James Smartd7c255b2008-08-24 21:50:00 -0400579 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400580}
581
James Smarte59058c2008-08-24 21:49:00 -0400582/**
James Smart3621a712009-04-06 18:47:14 -0400583 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400584 * @phba: pointer to lpfc HBA data structure.
585 *
586 * This routine will do LPFC uninitialization before the HBA is reset when
587 * bringing down the SLI Layer.
588 *
589 * Return codes
590 * 0 - success.
591 * Any other value - error.
592 **/
dea31012005-04-17 16:05:31 -0500593int
James Smart2e0fef82007-06-17 19:56:36 -0500594lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500595{
James Smart1b32f6a2008-02-08 18:49:39 -0500596 struct lpfc_vport **vports;
597 int i;
James Smart3772a992009-05-22 14:50:54 -0400598
599 if (phba->sli_rev <= LPFC_SLI_REV3) {
600 /* Disable interrupts */
601 writel(0, phba->HCregaddr);
602 readl(phba->HCregaddr); /* flush */
603 }
dea31012005-04-17 16:05:31 -0500604
James Smart1b32f6a2008-02-08 18:49:39 -0500605 if (phba->pport->load_flag & FC_UNLOADING)
606 lpfc_cleanup_discovery_resources(phba->pport);
607 else {
608 vports = lpfc_create_vport_work_array(phba);
609 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -0400610 for (i = 0; i <= phba->max_vports &&
611 vports[i] != NULL; i++)
James Smart1b32f6a2008-02-08 18:49:39 -0500612 lpfc_cleanup_discovery_resources(vports[i]);
613 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500614 }
615 return 0;
dea31012005-04-17 16:05:31 -0500616}
617
James Smarte59058c2008-08-24 21:49:00 -0400618/**
James Smart3772a992009-05-22 14:50:54 -0400619 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400620 * @phba: pointer to lpfc HBA data structure.
621 *
622 * This routine will do uninitialization after the HBA is reset when bring
623 * down the SLI Layer.
624 *
625 * Return codes
626 * 0 - sucess.
627 * Any other value - error.
628 **/
James Smart3772a992009-05-22 14:50:54 -0400629static int
630lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500631{
632 struct lpfc_sli *psli = &phba->sli;
633 struct lpfc_sli_ring *pring;
634 struct lpfc_dmabuf *mp, *next_mp;
James Smart09372822008-01-11 01:52:54 -0500635 LIST_HEAD(completions);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500636 int i;
637
James Smart92d7f7b2007-06-17 19:56:38 -0500638 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
639 lpfc_sli_hbqbuf_free_all(phba);
640 else {
641 /* Cleanup preposted buffers on the ELS ring */
642 pring = &psli->ring[LPFC_ELS_RING];
643 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
644 list_del(&mp->list);
645 pring->postbufq_cnt--;
646 lpfc_mbuf_free(phba, mp->virt, mp->phys);
647 kfree(mp);
648 }
Jamie Wellnitz41415862006-02-28 19:25:27 -0500649 }
650
James Smart09372822008-01-11 01:52:54 -0500651 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500652 for (i = 0; i < psli->num_rings; i++) {
653 pring = &psli->ring[i];
James Smart09372822008-01-11 01:52:54 -0500654
655 /* At this point in time the HBA is either reset or DOA. Either
656 * way, nothing should be on txcmplq as it will NEVER complete.
657 */
658 list_splice_init(&pring->txcmplq, &completions);
659 pring->txcmplq_cnt = 0;
660 spin_unlock_irq(&phba->hbalock);
661
James Smarta257bf92009-04-06 18:48:10 -0400662 /* Cancel all the IOCBs from the completions list */
663 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
664 IOERR_SLI_ABORTED);
James Smart09372822008-01-11 01:52:54 -0500665
Jamie Wellnitz41415862006-02-28 19:25:27 -0500666 lpfc_sli_abort_iocb_ring(phba, pring);
James Smart09372822008-01-11 01:52:54 -0500667 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500668 }
James Smart09372822008-01-11 01:52:54 -0500669 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500670
671 return 0;
672}
James Smartda0436e2009-05-22 14:51:39 -0400673/**
674 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
675 * @phba: pointer to lpfc HBA data structure.
676 *
677 * This routine will do uninitialization after the HBA is reset when bring
678 * down the SLI Layer.
679 *
680 * Return codes
681 * 0 - sucess.
682 * Any other value - error.
683 **/
684static int
685lpfc_hba_down_post_s4(struct lpfc_hba *phba)
686{
687 struct lpfc_scsi_buf *psb, *psb_next;
688 LIST_HEAD(aborts);
689 int ret;
690 unsigned long iflag = 0;
691 ret = lpfc_hba_down_post_s3(phba);
692 if (ret)
693 return ret;
694 /* At this point in time the HBA is either reset or DOA. Either
695 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
696 * on the lpfc_sgl_list so that it can either be freed if the
697 * driver is unloading or reposted if the driver is restarting
698 * the port.
699 */
700 spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */
701 /* scsl_buf_list */
702 /* abts_sgl_list_lock required because worker thread uses this
703 * list.
704 */
705 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
706 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
707 &phba->sli4_hba.lpfc_sgl_list);
708 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
709 /* abts_scsi_buf_list_lock required because worker thread uses this
710 * list.
711 */
712 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
713 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
714 &aborts);
715 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
716 spin_unlock_irq(&phba->hbalock);
717
718 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
719 psb->pCmd = NULL;
720 psb->status = IOSTAT_SUCCESS;
721 }
722 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
723 list_splice(&aborts, &phba->lpfc_scsi_buf_list);
724 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
725 return 0;
726}
727
728/**
729 * lpfc_hba_down_post - Wrapper func for hba down post routine
730 * @phba: pointer to lpfc HBA data structure.
731 *
732 * This routine wraps the actual SLI3 or SLI4 routine for performing
733 * uninitialization after the HBA is reset when bring down the SLI Layer.
734 *
735 * Return codes
736 * 0 - sucess.
737 * Any other value - error.
738 **/
739int
740lpfc_hba_down_post(struct lpfc_hba *phba)
741{
742 return (*phba->lpfc_hba_down_post)(phba);
743}
Jamie Wellnitz41415862006-02-28 19:25:27 -0500744
James Smarte59058c2008-08-24 21:49:00 -0400745/**
James Smart3621a712009-04-06 18:47:14 -0400746 * lpfc_hb_timeout - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -0400747 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
748 *
749 * This is the HBA-timer timeout handler registered to the lpfc driver. When
750 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
751 * work-port-events bitmap and the worker thread is notified. This timeout
752 * event will be used by the worker thread to invoke the actual timeout
753 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
754 * be performed in the timeout handler and the HBA timeout event bit shall
755 * be cleared by the worker thread after it has taken the event bitmap out.
756 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +0100757static void
James Smart858c9f62007-06-17 19:56:39 -0500758lpfc_hb_timeout(unsigned long ptr)
759{
760 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -0400761 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -0500762 unsigned long iflag;
763
764 phba = (struct lpfc_hba *)ptr;
James Smart93996272008-08-24 21:50:30 -0400765
766 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -0500767 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -0400768 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
769 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -0500770 phba->pport->work_port_events |= WORKER_HB_TMO;
771 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
772
James Smart93996272008-08-24 21:50:30 -0400773 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -0400774 if (!tmo_posted)
775 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -0500776 return;
777}
778
James Smarte59058c2008-08-24 21:49:00 -0400779/**
James Smart3621a712009-04-06 18:47:14 -0400780 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -0400781 * @phba: pointer to lpfc hba data structure.
782 * @pmboxq: pointer to the driver internal queue element for mailbox command.
783 *
784 * This is the callback function to the lpfc heart-beat mailbox command.
785 * If configured, the lpfc driver issues the heart-beat mailbox command to
786 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
787 * heart-beat mailbox command is issued, the driver shall set up heart-beat
788 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
789 * heart-beat outstanding state. Once the mailbox command comes back and
790 * no error conditions detected, the heart-beat mailbox command timer is
791 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
792 * state is cleared for the next heart-beat. If the timer expired with the
793 * heart-beat outstanding state set, the driver will put the HBA offline.
794 **/
James Smart858c9f62007-06-17 19:56:39 -0500795static void
796lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
797{
798 unsigned long drvr_flag;
799
800 spin_lock_irqsave(&phba->hbalock, drvr_flag);
801 phba->hb_outstanding = 0;
802 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
803
James Smart93996272008-08-24 21:50:30 -0400804 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -0500805 mempool_free(pmboxq, phba->mbox_mem_pool);
806 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
807 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -0400808 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -0500809 mod_timer(&phba->hb_tmofunc,
810 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
811 return;
812}
813
James Smarte59058c2008-08-24 21:49:00 -0400814/**
James Smart3621a712009-04-06 18:47:14 -0400815 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -0400816 * @phba: pointer to lpfc hba data structure.
817 *
818 * This is the actual HBA-timer timeout handler to be invoked by the worker
819 * thread whenever the HBA timer fired and HBA-timeout event posted. This
820 * handler performs any periodic operations needed for the device. If such
821 * periodic event has already been attended to either in the interrupt handler
822 * or by processing slow-ring or fast-ring events within the HBA-timer
823 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
824 * the timer for the next timeout period. If lpfc heart-beat mailbox command
825 * is configured and there is no heart-beat mailbox command outstanding, a
826 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
827 * has been a heart-beat mailbox command outstanding, the HBA shall be put
828 * to offline.
829 **/
James Smart858c9f62007-06-17 19:56:39 -0500830void
831lpfc_hb_timeout_handler(struct lpfc_hba *phba)
832{
833 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -0500834 struct lpfc_dmabuf *buf_ptr;
James Smart858c9f62007-06-17 19:56:39 -0500835 int retval;
836 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -0500837 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -0500838
839 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -0400840 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -0500841 (phba->pport->fc_flag & FC_OFFLINE_MODE))
842 return;
843
844 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -0500845
846 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
847 jiffies)) {
848 spin_unlock_irq(&phba->pport->work_port_lock);
849 if (!phba->hb_outstanding)
850 mod_timer(&phba->hb_tmofunc,
851 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
852 else
853 mod_timer(&phba->hb_tmofunc,
854 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
855 return;
856 }
857 spin_unlock_irq(&phba->pport->work_port_lock);
858
James Smart0ff10d42008-01-11 01:52:36 -0500859 if (phba->elsbuf_cnt &&
860 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
861 spin_lock_irq(&phba->hbalock);
862 list_splice_init(&phba->elsbuf, &completions);
863 phba->elsbuf_cnt = 0;
864 phba->elsbuf_prev_cnt = 0;
865 spin_unlock_irq(&phba->hbalock);
866
867 while (!list_empty(&completions)) {
868 list_remove_head(&completions, buf_ptr,
869 struct lpfc_dmabuf, list);
870 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
871 kfree(buf_ptr);
872 }
873 }
874 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
875
James Smart858c9f62007-06-17 19:56:39 -0500876 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -0500877 if (phba->cfg_enable_hba_heartbeat) {
878 if (!phba->hb_outstanding) {
879 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
880 if (!pmboxq) {
881 mod_timer(&phba->hb_tmofunc,
882 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
883 return;
884 }
885
886 lpfc_heart_beat(phba, pmboxq);
887 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
888 pmboxq->vport = phba->pport;
889 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
890
891 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
892 mempool_free(pmboxq, phba->mbox_mem_pool);
893 mod_timer(&phba->hb_tmofunc,
894 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
895 return;
896 }
James Smart858c9f62007-06-17 19:56:39 -0500897 mod_timer(&phba->hb_tmofunc,
James Smart13815c82008-01-11 01:52:48 -0500898 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
899 phba->hb_outstanding = 1;
James Smart858c9f62007-06-17 19:56:39 -0500900 return;
James Smart13815c82008-01-11 01:52:48 -0500901 } else {
902 /*
903 * If heart beat timeout called with hb_outstanding set
904 * we need to take the HBA offline.
905 */
906 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
907 "0459 Adapter heartbeat failure, "
908 "taking this port offline.\n");
909
910 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -0400911 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart13815c82008-01-11 01:52:48 -0500912 spin_unlock_irq(&phba->hbalock);
913
914 lpfc_offline_prep(phba);
915 lpfc_offline(phba);
916 lpfc_unblock_mgmt_io(phba);
917 phba->link_state = LPFC_HBA_ERROR;
918 lpfc_hba_down_post(phba);
James Smart858c9f62007-06-17 19:56:39 -0500919 }
James Smart858c9f62007-06-17 19:56:39 -0500920 }
921}
922
James Smarte59058c2008-08-24 21:49:00 -0400923/**
James Smart3621a712009-04-06 18:47:14 -0400924 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -0400925 * @phba: pointer to lpfc hba data structure.
926 *
927 * This routine is called to bring the HBA offline when HBA hardware error
928 * other than Port Error 6 has been detected.
929 **/
James Smart09372822008-01-11 01:52:54 -0500930static void
931lpfc_offline_eratt(struct lpfc_hba *phba)
932{
933 struct lpfc_sli *psli = &phba->sli;
934
935 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -0400936 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -0500937 spin_unlock_irq(&phba->hbalock);
938 lpfc_offline_prep(phba);
939
940 lpfc_offline(phba);
941 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -0400942 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -0500943 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -0400944 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -0500945 lpfc_hba_down_post(phba);
946 lpfc_sli_brdready(phba, HS_MBRDY);
947 lpfc_unblock_mgmt_io(phba);
948 phba->link_state = LPFC_HBA_ERROR;
949 return;
950}
951
James Smarte59058c2008-08-24 21:49:00 -0400952/**
James Smartda0436e2009-05-22 14:51:39 -0400953 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
954 * @phba: pointer to lpfc hba data structure.
955 *
956 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
957 * other than Port Error 6 has been detected.
958 **/
959static void
960lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
961{
962 lpfc_offline_prep(phba);
963 lpfc_offline(phba);
964 lpfc_sli4_brdreset(phba);
965 lpfc_hba_down_post(phba);
966 lpfc_sli4_post_status_check(phba);
967 lpfc_unblock_mgmt_io(phba);
968 phba->link_state = LPFC_HBA_ERROR;
969}
970
971/**
James Smarta257bf92009-04-06 18:48:10 -0400972 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
973 * @phba: pointer to lpfc hba data structure.
974 *
975 * This routine is invoked to handle the deferred HBA hardware error
976 * conditions. This type of error is indicated by HBA by setting ER1
977 * and another ER bit in the host status register. The driver will
978 * wait until the ER1 bit clears before handling the error condition.
979 **/
980static void
981lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
982{
983 uint32_t old_host_status = phba->work_hs;
984 struct lpfc_sli_ring *pring;
985 struct lpfc_sli *psli = &phba->sli;
986
James Smartf4b4c682009-05-22 14:53:12 -0400987 /* If the pci channel is offline, ignore possible errors,
988 * since we cannot communicate with the pci card anyway.
989 */
990 if (pci_channel_offline(phba->pcidev)) {
991 spin_lock_irq(&phba->hbalock);
992 phba->hba_flag &= ~DEFER_ERATT;
993 spin_unlock_irq(&phba->hbalock);
994 return;
995 }
996
James Smarta257bf92009-04-06 18:48:10 -0400997 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
998 "0479 Deferred Adapter Hardware Error "
999 "Data: x%x x%x x%x\n",
1000 phba->work_hs,
1001 phba->work_status[0], phba->work_status[1]);
1002
1003 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001004 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001005 spin_unlock_irq(&phba->hbalock);
1006
1007
1008 /*
1009 * Firmware stops when it triggred erratt. That could cause the I/Os
1010 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1011 * SCSI layer retry it after re-establishing link.
1012 */
1013 pring = &psli->ring[psli->fcp_ring];
1014 lpfc_sli_abort_iocb_ring(phba, pring);
1015
1016 /*
1017 * There was a firmware error. Take the hba offline and then
1018 * attempt to restart it.
1019 */
1020 lpfc_offline_prep(phba);
1021 lpfc_offline(phba);
1022
1023 /* Wait for the ER1 bit to clear.*/
1024 while (phba->work_hs & HS_FFER1) {
1025 msleep(100);
1026 phba->work_hs = readl(phba->HSregaddr);
1027 /* If driver is unloading let the worker thread continue */
1028 if (phba->pport->load_flag & FC_UNLOADING) {
1029 phba->work_hs = 0;
1030 break;
1031 }
1032 }
1033
1034 /*
1035 * This is to ptrotect against a race condition in which
1036 * first write to the host attention register clear the
1037 * host status register.
1038 */
1039 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1040 phba->work_hs = old_host_status & ~HS_FFER1;
1041
James Smart3772a992009-05-22 14:50:54 -04001042 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001043 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001044 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001045 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1046 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1047}
1048
James Smart3772a992009-05-22 14:50:54 -04001049static void
1050lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1051{
1052 struct lpfc_board_event_header board_event;
1053 struct Scsi_Host *shost;
1054
1055 board_event.event_type = FC_REG_BOARD_EVENT;
1056 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1057 shost = lpfc_shost_from_vport(phba->pport);
1058 fc_host_post_vendor_event(shost, fc_get_event_number(),
1059 sizeof(board_event),
1060 (char *) &board_event,
1061 LPFC_NL_VENDOR_ID);
1062}
1063
James Smarta257bf92009-04-06 18:48:10 -04001064/**
James Smart3772a992009-05-22 14:50:54 -04001065 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001066 * @phba: pointer to lpfc hba data structure.
1067 *
1068 * This routine is invoked to handle the following HBA hardware error
1069 * conditions:
1070 * 1 - HBA error attention interrupt
1071 * 2 - DMA ring index out of range
1072 * 3 - Mailbox command came back as unknown
1073 **/
James Smart3772a992009-05-22 14:50:54 -04001074static void
1075lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001076{
James Smart2e0fef82007-06-17 19:56:36 -05001077 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001078 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001079 struct lpfc_sli_ring *pring;
James Smartd2873e42006-08-18 17:46:43 -04001080 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001081 unsigned long temperature;
1082 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001083 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001084
Linas Vepstas8d63f372007-02-14 14:28:36 -06001085 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001086 * since we cannot communicate with the pci card anyway.
1087 */
1088 if (pci_channel_offline(phba->pcidev)) {
1089 spin_lock_irq(&phba->hbalock);
1090 phba->hba_flag &= ~DEFER_ERATT;
1091 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001092 return;
James Smart3772a992009-05-22 14:50:54 -04001093 }
1094
James Smart13815c82008-01-11 01:52:48 -05001095 /* If resets are disabled then leave the HBA alone and return */
1096 if (!phba->cfg_enable_hba_reset)
1097 return;
dea31012005-04-17 16:05:31 -05001098
James Smartea2151b2008-09-07 11:52:10 -04001099 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001100 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001101
James Smarta257bf92009-04-06 18:48:10 -04001102 if (phba->hba_flag & DEFER_ERATT)
1103 lpfc_handle_deferred_eratt(phba);
1104
James Smart97eab632008-04-07 10:16:05 -04001105 if (phba->work_hs & HS_FFER6) {
dea31012005-04-17 16:05:31 -05001106 /* Re-establishing Link */
1107 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001108 "1301 Re-establishing Link "
dea31012005-04-17 16:05:31 -05001109 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001110 phba->work_hs,
dea31012005-04-17 16:05:31 -05001111 phba->work_status[0], phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001112
James Smart92d7f7b2007-06-17 19:56:38 -05001113 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001114 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001115 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001116
1117 /*
1118 * Firmware stops when it triggled erratt with HS_FFER6.
1119 * That could cause the I/Os dropped by the firmware.
1120 * Error iocb (I/O) on txcmplq and let the SCSI layer
1121 * retry it after re-establishing link.
1122 */
1123 pring = &psli->ring[psli->fcp_ring];
1124 lpfc_sli_abort_iocb_ring(phba, pring);
1125
dea31012005-04-17 16:05:31 -05001126 /*
1127 * There was a firmware error. Take the hba offline and then
1128 * attempt to restart it.
1129 */
James Smart46fa3112007-04-25 09:51:45 -04001130 lpfc_offline_prep(phba);
dea31012005-04-17 16:05:31 -05001131 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001132 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001133 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001134 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001135 return;
1136 }
James Smart46fa3112007-04-25 09:51:45 -04001137 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001138 } else if (phba->work_hs & HS_CRIT_TEMP) {
1139 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1140 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1141 temp_event_data.event_code = LPFC_CRIT_TEMP;
1142 temp_event_data.data = (uint32_t)temperature;
1143
1144 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001145 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001146 "(%ld), taking this port offline "
1147 "Data: x%x x%x x%x\n",
1148 temperature, phba->work_hs,
1149 phba->work_status[0], phba->work_status[1]);
1150
1151 shost = lpfc_shost_from_vport(phba->pport);
1152 fc_host_post_vendor_event(shost, fc_get_event_number(),
1153 sizeof(temp_event_data),
1154 (char *) &temp_event_data,
1155 SCSI_NL_VID_TYPE_PCI
1156 | PCI_VENDOR_ID_EMULEX);
1157
James Smart7af67052007-10-27 13:38:11 -04001158 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001159 phba->over_temp_state = HBA_OVER_TEMP;
1160 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001161 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001162
dea31012005-04-17 16:05:31 -05001163 } else {
1164 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001165 * failure is a value other than FFER6. Do not call the offline
1166 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001167 */
1168 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001169 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001170 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001171 phba->work_hs,
dea31012005-04-17 16:05:31 -05001172 phba->work_status[0], phba->work_status[1]);
1173
James Smartd2873e42006-08-18 17:46:43 -04001174 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001175 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001176 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001177 sizeof(event_data), (char *) &event_data,
1178 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1179
James Smart09372822008-01-11 01:52:54 -05001180 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001181 }
James Smart93996272008-08-24 21:50:30 -04001182 return;
dea31012005-04-17 16:05:31 -05001183}
1184
James Smarte59058c2008-08-24 21:49:00 -04001185/**
James Smartda0436e2009-05-22 14:51:39 -04001186 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1187 * @phba: pointer to lpfc hba data structure.
1188 *
1189 * This routine is invoked to handle the SLI4 HBA hardware error attention
1190 * conditions.
1191 **/
1192static void
1193lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1194{
1195 struct lpfc_vport *vport = phba->pport;
1196 uint32_t event_data;
1197 struct Scsi_Host *shost;
1198
1199 /* If the pci channel is offline, ignore possible errors, since
1200 * we cannot communicate with the pci card anyway.
1201 */
1202 if (pci_channel_offline(phba->pcidev))
1203 return;
1204 /* If resets are disabled then leave the HBA alone and return */
1205 if (!phba->cfg_enable_hba_reset)
1206 return;
1207
1208 /* Send an internal error event to mgmt application */
1209 lpfc_board_errevt_to_mgmt(phba);
1210
1211 /* For now, the actual action for SLI4 device handling is not
1212 * specified yet, just treated it as adaptor hardware failure
1213 */
1214 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1215 "0143 SLI4 Adapter Hardware Error Data: x%x x%x\n",
1216 phba->work_status[0], phba->work_status[1]);
1217
1218 event_data = FC_REG_DUMP_EVENT;
1219 shost = lpfc_shost_from_vport(vport);
1220 fc_host_post_vendor_event(shost, fc_get_event_number(),
1221 sizeof(event_data), (char *) &event_data,
1222 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1223
1224 lpfc_sli4_offline_eratt(phba);
1225}
1226
1227/**
1228 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1229 * @phba: pointer to lpfc HBA data structure.
1230 *
1231 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1232 * routine from the API jump table function pointer from the lpfc_hba struct.
1233 *
1234 * Return codes
1235 * 0 - sucess.
1236 * Any other value - error.
1237 **/
1238void
1239lpfc_handle_eratt(struct lpfc_hba *phba)
1240{
1241 (*phba->lpfc_handle_eratt)(phba);
1242}
1243
1244/**
James Smart3621a712009-04-06 18:47:14 -04001245 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04001246 * @phba: pointer to lpfc hba data structure.
1247 *
1248 * This routine is invoked from the worker thread to handle a HBA host
1249 * attention link event.
1250 **/
dea31012005-04-17 16:05:31 -05001251void
James Smart2e0fef82007-06-17 19:56:36 -05001252lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001253{
James Smart2e0fef82007-06-17 19:56:36 -05001254 struct lpfc_vport *vport = phba->pport;
1255 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001256 LPFC_MBOXQ_t *pmb;
1257 volatile uint32_t control;
1258 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05001259 int rc = 0;
dea31012005-04-17 16:05:31 -05001260
1261 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001262 if (!pmb) {
1263 rc = 1;
dea31012005-04-17 16:05:31 -05001264 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05001265 }
dea31012005-04-17 16:05:31 -05001266
1267 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001268 if (!mp) {
1269 rc = 2;
dea31012005-04-17 16:05:31 -05001270 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05001271 }
dea31012005-04-17 16:05:31 -05001272
1273 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05001274 if (!mp->virt) {
1275 rc = 3;
dea31012005-04-17 16:05:31 -05001276 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05001277 }
dea31012005-04-17 16:05:31 -05001278
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001279 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04001280 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05001281
1282 psli->slistat.link_event++;
1283 lpfc_read_la(phba, pmb, mp);
1284 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
James Smart2e0fef82007-06-17 19:56:36 -05001285 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04001286 /* Block ELS IOCBs until we have processed this mbox command */
1287 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04001288 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05001289 if (rc == MBX_NOT_FINISHED) {
1290 rc = 4;
James Smart14691152006-12-02 13:34:28 -05001291 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05001292 }
dea31012005-04-17 16:05:31 -05001293
1294 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05001295 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001296 writel(HA_LATT, phba->HAregaddr);
1297 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001298 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001299
1300 return;
1301
James Smart14691152006-12-02 13:34:28 -05001302lpfc_handle_latt_free_mbuf:
James Smart0d2b6b82008-06-14 22:52:47 -04001303 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05001304 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05001305lpfc_handle_latt_free_mp:
1306 kfree(mp);
1307lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04001308 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001309lpfc_handle_latt_err_exit:
1310 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001311 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001312 psli->sli_flag |= LPFC_PROCESS_LA;
1313 control = readl(phba->HCregaddr);
1314 control |= HC_LAINT_ENA;
1315 writel(control, phba->HCregaddr);
1316 readl(phba->HCregaddr); /* flush */
1317
1318 /* Clear Link Attention in HA REG */
1319 writel(HA_LATT, phba->HAregaddr);
1320 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001321 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001322 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001323 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001324
James Smart09372822008-01-11 01:52:54 -05001325 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1326 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05001327
1328 return;
1329}
1330
James Smarte59058c2008-08-24 21:49:00 -04001331/**
James Smart3621a712009-04-06 18:47:14 -04001332 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04001333 * @phba: pointer to lpfc hba data structure.
1334 * @vpd: pointer to the vital product data.
1335 * @len: length of the vital product data in bytes.
1336 *
1337 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1338 * an array of characters. In this routine, the ModelName, ProgramType, and
1339 * ModelDesc, etc. fields of the phba data structure will be populated.
1340 *
1341 * Return codes
1342 * 0 - pointer to the VPD passed in is NULL
1343 * 1 - success
1344 **/
James Smart3772a992009-05-22 14:50:54 -04001345int
James Smart2e0fef82007-06-17 19:56:36 -05001346lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05001347{
1348 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05001349 int Length;
dea31012005-04-17 16:05:31 -05001350 int i, j;
1351 int finished = 0;
1352 int index = 0;
1353
1354 if (!vpd)
1355 return 0;
1356
1357 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05001358 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001359 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001360 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
1361 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001362 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05001363 switch (vpd[index]) {
1364 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001365 case 0x91:
dea31012005-04-17 16:05:31 -05001366 index += 1;
1367 lenlo = vpd[index];
1368 index += 1;
1369 lenhi = vpd[index];
1370 index += 1;
1371 i = ((((unsigned short)lenhi) << 8) + lenlo);
1372 index += i;
1373 break;
1374 case 0x90:
1375 index += 1;
1376 lenlo = vpd[index];
1377 index += 1;
1378 lenhi = vpd[index];
1379 index += 1;
1380 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001381 if (Length > len - index)
1382 Length = len - index;
dea31012005-04-17 16:05:31 -05001383 while (Length > 0) {
1384 /* Look for Serial Number */
1385 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
1386 index += 2;
1387 i = vpd[index];
1388 index += 1;
1389 j = 0;
1390 Length -= (3+i);
1391 while(i--) {
1392 phba->SerialNumber[j++] = vpd[index++];
1393 if (j == 31)
1394 break;
1395 }
1396 phba->SerialNumber[j] = 0;
1397 continue;
1398 }
1399 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
1400 phba->vpd_flag |= VPD_MODEL_DESC;
1401 index += 2;
1402 i = vpd[index];
1403 index += 1;
1404 j = 0;
1405 Length -= (3+i);
1406 while(i--) {
1407 phba->ModelDesc[j++] = vpd[index++];
1408 if (j == 255)
1409 break;
1410 }
1411 phba->ModelDesc[j] = 0;
1412 continue;
1413 }
1414 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
1415 phba->vpd_flag |= VPD_MODEL_NAME;
1416 index += 2;
1417 i = vpd[index];
1418 index += 1;
1419 j = 0;
1420 Length -= (3+i);
1421 while(i--) {
1422 phba->ModelName[j++] = vpd[index++];
1423 if (j == 79)
1424 break;
1425 }
1426 phba->ModelName[j] = 0;
1427 continue;
1428 }
1429 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
1430 phba->vpd_flag |= VPD_PROGRAM_TYPE;
1431 index += 2;
1432 i = vpd[index];
1433 index += 1;
1434 j = 0;
1435 Length -= (3+i);
1436 while(i--) {
1437 phba->ProgramType[j++] = vpd[index++];
1438 if (j == 255)
1439 break;
1440 }
1441 phba->ProgramType[j] = 0;
1442 continue;
1443 }
1444 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1445 phba->vpd_flag |= VPD_PORT;
1446 index += 2;
1447 i = vpd[index];
1448 index += 1;
1449 j = 0;
1450 Length -= (3+i);
1451 while(i--) {
1452 phba->Port[j++] = vpd[index++];
1453 if (j == 19)
1454 break;
1455 }
1456 phba->Port[j] = 0;
1457 continue;
1458 }
1459 else {
1460 index += 2;
1461 i = vpd[index];
1462 index += 1;
1463 index += i;
1464 Length -= (3 + i);
1465 }
1466 }
1467 finished = 0;
1468 break;
1469 case 0x78:
1470 finished = 1;
1471 break;
1472 default:
1473 index ++;
1474 break;
1475 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001476 }
dea31012005-04-17 16:05:31 -05001477
1478 return(1);
1479}
1480
James Smarte59058c2008-08-24 21:49:00 -04001481/**
James Smart3621a712009-04-06 18:47:14 -04001482 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04001483 * @phba: pointer to lpfc hba data structure.
1484 * @mdp: pointer to the data structure to hold the derived model name.
1485 * @descp: pointer to the data structure to hold the derived description.
1486 *
1487 * This routine retrieves HBA's description based on its registered PCI device
1488 * ID. The @descp passed into this function points to an array of 256 chars. It
1489 * shall be returned with the model name, maximum speed, and the host bus type.
1490 * The @mdp passed into this function points to an array of 80 chars. When the
1491 * function returns, the @mdp will be filled with the model name.
1492 **/
dea31012005-04-17 16:05:31 -05001493static void
James Smart2e0fef82007-06-17 19:56:36 -05001494lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05001495{
1496 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05001497 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001498 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04001499 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04001500 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001501 struct {
1502 char * name;
1503 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001504 char * bus;
James Smart18a3b592006-12-02 13:35:08 -05001505 } m = {"<Unknown>", 0, ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001506
1507 if (mdp && mdp[0] != '\0'
1508 && descp && descp[0] != '\0')
1509 return;
1510
1511 if (phba->lmt & LMT_10Gb)
1512 max_speed = 10;
1513 else if (phba->lmt & LMT_8Gb)
1514 max_speed = 8;
1515 else if (phba->lmt & LMT_4Gb)
1516 max_speed = 4;
1517 else if (phba->lmt & LMT_2Gb)
1518 max_speed = 2;
1519 else
1520 max_speed = 1;
dea31012005-04-17 16:05:31 -05001521
1522 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05001523
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001524 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001525 case PCI_DEVICE_ID_FIREFLY:
James Smart18a3b592006-12-02 13:35:08 -05001526 m = (typeof(m)){"LP6000", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001527 break;
dea31012005-04-17 16:05:31 -05001528 case PCI_DEVICE_ID_SUPERFLY:
1529 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart18a3b592006-12-02 13:35:08 -05001530 m = (typeof(m)){"LP7000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001531 else
James Smart18a3b592006-12-02 13:35:08 -05001532 m = (typeof(m)){"LP7000E", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001533 break;
1534 case PCI_DEVICE_ID_DRAGONFLY:
James Smart18a3b592006-12-02 13:35:08 -05001535 m = (typeof(m)){"LP8000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001536 break;
1537 case PCI_DEVICE_ID_CENTAUR:
1538 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart18a3b592006-12-02 13:35:08 -05001539 m = (typeof(m)){"LP9002", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001540 else
James Smart18a3b592006-12-02 13:35:08 -05001541 m = (typeof(m)){"LP9000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001542 break;
1543 case PCI_DEVICE_ID_RFLY:
James Smart18a3b592006-12-02 13:35:08 -05001544 m = (typeof(m)){"LP952", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001545 break;
1546 case PCI_DEVICE_ID_PEGASUS:
James Smart18a3b592006-12-02 13:35:08 -05001547 m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001548 break;
1549 case PCI_DEVICE_ID_THOR:
James Smart18a3b592006-12-02 13:35:08 -05001550 m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001551 break;
1552 case PCI_DEVICE_ID_VIPER:
James Smart18a3b592006-12-02 13:35:08 -05001553 m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001554 break;
1555 case PCI_DEVICE_ID_PFLY:
James Smart18a3b592006-12-02 13:35:08 -05001556 m = (typeof(m)){"LP982", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001557 break;
1558 case PCI_DEVICE_ID_TFLY:
James Smart18a3b592006-12-02 13:35:08 -05001559 m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001560 break;
1561 case PCI_DEVICE_ID_HELIOS:
James Smart18a3b592006-12-02 13:35:08 -05001562 m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001563 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001564 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001565 m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001566 break;
1567 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001568 m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001569 break;
1570 case PCI_DEVICE_ID_NEPTUNE:
James Smart18a3b592006-12-02 13:35:08 -05001571 m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001572 break;
1573 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001574 m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001575 break;
1576 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001577 m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001578 break;
dea31012005-04-17 16:05:31 -05001579 case PCI_DEVICE_ID_BMID:
James Smart18a3b592006-12-02 13:35:08 -05001580 m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001581 break;
1582 case PCI_DEVICE_ID_BSMB:
James Smart18a3b592006-12-02 13:35:08 -05001583 m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001584 break;
1585 case PCI_DEVICE_ID_ZEPHYR:
James Smart18a3b592006-12-02 13:35:08 -05001586 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001587 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001588 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001589 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001590 break;
1591 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta257bf92009-04-06 18:48:10 -04001592 m = (typeof(m)){"LP2105", max_speed, "PCIe"};
1593 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001594 break;
dea31012005-04-17 16:05:31 -05001595 case PCI_DEVICE_ID_ZMID:
James Smart18a3b592006-12-02 13:35:08 -05001596 m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001597 break;
1598 case PCI_DEVICE_ID_ZSMB:
James Smart18a3b592006-12-02 13:35:08 -05001599 m = (typeof(m)){"LPe111", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001600 break;
1601 case PCI_DEVICE_ID_LP101:
James Smart18a3b592006-12-02 13:35:08 -05001602 m = (typeof(m)){"LP101", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001603 break;
1604 case PCI_DEVICE_ID_LP10000S:
James Smart18a3b592006-12-02 13:35:08 -05001605 m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001606 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001607 case PCI_DEVICE_ID_LP11000S:
James Smart18a3b592006-12-02 13:35:08 -05001608 m = (typeof(m)){"LP11000-S", max_speed,
1609 "PCI-X2"};
1610 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001611 case PCI_DEVICE_ID_LPE11000S:
James Smart18a3b592006-12-02 13:35:08 -05001612 m = (typeof(m)){"LPe11000-S", max_speed,
1613 "PCIe"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001614 break;
James Smartb87eab32007-04-25 09:53:28 -04001615 case PCI_DEVICE_ID_SAT:
1616 m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
1617 break;
1618 case PCI_DEVICE_ID_SAT_MID:
1619 m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
1620 break;
1621 case PCI_DEVICE_ID_SAT_SMB:
1622 m = (typeof(m)){"LPe121", max_speed, "PCIe"};
1623 break;
1624 case PCI_DEVICE_ID_SAT_DCSP:
1625 m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
1626 break;
1627 case PCI_DEVICE_ID_SAT_SCSP:
1628 m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
1629 break;
1630 case PCI_DEVICE_ID_SAT_S:
1631 m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
1632 break;
James Smart84774a42008-08-24 21:50:06 -04001633 case PCI_DEVICE_ID_HORNET:
1634 m = (typeof(m)){"LP21000", max_speed, "PCIe"};
1635 GE = 1;
1636 break;
1637 case PCI_DEVICE_ID_PROTEUS_VF:
1638 m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"};
1639 break;
1640 case PCI_DEVICE_ID_PROTEUS_PF:
1641 m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"};
1642 break;
1643 case PCI_DEVICE_ID_PROTEUS_S:
1644 m = (typeof(m)) {"LPemv12002-S", max_speed, "PCIe IOV"};
1645 break;
James Smartda0436e2009-05-22 14:51:39 -04001646 case PCI_DEVICE_ID_TIGERSHARK:
1647 oneConnect = 1;
1648 m = (typeof(m)) {"OCe10100-F", max_speed, "PCIe"};
1649 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001650 default:
Randy Dunlap041976f2006-06-25 01:58:51 -07001651 m = (typeof(m)){ NULL };
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001652 break;
dea31012005-04-17 16:05:31 -05001653 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001654
1655 if (mdp && mdp[0] == '\0')
1656 snprintf(mdp, 79,"%s", m.name);
James Smartda0436e2009-05-22 14:51:39 -04001657 /* oneConnect hba requires special processing, they are all initiators
1658 * and we put the port number on the end
1659 */
1660 if (descp && descp[0] == '\0') {
1661 if (oneConnect)
1662 snprintf(descp, 255,
1663 "Emulex OneConnect %s, FCoE Initiator, Port %s",
1664 m.name,
1665 phba->Port);
1666 else
1667 snprintf(descp, 255,
1668 "Emulex %s %d%s %s %s",
1669 m.name, m.max_speed,
1670 (GE) ? "GE" : "Gb",
1671 m.bus,
1672 (GE) ? "FCoE Adapter" :
1673 "Fibre Channel Adapter");
1674 }
dea31012005-04-17 16:05:31 -05001675}
1676
James Smarte59058c2008-08-24 21:49:00 -04001677/**
James Smart3621a712009-04-06 18:47:14 -04001678 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04001679 * @phba: pointer to lpfc hba data structure.
1680 * @pring: pointer to a IOCB ring.
1681 * @cnt: the number of IOCBs to be posted to the IOCB ring.
1682 *
1683 * This routine posts a given number of IOCBs with the associated DMA buffer
1684 * descriptors specified by the cnt argument to the given IOCB ring.
1685 *
1686 * Return codes
1687 * The number of IOCBs NOT able to be posted to the IOCB ring.
1688 **/
dea31012005-04-17 16:05:31 -05001689int
James Smart495a7142008-06-14 22:52:59 -04001690lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05001691{
1692 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001693 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05001694 struct lpfc_dmabuf *mp1, *mp2;
1695
1696 cnt += pring->missbufcnt;
1697
1698 /* While there are buffers to post */
1699 while (cnt > 0) {
1700 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001701 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05001702 if (iocb == NULL) {
1703 pring->missbufcnt = cnt;
1704 return cnt;
1705 }
dea31012005-04-17 16:05:31 -05001706 icmd = &iocb->iocb;
1707
1708 /* 2 buffers can be posted per command */
1709 /* Allocate buffer to post */
1710 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1711 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04001712 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
1713 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001714 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001715 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001716 pring->missbufcnt = cnt;
1717 return cnt;
1718 }
1719
1720 INIT_LIST_HEAD(&mp1->list);
1721 /* Allocate buffer to post */
1722 if (cnt > 1) {
1723 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1724 if (mp2)
1725 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1726 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04001727 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001728 kfree(mp2);
dea31012005-04-17 16:05:31 -05001729 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1730 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001731 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001732 pring->missbufcnt = cnt;
1733 return cnt;
1734 }
1735
1736 INIT_LIST_HEAD(&mp2->list);
1737 } else {
1738 mp2 = NULL;
1739 }
1740
1741 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
1742 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
1743 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
1744 icmd->ulpBdeCount = 1;
1745 cnt--;
1746 if (mp2) {
1747 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
1748 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
1749 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
1750 cnt--;
1751 icmd->ulpBdeCount = 2;
1752 }
1753
1754 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1755 icmd->ulpLe = 1;
1756
James Smart3772a992009-05-22 14:50:54 -04001757 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
1758 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001759 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1760 kfree(mp1);
1761 cnt++;
1762 if (mp2) {
1763 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
1764 kfree(mp2);
1765 cnt++;
1766 }
James Bottomley604a3e32005-10-29 10:28:33 -05001767 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001768 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05001769 return cnt;
1770 }
dea31012005-04-17 16:05:31 -05001771 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05001772 if (mp2)
dea31012005-04-17 16:05:31 -05001773 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05001774 }
1775 pring->missbufcnt = 0;
1776 return 0;
1777}
1778
James Smarte59058c2008-08-24 21:49:00 -04001779/**
James Smart3621a712009-04-06 18:47:14 -04001780 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04001781 * @phba: pointer to lpfc hba data structure.
1782 *
1783 * This routine posts initial receive IOCB buffers to the ELS ring. The
1784 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
1785 * set to 64 IOCBs.
1786 *
1787 * Return codes
1788 * 0 - success (currently always success)
1789 **/
dea31012005-04-17 16:05:31 -05001790static int
James Smart2e0fef82007-06-17 19:56:36 -05001791lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001792{
1793 struct lpfc_sli *psli = &phba->sli;
1794
1795 /* Ring 0, ELS / CT buffers */
James Smart495a7142008-06-14 22:52:59 -04001796 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05001797 /* Ring 2 - FCP no buffers needed */
1798
1799 return 0;
1800}
1801
1802#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1803
James Smarte59058c2008-08-24 21:49:00 -04001804/**
James Smart3621a712009-04-06 18:47:14 -04001805 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04001806 * @HashResultPointer: pointer to an array as hash table.
1807 *
1808 * This routine sets up the initial values to the array of hash table entries
1809 * for the LC HBAs.
1810 **/
dea31012005-04-17 16:05:31 -05001811static void
1812lpfc_sha_init(uint32_t * HashResultPointer)
1813{
1814 HashResultPointer[0] = 0x67452301;
1815 HashResultPointer[1] = 0xEFCDAB89;
1816 HashResultPointer[2] = 0x98BADCFE;
1817 HashResultPointer[3] = 0x10325476;
1818 HashResultPointer[4] = 0xC3D2E1F0;
1819}
1820
James Smarte59058c2008-08-24 21:49:00 -04001821/**
James Smart3621a712009-04-06 18:47:14 -04001822 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04001823 * @HashResultPointer: pointer to an initial/result hash table.
1824 * @HashWorkingPointer: pointer to an working hash table.
1825 *
1826 * This routine iterates an initial hash table pointed by @HashResultPointer
1827 * with the values from the working hash table pointeed by @HashWorkingPointer.
1828 * The results are putting back to the initial hash table, returned through
1829 * the @HashResultPointer as the result hash table.
1830 **/
dea31012005-04-17 16:05:31 -05001831static void
1832lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1833{
1834 int t;
1835 uint32_t TEMP;
1836 uint32_t A, B, C, D, E;
1837 t = 16;
1838 do {
1839 HashWorkingPointer[t] =
1840 S(1,
1841 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1842 8] ^
1843 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1844 } while (++t <= 79);
1845 t = 0;
1846 A = HashResultPointer[0];
1847 B = HashResultPointer[1];
1848 C = HashResultPointer[2];
1849 D = HashResultPointer[3];
1850 E = HashResultPointer[4];
1851
1852 do {
1853 if (t < 20) {
1854 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1855 } else if (t < 40) {
1856 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1857 } else if (t < 60) {
1858 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1859 } else {
1860 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1861 }
1862 TEMP += S(5, A) + E + HashWorkingPointer[t];
1863 E = D;
1864 D = C;
1865 C = S(30, B);
1866 B = A;
1867 A = TEMP;
1868 } while (++t <= 79);
1869
1870 HashResultPointer[0] += A;
1871 HashResultPointer[1] += B;
1872 HashResultPointer[2] += C;
1873 HashResultPointer[3] += D;
1874 HashResultPointer[4] += E;
1875
1876}
1877
James Smarte59058c2008-08-24 21:49:00 -04001878/**
James Smart3621a712009-04-06 18:47:14 -04001879 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04001880 * @RandomChallenge: pointer to the entry of host challenge random number array.
1881 * @HashWorking: pointer to the entry of the working hash array.
1882 *
1883 * This routine calculates the working hash array referred by @HashWorking
1884 * from the challenge random numbers associated with the host, referred by
1885 * @RandomChallenge. The result is put into the entry of the working hash
1886 * array and returned by reference through @HashWorking.
1887 **/
dea31012005-04-17 16:05:31 -05001888static void
1889lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1890{
1891 *HashWorking = (*RandomChallenge ^ *HashWorking);
1892}
1893
James Smarte59058c2008-08-24 21:49:00 -04001894/**
James Smart3621a712009-04-06 18:47:14 -04001895 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04001896 * @phba: pointer to lpfc hba data structure.
1897 * @hbainit: pointer to an array of unsigned 32-bit integers.
1898 *
1899 * This routine performs the special handling for LC HBA initialization.
1900 **/
dea31012005-04-17 16:05:31 -05001901void
1902lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1903{
1904 int t;
1905 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05001906 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05001907
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001908 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05001909 if (!HashWorking)
1910 return;
1911
dea31012005-04-17 16:05:31 -05001912 HashWorking[0] = HashWorking[78] = *pwwnn++;
1913 HashWorking[1] = HashWorking[79] = *pwwnn;
1914
1915 for (t = 0; t < 7; t++)
1916 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1917
1918 lpfc_sha_init(hbainit);
1919 lpfc_sha_iterate(hbainit, HashWorking);
1920 kfree(HashWorking);
1921}
1922
James Smarte59058c2008-08-24 21:49:00 -04001923/**
James Smart3621a712009-04-06 18:47:14 -04001924 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04001925 * @vport: pointer to a virtual N_Port data structure.
1926 *
1927 * This routine performs the necessary cleanups before deleting the @vport.
1928 * It invokes the discovery state machine to perform necessary state
1929 * transitions and to release the ndlps associated with the @vport. Note,
1930 * the physical port is treated as @vport 0.
1931 **/
James Smart87af33f2007-10-27 13:37:43 -04001932void
James Smart2e0fef82007-06-17 19:56:36 -05001933lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001934{
James Smart87af33f2007-10-27 13:37:43 -04001935 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001936 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04001937 int i = 0;
dea31012005-04-17 16:05:31 -05001938
James Smart87af33f2007-10-27 13:37:43 -04001939 if (phba->link_state > LPFC_LINK_DOWN)
1940 lpfc_port_link_failure(vport);
1941
1942 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05001943 if (!NLP_CHK_NODE_ACT(ndlp)) {
1944 ndlp = lpfc_enable_node(vport, ndlp,
1945 NLP_STE_UNUSED_NODE);
1946 if (!ndlp)
1947 continue;
1948 spin_lock_irq(&phba->ndlp_lock);
1949 NLP_SET_FREE_REQ(ndlp);
1950 spin_unlock_irq(&phba->ndlp_lock);
1951 /* Trigger the release of the ndlp memory */
1952 lpfc_nlp_put(ndlp);
1953 continue;
1954 }
1955 spin_lock_irq(&phba->ndlp_lock);
1956 if (NLP_CHK_FREE_REQ(ndlp)) {
1957 /* The ndlp should not be in memory free mode already */
1958 spin_unlock_irq(&phba->ndlp_lock);
1959 continue;
1960 } else
1961 /* Indicate request for freeing ndlp memory */
1962 NLP_SET_FREE_REQ(ndlp);
1963 spin_unlock_irq(&phba->ndlp_lock);
1964
James Smart58da1ff2008-04-07 10:15:56 -04001965 if (vport->port_type != LPFC_PHYSICAL_PORT &&
1966 ndlp->nlp_DID == Fabric_DID) {
1967 /* Just free up ndlp with Fabric_DID for vports */
1968 lpfc_nlp_put(ndlp);
1969 continue;
1970 }
1971
James Smart87af33f2007-10-27 13:37:43 -04001972 if (ndlp->nlp_type & NLP_FABRIC)
1973 lpfc_disc_state_machine(vport, ndlp, NULL,
1974 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05001975
James Smart87af33f2007-10-27 13:37:43 -04001976 lpfc_disc_state_machine(vport, ndlp, NULL,
1977 NLP_EVT_DEVICE_RM);
James Smart495a7142008-06-14 22:52:59 -04001978
James Smart87af33f2007-10-27 13:37:43 -04001979 }
1980
James Smarta8adb832007-10-27 13:37:53 -04001981 /* At this point, ALL ndlp's should be gone
1982 * because of the previous NLP_EVT_DEVICE_RM.
1983 * Lets wait for this to happen, if needed.
1984 */
James Smart87af33f2007-10-27 13:37:43 -04001985 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04001986 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04001987 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04001988 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05001989 list_for_each_entry_safe(ndlp, next_ndlp,
1990 &vport->fc_nodes, nlp_listp) {
1991 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
1992 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04001993 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05001994 "usgmap:x%x refcnt:%d\n",
1995 ndlp->nlp_DID, (void *)ndlp,
1996 ndlp->nlp_usg_map,
1997 atomic_read(
1998 &ndlp->kref.refcount));
1999 }
James Smarta8adb832007-10-27 13:37:53 -04002000 break;
James Smart87af33f2007-10-27 13:37:43 -04002001 }
James Smarta8adb832007-10-27 13:37:53 -04002002
2003 /* Wait for any activity on ndlps to settle */
2004 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002005 }
dea31012005-04-17 16:05:31 -05002006}
2007
James Smarte59058c2008-08-24 21:49:00 -04002008/**
James Smart3621a712009-04-06 18:47:14 -04002009 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002010 * @vport: pointer to a virtual N_Port data structure.
2011 *
2012 * This routine stops all the timers associated with a @vport. This function
2013 * is invoked before disabling or deleting a @vport. Note that the physical
2014 * port is treated as @vport 0.
2015 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002016void
2017lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002018{
James Smart92d7f7b2007-06-17 19:56:38 -05002019 del_timer_sync(&vport->els_tmofunc);
2020 del_timer_sync(&vport->fc_fdmitmo);
2021 lpfc_can_disctmo(vport);
2022 return;
dea31012005-04-17 16:05:31 -05002023}
2024
James Smarte59058c2008-08-24 21:49:00 -04002025/**
James Smart3772a992009-05-22 14:50:54 -04002026 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002027 * @phba: pointer to lpfc hba data structure.
2028 *
2029 * This routine stops all the timers associated with a HBA. This function is
2030 * invoked before either putting a HBA offline or unloading the driver.
2031 **/
James Smart3772a992009-05-22 14:50:54 -04002032void
2033lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002034{
James Smart51ef4c22007-08-02 11:10:31 -04002035 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05002036 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002037 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002038 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002039 del_timer_sync(&phba->hb_tmofunc);
2040 phba->hb_outstanding = 0;
2041
2042 switch (phba->pci_dev_grp) {
2043 case LPFC_PCI_DEV_LP:
2044 /* Stop any LightPulse device specific driver timers */
2045 del_timer_sync(&phba->fcp_poll_timer);
2046 break;
2047 case LPFC_PCI_DEV_OC:
2048 /* Stop any OneConnect device sepcific driver timers */
2049 break;
2050 default:
2051 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2052 "0297 Invalid device group (x%x)\n",
2053 phba->pci_dev_grp);
2054 break;
2055 }
James Smart2e0fef82007-06-17 19:56:36 -05002056 return;
dea31012005-04-17 16:05:31 -05002057}
2058
James Smarte59058c2008-08-24 21:49:00 -04002059/**
James Smart3621a712009-04-06 18:47:14 -04002060 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002061 * @phba: pointer to lpfc hba data structure.
2062 *
2063 * This routine marks a HBA's management interface as blocked. Once the HBA's
2064 * management interface is marked as blocked, all the user space access to
2065 * the HBA, whether they are from sysfs interface or libdfc interface will
2066 * all be blocked. The HBA is set to block the management interface when the
2067 * driver prepares the HBA interface for online or offline.
2068 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01002069static void
2070lpfc_block_mgmt_io(struct lpfc_hba * phba)
2071{
2072 unsigned long iflag;
2073
2074 spin_lock_irqsave(&phba->hbalock, iflag);
2075 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
2076 spin_unlock_irqrestore(&phba->hbalock, iflag);
2077}
2078
James Smarte59058c2008-08-24 21:49:00 -04002079/**
James Smart3621a712009-04-06 18:47:14 -04002080 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04002081 * @phba: pointer to lpfc hba data structure.
2082 *
2083 * This routine initializes the HBA and brings a HBA online. During this
2084 * process, the management interface is blocked to prevent user space access
2085 * to the HBA interfering with the driver initialization.
2086 *
2087 * Return codes
2088 * 0 - successful
2089 * 1 - failed
2090 **/
dea31012005-04-17 16:05:31 -05002091int
James Smart2e0fef82007-06-17 19:56:36 -05002092lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002093{
Julia Lawall372bd282008-12-16 16:15:08 +01002094 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04002095 struct lpfc_vport **vports;
2096 int i;
James Smart2e0fef82007-06-17 19:56:36 -05002097
dea31012005-04-17 16:05:31 -05002098 if (!phba)
2099 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01002100 vport = phba->pport;
dea31012005-04-17 16:05:31 -05002101
James Smart2e0fef82007-06-17 19:56:36 -05002102 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05002103 return 0;
2104
James Smarted957682007-06-17 19:56:37 -05002105 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002106 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05002107
James Smart46fa3112007-04-25 09:51:45 -04002108 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002109
James Smart46fa3112007-04-25 09:51:45 -04002110 if (!lpfc_sli_queue_setup(phba)) {
2111 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002112 return 1;
James Smart46fa3112007-04-25 09:51:45 -04002113 }
2114
James Smartda0436e2009-05-22 14:51:39 -04002115 if (phba->sli_rev == LPFC_SLI_REV4) {
2116 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
2117 lpfc_unblock_mgmt_io(phba);
2118 return 1;
2119 }
2120 } else {
2121 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
2122 lpfc_unblock_mgmt_io(phba);
2123 return 1;
2124 }
James Smart46fa3112007-04-25 09:51:45 -04002125 }
dea31012005-04-17 16:05:31 -05002126
James Smart549e55c2007-08-02 11:09:51 -04002127 vports = lpfc_create_vport_work_array(phba);
2128 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002129 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002130 struct Scsi_Host *shost;
2131 shost = lpfc_shost_from_vport(vports[i]);
2132 spin_lock_irq(shost->host_lock);
2133 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
2134 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2135 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2136 spin_unlock_irq(shost->host_lock);
2137 }
James Smart09372822008-01-11 01:52:54 -05002138 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002139
James Smart46fa3112007-04-25 09:51:45 -04002140 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002141 return 0;
2142}
2143
James Smarte59058c2008-08-24 21:49:00 -04002144/**
James Smart3621a712009-04-06 18:47:14 -04002145 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04002146 * @phba: pointer to lpfc hba data structure.
2147 *
2148 * This routine marks a HBA's management interface as not blocked. Once the
2149 * HBA's management interface is marked as not blocked, all the user space
2150 * access to the HBA, whether they are from sysfs interface or libdfc
2151 * interface will be allowed. The HBA is set to block the management interface
2152 * when the driver prepares the HBA interface for online or offline and then
2153 * set to unblock the management interface afterwards.
2154 **/
James Smart46fa3112007-04-25 09:51:45 -04002155void
James Smart46fa3112007-04-25 09:51:45 -04002156lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
2157{
2158 unsigned long iflag;
2159
James Smart2e0fef82007-06-17 19:56:36 -05002160 spin_lock_irqsave(&phba->hbalock, iflag);
2161 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
2162 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04002163}
2164
James Smarte59058c2008-08-24 21:49:00 -04002165/**
James Smart3621a712009-04-06 18:47:14 -04002166 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04002167 * @phba: pointer to lpfc hba data structure.
2168 *
2169 * This routine is invoked to prepare a HBA to be brought offline. It performs
2170 * unregistration login to all the nodes on all vports and flushes the mailbox
2171 * queue to make it ready to be brought offline.
2172 **/
James Smart46fa3112007-04-25 09:51:45 -04002173void
2174lpfc_offline_prep(struct lpfc_hba * phba)
2175{
James Smart2e0fef82007-06-17 19:56:36 -05002176 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04002177 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04002178 struct lpfc_vport **vports;
2179 int i;
dea31012005-04-17 16:05:31 -05002180
James Smart2e0fef82007-06-17 19:56:36 -05002181 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002182 return;
dea31012005-04-17 16:05:31 -05002183
James Smart46fa3112007-04-25 09:51:45 -04002184 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002185
2186 lpfc_linkdown(phba);
2187
James Smart87af33f2007-10-27 13:37:43 -04002188 /* Issue an unreg_login to all nodes on all vports */
2189 vports = lpfc_create_vport_work_array(phba);
2190 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04002191 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart87af33f2007-10-27 13:37:43 -04002192 struct Scsi_Host *shost;
2193
James Smarta8adb832007-10-27 13:37:53 -04002194 if (vports[i]->load_flag & FC_UNLOADING)
2195 continue;
James Smartda0436e2009-05-22 14:51:39 -04002196 vports[i]->vfi_state &= ~LPFC_VFI_REGISTERED;
James Smart87af33f2007-10-27 13:37:43 -04002197 shost = lpfc_shost_from_vport(vports[i]);
2198 list_for_each_entry_safe(ndlp, next_ndlp,
2199 &vports[i]->fc_nodes,
2200 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002201 if (!NLP_CHK_NODE_ACT(ndlp))
2202 continue;
James Smart87af33f2007-10-27 13:37:43 -04002203 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2204 continue;
2205 if (ndlp->nlp_type & NLP_FABRIC) {
2206 lpfc_disc_state_machine(vports[i], ndlp,
2207 NULL, NLP_EVT_DEVICE_RECOVERY);
2208 lpfc_disc_state_machine(vports[i], ndlp,
2209 NULL, NLP_EVT_DEVICE_RM);
2210 }
2211 spin_lock_irq(shost->host_lock);
2212 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2213 spin_unlock_irq(shost->host_lock);
2214 lpfc_unreg_rpi(vports[i], ndlp);
2215 }
2216 }
2217 }
James Smart09372822008-01-11 01:52:54 -05002218 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002219
James Smart04c68492009-05-22 14:52:52 -04002220 lpfc_sli_mbox_sys_shutdown(phba);
James Smart46fa3112007-04-25 09:51:45 -04002221}
2222
James Smarte59058c2008-08-24 21:49:00 -04002223/**
James Smart3621a712009-04-06 18:47:14 -04002224 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04002225 * @phba: pointer to lpfc hba data structure.
2226 *
2227 * This routine actually brings a HBA offline. It stops all the timers
2228 * associated with the HBA, brings down the SLI layer, and eventually
2229 * marks the HBA as in offline state for the upper layer protocol.
2230 **/
James Smart46fa3112007-04-25 09:51:45 -04002231void
James Smart2e0fef82007-06-17 19:56:36 -05002232lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04002233{
James Smart549e55c2007-08-02 11:09:51 -04002234 struct Scsi_Host *shost;
2235 struct lpfc_vport **vports;
2236 int i;
James Smart46fa3112007-04-25 09:51:45 -04002237
James Smart549e55c2007-08-02 11:09:51 -04002238 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002239 return;
James Smart688a8862006-07-06 15:49:56 -04002240
James Smartda0436e2009-05-22 14:51:39 -04002241 /* stop port and all timers associated with this hba */
2242 lpfc_stop_port(phba);
James Smart51ef4c22007-08-02 11:10:31 -04002243 vports = lpfc_create_vport_work_array(phba);
2244 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002245 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04002246 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05002247 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05002248 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002249 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05002250 /* Bring down the SLI Layer and cleanup. The HBA is offline
2251 now. */
2252 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002253 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04002254 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05002255 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04002256 vports = lpfc_create_vport_work_array(phba);
2257 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04002258 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002259 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04002260 spin_lock_irq(shost->host_lock);
2261 vports[i]->work_port_events = 0;
2262 vports[i]->fc_flag |= FC_OFFLINE_MODE;
2263 spin_unlock_irq(shost->host_lock);
2264 }
James Smart09372822008-01-11 01:52:54 -05002265 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002266}
2267
James Smarte59058c2008-08-24 21:49:00 -04002268/**
James Smart3621a712009-04-06 18:47:14 -04002269 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04002270 * @phba: pointer to lpfc hba data structure.
2271 *
2272 * This routine is to free all the SCSI buffers and IOCBs from the driver
2273 * list back to kernel. It is called from lpfc_pci_remove_one to free
2274 * the internal resources before the device is removed from the system.
2275 *
2276 * Return codes
2277 * 0 - successful (for now, it always returns 0)
2278 **/
dea31012005-04-17 16:05:31 -05002279static int
James Smart2e0fef82007-06-17 19:56:36 -05002280lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002281{
2282 struct lpfc_scsi_buf *sb, *sb_next;
2283 struct lpfc_iocbq *io, *io_next;
2284
James Smart2e0fef82007-06-17 19:56:36 -05002285 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002286 /* Release all the lpfc_scsi_bufs maintained by this host. */
2287 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
2288 list_del(&sb->list);
2289 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05002290 sb->dma_handle);
dea31012005-04-17 16:05:31 -05002291 kfree(sb);
2292 phba->total_scsi_bufs--;
2293 }
2294
2295 /* Release all the lpfc_iocbq entries maintained by this host. */
2296 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
2297 list_del(&io->list);
2298 kfree(io);
2299 phba->total_iocbq_bufs--;
2300 }
2301
James Smart2e0fef82007-06-17 19:56:36 -05002302 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002303
2304 return 0;
2305}
2306
James Smarte59058c2008-08-24 21:49:00 -04002307/**
James Smart3621a712009-04-06 18:47:14 -04002308 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04002309 * @phba: pointer to lpfc hba data structure.
2310 * @instance: a unique integer ID to this FC port.
2311 * @dev: pointer to the device data structure.
2312 *
2313 * This routine creates a FC port for the upper layer protocol. The FC port
2314 * can be created on top of either a physical port or a virtual port provided
2315 * by the HBA. This routine also allocates a SCSI host data structure (shost)
2316 * and associates the FC port created before adding the shost into the SCSI
2317 * layer.
2318 *
2319 * Return codes
2320 * @vport - pointer to the virtual N_Port data structure.
2321 * NULL - port create failed.
2322 **/
James Smart2e0fef82007-06-17 19:56:36 -05002323struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04002324lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04002325{
James Smart2e0fef82007-06-17 19:56:36 -05002326 struct lpfc_vport *vport;
2327 struct Scsi_Host *shost;
2328 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04002329
James Smart3de2a652007-08-02 11:09:59 -04002330 if (dev != &phba->pcidev->dev)
2331 shost = scsi_host_alloc(&lpfc_vport_template,
2332 sizeof(struct lpfc_vport));
2333 else
2334 shost = scsi_host_alloc(&lpfc_template,
2335 sizeof(struct lpfc_vport));
James Smart2e0fef82007-06-17 19:56:36 -05002336 if (!shost)
2337 goto out;
James Smart47a86172007-04-25 09:53:22 -04002338
James Smart2e0fef82007-06-17 19:56:36 -05002339 vport = (struct lpfc_vport *) shost->hostdata;
2340 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05002341 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05002342 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05002343 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04002344
James Smart3de2a652007-08-02 11:09:59 -04002345 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002346 shost->unique_id = instance;
2347 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04002348 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05002349 shost->this_id = -1;
2350 shost->max_cmd_len = 16;
James Smartda0436e2009-05-22 14:51:39 -04002351 if (phba->sli_rev == LPFC_SLI_REV4) {
2352 shost->dma_boundary = LPFC_SLI4_MAX_SEGMENT_SIZE;
2353 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
2354 }
James Smart81301a92008-12-04 22:39:46 -05002355
James Smart47a86172007-04-25 09:53:22 -04002356 /*
James Smart2e0fef82007-06-17 19:56:36 -05002357 * Set initial can_queue value since 0 is no longer supported and
2358 * scsi_add_host will fail. This will be adjusted later based on the
2359 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04002360 */
James Smart2e0fef82007-06-17 19:56:36 -05002361 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04002362 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05002363 shost->transportt = lpfc_vport_transport_template;
2364 vport->port_type = LPFC_NPIV_PORT;
2365 } else {
2366 shost->transportt = lpfc_transport_template;
2367 vport->port_type = LPFC_PHYSICAL_PORT;
2368 }
James Smart47a86172007-04-25 09:53:22 -04002369
James Smart2e0fef82007-06-17 19:56:36 -05002370 /* Initialize all internally managed lists. */
2371 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04002372 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05002373 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04002374
James Smart2e0fef82007-06-17 19:56:36 -05002375 init_timer(&vport->fc_disctmo);
2376 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05002377 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04002378
James Smart2e0fef82007-06-17 19:56:36 -05002379 init_timer(&vport->fc_fdmitmo);
2380 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
James Smart92d7f7b2007-06-17 19:56:38 -05002381 vport->fc_fdmitmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04002382
James Smart2e0fef82007-06-17 19:56:36 -05002383 init_timer(&vport->els_tmofunc);
2384 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05002385 vport->els_tmofunc.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04002386
James Smart3de2a652007-08-02 11:09:59 -04002387 error = scsi_add_host(shost, dev);
James Smart2e0fef82007-06-17 19:56:36 -05002388 if (error)
2389 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04002390
James Smart549e55c2007-08-02 11:09:51 -04002391 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05002392 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04002393 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05002394 return vport;
James Smart47a86172007-04-25 09:53:22 -04002395
James Smart2e0fef82007-06-17 19:56:36 -05002396out_put_shost:
2397 scsi_host_put(shost);
2398out:
2399 return NULL;
James Smart47a86172007-04-25 09:53:22 -04002400}
2401
James Smarte59058c2008-08-24 21:49:00 -04002402/**
James Smart3621a712009-04-06 18:47:14 -04002403 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04002404 * @vport: pointer to an lpfc virtual N_Port data structure.
2405 *
2406 * This routine destroys a FC port from the upper layer protocol. All the
2407 * resources associated with the port are released.
2408 **/
James Smart2e0fef82007-06-17 19:56:36 -05002409void
2410destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04002411{
James Smart92d7f7b2007-06-17 19:56:38 -05002412 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2413 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04002414
James Smart858c9f62007-06-17 19:56:39 -05002415 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05002416 fc_remove_host(shost);
2417 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04002418
James Smart92d7f7b2007-06-17 19:56:38 -05002419 spin_lock_irq(&phba->hbalock);
2420 list_del_init(&vport->listentry);
2421 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04002422
James Smart92d7f7b2007-06-17 19:56:38 -05002423 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04002424 return;
James Smart47a86172007-04-25 09:53:22 -04002425}
2426
James Smarte59058c2008-08-24 21:49:00 -04002427/**
James Smart3621a712009-04-06 18:47:14 -04002428 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04002429 *
2430 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
2431 * uses the kernel idr facility to perform the task.
2432 *
2433 * Return codes:
2434 * instance - a unique integer ID allocated as the new instance.
2435 * -1 - lpfc get instance failed.
2436 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002437int
2438lpfc_get_instance(void)
2439{
2440 int instance = 0;
2441
2442 /* Assign an unused number */
2443 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
2444 return -1;
2445 if (idr_get_new(&lpfc_hba_index, NULL, &instance))
2446 return -1;
2447 return instance;
2448}
2449
James Smarte59058c2008-08-24 21:49:00 -04002450/**
James Smart3621a712009-04-06 18:47:14 -04002451 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04002452 * @shost: pointer to SCSI host data structure.
2453 * @time: elapsed time of the scan in jiffies.
2454 *
2455 * This routine is called by the SCSI layer with a SCSI host to determine
2456 * whether the scan host is finished.
2457 *
2458 * Note: there is no scan_start function as adapter initialization will have
2459 * asynchronously kicked off the link initialization.
2460 *
2461 * Return codes
2462 * 0 - SCSI host scan is not over yet.
2463 * 1 - SCSI host scan is over.
2464 **/
James Smart47a86172007-04-25 09:53:22 -04002465int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
2466{
James Smart2e0fef82007-06-17 19:56:36 -05002467 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2468 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05002469 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04002470
James Smart858c9f62007-06-17 19:56:39 -05002471 spin_lock_irq(shost->host_lock);
2472
James Smart51ef4c22007-08-02 11:10:31 -04002473 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05002474 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002475 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05002476 }
James Smart2e0fef82007-06-17 19:56:36 -05002477 if (time >= 30 * HZ) {
2478 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002479 "0461 Scanning longer than 30 "
2480 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05002481 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002482 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002483 }
2484 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
2485 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002486 "0465 Link down longer than 15 "
2487 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05002488 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05002489 goto finished;
James Smart47a86172007-04-25 09:53:22 -04002490 }
2491
James Smart2e0fef82007-06-17 19:56:36 -05002492 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05002493 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002494 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05002495 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002496 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
James Smart858c9f62007-06-17 19:56:39 -05002497 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002498 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05002499 goto finished;
2500
2501 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002502
2503finished:
James Smart858c9f62007-06-17 19:56:39 -05002504 spin_unlock_irq(shost->host_lock);
2505 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05002506}
2507
James Smarte59058c2008-08-24 21:49:00 -04002508/**
James Smart3621a712009-04-06 18:47:14 -04002509 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04002510 * @shost: pointer to SCSI host data structure.
2511 *
2512 * This routine initializes a given SCSI host attributes on a FC port. The
2513 * SCSI host can be either on top of a physical port or a virtual port.
2514 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002515void lpfc_host_attrib_init(struct Scsi_Host *shost)
2516{
2517 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2518 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04002519 /*
James Smart2e0fef82007-06-17 19:56:36 -05002520 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04002521 */
2522
James Smart2e0fef82007-06-17 19:56:36 -05002523 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
2524 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04002525 fc_host_supported_classes(shost) = FC_COS_CLASS3;
2526
2527 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05002528 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04002529 fc_host_supported_fc4s(shost)[2] = 1;
2530 fc_host_supported_fc4s(shost)[7] = 1;
2531
James Smart92d7f7b2007-06-17 19:56:38 -05002532 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
2533 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04002534
2535 fc_host_supported_speeds(shost) = 0;
2536 if (phba->lmt & LMT_10Gb)
2537 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04002538 if (phba->lmt & LMT_8Gb)
2539 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04002540 if (phba->lmt & LMT_4Gb)
2541 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
2542 if (phba->lmt & LMT_2Gb)
2543 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
2544 if (phba->lmt & LMT_1Gb)
2545 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
2546
2547 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05002548 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
2549 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04002550
2551 /* This value is also unchanging */
2552 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05002553 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04002554 fc_host_active_fc4s(shost)[2] = 1;
2555 fc_host_active_fc4s(shost)[7] = 1;
2556
James Smart92d7f7b2007-06-17 19:56:38 -05002557 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04002558 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04002559 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04002560 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04002561}
dea31012005-04-17 16:05:31 -05002562
James Smarte59058c2008-08-24 21:49:00 -04002563/**
James Smartda0436e2009-05-22 14:51:39 -04002564 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04002565 * @phba: pointer to lpfc hba data structure.
2566 *
James Smartda0436e2009-05-22 14:51:39 -04002567 * This routine is invoked to stop an SLI3 device port, it stops the device
2568 * from generating interrupts and stops the device driver's timers for the
2569 * device.
James Smarte59058c2008-08-24 21:49:00 -04002570 **/
James Smartdb2378e2008-02-08 18:49:51 -05002571static void
James Smartda0436e2009-05-22 14:51:39 -04002572lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05002573{
James Smartda0436e2009-05-22 14:51:39 -04002574 /* Clear all interrupt enable conditions */
2575 writel(0, phba->HCregaddr);
2576 readl(phba->HCregaddr); /* flush */
2577 /* Clear all pending interrupts */
2578 writel(0xffffffff, phba->HAregaddr);
2579 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04002580
James Smartda0436e2009-05-22 14:51:39 -04002581 /* Reset some HBA SLI setup states */
2582 lpfc_stop_hba_timers(phba);
2583 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05002584}
2585
James Smarte59058c2008-08-24 21:49:00 -04002586/**
James Smartda0436e2009-05-22 14:51:39 -04002587 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05002588 * @phba: pointer to lpfc hba data structure.
2589 *
James Smartda0436e2009-05-22 14:51:39 -04002590 * This routine is invoked to stop an SLI4 device port, it stops the device
2591 * from generating interrupts and stops the device driver's timers for the
2592 * device.
2593 **/
2594static void
2595lpfc_stop_port_s4(struct lpfc_hba *phba)
2596{
2597 /* Reset some HBA SLI4 setup states */
2598 lpfc_stop_hba_timers(phba);
2599 phba->pport->work_port_events = 0;
2600 phba->sli4_hba.intr_enable = 0;
2601 /* Hard clear it for now, shall have more graceful way to wait later */
2602 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2603}
2604
2605/**
2606 * lpfc_stop_port - Wrapper function for stopping hba port
2607 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05002608 *
James Smartda0436e2009-05-22 14:51:39 -04002609 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
2610 * the API jump table function pointer from the lpfc_hba struct.
2611 **/
2612void
2613lpfc_stop_port(struct lpfc_hba *phba)
2614{
2615 phba->lpfc_stop_port(phba);
2616}
2617
2618/**
2619 * lpfc_sli4_remove_dflt_fcf - Remove the driver default fcf record from the port.
2620 * @phba: pointer to lpfc hba data structure.
2621 *
2622 * This routine is invoked to remove the driver default fcf record from
2623 * the port. This routine currently acts on FCF Index 0.
2624 *
2625 **/
2626void
2627lpfc_sli_remove_dflt_fcf(struct lpfc_hba *phba)
2628{
2629 int rc = 0;
2630 LPFC_MBOXQ_t *mboxq;
2631 struct lpfc_mbx_del_fcf_tbl_entry *del_fcf_record;
2632 uint32_t mbox_tmo, req_len;
2633 uint32_t shdr_status, shdr_add_status;
2634
2635 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2636 if (!mboxq) {
2637 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2638 "2020 Failed to allocate mbox for ADD_FCF cmd\n");
2639 return;
2640 }
2641
2642 req_len = sizeof(struct lpfc_mbx_del_fcf_tbl_entry) -
2643 sizeof(struct lpfc_sli4_cfg_mhdr);
2644 rc = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
2645 LPFC_MBOX_OPCODE_FCOE_DELETE_FCF,
2646 req_len, LPFC_SLI4_MBX_EMBED);
2647 /*
2648 * In phase 1, there is a single FCF index, 0. In phase2, the driver
2649 * supports multiple FCF indices.
2650 */
2651 del_fcf_record = &mboxq->u.mqe.un.del_fcf_entry;
2652 bf_set(lpfc_mbx_del_fcf_tbl_count, del_fcf_record, 1);
2653 bf_set(lpfc_mbx_del_fcf_tbl_index, del_fcf_record,
2654 phba->fcf.fcf_indx);
2655
2656 if (!phba->sli4_hba.intr_enable)
2657 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
2658 else {
2659 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
2660 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
2661 }
2662 /* The IOCTL status is embedded in the mailbox subheader. */
2663 shdr_status = bf_get(lpfc_mbox_hdr_status,
2664 &del_fcf_record->header.cfg_shdr.response);
2665 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
2666 &del_fcf_record->header.cfg_shdr.response);
2667 if (shdr_status || shdr_add_status || rc != MBX_SUCCESS) {
2668 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2669 "2516 DEL FCF of default FCF Index failed "
2670 "mbx status x%x, status x%x add_status x%x\n",
2671 rc, shdr_status, shdr_add_status);
2672 }
2673 if (rc != MBX_TIMEOUT)
2674 mempool_free(mboxq, phba->mbox_mem_pool);
2675}
2676
2677/**
2678 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
2679 * @phba: pointer to lpfc hba data structure.
2680 * @acqe_link: pointer to the async link completion queue entry.
2681 *
2682 * This routine is to parse the SLI4 link-attention link fault code and
2683 * translate it into the base driver's read link attention mailbox command
2684 * status.
2685 *
2686 * Return: Link-attention status in terms of base driver's coding.
2687 **/
2688static uint16_t
2689lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
2690 struct lpfc_acqe_link *acqe_link)
2691{
2692 uint16_t latt_fault;
2693
2694 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
2695 case LPFC_ASYNC_LINK_FAULT_NONE:
2696 case LPFC_ASYNC_LINK_FAULT_LOCAL:
2697 case LPFC_ASYNC_LINK_FAULT_REMOTE:
2698 latt_fault = 0;
2699 break;
2700 default:
2701 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2702 "0398 Invalid link fault code: x%x\n",
2703 bf_get(lpfc_acqe_link_fault, acqe_link));
2704 latt_fault = MBXERR_ERROR;
2705 break;
2706 }
2707 return latt_fault;
2708}
2709
2710/**
2711 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
2712 * @phba: pointer to lpfc hba data structure.
2713 * @acqe_link: pointer to the async link completion queue entry.
2714 *
2715 * This routine is to parse the SLI4 link attention type and translate it
2716 * into the base driver's link attention type coding.
2717 *
2718 * Return: Link attention type in terms of base driver's coding.
2719 **/
2720static uint8_t
2721lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
2722 struct lpfc_acqe_link *acqe_link)
2723{
2724 uint8_t att_type;
2725
2726 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
2727 case LPFC_ASYNC_LINK_STATUS_DOWN:
2728 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
2729 att_type = AT_LINK_DOWN;
2730 break;
2731 case LPFC_ASYNC_LINK_STATUS_UP:
2732 /* Ignore physical link up events - wait for logical link up */
2733 att_type = AT_RESERVED;
2734 break;
2735 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
2736 att_type = AT_LINK_UP;
2737 break;
2738 default:
2739 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2740 "0399 Invalid link attention type: x%x\n",
2741 bf_get(lpfc_acqe_link_status, acqe_link));
2742 att_type = AT_RESERVED;
2743 break;
2744 }
2745 return att_type;
2746}
2747
2748/**
2749 * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
2750 * @phba: pointer to lpfc hba data structure.
2751 * @acqe_link: pointer to the async link completion queue entry.
2752 *
2753 * This routine is to parse the SLI4 link-attention link speed and translate
2754 * it into the base driver's link-attention link speed coding.
2755 *
2756 * Return: Link-attention link speed in terms of base driver's coding.
2757 **/
2758static uint8_t
2759lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba,
2760 struct lpfc_acqe_link *acqe_link)
2761{
2762 uint8_t link_speed;
2763
2764 switch (bf_get(lpfc_acqe_link_speed, acqe_link)) {
2765 case LPFC_ASYNC_LINK_SPEED_ZERO:
2766 link_speed = LA_UNKNW_LINK;
2767 break;
2768 case LPFC_ASYNC_LINK_SPEED_10MBPS:
2769 link_speed = LA_UNKNW_LINK;
2770 break;
2771 case LPFC_ASYNC_LINK_SPEED_100MBPS:
2772 link_speed = LA_UNKNW_LINK;
2773 break;
2774 case LPFC_ASYNC_LINK_SPEED_1GBPS:
2775 link_speed = LA_1GHZ_LINK;
2776 break;
2777 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2778 link_speed = LA_10GHZ_LINK;
2779 break;
2780 default:
2781 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2782 "0483 Invalid link-attention link speed: x%x\n",
2783 bf_get(lpfc_acqe_link_speed, acqe_link));
2784 link_speed = LA_UNKNW_LINK;
2785 break;
2786 }
2787 return link_speed;
2788}
2789
2790/**
2791 * lpfc_sli4_async_link_evt - Process the asynchronous link event
2792 * @phba: pointer to lpfc hba data structure.
2793 * @acqe_link: pointer to the async link completion queue entry.
2794 *
2795 * This routine is to handle the SLI4 asynchronous link event.
2796 **/
2797static void
2798lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
2799 struct lpfc_acqe_link *acqe_link)
2800{
2801 struct lpfc_dmabuf *mp;
2802 LPFC_MBOXQ_t *pmb;
2803 MAILBOX_t *mb;
2804 READ_LA_VAR *la;
2805 uint8_t att_type;
2806
2807 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
2808 if (att_type != AT_LINK_DOWN && att_type != AT_LINK_UP)
2809 return;
2810 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2811 if (!pmb) {
2812 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2813 "0395 The mboxq allocation failed\n");
2814 return;
2815 }
2816 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2817 if (!mp) {
2818 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2819 "0396 The lpfc_dmabuf allocation failed\n");
2820 goto out_free_pmb;
2821 }
2822 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
2823 if (!mp->virt) {
2824 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2825 "0397 The mbuf allocation failed\n");
2826 goto out_free_dmabuf;
2827 }
2828
2829 /* Cleanup any outstanding ELS commands */
2830 lpfc_els_flush_all_cmd(phba);
2831
2832 /* Block ELS IOCBs until we have done process link event */
2833 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
2834
2835 /* Update link event statistics */
2836 phba->sli.slistat.link_event++;
2837
2838 /* Create pseudo lpfc_handle_latt mailbox command from link ACQE */
2839 lpfc_read_la(phba, pmb, mp);
2840 pmb->vport = phba->pport;
2841
2842 /* Parse and translate status field */
2843 mb = &pmb->u.mb;
2844 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
2845
2846 /* Parse and translate link attention fields */
2847 la = (READ_LA_VAR *) &pmb->u.mb.un.varReadLA;
2848 la->eventTag = acqe_link->event_tag;
2849 la->attType = att_type;
2850 la->UlnkSpeed = lpfc_sli4_parse_latt_link_speed(phba, acqe_link);
2851
2852 /* Fake the the following irrelvant fields */
2853 la->topology = TOPOLOGY_PT_PT;
2854 la->granted_AL_PA = 0;
2855 la->il = 0;
2856 la->pb = 0;
2857 la->fa = 0;
2858 la->mm = 0;
2859
2860 /* Keep the link status for extra SLI4 state machine reference */
2861 phba->sli4_hba.link_state.speed =
2862 bf_get(lpfc_acqe_link_speed, acqe_link);
2863 phba->sli4_hba.link_state.duplex =
2864 bf_get(lpfc_acqe_link_duplex, acqe_link);
2865 phba->sli4_hba.link_state.status =
2866 bf_get(lpfc_acqe_link_status, acqe_link);
2867 phba->sli4_hba.link_state.physical =
2868 bf_get(lpfc_acqe_link_physical, acqe_link);
2869 phba->sli4_hba.link_state.fault =
2870 bf_get(lpfc_acqe_link_fault, acqe_link);
2871
2872 /* Invoke the lpfc_handle_latt mailbox command callback function */
2873 lpfc_mbx_cmpl_read_la(phba, pmb);
2874
2875 return;
2876
2877out_free_dmabuf:
2878 kfree(mp);
2879out_free_pmb:
2880 mempool_free(pmb, phba->mbox_mem_pool);
2881}
2882
2883/**
2884 * lpfc_sli4_async_fcoe_evt - Process the asynchronous fcoe event
2885 * @phba: pointer to lpfc hba data structure.
2886 * @acqe_link: pointer to the async fcoe completion queue entry.
2887 *
2888 * This routine is to handle the SLI4 asynchronous fcoe event.
2889 **/
2890static void
2891lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba,
2892 struct lpfc_acqe_fcoe *acqe_fcoe)
2893{
2894 uint8_t event_type = bf_get(lpfc_acqe_fcoe_event_type, acqe_fcoe);
2895 int rc;
2896
2897 switch (event_type) {
2898 case LPFC_FCOE_EVENT_TYPE_NEW_FCF:
2899 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2900 "2546 New FCF found index 0x%x tag 0x%x \n",
2901 acqe_fcoe->fcf_index,
2902 acqe_fcoe->event_tag);
2903 /*
2904 * If the current FCF is in discovered state,
2905 * do nothing.
2906 */
2907 spin_lock_irq(&phba->hbalock);
2908 if (phba->fcf.fcf_flag & FCF_DISCOVERED) {
2909 spin_unlock_irq(&phba->hbalock);
2910 break;
2911 }
2912 spin_unlock_irq(&phba->hbalock);
2913
2914 /* Read the FCF table and re-discover SAN. */
2915 rc = lpfc_sli4_read_fcf_record(phba,
2916 LPFC_FCOE_FCF_GET_FIRST);
2917 if (rc)
2918 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2919 "2547 Read FCF record failed 0x%x\n",
2920 rc);
2921 break;
2922
2923 case LPFC_FCOE_EVENT_TYPE_FCF_TABLE_FULL:
2924 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2925 "2548 FCF Table full count 0x%x tag 0x%x \n",
2926 bf_get(lpfc_acqe_fcoe_fcf_count, acqe_fcoe),
2927 acqe_fcoe->event_tag);
2928 break;
2929
2930 case LPFC_FCOE_EVENT_TYPE_FCF_DEAD:
2931 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2932 "2549 FCF disconnected fron network index 0x%x"
2933 " tag 0x%x \n", acqe_fcoe->fcf_index,
2934 acqe_fcoe->event_tag);
2935 /* If the event is not for currently used fcf do nothing */
2936 if (phba->fcf.fcf_indx != acqe_fcoe->fcf_index)
2937 break;
2938 /*
2939 * Currently, driver support only one FCF - so treat this as
2940 * a link down.
2941 */
2942 lpfc_linkdown(phba);
2943 /* Unregister FCF if no devices connected to it */
2944 lpfc_unregister_unused_fcf(phba);
2945 break;
2946
2947 default:
2948 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2949 "0288 Unknown FCoE event type 0x%x event tag "
2950 "0x%x\n", event_type, acqe_fcoe->event_tag);
2951 break;
2952 }
2953}
2954
2955/**
2956 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
2957 * @phba: pointer to lpfc hba data structure.
2958 * @acqe_link: pointer to the async dcbx completion queue entry.
2959 *
2960 * This routine is to handle the SLI4 asynchronous dcbx event.
2961 **/
2962static void
2963lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
2964 struct lpfc_acqe_dcbx *acqe_dcbx)
2965{
2966 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2967 "0290 The SLI4 DCBX asynchronous event is not "
2968 "handled yet\n");
2969}
2970
2971/**
2972 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
2973 * @phba: pointer to lpfc hba data structure.
2974 *
2975 * This routine is invoked by the worker thread to process all the pending
2976 * SLI4 asynchronous events.
2977 **/
2978void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
2979{
2980 struct lpfc_cq_event *cq_event;
2981
2982 /* First, declare the async event has been handled */
2983 spin_lock_irq(&phba->hbalock);
2984 phba->hba_flag &= ~ASYNC_EVENT;
2985 spin_unlock_irq(&phba->hbalock);
2986 /* Now, handle all the async events */
2987 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
2988 /* Get the first event from the head of the event queue */
2989 spin_lock_irq(&phba->hbalock);
2990 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
2991 cq_event, struct lpfc_cq_event, list);
2992 spin_unlock_irq(&phba->hbalock);
2993 /* Process the asynchronous event */
2994 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
2995 case LPFC_TRAILER_CODE_LINK:
2996 lpfc_sli4_async_link_evt(phba,
2997 &cq_event->cqe.acqe_link);
2998 break;
2999 case LPFC_TRAILER_CODE_FCOE:
3000 lpfc_sli4_async_fcoe_evt(phba,
3001 &cq_event->cqe.acqe_fcoe);
3002 break;
3003 case LPFC_TRAILER_CODE_DCBX:
3004 lpfc_sli4_async_dcbx_evt(phba,
3005 &cq_event->cqe.acqe_dcbx);
3006 break;
3007 default:
3008 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3009 "1804 Invalid asynchrous event code: "
3010 "x%x\n", bf_get(lpfc_trailer_code,
3011 &cq_event->cqe.mcqe_cmpl));
3012 break;
3013 }
3014 /* Free the completion event processed to the free pool */
3015 lpfc_sli4_cq_event_release(phba, cq_event);
3016 }
3017}
3018
3019/**
3020 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
3021 * @phba: pointer to lpfc hba data structure.
3022 * @dev_grp: The HBA PCI-Device group number.
3023 *
3024 * This routine is invoked to set up the per HBA PCI-Device group function
3025 * API jump table entries.
3026 *
3027 * Return: 0 if success, otherwise -ENODEV
3028 **/
3029int
3030lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05003031{
3032 int rc;
3033
James Smartda0436e2009-05-22 14:51:39 -04003034 /* Set up lpfc PCI-device group */
3035 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05003036
James Smartda0436e2009-05-22 14:51:39 -04003037 /* The LPFC_PCI_DEV_OC uses SLI4 */
3038 if (dev_grp == LPFC_PCI_DEV_OC)
3039 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05003040
James Smartda0436e2009-05-22 14:51:39 -04003041 /* Set up device INIT API function jump table */
3042 rc = lpfc_init_api_table_setup(phba, dev_grp);
3043 if (rc)
3044 return -ENODEV;
3045 /* Set up SCSI API function jump table */
3046 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
3047 if (rc)
3048 return -ENODEV;
3049 /* Set up SLI API function jump table */
3050 rc = lpfc_sli_api_table_setup(phba, dev_grp);
3051 if (rc)
3052 return -ENODEV;
3053 /* Set up MBOX API function jump table */
3054 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
3055 if (rc)
3056 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05003057
James Smartda0436e2009-05-22 14:51:39 -04003058 return 0;
James Smart5b75da22008-12-04 22:39:35 -05003059}
3060
3061/**
James Smart3621a712009-04-06 18:47:14 -04003062 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05003063 * @phba: pointer to lpfc hba data structure.
3064 * @intr_mode: active interrupt mode adopted.
3065 *
3066 * This routine it invoked to log the currently used active interrupt mode
3067 * to the device.
James Smart3772a992009-05-22 14:50:54 -04003068 **/
3069static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05003070{
3071 switch (intr_mode) {
3072 case 0:
3073 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3074 "0470 Enable INTx interrupt mode.\n");
3075 break;
3076 case 1:
3077 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3078 "0481 Enabled MSI interrupt mode.\n");
3079 break;
3080 case 2:
3081 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3082 "0480 Enabled MSI-X interrupt mode.\n");
3083 break;
3084 default:
3085 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3086 "0482 Illegal interrupt mode.\n");
3087 break;
3088 }
3089 return;
3090}
3091
James Smart5b75da22008-12-04 22:39:35 -05003092/**
James Smart3772a992009-05-22 14:50:54 -04003093 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05003094 * @phba: pointer to lpfc hba data structure.
3095 *
James Smart3772a992009-05-22 14:50:54 -04003096 * This routine is invoked to enable the PCI device that is common to all
3097 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05003098 *
3099 * Return codes
James Smart3772a992009-05-22 14:50:54 -04003100 * 0 - sucessful
3101 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05003102 **/
James Smart3772a992009-05-22 14:50:54 -04003103static int
3104lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05003105{
James Smart3772a992009-05-22 14:50:54 -04003106 struct pci_dev *pdev;
3107 int bars;
James Smart5b75da22008-12-04 22:39:35 -05003108
James Smart3772a992009-05-22 14:50:54 -04003109 /* Obtain PCI device reference */
3110 if (!phba->pcidev)
3111 goto out_error;
3112 else
3113 pdev = phba->pcidev;
3114 /* Select PCI BARs */
3115 bars = pci_select_bars(pdev, IORESOURCE_MEM);
3116 /* Enable PCI device */
3117 if (pci_enable_device_mem(pdev))
3118 goto out_error;
3119 /* Request PCI resource for the device */
3120 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
3121 goto out_disable_device;
3122 /* Set up device as PCI master and save state for EEH */
3123 pci_set_master(pdev);
3124 pci_try_set_mwi(pdev);
3125 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05003126
James Smart3772a992009-05-22 14:50:54 -04003127 return 0;
James Smart5b75da22008-12-04 22:39:35 -05003128
James Smart3772a992009-05-22 14:50:54 -04003129out_disable_device:
3130 pci_disable_device(pdev);
3131out_error:
3132 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05003133}
3134
3135/**
James Smart3772a992009-05-22 14:50:54 -04003136 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05003137 * @phba: pointer to lpfc hba data structure.
3138 *
James Smart3772a992009-05-22 14:50:54 -04003139 * This routine is invoked to disable the PCI device that is common to all
3140 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05003141 **/
3142static void
James Smart3772a992009-05-22 14:50:54 -04003143lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05003144{
James Smart3772a992009-05-22 14:50:54 -04003145 struct pci_dev *pdev;
3146 int bars;
James Smart5b75da22008-12-04 22:39:35 -05003147
James Smart3772a992009-05-22 14:50:54 -04003148 /* Obtain PCI device reference */
3149 if (!phba->pcidev)
3150 return;
3151 else
3152 pdev = phba->pcidev;
3153 /* Select PCI BARs */
3154 bars = pci_select_bars(pdev, IORESOURCE_MEM);
3155 /* Release PCI resource and disable PCI device */
3156 pci_release_selected_regions(pdev, bars);
3157 pci_disable_device(pdev);
3158 /* Null out PCI private reference to driver */
3159 pci_set_drvdata(pdev, NULL);
James Smart5b75da22008-12-04 22:39:35 -05003160
3161 return;
3162}
3163
3164/**
James Smart3772a992009-05-22 14:50:54 -04003165 * lpfc_reset_hba - Reset a hba
3166 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04003167 *
James Smart3772a992009-05-22 14:50:54 -04003168 * This routine is invoked to reset a hba device. It brings the HBA
3169 * offline, performs a board restart, and then brings the board back
3170 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
3171 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04003172 **/
James Smart3772a992009-05-22 14:50:54 -04003173void
3174lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003175{
James Smart3772a992009-05-22 14:50:54 -04003176 /* If resets are disabled then set error state and return. */
3177 if (!phba->cfg_enable_hba_reset) {
3178 phba->link_state = LPFC_HBA_ERROR;
3179 return;
3180 }
3181 lpfc_offline_prep(phba);
3182 lpfc_offline(phba);
3183 lpfc_sli_brdrestart(phba);
3184 lpfc_online(phba);
3185 lpfc_unblock_mgmt_io(phba);
3186}
dea31012005-04-17 16:05:31 -05003187
James Smart3772a992009-05-22 14:50:54 -04003188/**
3189 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
3190 * @phba: pointer to lpfc hba data structure.
3191 *
3192 * This routine is invoked to set up the driver internal resources specific to
3193 * support the SLI-3 HBA device it attached to.
3194 *
3195 * Return codes
3196 * 0 - sucessful
3197 * other values - error
3198 **/
3199static int
3200lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
3201{
3202 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05003203
James Smart3772a992009-05-22 14:50:54 -04003204 /*
3205 * Initialize timers used by driver
3206 */
dea31012005-04-17 16:05:31 -05003207
James Smart3772a992009-05-22 14:50:54 -04003208 /* Heartbeat timer */
3209 init_timer(&phba->hb_tmofunc);
3210 phba->hb_tmofunc.function = lpfc_hb_timeout;
3211 phba->hb_tmofunc.data = (unsigned long)phba;
3212
3213 psli = &phba->sli;
3214 /* MBOX heartbeat timer */
3215 init_timer(&psli->mbox_tmo);
3216 psli->mbox_tmo.function = lpfc_mbox_timeout;
3217 psli->mbox_tmo.data = (unsigned long) phba;
3218 /* FCP polling mode timer */
3219 init_timer(&phba->fcp_poll_timer);
3220 phba->fcp_poll_timer.function = lpfc_poll_timeout;
3221 phba->fcp_poll_timer.data = (unsigned long) phba;
3222 /* Fabric block timer */
3223 init_timer(&phba->fabric_block_timer);
3224 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
3225 phba->fabric_block_timer.data = (unsigned long) phba;
3226 /* EA polling mode timer */
3227 init_timer(&phba->eratt_poll);
3228 phba->eratt_poll.function = lpfc_poll_eratt;
3229 phba->eratt_poll.data = (unsigned long) phba;
3230
3231 /* Host attention work mask setup */
3232 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
3233 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
3234
3235 /* Get all the module params for configuring this host */
3236 lpfc_get_cfgparam(phba);
3237 /*
3238 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
3239 * used to create the sg_dma_buf_pool must be dynamically calculated.
3240 * 2 segments are added since the IOCB needs a command and response bde.
3241 */
3242 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
3243 sizeof(struct fcp_rsp) +
3244 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
3245
3246 if (phba->cfg_enable_bg) {
3247 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT;
3248 phba->cfg_sg_dma_buf_size +=
3249 phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64);
3250 }
3251
3252 /* Also reinitialize the host templates with new values. */
3253 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
3254 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
3255
3256 phba->max_vpi = LPFC_MAX_VPI;
3257 /* This will be set to correct value after config_port mbox */
3258 phba->max_vports = 0;
3259
3260 /*
3261 * Initialize the SLI Layer to run with lpfc HBAs.
3262 */
3263 lpfc_sli_setup(phba);
3264 lpfc_sli_queue_setup(phba);
3265
3266 /* Allocate device driver memory */
3267 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
3268 return -ENOMEM;
3269
3270 return 0;
3271}
3272
3273/**
3274 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
3275 * @phba: pointer to lpfc hba data structure.
3276 *
3277 * This routine is invoked to unset the driver internal resources set up
3278 * specific for supporting the SLI-3 HBA device it attached to.
3279 **/
3280static void
3281lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
3282{
3283 /* Free device driver memory allocated */
3284 lpfc_mem_free_all(phba);
3285
3286 return;
3287}
3288
3289/**
James Smartda0436e2009-05-22 14:51:39 -04003290 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
3291 * @phba: pointer to lpfc hba data structure.
3292 *
3293 * This routine is invoked to set up the driver internal resources specific to
3294 * support the SLI-4 HBA device it attached to.
3295 *
3296 * Return codes
3297 * 0 - sucessful
3298 * other values - error
3299 **/
3300static int
3301lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
3302{
3303 struct lpfc_sli *psli;
3304 int rc;
3305 int i, hbq_count;
3306
3307 /* Before proceed, wait for POST done and device ready */
3308 rc = lpfc_sli4_post_status_check(phba);
3309 if (rc)
3310 return -ENODEV;
3311
3312 /*
3313 * Initialize timers used by driver
3314 */
3315
3316 /* Heartbeat timer */
3317 init_timer(&phba->hb_tmofunc);
3318 phba->hb_tmofunc.function = lpfc_hb_timeout;
3319 phba->hb_tmofunc.data = (unsigned long)phba;
3320
3321 psli = &phba->sli;
3322 /* MBOX heartbeat timer */
3323 init_timer(&psli->mbox_tmo);
3324 psli->mbox_tmo.function = lpfc_mbox_timeout;
3325 psli->mbox_tmo.data = (unsigned long) phba;
3326 /* Fabric block timer */
3327 init_timer(&phba->fabric_block_timer);
3328 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
3329 phba->fabric_block_timer.data = (unsigned long) phba;
3330 /* EA polling mode timer */
3331 init_timer(&phba->eratt_poll);
3332 phba->eratt_poll.function = lpfc_poll_eratt;
3333 phba->eratt_poll.data = (unsigned long) phba;
3334 /*
3335 * We need to do a READ_CONFIG mailbox command here before
3336 * calling lpfc_get_cfgparam. For VFs this will report the
3337 * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings.
3338 * All of the resources allocated
3339 * for this Port are tied to these values.
3340 */
3341 /* Get all the module params for configuring this host */
3342 lpfc_get_cfgparam(phba);
3343 phba->max_vpi = LPFC_MAX_VPI;
3344 /* This will be set to correct value after the read_config mbox */
3345 phba->max_vports = 0;
3346
3347 /* Program the default value of vlan_id and fc_map */
3348 phba->valid_vlan = 0;
3349 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
3350 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
3351 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
3352
3353 /*
3354 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
3355 * used to create the sg_dma_buf_pool must be dynamically calculated.
3356 * 2 segments are added since the IOCB needs a command and response bde.
3357 * To insure that the scsi sgl does not cross a 4k page boundary only
3358 * sgl sizes of 1k, 2k, 4k, and 8k are supported.
3359 * Table of sgl sizes and seg_cnt:
3360 * sgl size, sg_seg_cnt total seg
3361 * 1k 50 52
3362 * 2k 114 116
3363 * 4k 242 244
3364 * 8k 498 500
3365 * cmd(32) + rsp(160) + (52 * sizeof(sli4_sge)) = 1024
3366 * cmd(32) + rsp(160) + (116 * sizeof(sli4_sge)) = 2048
3367 * cmd(32) + rsp(160) + (244 * sizeof(sli4_sge)) = 4096
3368 * cmd(32) + rsp(160) + (500 * sizeof(sli4_sge)) = 8192
3369 */
3370 if (phba->cfg_sg_seg_cnt <= LPFC_DEFAULT_SG_SEG_CNT)
3371 phba->cfg_sg_seg_cnt = 50;
3372 else if (phba->cfg_sg_seg_cnt <= 114)
3373 phba->cfg_sg_seg_cnt = 114;
3374 else if (phba->cfg_sg_seg_cnt <= 242)
3375 phba->cfg_sg_seg_cnt = 242;
3376 else
3377 phba->cfg_sg_seg_cnt = 498;
3378
3379 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd)
3380 + sizeof(struct fcp_rsp);
3381 phba->cfg_sg_dma_buf_size +=
3382 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge));
3383
3384 /* Initialize buffer queue management fields */
3385 hbq_count = lpfc_sli_hbq_count();
3386 for (i = 0; i < hbq_count; ++i)
3387 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
3388 INIT_LIST_HEAD(&phba->rb_pend_list);
3389 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
3390 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
3391
3392 /*
3393 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
3394 */
3395 /* Initialize the Abort scsi buffer list used by driver */
3396 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
3397 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
3398 /* This abort list used by worker thread */
3399 spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
3400
3401 /*
3402 * Initialize dirver internal slow-path work queues
3403 */
3404
3405 /* Driver internel slow-path CQ Event pool */
3406 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
3407 /* Response IOCB work queue list */
3408 INIT_LIST_HEAD(&phba->sli4_hba.sp_rspiocb_work_queue);
3409 /* Asynchronous event CQ Event work queue list */
3410 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
3411 /* Fast-path XRI aborted CQ Event work queue list */
3412 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
3413 /* Slow-path XRI aborted CQ Event work queue list */
3414 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
3415 /* Receive queue CQ Event work queue list */
3416 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
3417
3418 /* Initialize the driver internal SLI layer lists. */
3419 lpfc_sli_setup(phba);
3420 lpfc_sli_queue_setup(phba);
3421
3422 /* Allocate device driver memory */
3423 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
3424 if (rc)
3425 return -ENOMEM;
3426
3427 /* Create the bootstrap mailbox command */
3428 rc = lpfc_create_bootstrap_mbox(phba);
3429 if (unlikely(rc))
3430 goto out_free_mem;
3431
3432 /* Set up the host's endian order with the device. */
3433 rc = lpfc_setup_endian_order(phba);
3434 if (unlikely(rc))
3435 goto out_free_bsmbx;
3436
3437 /* Set up the hba's configuration parameters. */
3438 rc = lpfc_sli4_read_config(phba);
3439 if (unlikely(rc))
3440 goto out_free_bsmbx;
3441
3442 /* Perform a function reset */
3443 rc = lpfc_pci_function_reset(phba);
3444 if (unlikely(rc))
3445 goto out_free_bsmbx;
3446
3447 /* Create all the SLI4 queues */
3448 rc = lpfc_sli4_queue_create(phba);
3449 if (rc)
3450 goto out_free_bsmbx;
3451
3452 /* Create driver internal CQE event pool */
3453 rc = lpfc_sli4_cq_event_pool_create(phba);
3454 if (rc)
3455 goto out_destroy_queue;
3456
3457 /* Initialize and populate the iocb list per host */
3458 rc = lpfc_init_sgl_list(phba);
3459 if (rc) {
3460 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3461 "1400 Failed to initialize sgl list.\n");
3462 goto out_destroy_cq_event_pool;
3463 }
3464 rc = lpfc_init_active_sgl_array(phba);
3465 if (rc) {
3466 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3467 "1430 Failed to initialize sgl list.\n");
3468 goto out_free_sgl_list;
3469 }
3470
3471 rc = lpfc_sli4_init_rpi_hdrs(phba);
3472 if (rc) {
3473 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3474 "1432 Failed to initialize rpi headers.\n");
3475 goto out_free_active_sgl;
3476 }
3477
3478 phba->sli4_hba.fcp_eq_hdl = kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
3479 phba->cfg_fcp_eq_count), GFP_KERNEL);
3480 if (!phba->sli4_hba.fcp_eq_hdl) {
3481 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3482 "2572 Failed allocate memory for fast-path "
3483 "per-EQ handle array\n");
3484 goto out_remove_rpi_hdrs;
3485 }
3486
3487 phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
3488 phba->sli4_hba.cfg_eqn), GFP_KERNEL);
3489 if (!phba->sli4_hba.msix_entries) {
3490 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3491 "2573 Failed allocate memory for msi-x "
3492 "interrupt vector entries\n");
3493 goto out_free_fcp_eq_hdl;
3494 }
3495
3496 return rc;
3497
3498out_free_fcp_eq_hdl:
3499 kfree(phba->sli4_hba.fcp_eq_hdl);
3500out_remove_rpi_hdrs:
3501 lpfc_sli4_remove_rpi_hdrs(phba);
3502out_free_active_sgl:
3503 lpfc_free_active_sgl(phba);
3504out_free_sgl_list:
3505 lpfc_free_sgl_list(phba);
3506out_destroy_cq_event_pool:
3507 lpfc_sli4_cq_event_pool_destroy(phba);
3508out_destroy_queue:
3509 lpfc_sli4_queue_destroy(phba);
3510out_free_bsmbx:
3511 lpfc_destroy_bootstrap_mbox(phba);
3512out_free_mem:
3513 lpfc_mem_free(phba);
3514 return rc;
3515}
3516
3517/**
3518 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
3519 * @phba: pointer to lpfc hba data structure.
3520 *
3521 * This routine is invoked to unset the driver internal resources set up
3522 * specific for supporting the SLI-4 HBA device it attached to.
3523 **/
3524static void
3525lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
3526{
3527 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
3528
3529 /* unregister default FCFI from the HBA */
3530 lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
3531
3532 /* Free the default FCR table */
3533 lpfc_sli_remove_dflt_fcf(phba);
3534
3535 /* Free memory allocated for msi-x interrupt vector entries */
3536 kfree(phba->sli4_hba.msix_entries);
3537
3538 /* Free memory allocated for fast-path work queue handles */
3539 kfree(phba->sli4_hba.fcp_eq_hdl);
3540
3541 /* Free the allocated rpi headers. */
3542 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04003543 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04003544
3545 /* Free the ELS sgl list */
3546 lpfc_free_active_sgl(phba);
3547 lpfc_free_sgl_list(phba);
3548
3549 /* Free the SCSI sgl management array */
3550 kfree(phba->sli4_hba.lpfc_scsi_psb_array);
3551
3552 /* Free the SLI4 queues */
3553 lpfc_sli4_queue_destroy(phba);
3554
3555 /* Free the completion queue EQ event pool */
3556 lpfc_sli4_cq_event_release_all(phba);
3557 lpfc_sli4_cq_event_pool_destroy(phba);
3558
3559 /* Reset SLI4 HBA FCoE function */
3560 lpfc_pci_function_reset(phba);
3561
3562 /* Free the bsmbx region. */
3563 lpfc_destroy_bootstrap_mbox(phba);
3564
3565 /* Free the SLI Layer memory with SLI4 HBAs */
3566 lpfc_mem_free_all(phba);
3567
3568 /* Free the current connect table */
3569 list_for_each_entry_safe(conn_entry, next_conn_entry,
3570 &phba->fcf_conn_rec_list, list)
3571 kfree(conn_entry);
3572
3573 return;
3574}
3575
3576/**
James Smart3772a992009-05-22 14:50:54 -04003577 * lpfc_init_api_table_setup - Set up init api fucntion jump table
3578 * @phba: The hba struct for which this call is being executed.
3579 * @dev_grp: The HBA PCI-Device group number.
3580 *
3581 * This routine sets up the device INIT interface API function jump table
3582 * in @phba struct.
3583 *
3584 * Returns: 0 - success, -ENODEV - failure.
3585 **/
3586int
3587lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
3588{
3589 switch (dev_grp) {
3590 case LPFC_PCI_DEV_LP:
3591 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
3592 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
3593 phba->lpfc_stop_port = lpfc_stop_port_s3;
3594 break;
James Smartda0436e2009-05-22 14:51:39 -04003595 case LPFC_PCI_DEV_OC:
3596 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
3597 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
3598 phba->lpfc_stop_port = lpfc_stop_port_s4;
3599 break;
James Smart3772a992009-05-22 14:50:54 -04003600 default:
3601 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3602 "1431 Invalid HBA PCI-device group: 0x%x\n",
3603 dev_grp);
3604 return -ENODEV;
3605 break;
3606 }
3607 return 0;
3608}
3609
3610/**
3611 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
3612 * @phba: pointer to lpfc hba data structure.
3613 *
3614 * This routine is invoked to set up the driver internal resources before the
3615 * device specific resource setup to support the HBA device it attached to.
3616 *
3617 * Return codes
3618 * 0 - sucessful
3619 * other values - error
3620 **/
3621static int
3622lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
3623{
3624 /*
3625 * Driver resources common to all SLI revisions
3626 */
James Smartea2151b2008-09-07 11:52:10 -04003627 atomic_set(&phba->fast_event_count, 0);
James Smart2e0fef82007-06-17 19:56:36 -05003628 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003629
James Smarte47c9092008-02-08 18:49:26 -05003630 /* Initialize ndlp management spinlock */
3631 spin_lock_init(&phba->ndlp_lock);
3632
James Smart2e0fef82007-06-17 19:56:36 -05003633 INIT_LIST_HEAD(&phba->port_list);
James Smart3772a992009-05-22 14:50:54 -04003634 INIT_LIST_HEAD(&phba->work_list);
James Smart84774a42008-08-24 21:50:06 -04003635 init_waitqueue_head(&phba->wait_4_mlo_m_q);
dea31012005-04-17 16:05:31 -05003636
James Smart3772a992009-05-22 14:50:54 -04003637 /* Initialize the wait queue head for the kernel thread */
3638 init_waitqueue_head(&phba->work_waitq);
James Smart858c9f62007-06-17 19:56:39 -05003639
James Smart3772a992009-05-22 14:50:54 -04003640 /* Initialize the scsi buffer list used by driver for scsi IO */
3641 spin_lock_init(&phba->scsi_buf_list_lock);
3642 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
dea31012005-04-17 16:05:31 -05003643
James Smart3772a992009-05-22 14:50:54 -04003644 /* Initialize the fabric iocb list */
3645 INIT_LIST_HEAD(&phba->fabric_iocb_list);
dea31012005-04-17 16:05:31 -05003646
James Smart3772a992009-05-22 14:50:54 -04003647 /* Initialize list to save ELS buffers */
3648 INIT_LIST_HEAD(&phba->elsbuf);
dea31012005-04-17 16:05:31 -05003649
James Smart3772a992009-05-22 14:50:54 -04003650 /* Initialize FCF connection rec list */
3651 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
dea31012005-04-17 16:05:31 -05003652
James Smart3772a992009-05-22 14:50:54 -04003653 return 0;
3654}
dea31012005-04-17 16:05:31 -05003655
James Smart3772a992009-05-22 14:50:54 -04003656/**
3657 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
3658 * @phba: pointer to lpfc hba data structure.
3659 *
3660 * This routine is invoked to set up the driver internal resources after the
3661 * device specific resource setup to support the HBA device it attached to.
3662 *
3663 * Return codes
3664 * 0 - sucessful
3665 * other values - error
3666 **/
3667static int
3668lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
3669{
3670 int error;
3671
3672 /* Startup the kernel thread for this host adapter. */
3673 phba->worker_thread = kthread_run(lpfc_do_work, phba,
3674 "lpfc_worker_%d", phba->brd_no);
3675 if (IS_ERR(phba->worker_thread)) {
3676 error = PTR_ERR(phba->worker_thread);
3677 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05003678 }
3679
James Smart3772a992009-05-22 14:50:54 -04003680 return 0;
3681}
3682
3683/**
3684 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
3685 * @phba: pointer to lpfc hba data structure.
3686 *
3687 * This routine is invoked to unset the driver internal resources set up after
3688 * the device specific resource setup for supporting the HBA device it
3689 * attached to.
3690 **/
3691static void
3692lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
3693{
3694 /* Stop kernel worker thread */
3695 kthread_stop(phba->worker_thread);
3696}
3697
3698/**
3699 * lpfc_free_iocb_list - Free iocb list.
3700 * @phba: pointer to lpfc hba data structure.
3701 *
3702 * This routine is invoked to free the driver's IOCB list and memory.
3703 **/
3704static void
3705lpfc_free_iocb_list(struct lpfc_hba *phba)
3706{
3707 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
3708
3709 spin_lock_irq(&phba->hbalock);
3710 list_for_each_entry_safe(iocbq_entry, iocbq_next,
3711 &phba->lpfc_iocb_list, list) {
3712 list_del(&iocbq_entry->list);
3713 kfree(iocbq_entry);
3714 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05003715 }
James Smart3772a992009-05-22 14:50:54 -04003716 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003717
James Smart3772a992009-05-22 14:50:54 -04003718 return;
3719}
dea31012005-04-17 16:05:31 -05003720
James Smart3772a992009-05-22 14:50:54 -04003721/**
3722 * lpfc_init_iocb_list - Allocate and initialize iocb list.
3723 * @phba: pointer to lpfc hba data structure.
3724 *
3725 * This routine is invoked to allocate and initizlize the driver's IOCB
3726 * list and set up the IOCB tag array accordingly.
3727 *
3728 * Return codes
3729 * 0 - sucessful
3730 * other values - error
3731 **/
3732static int
3733lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
3734{
3735 struct lpfc_iocbq *iocbq_entry = NULL;
3736 uint16_t iotag;
3737 int i;
dea31012005-04-17 16:05:31 -05003738
3739 /* Initialize and populate the iocb list per host. */
3740 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04003741 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07003742 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05003743 if (iocbq_entry == NULL) {
3744 printk(KERN_ERR "%s: only allocated %d iocbs of "
3745 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07003746 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05003747 goto out_free_iocbq;
3748 }
3749
James Bottomley604a3e32005-10-29 10:28:33 -05003750 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
3751 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04003752 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05003753 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04003754 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05003755 goto out_free_iocbq;
3756 }
James Smart3772a992009-05-22 14:50:54 -04003757 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05003758
3759 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003760 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
3761 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05003762 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003763 }
3764
James Smart3772a992009-05-22 14:50:54 -04003765 return 0;
3766
3767out_free_iocbq:
3768 lpfc_free_iocb_list(phba);
3769
3770 return -ENOMEM;
3771}
3772
3773/**
James Smartda0436e2009-05-22 14:51:39 -04003774 * lpfc_free_sgl_list - Free sgl list.
3775 * @phba: pointer to lpfc hba data structure.
3776 *
3777 * This routine is invoked to free the driver's sgl list and memory.
3778 **/
3779static void
3780lpfc_free_sgl_list(struct lpfc_hba *phba)
3781{
3782 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
3783 LIST_HEAD(sglq_list);
3784 int rc = 0;
3785
3786 spin_lock_irq(&phba->hbalock);
3787 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
3788 spin_unlock_irq(&phba->hbalock);
3789
3790 list_for_each_entry_safe(sglq_entry, sglq_next,
3791 &sglq_list, list) {
3792 list_del(&sglq_entry->list);
3793 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
3794 kfree(sglq_entry);
3795 phba->sli4_hba.total_sglq_bufs--;
3796 }
3797 rc = lpfc_sli4_remove_all_sgl_pages(phba);
3798 if (rc) {
3799 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3800 "2005 Unable to deregister pages from HBA: %x", rc);
3801 }
3802 kfree(phba->sli4_hba.lpfc_els_sgl_array);
3803}
3804
3805/**
3806 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
3807 * @phba: pointer to lpfc hba data structure.
3808 *
3809 * This routine is invoked to allocate the driver's active sgl memory.
3810 * This array will hold the sglq_entry's for active IOs.
3811 **/
3812static int
3813lpfc_init_active_sgl_array(struct lpfc_hba *phba)
3814{
3815 int size;
3816 size = sizeof(struct lpfc_sglq *);
3817 size *= phba->sli4_hba.max_cfg_param.max_xri;
3818
3819 phba->sli4_hba.lpfc_sglq_active_list =
3820 kzalloc(size, GFP_KERNEL);
3821 if (!phba->sli4_hba.lpfc_sglq_active_list)
3822 return -ENOMEM;
3823 return 0;
3824}
3825
3826/**
3827 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
3828 * @phba: pointer to lpfc hba data structure.
3829 *
3830 * This routine is invoked to walk through the array of active sglq entries
3831 * and free all of the resources.
3832 * This is just a place holder for now.
3833 **/
3834static void
3835lpfc_free_active_sgl(struct lpfc_hba *phba)
3836{
3837 kfree(phba->sli4_hba.lpfc_sglq_active_list);
3838}
3839
3840/**
3841 * lpfc_init_sgl_list - Allocate and initialize sgl list.
3842 * @phba: pointer to lpfc hba data structure.
3843 *
3844 * This routine is invoked to allocate and initizlize the driver's sgl
3845 * list and set up the sgl xritag tag array accordingly.
3846 *
3847 * Return codes
3848 * 0 - sucessful
3849 * other values - error
3850 **/
3851static int
3852lpfc_init_sgl_list(struct lpfc_hba *phba)
3853{
3854 struct lpfc_sglq *sglq_entry = NULL;
3855 int i;
3856 int els_xri_cnt;
3857
3858 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3859 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3860 "2400 lpfc_init_sgl_list els %d.\n",
3861 els_xri_cnt);
3862 /* Initialize and populate the sglq list per host/VF. */
3863 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
3864 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
3865
3866 /* Sanity check on XRI management */
3867 if (phba->sli4_hba.max_cfg_param.max_xri <= els_xri_cnt) {
3868 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3869 "2562 No room left for SCSI XRI allocation: "
3870 "max_xri=%d, els_xri=%d\n",
3871 phba->sli4_hba.max_cfg_param.max_xri,
3872 els_xri_cnt);
3873 return -ENOMEM;
3874 }
3875
3876 /* Allocate memory for the ELS XRI management array */
3877 phba->sli4_hba.lpfc_els_sgl_array =
3878 kzalloc((sizeof(struct lpfc_sglq *) * els_xri_cnt),
3879 GFP_KERNEL);
3880
3881 if (!phba->sli4_hba.lpfc_els_sgl_array) {
3882 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3883 "2401 Failed to allocate memory for ELS "
3884 "XRI management array of size %d.\n",
3885 els_xri_cnt);
3886 return -ENOMEM;
3887 }
3888
3889 /* Keep the SCSI XRI into the XRI management array */
3890 phba->sli4_hba.scsi_xri_max =
3891 phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3892 phba->sli4_hba.scsi_xri_cnt = 0;
3893
3894 phba->sli4_hba.lpfc_scsi_psb_array =
3895 kzalloc((sizeof(struct lpfc_scsi_buf *) *
3896 phba->sli4_hba.scsi_xri_max), GFP_KERNEL);
3897
3898 if (!phba->sli4_hba.lpfc_scsi_psb_array) {
3899 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3900 "2563 Failed to allocate memory for SCSI "
3901 "XRI management array of size %d.\n",
3902 phba->sli4_hba.scsi_xri_max);
3903 kfree(phba->sli4_hba.lpfc_els_sgl_array);
3904 return -ENOMEM;
3905 }
3906
3907 for (i = 0; i < els_xri_cnt; i++) {
3908 sglq_entry = kzalloc(sizeof(struct lpfc_sglq), GFP_KERNEL);
3909 if (sglq_entry == NULL) {
3910 printk(KERN_ERR "%s: only allocated %d sgls of "
3911 "expected %d count. Unloading driver.\n",
3912 __func__, i, els_xri_cnt);
3913 goto out_free_mem;
3914 }
3915
3916 sglq_entry->sli4_xritag = lpfc_sli4_next_xritag(phba);
3917 if (sglq_entry->sli4_xritag == NO_XRI) {
3918 kfree(sglq_entry);
3919 printk(KERN_ERR "%s: failed to allocate XRI.\n"
3920 "Unloading driver.\n", __func__);
3921 goto out_free_mem;
3922 }
3923 sglq_entry->buff_type = GEN_BUFF_TYPE;
3924 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, &sglq_entry->phys);
3925 if (sglq_entry->virt == NULL) {
3926 kfree(sglq_entry);
3927 printk(KERN_ERR "%s: failed to allocate mbuf.\n"
3928 "Unloading driver.\n", __func__);
3929 goto out_free_mem;
3930 }
3931 sglq_entry->sgl = sglq_entry->virt;
3932 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3933
3934 /* The list order is used by later block SGL registraton */
3935 spin_lock_irq(&phba->hbalock);
3936 list_add_tail(&sglq_entry->list, &phba->sli4_hba.lpfc_sgl_list);
3937 phba->sli4_hba.lpfc_els_sgl_array[i] = sglq_entry;
3938 phba->sli4_hba.total_sglq_bufs++;
3939 spin_unlock_irq(&phba->hbalock);
3940 }
3941 return 0;
3942
3943out_free_mem:
3944 kfree(phba->sli4_hba.lpfc_scsi_psb_array);
3945 lpfc_free_sgl_list(phba);
3946 return -ENOMEM;
3947}
3948
3949/**
3950 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
3951 * @phba: pointer to lpfc hba data structure.
3952 *
3953 * This routine is invoked to post rpi header templates to the
3954 * HBA consistent with the SLI-4 interface spec. This routine
3955 * posts a PAGE_SIZE memory region to the port to hold up to
3956 * PAGE_SIZE modulo 64 rpi context headers.
3957 * No locks are held here because this is an initialization routine
3958 * called only from probe or lpfc_online when interrupts are not
3959 * enabled and the driver is reinitializing the device.
3960 *
3961 * Return codes
3962 * 0 - sucessful
3963 * ENOMEM - No availble memory
3964 * EIO - The mailbox failed to complete successfully.
3965 **/
3966int
3967lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
3968{
3969 int rc = 0;
3970 int longs;
3971 uint16_t rpi_count;
3972 struct lpfc_rpi_hdr *rpi_hdr;
3973
3974 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
3975
3976 /*
3977 * Provision an rpi bitmask range for discovery. The total count
3978 * is the difference between max and base + 1.
3979 */
3980 rpi_count = phba->sli4_hba.max_cfg_param.rpi_base +
3981 phba->sli4_hba.max_cfg_param.max_rpi - 1;
3982
3983 longs = ((rpi_count) + BITS_PER_LONG - 1) / BITS_PER_LONG;
3984 phba->sli4_hba.rpi_bmask = kzalloc(longs * sizeof(unsigned long),
3985 GFP_KERNEL);
3986 if (!phba->sli4_hba.rpi_bmask)
3987 return -ENOMEM;
3988
3989 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
3990 if (!rpi_hdr) {
3991 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
3992 "0391 Error during rpi post operation\n");
3993 lpfc_sli4_remove_rpis(phba);
3994 rc = -ENODEV;
3995 }
3996
3997 return rc;
3998}
3999
4000/**
4001 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
4002 * @phba: pointer to lpfc hba data structure.
4003 *
4004 * This routine is invoked to allocate a single 4KB memory region to
4005 * support rpis and stores them in the phba. This single region
4006 * provides support for up to 64 rpis. The region is used globally
4007 * by the device.
4008 *
4009 * Returns:
4010 * A valid rpi hdr on success.
4011 * A NULL pointer on any failure.
4012 **/
4013struct lpfc_rpi_hdr *
4014lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
4015{
4016 uint16_t rpi_limit, curr_rpi_range;
4017 struct lpfc_dmabuf *dmabuf;
4018 struct lpfc_rpi_hdr *rpi_hdr;
4019
4020 rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
4021 phba->sli4_hba.max_cfg_param.max_rpi - 1;
4022
4023 spin_lock_irq(&phba->hbalock);
4024 curr_rpi_range = phba->sli4_hba.next_rpi;
4025 spin_unlock_irq(&phba->hbalock);
4026
4027 /*
4028 * The port has a limited number of rpis. The increment here
4029 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
4030 * and to allow the full max_rpi range per port.
4031 */
4032 if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
4033 return NULL;
4034
4035 /*
4036 * First allocate the protocol header region for the port. The
4037 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
4038 */
4039 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4040 if (!dmabuf)
4041 return NULL;
4042
4043 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
4044 LPFC_HDR_TEMPLATE_SIZE,
4045 &dmabuf->phys,
4046 GFP_KERNEL);
4047 if (!dmabuf->virt) {
4048 rpi_hdr = NULL;
4049 goto err_free_dmabuf;
4050 }
4051
4052 memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE);
4053 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
4054 rpi_hdr = NULL;
4055 goto err_free_coherent;
4056 }
4057
4058 /* Save the rpi header data for cleanup later. */
4059 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
4060 if (!rpi_hdr)
4061 goto err_free_coherent;
4062
4063 rpi_hdr->dmabuf = dmabuf;
4064 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
4065 rpi_hdr->page_count = 1;
4066 spin_lock_irq(&phba->hbalock);
4067 rpi_hdr->start_rpi = phba->sli4_hba.next_rpi;
4068 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
4069
4070 /*
4071 * The next_rpi stores the next module-64 rpi value to post
4072 * in any subsequent rpi memory region postings.
4073 */
4074 phba->sli4_hba.next_rpi += LPFC_RPI_HDR_COUNT;
4075 spin_unlock_irq(&phba->hbalock);
4076 return rpi_hdr;
4077
4078 err_free_coherent:
4079 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
4080 dmabuf->virt, dmabuf->phys);
4081 err_free_dmabuf:
4082 kfree(dmabuf);
4083 return NULL;
4084}
4085
4086/**
4087 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
4088 * @phba: pointer to lpfc hba data structure.
4089 *
4090 * This routine is invoked to remove all memory resources allocated
4091 * to support rpis. This routine presumes the caller has released all
4092 * rpis consumed by fabric or port logins and is prepared to have
4093 * the header pages removed.
4094 **/
4095void
4096lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
4097{
4098 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
4099
4100 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
4101 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
4102 list_del(&rpi_hdr->list);
4103 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
4104 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
4105 kfree(rpi_hdr->dmabuf);
4106 kfree(rpi_hdr);
4107 }
4108
4109 phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base;
4110 memset(phba->sli4_hba.rpi_bmask, 0, sizeof(*phba->sli4_hba.rpi_bmask));
4111}
4112
4113/**
James Smart3772a992009-05-22 14:50:54 -04004114 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
4115 * @pdev: pointer to pci device data structure.
4116 *
4117 * This routine is invoked to allocate the driver hba data structure for an
4118 * HBA device. If the allocation is successful, the phba reference to the
4119 * PCI device data structure is set.
4120 *
4121 * Return codes
4122 * pointer to @phba - sucessful
4123 * NULL - error
4124 **/
4125static struct lpfc_hba *
4126lpfc_hba_alloc(struct pci_dev *pdev)
4127{
4128 struct lpfc_hba *phba;
4129
4130 /* Allocate memory for HBA structure */
4131 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
4132 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02004133 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04004134 return NULL;
4135 }
4136
4137 /* Set reference to PCI device in HBA structure */
4138 phba->pcidev = pdev;
4139
4140 /* Assign an unused board number */
4141 phba->brd_no = lpfc_get_instance();
4142 if (phba->brd_no < 0) {
4143 kfree(phba);
4144 return NULL;
4145 }
4146
4147 return phba;
4148}
4149
4150/**
4151 * lpfc_hba_free - Free driver hba data structure with a device.
4152 * @phba: pointer to lpfc hba data structure.
4153 *
4154 * This routine is invoked to free the driver hba data structure with an
4155 * HBA device.
4156 **/
4157static void
4158lpfc_hba_free(struct lpfc_hba *phba)
4159{
4160 /* Release the driver assigned board number */
4161 idr_remove(&lpfc_hba_index, phba->brd_no);
4162
4163 kfree(phba);
4164 return;
4165}
4166
4167/**
4168 * lpfc_create_shost - Create hba physical port with associated scsi host.
4169 * @phba: pointer to lpfc hba data structure.
4170 *
4171 * This routine is invoked to create HBA physical port and associate a SCSI
4172 * host with it.
4173 *
4174 * Return codes
4175 * 0 - sucessful
4176 * other values - error
4177 **/
4178static int
4179lpfc_create_shost(struct lpfc_hba *phba)
4180{
4181 struct lpfc_vport *vport;
4182 struct Scsi_Host *shost;
4183
4184 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05004185 phba->fc_edtov = FF_DEF_EDTOV;
4186 phba->fc_ratov = FF_DEF_RATOV;
4187 phba->fc_altov = FF_DEF_ALTOV;
4188 phba->fc_arbtov = FF_DEF_ARBTOV;
4189
James Smart3de2a652007-08-02 11:09:59 -04004190 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05004191 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04004192 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05004193
4194 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004195 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05004196 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04004197 /* Put reference to SCSI host to driver's device private data */
4198 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05004199
James Smart3772a992009-05-22 14:50:54 -04004200 return 0;
4201}
dea31012005-04-17 16:05:31 -05004202
James Smart3772a992009-05-22 14:50:54 -04004203/**
4204 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
4205 * @phba: pointer to lpfc hba data structure.
4206 *
4207 * This routine is invoked to destroy HBA physical port and the associated
4208 * SCSI host.
4209 **/
4210static void
4211lpfc_destroy_shost(struct lpfc_hba *phba)
4212{
4213 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04004214
James Smart3772a992009-05-22 14:50:54 -04004215 /* Destroy physical port that associated with the SCSI host */
4216 destroy_port(vport);
4217
4218 return;
4219}
4220
4221/**
4222 * lpfc_setup_bg - Setup Block guard structures and debug areas.
4223 * @phba: pointer to lpfc hba data structure.
4224 * @shost: the shost to be used to detect Block guard settings.
4225 *
4226 * This routine sets up the local Block guard protocol settings for @shost.
4227 * This routine also allocates memory for debugging bg buffers.
4228 **/
4229static void
4230lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
4231{
4232 int pagecnt = 10;
4233 if (lpfc_prot_mask && lpfc_prot_guard) {
4234 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4235 "1478 Registering BlockGuard with the "
4236 "SCSI layer\n");
4237 scsi_host_set_prot(shost, lpfc_prot_mask);
4238 scsi_host_set_guard(shost, lpfc_prot_guard);
James Smart98c9ea52007-10-27 13:37:33 -04004239 }
James Smart81301a92008-12-04 22:39:46 -05004240 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05004241 while (pagecnt) {
4242 spin_lock_init(&_dump_buf_lock);
4243 _dump_buf_data =
4244 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
4245 if (_dump_buf_data) {
4246 printk(KERN_ERR "BLKGRD allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04004247 "_dump_buf_data at 0x%p\n",
4248 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05004249 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04004250 memset(_dump_buf_data, 0,
4251 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05004252 break;
James Smart3772a992009-05-22 14:50:54 -04004253 } else
James Smart81301a92008-12-04 22:39:46 -05004254 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05004255 }
James Smart81301a92008-12-04 22:39:46 -05004256 if (!_dump_buf_data_order)
4257 printk(KERN_ERR "BLKGRD ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04004258 "memory for hexdump\n");
4259 } else
James Smart81301a92008-12-04 22:39:46 -05004260 printk(KERN_ERR "BLKGRD already allocated _dump_buf_data=0x%p"
4261 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05004262 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05004263 while (pagecnt) {
4264 _dump_buf_dif =
4265 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
4266 if (_dump_buf_dif) {
4267 printk(KERN_ERR "BLKGRD allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04004268 "_dump_buf_dif at 0x%p\n",
4269 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05004270 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04004271 memset(_dump_buf_dif, 0,
4272 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05004273 break;
James Smart3772a992009-05-22 14:50:54 -04004274 } else
James Smart81301a92008-12-04 22:39:46 -05004275 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05004276 }
James Smart81301a92008-12-04 22:39:46 -05004277 if (!_dump_buf_dif_order)
4278 printk(KERN_ERR "BLKGRD ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04004279 "memory for hexdump\n");
4280 } else
James Smart81301a92008-12-04 22:39:46 -05004281 printk(KERN_ERR "BLKGRD already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04004282 _dump_buf_dif);
4283}
4284
4285/**
4286 * lpfc_post_init_setup - Perform necessary device post initialization setup.
4287 * @phba: pointer to lpfc hba data structure.
4288 *
4289 * This routine is invoked to perform all the necessary post initialization
4290 * setup for the device.
4291 **/
4292static void
4293lpfc_post_init_setup(struct lpfc_hba *phba)
4294{
4295 struct Scsi_Host *shost;
4296 struct lpfc_adapter_event_header adapter_event;
4297
4298 /* Get the default values for Model Name and Description */
4299 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
4300
4301 /*
4302 * hba setup may have changed the hba_queue_depth so we need to
4303 * adjust the value of can_queue.
4304 */
4305 shost = pci_get_drvdata(phba->pcidev);
4306 shost->can_queue = phba->cfg_hba_queue_depth - 10;
4307 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
4308 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05004309
4310 lpfc_host_attrib_init(shost);
4311
James Smart2e0fef82007-06-17 19:56:36 -05004312 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
4313 spin_lock_irq(shost->host_lock);
4314 lpfc_poll_start_timer(phba);
4315 spin_unlock_irq(shost->host_lock);
4316 }
James Smart8f6d98d2006-08-01 07:34:00 -04004317
James Smart93996272008-08-24 21:50:30 -04004318 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4319 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04004320 /* Send board arrival event to upper layer */
4321 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
4322 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
4323 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04004324 sizeof(adapter_event),
4325 (char *) &adapter_event,
4326 LPFC_NL_VENDOR_ID);
4327 return;
4328}
4329
4330/**
4331 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
4332 * @phba: pointer to lpfc hba data structure.
4333 *
4334 * This routine is invoked to set up the PCI device memory space for device
4335 * with SLI-3 interface spec.
4336 *
4337 * Return codes
4338 * 0 - sucessful
4339 * other values - error
4340 **/
4341static int
4342lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
4343{
4344 struct pci_dev *pdev;
4345 unsigned long bar0map_len, bar2map_len;
4346 int i, hbq_count;
4347 void *ptr;
4348 int error = -ENODEV;
4349
4350 /* Obtain PCI device reference */
4351 if (!phba->pcidev)
4352 return error;
4353 else
4354 pdev = phba->pcidev;
4355
4356 /* Set the device DMA mask size */
4357 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)
4358 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0)
4359 return error;
4360
4361 /* Get the bus address of Bar0 and Bar2 and the number of bytes
4362 * required by each mapping.
4363 */
4364 phba->pci_bar0_map = pci_resource_start(pdev, 0);
4365 bar0map_len = pci_resource_len(pdev, 0);
4366
4367 phba->pci_bar2_map = pci_resource_start(pdev, 2);
4368 bar2map_len = pci_resource_len(pdev, 2);
4369
4370 /* Map HBA SLIM to a kernel virtual address. */
4371 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
4372 if (!phba->slim_memmap_p) {
4373 dev_printk(KERN_ERR, &pdev->dev,
4374 "ioremap failed for SLIM memory.\n");
4375 goto out;
4376 }
4377
4378 /* Map HBA Control Registers to a kernel virtual address. */
4379 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
4380 if (!phba->ctrl_regs_memmap_p) {
4381 dev_printk(KERN_ERR, &pdev->dev,
4382 "ioremap failed for HBA control registers.\n");
4383 goto out_iounmap_slim;
4384 }
4385
4386 /* Allocate memory for SLI-2 structures */
4387 phba->slim2p.virt = dma_alloc_coherent(&pdev->dev,
4388 SLI2_SLIM_SIZE,
4389 &phba->slim2p.phys,
4390 GFP_KERNEL);
4391 if (!phba->slim2p.virt)
4392 goto out_iounmap;
4393
4394 memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
4395 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
4396 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
4397 phba->IOCBs = (phba->slim2p.virt +
4398 offsetof(struct lpfc_sli2_slim, IOCBs));
4399
4400 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
4401 lpfc_sli_hbq_size(),
4402 &phba->hbqslimp.phys,
4403 GFP_KERNEL);
4404 if (!phba->hbqslimp.virt)
4405 goto out_free_slim;
4406
4407 hbq_count = lpfc_sli_hbq_count();
4408 ptr = phba->hbqslimp.virt;
4409 for (i = 0; i < hbq_count; ++i) {
4410 phba->hbqs[i].hbq_virt = ptr;
4411 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
4412 ptr += (lpfc_hbq_defs[i]->entry_count *
4413 sizeof(struct lpfc_hbq_entry));
4414 }
4415 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
4416 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
4417
4418 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
4419
4420 INIT_LIST_HEAD(&phba->rb_pend_list);
4421
4422 phba->MBslimaddr = phba->slim_memmap_p;
4423 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
4424 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
4425 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
4426 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04004427
dea31012005-04-17 16:05:31 -05004428 return 0;
4429
dea31012005-04-17 16:05:31 -05004430out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04004431 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
4432 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05004433out_iounmap:
4434 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05004435out_iounmap_slim:
dea31012005-04-17 16:05:31 -05004436 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05004437out:
4438 return error;
4439}
4440
James Smarte59058c2008-08-24 21:49:00 -04004441/**
James Smart3772a992009-05-22 14:50:54 -04004442 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
4443 * @phba: pointer to lpfc hba data structure.
4444 *
4445 * This routine is invoked to unset the PCI device memory space for device
4446 * with SLI-3 interface spec.
4447 **/
4448static void
4449lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
4450{
4451 struct pci_dev *pdev;
4452
4453 /* Obtain PCI device reference */
4454 if (!phba->pcidev)
4455 return;
4456 else
4457 pdev = phba->pcidev;
4458
4459 /* Free coherent DMA memory allocated */
4460 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
4461 phba->hbqslimp.virt, phba->hbqslimp.phys);
4462 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
4463 phba->slim2p.virt, phba->slim2p.phys);
4464
4465 /* I/O memory unmap */
4466 iounmap(phba->ctrl_regs_memmap_p);
4467 iounmap(phba->slim_memmap_p);
4468
4469 return;
4470}
4471
4472/**
James Smartda0436e2009-05-22 14:51:39 -04004473 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
4474 * @phba: pointer to lpfc hba data structure.
4475 *
4476 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
4477 * done and check status.
4478 *
4479 * Return 0 if successful, otherwise -ENODEV.
4480 **/
4481int
4482lpfc_sli4_post_status_check(struct lpfc_hba *phba)
4483{
4484 struct lpfc_register sta_reg, uerrlo_reg, uerrhi_reg, scratchpad;
4485 uint32_t onlnreg0, onlnreg1;
4486 int i, port_error = -ENODEV;
4487
4488 if (!phba->sli4_hba.STAregaddr)
4489 return -ENODEV;
4490
James Smartda0436e2009-05-22 14:51:39 -04004491 /* Wait up to 30 seconds for the SLI Port POST done and ready */
4492 for (i = 0; i < 3000; i++) {
4493 sta_reg.word0 = readl(phba->sli4_hba.STAregaddr);
4494 /* Encounter fatal POST error, break out */
4495 if (bf_get(lpfc_hst_state_perr, &sta_reg)) {
4496 port_error = -ENODEV;
4497 break;
4498 }
4499 if (LPFC_POST_STAGE_ARMFW_READY ==
4500 bf_get(lpfc_hst_state_port_status, &sta_reg)) {
4501 port_error = 0;
4502 break;
4503 }
4504 msleep(10);
4505 }
4506
4507 if (port_error)
4508 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4509 "1408 Failure HBA POST Status: sta_reg=0x%x, "
4510 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, xrom=x%x, "
4511 "dl=x%x, pstatus=x%x\n", sta_reg.word0,
4512 bf_get(lpfc_hst_state_perr, &sta_reg),
4513 bf_get(lpfc_hst_state_sfi, &sta_reg),
4514 bf_get(lpfc_hst_state_nip, &sta_reg),
4515 bf_get(lpfc_hst_state_ipc, &sta_reg),
4516 bf_get(lpfc_hst_state_xrom, &sta_reg),
4517 bf_get(lpfc_hst_state_dl, &sta_reg),
4518 bf_get(lpfc_hst_state_port_status, &sta_reg));
4519
4520 /* Log device information */
4521 scratchpad.word0 = readl(phba->sli4_hba.SCRATCHPADregaddr);
4522 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4523 "2534 Device Info: ChipType=0x%x, SliRev=0x%x, "
4524 "FeatureL1=0x%x, FeatureL2=0x%x\n",
4525 bf_get(lpfc_scratchpad_chiptype, &scratchpad),
4526 bf_get(lpfc_scratchpad_slirev, &scratchpad),
4527 bf_get(lpfc_scratchpad_featurelevel1, &scratchpad),
4528 bf_get(lpfc_scratchpad_featurelevel2, &scratchpad));
4529
James Smart8fa38512009-07-19 10:01:03 -04004530 /* With uncoverable error, log the error message and return error */
4531 onlnreg0 = readl(phba->sli4_hba.ONLINE0regaddr);
4532 onlnreg1 = readl(phba->sli4_hba.ONLINE1regaddr);
4533 if ((onlnreg0 != LPFC_ONLINE_NERR) || (onlnreg1 != LPFC_ONLINE_NERR)) {
4534 uerrlo_reg.word0 = readl(phba->sli4_hba.UERRLOregaddr);
4535 uerrhi_reg.word0 = readl(phba->sli4_hba.UERRHIregaddr);
4536 if (uerrlo_reg.word0 || uerrhi_reg.word0) {
4537 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4538 "1422 HBA Unrecoverable error: "
4539 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
4540 "online0_reg=0x%x, online1_reg=0x%x\n",
4541 uerrlo_reg.word0, uerrhi_reg.word0,
4542 onlnreg0, onlnreg1);
4543 }
4544 return -ENODEV;
4545 }
4546
James Smartda0436e2009-05-22 14:51:39 -04004547 return port_error;
4548}
4549
4550/**
4551 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
4552 * @phba: pointer to lpfc hba data structure.
4553 *
4554 * This routine is invoked to set up SLI4 BAR0 PCI config space register
4555 * memory map.
4556 **/
4557static void
4558lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba)
4559{
4560 phba->sli4_hba.UERRLOregaddr = phba->sli4_hba.conf_regs_memmap_p +
4561 LPFC_UERR_STATUS_LO;
4562 phba->sli4_hba.UERRHIregaddr = phba->sli4_hba.conf_regs_memmap_p +
4563 LPFC_UERR_STATUS_HI;
4564 phba->sli4_hba.ONLINE0regaddr = phba->sli4_hba.conf_regs_memmap_p +
4565 LPFC_ONLINE0;
4566 phba->sli4_hba.ONLINE1regaddr = phba->sli4_hba.conf_regs_memmap_p +
4567 LPFC_ONLINE1;
4568 phba->sli4_hba.SCRATCHPADregaddr = phba->sli4_hba.conf_regs_memmap_p +
4569 LPFC_SCRATCHPAD;
4570}
4571
4572/**
4573 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
4574 * @phba: pointer to lpfc hba data structure.
4575 *
4576 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
4577 * memory map.
4578 **/
4579static void
4580lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
4581{
4582
4583 phba->sli4_hba.STAregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
4584 LPFC_HST_STATE;
4585 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
4586 LPFC_HST_ISR0;
4587 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
4588 LPFC_HST_IMR0;
4589 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
4590 LPFC_HST_ISCR0;
4591 return;
4592}
4593
4594/**
4595 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
4596 * @phba: pointer to lpfc hba data structure.
4597 * @vf: virtual function number
4598 *
4599 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
4600 * based on the given viftual function number, @vf.
4601 *
4602 * Return 0 if successful, otherwise -ENODEV.
4603 **/
4604static int
4605lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
4606{
4607 if (vf > LPFC_VIR_FUNC_MAX)
4608 return -ENODEV;
4609
4610 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
4611 vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL);
4612 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
4613 vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL);
4614 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
4615 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
4616 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
4617 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
4618 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
4619 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
4620 return 0;
4621}
4622
4623/**
4624 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
4625 * @phba: pointer to lpfc hba data structure.
4626 *
4627 * This routine is invoked to create the bootstrap mailbox
4628 * region consistent with the SLI-4 interface spec. This
4629 * routine allocates all memory necessary to communicate
4630 * mailbox commands to the port and sets up all alignment
4631 * needs. No locks are expected to be held when calling
4632 * this routine.
4633 *
4634 * Return codes
4635 * 0 - sucessful
4636 * ENOMEM - could not allocated memory.
4637 **/
4638static int
4639lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
4640{
4641 uint32_t bmbx_size;
4642 struct lpfc_dmabuf *dmabuf;
4643 struct dma_address *dma_address;
4644 uint32_t pa_addr;
4645 uint64_t phys_addr;
4646
4647 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4648 if (!dmabuf)
4649 return -ENOMEM;
4650
4651 /*
4652 * The bootstrap mailbox region is comprised of 2 parts
4653 * plus an alignment restriction of 16 bytes.
4654 */
4655 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
4656 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
4657 bmbx_size,
4658 &dmabuf->phys,
4659 GFP_KERNEL);
4660 if (!dmabuf->virt) {
4661 kfree(dmabuf);
4662 return -ENOMEM;
4663 }
4664 memset(dmabuf->virt, 0, bmbx_size);
4665
4666 /*
4667 * Initialize the bootstrap mailbox pointers now so that the register
4668 * operations are simple later. The mailbox dma address is required
4669 * to be 16-byte aligned. Also align the virtual memory as each
4670 * maibox is copied into the bmbx mailbox region before issuing the
4671 * command to the port.
4672 */
4673 phba->sli4_hba.bmbx.dmabuf = dmabuf;
4674 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
4675
4676 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
4677 LPFC_ALIGN_16_BYTE);
4678 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
4679 LPFC_ALIGN_16_BYTE);
4680
4681 /*
4682 * Set the high and low physical addresses now. The SLI4 alignment
4683 * requirement is 16 bytes and the mailbox is posted to the port
4684 * as two 30-bit addresses. The other data is a bit marking whether
4685 * the 30-bit address is the high or low address.
4686 * Upcast bmbx aphys to 64bits so shift instruction compiles
4687 * clean on 32 bit machines.
4688 */
4689 dma_address = &phba->sli4_hba.bmbx.dma_address;
4690 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
4691 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
4692 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
4693 LPFC_BMBX_BIT1_ADDR_HI);
4694
4695 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
4696 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
4697 LPFC_BMBX_BIT1_ADDR_LO);
4698 return 0;
4699}
4700
4701/**
4702 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
4703 * @phba: pointer to lpfc hba data structure.
4704 *
4705 * This routine is invoked to teardown the bootstrap mailbox
4706 * region and release all host resources. This routine requires
4707 * the caller to ensure all mailbox commands recovered, no
4708 * additional mailbox comands are sent, and interrupts are disabled
4709 * before calling this routine.
4710 *
4711 **/
4712static void
4713lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
4714{
4715 dma_free_coherent(&phba->pcidev->dev,
4716 phba->sli4_hba.bmbx.bmbx_size,
4717 phba->sli4_hba.bmbx.dmabuf->virt,
4718 phba->sli4_hba.bmbx.dmabuf->phys);
4719
4720 kfree(phba->sli4_hba.bmbx.dmabuf);
4721 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
4722}
4723
4724/**
4725 * lpfc_sli4_read_config - Get the config parameters.
4726 * @phba: pointer to lpfc hba data structure.
4727 *
4728 * This routine is invoked to read the configuration parameters from the HBA.
4729 * The configuration parameters are used to set the base and maximum values
4730 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
4731 * allocation for the port.
4732 *
4733 * Return codes
4734 * 0 - sucessful
4735 * ENOMEM - No availble memory
4736 * EIO - The mailbox failed to complete successfully.
4737 **/
4738static int
4739lpfc_sli4_read_config(struct lpfc_hba *phba)
4740{
4741 LPFC_MBOXQ_t *pmb;
4742 struct lpfc_mbx_read_config *rd_config;
4743 uint32_t rc = 0;
4744
4745 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4746 if (!pmb) {
4747 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4748 "2011 Unable to allocate memory for issuing "
4749 "SLI_CONFIG_SPECIAL mailbox command\n");
4750 return -ENOMEM;
4751 }
4752
4753 lpfc_read_config(phba, pmb);
4754
4755 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
4756 if (rc != MBX_SUCCESS) {
4757 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4758 "2012 Mailbox failed , mbxCmd x%x "
4759 "READ_CONFIG, mbxStatus x%x\n",
4760 bf_get(lpfc_mqe_command, &pmb->u.mqe),
4761 bf_get(lpfc_mqe_status, &pmb->u.mqe));
4762 rc = -EIO;
4763 } else {
4764 rd_config = &pmb->u.mqe.un.rd_config;
4765 phba->sli4_hba.max_cfg_param.max_xri =
4766 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
4767 phba->sli4_hba.max_cfg_param.xri_base =
4768 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
4769 phba->sli4_hba.max_cfg_param.max_vpi =
4770 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
4771 phba->sli4_hba.max_cfg_param.vpi_base =
4772 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
4773 phba->sli4_hba.max_cfg_param.max_rpi =
4774 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
4775 phba->sli4_hba.max_cfg_param.rpi_base =
4776 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
4777 phba->sli4_hba.max_cfg_param.max_vfi =
4778 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
4779 phba->sli4_hba.max_cfg_param.vfi_base =
4780 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
4781 phba->sli4_hba.max_cfg_param.max_fcfi =
4782 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
4783 phba->sli4_hba.max_cfg_param.fcfi_base =
4784 bf_get(lpfc_mbx_rd_conf_fcfi_base, rd_config);
4785 phba->sli4_hba.max_cfg_param.max_eq =
4786 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
4787 phba->sli4_hba.max_cfg_param.max_rq =
4788 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
4789 phba->sli4_hba.max_cfg_param.max_wq =
4790 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
4791 phba->sli4_hba.max_cfg_param.max_cq =
4792 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
4793 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
4794 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
4795 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
4796 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
4797 phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base;
4798 phba->max_vpi = phba->sli4_hba.max_cfg_param.max_vpi;
4799 phba->max_vports = phba->max_vpi;
4800 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4801 "2003 cfg params XRI(B:%d M:%d), "
4802 "VPI(B:%d M:%d) "
4803 "VFI(B:%d M:%d) "
4804 "RPI(B:%d M:%d) "
4805 "FCFI(B:%d M:%d)\n",
4806 phba->sli4_hba.max_cfg_param.xri_base,
4807 phba->sli4_hba.max_cfg_param.max_xri,
4808 phba->sli4_hba.max_cfg_param.vpi_base,
4809 phba->sli4_hba.max_cfg_param.max_vpi,
4810 phba->sli4_hba.max_cfg_param.vfi_base,
4811 phba->sli4_hba.max_cfg_param.max_vfi,
4812 phba->sli4_hba.max_cfg_param.rpi_base,
4813 phba->sli4_hba.max_cfg_param.max_rpi,
4814 phba->sli4_hba.max_cfg_param.fcfi_base,
4815 phba->sli4_hba.max_cfg_param.max_fcfi);
4816 }
4817 mempool_free(pmb, phba->mbox_mem_pool);
4818
4819 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
4820 if (phba->cfg_hba_queue_depth > (phba->sli4_hba.max_cfg_param.max_xri))
4821 phba->cfg_hba_queue_depth =
4822 phba->sli4_hba.max_cfg_param.max_xri;
4823 return rc;
4824}
4825
4826/**
4827 * lpfc_dev_endian_order_setup - Notify the port of the host's endian order.
4828 * @phba: pointer to lpfc hba data structure.
4829 *
4830 * This routine is invoked to setup the host-side endian order to the
4831 * HBA consistent with the SLI-4 interface spec.
4832 *
4833 * Return codes
4834 * 0 - sucessful
4835 * ENOMEM - No availble memory
4836 * EIO - The mailbox failed to complete successfully.
4837 **/
4838static int
4839lpfc_setup_endian_order(struct lpfc_hba *phba)
4840{
4841 LPFC_MBOXQ_t *mboxq;
4842 uint32_t rc = 0;
4843 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
4844 HOST_ENDIAN_HIGH_WORD1};
4845
4846 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4847 if (!mboxq) {
4848 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4849 "0492 Unable to allocate memory for issuing "
4850 "SLI_CONFIG_SPECIAL mailbox command\n");
4851 return -ENOMEM;
4852 }
4853
4854 /*
4855 * The SLI4_CONFIG_SPECIAL mailbox command requires the first two
4856 * words to contain special data values and no other data.
4857 */
4858 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
4859 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
4860 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4861 if (rc != MBX_SUCCESS) {
4862 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4863 "0493 SLI_CONFIG_SPECIAL mailbox failed with "
4864 "status x%x\n",
4865 rc);
4866 rc = -EIO;
4867 }
4868
4869 mempool_free(mboxq, phba->mbox_mem_pool);
4870 return rc;
4871}
4872
4873/**
4874 * lpfc_sli4_queue_create - Create all the SLI4 queues
4875 * @phba: pointer to lpfc hba data structure.
4876 *
4877 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
4878 * operation. For each SLI4 queue type, the parameters such as queue entry
4879 * count (queue depth) shall be taken from the module parameter. For now,
4880 * we just use some constant number as place holder.
4881 *
4882 * Return codes
4883 * 0 - sucessful
4884 * ENOMEM - No availble memory
4885 * EIO - The mailbox failed to complete successfully.
4886 **/
4887static int
4888lpfc_sli4_queue_create(struct lpfc_hba *phba)
4889{
4890 struct lpfc_queue *qdesc;
4891 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
4892 int cfg_fcp_wq_count;
4893 int cfg_fcp_eq_count;
4894
4895 /*
4896 * Sanity check for confiugred queue parameters against the run-time
4897 * device parameters
4898 */
4899
4900 /* Sanity check on FCP fast-path WQ parameters */
4901 cfg_fcp_wq_count = phba->cfg_fcp_wq_count;
4902 if (cfg_fcp_wq_count >
4903 (phba->sli4_hba.max_cfg_param.max_wq - LPFC_SP_WQN_DEF)) {
4904 cfg_fcp_wq_count = phba->sli4_hba.max_cfg_param.max_wq -
4905 LPFC_SP_WQN_DEF;
4906 if (cfg_fcp_wq_count < LPFC_FP_WQN_MIN) {
4907 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4908 "2581 Not enough WQs (%d) from "
4909 "the pci function for supporting "
4910 "FCP WQs (%d)\n",
4911 phba->sli4_hba.max_cfg_param.max_wq,
4912 phba->cfg_fcp_wq_count);
4913 goto out_error;
4914 }
4915 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4916 "2582 Not enough WQs (%d) from the pci "
4917 "function for supporting the requested "
4918 "FCP WQs (%d), the actual FCP WQs can "
4919 "be supported: %d\n",
4920 phba->sli4_hba.max_cfg_param.max_wq,
4921 phba->cfg_fcp_wq_count, cfg_fcp_wq_count);
4922 }
4923 /* The actual number of FCP work queues adopted */
4924 phba->cfg_fcp_wq_count = cfg_fcp_wq_count;
4925
4926 /* Sanity check on FCP fast-path EQ parameters */
4927 cfg_fcp_eq_count = phba->cfg_fcp_eq_count;
4928 if (cfg_fcp_eq_count >
4929 (phba->sli4_hba.max_cfg_param.max_eq - LPFC_SP_EQN_DEF)) {
4930 cfg_fcp_eq_count = phba->sli4_hba.max_cfg_param.max_eq -
4931 LPFC_SP_EQN_DEF;
4932 if (cfg_fcp_eq_count < LPFC_FP_EQN_MIN) {
4933 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4934 "2574 Not enough EQs (%d) from the "
4935 "pci function for supporting FCP "
4936 "EQs (%d)\n",
4937 phba->sli4_hba.max_cfg_param.max_eq,
4938 phba->cfg_fcp_eq_count);
4939 goto out_error;
4940 }
4941 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4942 "2575 Not enough EQs (%d) from the pci "
4943 "function for supporting the requested "
4944 "FCP EQs (%d), the actual FCP EQs can "
4945 "be supported: %d\n",
4946 phba->sli4_hba.max_cfg_param.max_eq,
4947 phba->cfg_fcp_eq_count, cfg_fcp_eq_count);
4948 }
4949 /* It does not make sense to have more EQs than WQs */
4950 if (cfg_fcp_eq_count > phba->cfg_fcp_wq_count) {
4951 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4952 "2593 The number of FCP EQs (%d) is more "
4953 "than the number of FCP WQs (%d), take "
4954 "the number of FCP EQs same as than of "
4955 "WQs (%d)\n", cfg_fcp_eq_count,
4956 phba->cfg_fcp_wq_count,
4957 phba->cfg_fcp_wq_count);
4958 cfg_fcp_eq_count = phba->cfg_fcp_wq_count;
4959 }
4960 /* The actual number of FCP event queues adopted */
4961 phba->cfg_fcp_eq_count = cfg_fcp_eq_count;
4962 /* The overall number of event queues used */
4963 phba->sli4_hba.cfg_eqn = phba->cfg_fcp_eq_count + LPFC_SP_EQN_DEF;
4964
4965 /*
4966 * Create Event Queues (EQs)
4967 */
4968
4969 /* Get EQ depth from module parameter, fake the default for now */
4970 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
4971 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
4972
4973 /* Create slow path event queue */
4974 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
4975 phba->sli4_hba.eq_ecount);
4976 if (!qdesc) {
4977 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4978 "0496 Failed allocate slow-path EQ\n");
4979 goto out_error;
4980 }
4981 phba->sli4_hba.sp_eq = qdesc;
4982
4983 /* Create fast-path FCP Event Queue(s) */
4984 phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) *
4985 phba->cfg_fcp_eq_count), GFP_KERNEL);
4986 if (!phba->sli4_hba.fp_eq) {
4987 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4988 "2576 Failed allocate memory for fast-path "
4989 "EQ record array\n");
4990 goto out_free_sp_eq;
4991 }
4992 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
4993 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
4994 phba->sli4_hba.eq_ecount);
4995 if (!qdesc) {
4996 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4997 "0497 Failed allocate fast-path EQ\n");
4998 goto out_free_fp_eq;
4999 }
5000 phba->sli4_hba.fp_eq[fcp_eqidx] = qdesc;
5001 }
5002
5003 /*
5004 * Create Complete Queues (CQs)
5005 */
5006
5007 /* Get CQ depth from module parameter, fake the default for now */
5008 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
5009 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
5010
5011 /* Create slow-path Mailbox Command Complete Queue */
5012 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
5013 phba->sli4_hba.cq_ecount);
5014 if (!qdesc) {
5015 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5016 "0500 Failed allocate slow-path mailbox CQ\n");
5017 goto out_free_fp_eq;
5018 }
5019 phba->sli4_hba.mbx_cq = qdesc;
5020
5021 /* Create slow-path ELS Complete Queue */
5022 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
5023 phba->sli4_hba.cq_ecount);
5024 if (!qdesc) {
5025 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5026 "0501 Failed allocate slow-path ELS CQ\n");
5027 goto out_free_mbx_cq;
5028 }
5029 phba->sli4_hba.els_cq = qdesc;
5030
5031 /* Create slow-path Unsolicited Receive Complete Queue */
5032 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
5033 phba->sli4_hba.cq_ecount);
5034 if (!qdesc) {
5035 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5036 "0502 Failed allocate slow-path USOL RX CQ\n");
5037 goto out_free_els_cq;
5038 }
5039 phba->sli4_hba.rxq_cq = qdesc;
5040
5041 /* Create fast-path FCP Completion Queue(s), one-to-one with EQs */
5042 phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
5043 phba->cfg_fcp_eq_count), GFP_KERNEL);
5044 if (!phba->sli4_hba.fcp_cq) {
5045 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5046 "2577 Failed allocate memory for fast-path "
5047 "CQ record array\n");
5048 goto out_free_rxq_cq;
5049 }
5050 for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) {
5051 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
5052 phba->sli4_hba.cq_ecount);
5053 if (!qdesc) {
5054 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5055 "0499 Failed allocate fast-path FCP "
5056 "CQ (%d)\n", fcp_cqidx);
5057 goto out_free_fcp_cq;
5058 }
5059 phba->sli4_hba.fcp_cq[fcp_cqidx] = qdesc;
5060 }
5061
5062 /* Create Mailbox Command Queue */
5063 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
5064 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
5065
5066 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
5067 phba->sli4_hba.mq_ecount);
5068 if (!qdesc) {
5069 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5070 "0505 Failed allocate slow-path MQ\n");
5071 goto out_free_fcp_cq;
5072 }
5073 phba->sli4_hba.mbx_wq = qdesc;
5074
5075 /*
5076 * Create all the Work Queues (WQs)
5077 */
5078 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
5079 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
5080
5081 /* Create slow-path ELS Work Queue */
5082 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
5083 phba->sli4_hba.wq_ecount);
5084 if (!qdesc) {
5085 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5086 "0504 Failed allocate slow-path ELS WQ\n");
5087 goto out_free_mbx_wq;
5088 }
5089 phba->sli4_hba.els_wq = qdesc;
5090
5091 /* Create fast-path FCP Work Queue(s) */
5092 phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
5093 phba->cfg_fcp_wq_count), GFP_KERNEL);
5094 if (!phba->sli4_hba.fcp_wq) {
5095 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5096 "2578 Failed allocate memory for fast-path "
5097 "WQ record array\n");
5098 goto out_free_els_wq;
5099 }
5100 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
5101 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
5102 phba->sli4_hba.wq_ecount);
5103 if (!qdesc) {
5104 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5105 "0503 Failed allocate fast-path FCP "
5106 "WQ (%d)\n", fcp_wqidx);
5107 goto out_free_fcp_wq;
5108 }
5109 phba->sli4_hba.fcp_wq[fcp_wqidx] = qdesc;
5110 }
5111
5112 /*
5113 * Create Receive Queue (RQ)
5114 */
5115 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
5116 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
5117
5118 /* Create Receive Queue for header */
5119 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
5120 phba->sli4_hba.rq_ecount);
5121 if (!qdesc) {
5122 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5123 "0506 Failed allocate receive HRQ\n");
5124 goto out_free_fcp_wq;
5125 }
5126 phba->sli4_hba.hdr_rq = qdesc;
5127
5128 /* Create Receive Queue for data */
5129 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
5130 phba->sli4_hba.rq_ecount);
5131 if (!qdesc) {
5132 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5133 "0507 Failed allocate receive DRQ\n");
5134 goto out_free_hdr_rq;
5135 }
5136 phba->sli4_hba.dat_rq = qdesc;
5137
5138 return 0;
5139
5140out_free_hdr_rq:
5141 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
5142 phba->sli4_hba.hdr_rq = NULL;
5143out_free_fcp_wq:
5144 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) {
5145 lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_wqidx]);
5146 phba->sli4_hba.fcp_wq[fcp_wqidx] = NULL;
5147 }
5148 kfree(phba->sli4_hba.fcp_wq);
5149out_free_els_wq:
5150 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
5151 phba->sli4_hba.els_wq = NULL;
5152out_free_mbx_wq:
5153 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
5154 phba->sli4_hba.mbx_wq = NULL;
5155out_free_fcp_cq:
5156 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) {
5157 lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_cqidx]);
5158 phba->sli4_hba.fcp_cq[fcp_cqidx] = NULL;
5159 }
5160 kfree(phba->sli4_hba.fcp_cq);
5161out_free_rxq_cq:
5162 lpfc_sli4_queue_free(phba->sli4_hba.rxq_cq);
5163 phba->sli4_hba.rxq_cq = NULL;
5164out_free_els_cq:
5165 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
5166 phba->sli4_hba.els_cq = NULL;
5167out_free_mbx_cq:
5168 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
5169 phba->sli4_hba.mbx_cq = NULL;
5170out_free_fp_eq:
5171 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) {
5172 lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_eqidx]);
5173 phba->sli4_hba.fp_eq[fcp_eqidx] = NULL;
5174 }
5175 kfree(phba->sli4_hba.fp_eq);
5176out_free_sp_eq:
5177 lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
5178 phba->sli4_hba.sp_eq = NULL;
5179out_error:
5180 return -ENOMEM;
5181}
5182
5183/**
5184 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
5185 * @phba: pointer to lpfc hba data structure.
5186 *
5187 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
5188 * operation.
5189 *
5190 * Return codes
5191 * 0 - sucessful
5192 * ENOMEM - No availble memory
5193 * EIO - The mailbox failed to complete successfully.
5194 **/
5195static void
5196lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
5197{
5198 int fcp_qidx;
5199
5200 /* Release mailbox command work queue */
5201 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
5202 phba->sli4_hba.mbx_wq = NULL;
5203
5204 /* Release ELS work queue */
5205 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
5206 phba->sli4_hba.els_wq = NULL;
5207
5208 /* Release FCP work queue */
5209 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
5210 lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_qidx]);
5211 kfree(phba->sli4_hba.fcp_wq);
5212 phba->sli4_hba.fcp_wq = NULL;
5213
5214 /* Release unsolicited receive queue */
5215 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
5216 phba->sli4_hba.hdr_rq = NULL;
5217 lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
5218 phba->sli4_hba.dat_rq = NULL;
5219
5220 /* Release unsolicited receive complete queue */
5221 lpfc_sli4_queue_free(phba->sli4_hba.rxq_cq);
5222 phba->sli4_hba.rxq_cq = NULL;
5223
5224 /* Release ELS complete queue */
5225 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
5226 phba->sli4_hba.els_cq = NULL;
5227
5228 /* Release mailbox command complete queue */
5229 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
5230 phba->sli4_hba.mbx_cq = NULL;
5231
5232 /* Release FCP response complete queue */
5233 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
5234 lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_qidx]);
5235 kfree(phba->sli4_hba.fcp_cq);
5236 phba->sli4_hba.fcp_cq = NULL;
5237
5238 /* Release fast-path event queue */
5239 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
5240 lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]);
5241 kfree(phba->sli4_hba.fp_eq);
5242 phba->sli4_hba.fp_eq = NULL;
5243
5244 /* Release slow-path event queue */
5245 lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
5246 phba->sli4_hba.sp_eq = NULL;
5247
5248 return;
5249}
5250
5251/**
5252 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
5253 * @phba: pointer to lpfc hba data structure.
5254 *
5255 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
5256 * operation.
5257 *
5258 * Return codes
5259 * 0 - sucessful
5260 * ENOMEM - No availble memory
5261 * EIO - The mailbox failed to complete successfully.
5262 **/
5263int
5264lpfc_sli4_queue_setup(struct lpfc_hba *phba)
5265{
5266 int rc = -ENOMEM;
5267 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
5268 int fcp_cq_index = 0;
5269
5270 /*
5271 * Set up Event Queues (EQs)
5272 */
5273
5274 /* Set up slow-path event queue */
5275 if (!phba->sli4_hba.sp_eq) {
5276 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5277 "0520 Slow-path EQ not allocated\n");
5278 goto out_error;
5279 }
5280 rc = lpfc_eq_create(phba, phba->sli4_hba.sp_eq,
5281 LPFC_SP_DEF_IMAX);
5282 if (rc) {
5283 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5284 "0521 Failed setup of slow-path EQ: "
5285 "rc = 0x%x\n", rc);
5286 goto out_error;
5287 }
5288 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5289 "2583 Slow-path EQ setup: queue-id=%d\n",
5290 phba->sli4_hba.sp_eq->queue_id);
5291
5292 /* Set up fast-path event queue */
5293 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
5294 if (!phba->sli4_hba.fp_eq[fcp_eqidx]) {
5295 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5296 "0522 Fast-path EQ (%d) not "
5297 "allocated\n", fcp_eqidx);
5298 goto out_destroy_fp_eq;
5299 }
5300 rc = lpfc_eq_create(phba, phba->sli4_hba.fp_eq[fcp_eqidx],
5301 phba->cfg_fcp_imax);
5302 if (rc) {
5303 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5304 "0523 Failed setup of fast-path EQ "
5305 "(%d), rc = 0x%x\n", fcp_eqidx, rc);
5306 goto out_destroy_fp_eq;
5307 }
5308 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5309 "2584 Fast-path EQ setup: "
5310 "queue[%d]-id=%d\n", fcp_eqidx,
5311 phba->sli4_hba.fp_eq[fcp_eqidx]->queue_id);
5312 }
5313
5314 /*
5315 * Set up Complete Queues (CQs)
5316 */
5317
5318 /* Set up slow-path MBOX Complete Queue as the first CQ */
5319 if (!phba->sli4_hba.mbx_cq) {
5320 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5321 "0528 Mailbox CQ not allocated\n");
5322 goto out_destroy_fp_eq;
5323 }
5324 rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, phba->sli4_hba.sp_eq,
5325 LPFC_MCQ, LPFC_MBOX);
5326 if (rc) {
5327 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5328 "0529 Failed setup of slow-path mailbox CQ: "
5329 "rc = 0x%x\n", rc);
5330 goto out_destroy_fp_eq;
5331 }
5332 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5333 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
5334 phba->sli4_hba.mbx_cq->queue_id,
5335 phba->sli4_hba.sp_eq->queue_id);
5336
5337 /* Set up slow-path ELS Complete Queue */
5338 if (!phba->sli4_hba.els_cq) {
5339 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5340 "0530 ELS CQ not allocated\n");
5341 goto out_destroy_mbx_cq;
5342 }
5343 rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, phba->sli4_hba.sp_eq,
5344 LPFC_WCQ, LPFC_ELS);
5345 if (rc) {
5346 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5347 "0531 Failed setup of slow-path ELS CQ: "
5348 "rc = 0x%x\n", rc);
5349 goto out_destroy_mbx_cq;
5350 }
5351 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5352 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
5353 phba->sli4_hba.els_cq->queue_id,
5354 phba->sli4_hba.sp_eq->queue_id);
5355
5356 /* Set up slow-path Unsolicited Receive Complete Queue */
5357 if (!phba->sli4_hba.rxq_cq) {
5358 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5359 "0532 USOL RX CQ not allocated\n");
5360 goto out_destroy_els_cq;
5361 }
5362 rc = lpfc_cq_create(phba, phba->sli4_hba.rxq_cq, phba->sli4_hba.sp_eq,
5363 LPFC_RCQ, LPFC_USOL);
5364 if (rc) {
5365 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5366 "0533 Failed setup of slow-path USOL RX CQ: "
5367 "rc = 0x%x\n", rc);
5368 goto out_destroy_els_cq;
5369 }
5370 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5371 "2587 USL CQ setup: cq-id=%d, parent eq-id=%d\n",
5372 phba->sli4_hba.rxq_cq->queue_id,
5373 phba->sli4_hba.sp_eq->queue_id);
5374
5375 /* Set up fast-path FCP Response Complete Queue */
5376 for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) {
5377 if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
5378 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5379 "0526 Fast-path FCP CQ (%d) not "
5380 "allocated\n", fcp_cqidx);
5381 goto out_destroy_fcp_cq;
5382 }
5383 rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
5384 phba->sli4_hba.fp_eq[fcp_cqidx],
5385 LPFC_WCQ, LPFC_FCP);
5386 if (rc) {
5387 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5388 "0527 Failed setup of fast-path FCP "
5389 "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc);
5390 goto out_destroy_fcp_cq;
5391 }
5392 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5393 "2588 FCP CQ setup: cq[%d]-id=%d, "
5394 "parent eq[%d]-id=%d\n",
5395 fcp_cqidx,
5396 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
5397 fcp_cqidx,
5398 phba->sli4_hba.fp_eq[fcp_cqidx]->queue_id);
5399 }
5400
5401 /*
5402 * Set up all the Work Queues (WQs)
5403 */
5404
5405 /* Set up Mailbox Command Queue */
5406 if (!phba->sli4_hba.mbx_wq) {
5407 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5408 "0538 Slow-path MQ not allocated\n");
5409 goto out_destroy_fcp_cq;
5410 }
5411 rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
5412 phba->sli4_hba.mbx_cq, LPFC_MBOX);
5413 if (rc) {
5414 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5415 "0539 Failed setup of slow-path MQ: "
5416 "rc = 0x%x\n", rc);
5417 goto out_destroy_fcp_cq;
5418 }
5419 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5420 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
5421 phba->sli4_hba.mbx_wq->queue_id,
5422 phba->sli4_hba.mbx_cq->queue_id);
5423
5424 /* Set up slow-path ELS Work Queue */
5425 if (!phba->sli4_hba.els_wq) {
5426 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5427 "0536 Slow-path ELS WQ not allocated\n");
5428 goto out_destroy_mbx_wq;
5429 }
5430 rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
5431 phba->sli4_hba.els_cq, LPFC_ELS);
5432 if (rc) {
5433 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5434 "0537 Failed setup of slow-path ELS WQ: "
5435 "rc = 0x%x\n", rc);
5436 goto out_destroy_mbx_wq;
5437 }
5438 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5439 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
5440 phba->sli4_hba.els_wq->queue_id,
5441 phba->sli4_hba.els_cq->queue_id);
5442
5443 /* Set up fast-path FCP Work Queue */
5444 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
5445 if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
5446 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5447 "0534 Fast-path FCP WQ (%d) not "
5448 "allocated\n", fcp_wqidx);
5449 goto out_destroy_fcp_wq;
5450 }
5451 rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
5452 phba->sli4_hba.fcp_cq[fcp_cq_index],
5453 LPFC_FCP);
5454 if (rc) {
5455 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5456 "0535 Failed setup of fast-path FCP "
5457 "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc);
5458 goto out_destroy_fcp_wq;
5459 }
5460 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5461 "2591 FCP WQ setup: wq[%d]-id=%d, "
5462 "parent cq[%d]-id=%d\n",
5463 fcp_wqidx,
5464 phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
5465 fcp_cq_index,
5466 phba->sli4_hba.fcp_cq[fcp_cq_index]->queue_id);
5467 /* Round robin FCP Work Queue's Completion Queue assignment */
5468 fcp_cq_index = ((fcp_cq_index + 1) % phba->cfg_fcp_eq_count);
5469 }
5470
5471 /*
5472 * Create Receive Queue (RQ)
5473 */
5474 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
5475 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5476 "0540 Receive Queue not allocated\n");
5477 goto out_destroy_fcp_wq;
5478 }
5479 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
5480 phba->sli4_hba.rxq_cq, LPFC_USOL);
5481 if (rc) {
5482 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5483 "0541 Failed setup of Receive Queue: "
5484 "rc = 0x%x\n", rc);
5485 goto out_destroy_fcp_wq;
5486 }
5487 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5488 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
5489 "parent cq-id=%d\n",
5490 phba->sli4_hba.hdr_rq->queue_id,
5491 phba->sli4_hba.dat_rq->queue_id,
5492 phba->sli4_hba.rxq_cq->queue_id);
5493 return 0;
5494
5495out_destroy_fcp_wq:
5496 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
5497 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
5498 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
5499out_destroy_mbx_wq:
5500 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
5501out_destroy_fcp_cq:
5502 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
5503 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
5504 lpfc_cq_destroy(phba, phba->sli4_hba.rxq_cq);
5505out_destroy_els_cq:
5506 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
5507out_destroy_mbx_cq:
5508 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
5509out_destroy_fp_eq:
5510 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
5511 lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_eqidx]);
5512 lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
5513out_error:
5514 return rc;
5515}
5516
5517/**
5518 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
5519 * @phba: pointer to lpfc hba data structure.
5520 *
5521 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
5522 * operation.
5523 *
5524 * Return codes
5525 * 0 - sucessful
5526 * ENOMEM - No availble memory
5527 * EIO - The mailbox failed to complete successfully.
5528 **/
5529void
5530lpfc_sli4_queue_unset(struct lpfc_hba *phba)
5531{
5532 int fcp_qidx;
5533
5534 /* Unset mailbox command work queue */
5535 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
5536 /* Unset ELS work queue */
5537 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
5538 /* Unset unsolicited receive queue */
5539 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
5540 /* Unset FCP work queue */
5541 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
5542 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
5543 /* Unset mailbox command complete queue */
5544 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
5545 /* Unset ELS complete queue */
5546 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
5547 /* Unset unsolicited receive complete queue */
5548 lpfc_cq_destroy(phba, phba->sli4_hba.rxq_cq);
5549 /* Unset FCP response complete queue */
5550 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
5551 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
5552 /* Unset fast-path event queue */
5553 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
5554 lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_qidx]);
5555 /* Unset slow-path event queue */
5556 lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
5557}
5558
5559/**
5560 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
5561 * @phba: pointer to lpfc hba data structure.
5562 *
5563 * This routine is invoked to allocate and set up a pool of completion queue
5564 * events. The body of the completion queue event is a completion queue entry
5565 * CQE. For now, this pool is used for the interrupt service routine to queue
5566 * the following HBA completion queue events for the worker thread to process:
5567 * - Mailbox asynchronous events
5568 * - Receive queue completion unsolicited events
5569 * Later, this can be used for all the slow-path events.
5570 *
5571 * Return codes
5572 * 0 - sucessful
5573 * -ENOMEM - No availble memory
5574 **/
5575static int
5576lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
5577{
5578 struct lpfc_cq_event *cq_event;
5579 int i;
5580
5581 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
5582 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
5583 if (!cq_event)
5584 goto out_pool_create_fail;
5585 list_add_tail(&cq_event->list,
5586 &phba->sli4_hba.sp_cqe_event_pool);
5587 }
5588 return 0;
5589
5590out_pool_create_fail:
5591 lpfc_sli4_cq_event_pool_destroy(phba);
5592 return -ENOMEM;
5593}
5594
5595/**
5596 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
5597 * @phba: pointer to lpfc hba data structure.
5598 *
5599 * This routine is invoked to free the pool of completion queue events at
5600 * driver unload time. Note that, it is the responsibility of the driver
5601 * cleanup routine to free all the outstanding completion-queue events
5602 * allocated from this pool back into the pool before invoking this routine
5603 * to destroy the pool.
5604 **/
5605static void
5606lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
5607{
5608 struct lpfc_cq_event *cq_event, *next_cq_event;
5609
5610 list_for_each_entry_safe(cq_event, next_cq_event,
5611 &phba->sli4_hba.sp_cqe_event_pool, list) {
5612 list_del(&cq_event->list);
5613 kfree(cq_event);
5614 }
5615}
5616
5617/**
5618 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
5619 * @phba: pointer to lpfc hba data structure.
5620 *
5621 * This routine is the lock free version of the API invoked to allocate a
5622 * completion-queue event from the free pool.
5623 *
5624 * Return: Pointer to the newly allocated completion-queue event if successful
5625 * NULL otherwise.
5626 **/
5627struct lpfc_cq_event *
5628__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
5629{
5630 struct lpfc_cq_event *cq_event = NULL;
5631
5632 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
5633 struct lpfc_cq_event, list);
5634 return cq_event;
5635}
5636
5637/**
5638 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
5639 * @phba: pointer to lpfc hba data structure.
5640 *
5641 * This routine is the lock version of the API invoked to allocate a
5642 * completion-queue event from the free pool.
5643 *
5644 * Return: Pointer to the newly allocated completion-queue event if successful
5645 * NULL otherwise.
5646 **/
5647struct lpfc_cq_event *
5648lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
5649{
5650 struct lpfc_cq_event *cq_event;
5651 unsigned long iflags;
5652
5653 spin_lock_irqsave(&phba->hbalock, iflags);
5654 cq_event = __lpfc_sli4_cq_event_alloc(phba);
5655 spin_unlock_irqrestore(&phba->hbalock, iflags);
5656 return cq_event;
5657}
5658
5659/**
5660 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
5661 * @phba: pointer to lpfc hba data structure.
5662 * @cq_event: pointer to the completion queue event to be freed.
5663 *
5664 * This routine is the lock free version of the API invoked to release a
5665 * completion-queue event back into the free pool.
5666 **/
5667void
5668__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
5669 struct lpfc_cq_event *cq_event)
5670{
5671 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
5672}
5673
5674/**
5675 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
5676 * @phba: pointer to lpfc hba data structure.
5677 * @cq_event: pointer to the completion queue event to be freed.
5678 *
5679 * This routine is the lock version of the API invoked to release a
5680 * completion-queue event back into the free pool.
5681 **/
5682void
5683lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
5684 struct lpfc_cq_event *cq_event)
5685{
5686 unsigned long iflags;
5687 spin_lock_irqsave(&phba->hbalock, iflags);
5688 __lpfc_sli4_cq_event_release(phba, cq_event);
5689 spin_unlock_irqrestore(&phba->hbalock, iflags);
5690}
5691
5692/**
5693 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
5694 * @phba: pointer to lpfc hba data structure.
5695 *
5696 * This routine is to free all the pending completion-queue events to the
5697 * back into the free pool for device reset.
5698 **/
5699static void
5700lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
5701{
5702 LIST_HEAD(cqelist);
5703 struct lpfc_cq_event *cqe;
5704 unsigned long iflags;
5705
5706 /* Retrieve all the pending WCQEs from pending WCQE lists */
5707 spin_lock_irqsave(&phba->hbalock, iflags);
5708 /* Pending FCP XRI abort events */
5709 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
5710 &cqelist);
5711 /* Pending ELS XRI abort events */
5712 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
5713 &cqelist);
5714 /* Pending asynnc events */
5715 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
5716 &cqelist);
5717 spin_unlock_irqrestore(&phba->hbalock, iflags);
5718
5719 while (!list_empty(&cqelist)) {
5720 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
5721 lpfc_sli4_cq_event_release(phba, cqe);
5722 }
5723}
5724
5725/**
5726 * lpfc_pci_function_reset - Reset pci function.
5727 * @phba: pointer to lpfc hba data structure.
5728 *
5729 * This routine is invoked to request a PCI function reset. It will destroys
5730 * all resources assigned to the PCI function which originates this request.
5731 *
5732 * Return codes
5733 * 0 - sucessful
5734 * ENOMEM - No availble memory
5735 * EIO - The mailbox failed to complete successfully.
5736 **/
5737int
5738lpfc_pci_function_reset(struct lpfc_hba *phba)
5739{
5740 LPFC_MBOXQ_t *mboxq;
5741 uint32_t rc = 0;
5742 uint32_t shdr_status, shdr_add_status;
5743 union lpfc_sli4_cfg_shdr *shdr;
5744
5745 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5746 if (!mboxq) {
5747 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5748 "0494 Unable to allocate memory for issuing "
5749 "SLI_FUNCTION_RESET mailbox command\n");
5750 return -ENOMEM;
5751 }
5752
5753 /* Set up PCI function reset SLI4_CONFIG mailbox-ioctl command */
5754 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
5755 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
5756 LPFC_SLI4_MBX_EMBED);
5757 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5758 shdr = (union lpfc_sli4_cfg_shdr *)
5759 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
5760 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5761 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5762 if (rc != MBX_TIMEOUT)
5763 mempool_free(mboxq, phba->mbox_mem_pool);
5764 if (shdr_status || shdr_add_status || rc) {
5765 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5766 "0495 SLI_FUNCTION_RESET mailbox failed with "
5767 "status x%x add_status x%x, mbx status x%x\n",
5768 shdr_status, shdr_add_status, rc);
5769 rc = -ENXIO;
5770 }
5771 return rc;
5772}
5773
5774/**
5775 * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands
5776 * @phba: pointer to lpfc hba data structure.
5777 * @cnt: number of nop mailbox commands to send.
5778 *
5779 * This routine is invoked to send a number @cnt of NOP mailbox command and
5780 * wait for each command to complete.
5781 *
5782 * Return: the number of NOP mailbox command completed.
5783 **/
5784static int
5785lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt)
5786{
5787 LPFC_MBOXQ_t *mboxq;
5788 int length, cmdsent;
5789 uint32_t mbox_tmo;
5790 uint32_t rc = 0;
5791 uint32_t shdr_status, shdr_add_status;
5792 union lpfc_sli4_cfg_shdr *shdr;
5793
5794 if (cnt == 0) {
5795 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5796 "2518 Requested to send 0 NOP mailbox cmd\n");
5797 return cnt;
5798 }
5799
5800 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5801 if (!mboxq) {
5802 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5803 "2519 Unable to allocate memory for issuing "
5804 "NOP mailbox command\n");
5805 return 0;
5806 }
5807
5808 /* Set up NOP SLI4_CONFIG mailbox-ioctl command */
5809 length = (sizeof(struct lpfc_mbx_nop) -
5810 sizeof(struct lpfc_sli4_cfg_mhdr));
5811 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
5812 LPFC_MBOX_OPCODE_NOP, length, LPFC_SLI4_MBX_EMBED);
5813
5814 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
5815 for (cmdsent = 0; cmdsent < cnt; cmdsent++) {
5816 if (!phba->sli4_hba.intr_enable)
5817 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5818 else
5819 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
5820 if (rc == MBX_TIMEOUT)
5821 break;
5822 /* Check return status */
5823 shdr = (union lpfc_sli4_cfg_shdr *)
5824 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
5825 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5826 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
5827 &shdr->response);
5828 if (shdr_status || shdr_add_status || rc) {
5829 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5830 "2520 NOP mailbox command failed "
5831 "status x%x add_status x%x mbx "
5832 "status x%x\n", shdr_status,
5833 shdr_add_status, rc);
5834 break;
5835 }
5836 }
5837
5838 if (rc != MBX_TIMEOUT)
5839 mempool_free(mboxq, phba->mbox_mem_pool);
5840
5841 return cmdsent;
5842}
5843
5844/**
5845 * lpfc_sli4_fcfi_unreg - Unregister fcfi to device
5846 * @phba: pointer to lpfc hba data structure.
5847 * @fcfi: fcf index.
5848 *
5849 * This routine is invoked to unregister a FCFI from device.
5850 **/
5851void
5852lpfc_sli4_fcfi_unreg(struct lpfc_hba *phba, uint16_t fcfi)
5853{
5854 LPFC_MBOXQ_t *mbox;
5855 uint32_t mbox_tmo;
5856 int rc;
5857 unsigned long flags;
5858
5859 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5860
5861 if (!mbox)
5862 return;
5863
5864 lpfc_unreg_fcfi(mbox, fcfi);
5865
5866 if (!phba->sli4_hba.intr_enable)
5867 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
5868 else {
5869 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
5870 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
5871 }
5872 if (rc != MBX_TIMEOUT)
5873 mempool_free(mbox, phba->mbox_mem_pool);
5874 if (rc != MBX_SUCCESS)
5875 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5876 "2517 Unregister FCFI command failed "
5877 "status %d, mbxStatus x%x\n", rc,
5878 bf_get(lpfc_mqe_status, &mbox->u.mqe));
5879 else {
5880 spin_lock_irqsave(&phba->hbalock, flags);
5881 /* Mark the FCFI is no longer registered */
5882 phba->fcf.fcf_flag &=
5883 ~(FCF_AVAILABLE | FCF_REGISTERED | FCF_DISCOVERED);
5884 spin_unlock_irqrestore(&phba->hbalock, flags);
5885 }
5886}
5887
5888/**
5889 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
5890 * @phba: pointer to lpfc hba data structure.
5891 *
5892 * This routine is invoked to set up the PCI device memory space for device
5893 * with SLI-4 interface spec.
5894 *
5895 * Return codes
5896 * 0 - sucessful
5897 * other values - error
5898 **/
5899static int
5900lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
5901{
5902 struct pci_dev *pdev;
5903 unsigned long bar0map_len, bar1map_len, bar2map_len;
5904 int error = -ENODEV;
5905
5906 /* Obtain PCI device reference */
5907 if (!phba->pcidev)
5908 return error;
5909 else
5910 pdev = phba->pcidev;
5911
5912 /* Set the device DMA mask size */
5913 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)
5914 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0)
5915 return error;
5916
5917 /* Get the bus address of SLI4 device Bar0, Bar1, and Bar2 and the
5918 * number of bytes required by each mapping. They are actually
5919 * mapping to the PCI BAR regions 1, 2, and 4 by the SLI4 device.
5920 */
5921 phba->pci_bar0_map = pci_resource_start(pdev, LPFC_SLI4_BAR0);
5922 bar0map_len = pci_resource_len(pdev, LPFC_SLI4_BAR0);
5923
5924 phba->pci_bar1_map = pci_resource_start(pdev, LPFC_SLI4_BAR1);
5925 bar1map_len = pci_resource_len(pdev, LPFC_SLI4_BAR1);
5926
5927 phba->pci_bar2_map = pci_resource_start(pdev, LPFC_SLI4_BAR2);
5928 bar2map_len = pci_resource_len(pdev, LPFC_SLI4_BAR2);
5929
5930 /* Map SLI4 PCI Config Space Register base to a kernel virtual addr */
5931 phba->sli4_hba.conf_regs_memmap_p =
5932 ioremap(phba->pci_bar0_map, bar0map_len);
5933 if (!phba->sli4_hba.conf_regs_memmap_p) {
5934 dev_printk(KERN_ERR, &pdev->dev,
5935 "ioremap failed for SLI4 PCI config registers.\n");
5936 goto out;
5937 }
5938
5939 /* Map SLI4 HBA Control Register base to a kernel virtual address. */
5940 phba->sli4_hba.ctrl_regs_memmap_p =
5941 ioremap(phba->pci_bar1_map, bar1map_len);
5942 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
5943 dev_printk(KERN_ERR, &pdev->dev,
5944 "ioremap failed for SLI4 HBA control registers.\n");
5945 goto out_iounmap_conf;
5946 }
5947
5948 /* Map SLI4 HBA Doorbell Register base to a kernel virtual address. */
5949 phba->sli4_hba.drbl_regs_memmap_p =
5950 ioremap(phba->pci_bar2_map, bar2map_len);
5951 if (!phba->sli4_hba.drbl_regs_memmap_p) {
5952 dev_printk(KERN_ERR, &pdev->dev,
5953 "ioremap failed for SLI4 HBA doorbell registers.\n");
5954 goto out_iounmap_ctrl;
5955 }
5956
5957 /* Set up BAR0 PCI config space register memory map */
5958 lpfc_sli4_bar0_register_memmap(phba);
5959
5960 /* Set up BAR1 register memory map */
5961 lpfc_sli4_bar1_register_memmap(phba);
5962
5963 /* Set up BAR2 register memory map */
5964 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
5965 if (error)
5966 goto out_iounmap_all;
5967
5968 return 0;
5969
5970out_iounmap_all:
5971 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
5972out_iounmap_ctrl:
5973 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
5974out_iounmap_conf:
5975 iounmap(phba->sli4_hba.conf_regs_memmap_p);
5976out:
5977 return error;
5978}
5979
5980/**
5981 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
5982 * @phba: pointer to lpfc hba data structure.
5983 *
5984 * This routine is invoked to unset the PCI device memory space for device
5985 * with SLI-4 interface spec.
5986 **/
5987static void
5988lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
5989{
5990 struct pci_dev *pdev;
5991
5992 /* Obtain PCI device reference */
5993 if (!phba->pcidev)
5994 return;
5995 else
5996 pdev = phba->pcidev;
5997
5998 /* Free coherent DMA memory allocated */
5999
6000 /* Unmap I/O memory space */
6001 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
6002 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
6003 iounmap(phba->sli4_hba.conf_regs_memmap_p);
6004
6005 return;
6006}
6007
6008/**
James Smart3772a992009-05-22 14:50:54 -04006009 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
6010 * @phba: pointer to lpfc hba data structure.
6011 *
6012 * This routine is invoked to enable the MSI-X interrupt vectors to device
6013 * with SLI-3 interface specs. The kernel function pci_enable_msix() is
6014 * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
6015 * invoked, enables either all or nothing, depending on the current
6016 * availability of PCI vector resources. The device driver is responsible
6017 * for calling the individual request_irq() to register each MSI-X vector
6018 * with a interrupt handler, which is done in this function. Note that
6019 * later when device is unloading, the driver should always call free_irq()
6020 * on all MSI-X vectors it has done request_irq() on before calling
6021 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
6022 * will be left with MSI-X enabled and leaks its vectors.
6023 *
6024 * Return codes
6025 * 0 - sucessful
6026 * other values - error
6027 **/
6028static int
6029lpfc_sli_enable_msix(struct lpfc_hba *phba)
6030{
6031 int rc, i;
6032 LPFC_MBOXQ_t *pmb;
6033
6034 /* Set up MSI-X multi-message vectors */
6035 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
6036 phba->msix_entries[i].entry = i;
6037
6038 /* Configure MSI-X capability structure */
6039 rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
6040 ARRAY_SIZE(phba->msix_entries));
6041 if (rc) {
6042 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6043 "0420 PCI enable MSI-X failed (%d)\n", rc);
6044 goto msi_fail_out;
6045 }
6046 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
6047 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6048 "0477 MSI-X entry[%d]: vector=x%x "
6049 "message=%d\n", i,
6050 phba->msix_entries[i].vector,
6051 phba->msix_entries[i].entry);
6052 /*
6053 * Assign MSI-X vectors to interrupt handlers
6054 */
6055
6056 /* vector-0 is associated to slow-path handler */
6057 rc = request_irq(phba->msix_entries[0].vector,
6058 &lpfc_sli_sp_intr_handler, IRQF_SHARED,
6059 LPFC_SP_DRIVER_HANDLER_NAME, phba);
6060 if (rc) {
6061 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6062 "0421 MSI-X slow-path request_irq failed "
6063 "(%d)\n", rc);
6064 goto msi_fail_out;
6065 }
6066
6067 /* vector-1 is associated to fast-path handler */
6068 rc = request_irq(phba->msix_entries[1].vector,
6069 &lpfc_sli_fp_intr_handler, IRQF_SHARED,
6070 LPFC_FP_DRIVER_HANDLER_NAME, phba);
6071
6072 if (rc) {
6073 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6074 "0429 MSI-X fast-path request_irq failed "
6075 "(%d)\n", rc);
6076 goto irq_fail_out;
6077 }
6078
6079 /*
6080 * Configure HBA MSI-X attention conditions to messages
6081 */
6082 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6083
6084 if (!pmb) {
6085 rc = -ENOMEM;
6086 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6087 "0474 Unable to allocate memory for issuing "
6088 "MBOX_CONFIG_MSI command\n");
6089 goto mem_fail_out;
6090 }
6091 rc = lpfc_config_msi(phba, pmb);
6092 if (rc)
6093 goto mbx_fail_out;
6094 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
6095 if (rc != MBX_SUCCESS) {
6096 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
6097 "0351 Config MSI mailbox command failed, "
6098 "mbxCmd x%x, mbxStatus x%x\n",
6099 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
6100 goto mbx_fail_out;
6101 }
6102
6103 /* Free memory allocated for mailbox command */
6104 mempool_free(pmb, phba->mbox_mem_pool);
6105 return rc;
6106
6107mbx_fail_out:
6108 /* Free memory allocated for mailbox command */
6109 mempool_free(pmb, phba->mbox_mem_pool);
6110
6111mem_fail_out:
6112 /* free the irq already requested */
6113 free_irq(phba->msix_entries[1].vector, phba);
6114
6115irq_fail_out:
6116 /* free the irq already requested */
6117 free_irq(phba->msix_entries[0].vector, phba);
6118
6119msi_fail_out:
6120 /* Unconfigure MSI-X capability structure */
6121 pci_disable_msix(phba->pcidev);
6122 return rc;
6123}
6124
6125/**
6126 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
6127 * @phba: pointer to lpfc hba data structure.
6128 *
6129 * This routine is invoked to release the MSI-X vectors and then disable the
6130 * MSI-X interrupt mode to device with SLI-3 interface spec.
6131 **/
6132static void
6133lpfc_sli_disable_msix(struct lpfc_hba *phba)
6134{
6135 int i;
6136
6137 /* Free up MSI-X multi-message vectors */
6138 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
6139 free_irq(phba->msix_entries[i].vector, phba);
6140 /* Disable MSI-X */
6141 pci_disable_msix(phba->pcidev);
6142
6143 return;
6144}
6145
6146/**
6147 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
6148 * @phba: pointer to lpfc hba data structure.
6149 *
6150 * This routine is invoked to enable the MSI interrupt mode to device with
6151 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
6152 * enable the MSI vector. The device driver is responsible for calling the
6153 * request_irq() to register MSI vector with a interrupt the handler, which
6154 * is done in this function.
6155 *
6156 * Return codes
6157 * 0 - sucessful
6158 * other values - error
6159 */
6160static int
6161lpfc_sli_enable_msi(struct lpfc_hba *phba)
6162{
6163 int rc;
6164
6165 rc = pci_enable_msi(phba->pcidev);
6166 if (!rc)
6167 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6168 "0462 PCI enable MSI mode success.\n");
6169 else {
6170 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6171 "0471 PCI enable MSI mode failed (%d)\n", rc);
6172 return rc;
6173 }
6174
6175 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
6176 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
6177 if (rc) {
6178 pci_disable_msi(phba->pcidev);
6179 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6180 "0478 MSI request_irq failed (%d)\n", rc);
6181 }
6182 return rc;
6183}
6184
6185/**
6186 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
6187 * @phba: pointer to lpfc hba data structure.
6188 *
6189 * This routine is invoked to disable the MSI interrupt mode to device with
6190 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
6191 * done request_irq() on before calling pci_disable_msi(). Failure to do so
6192 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
6193 * its vector.
6194 */
6195static void
6196lpfc_sli_disable_msi(struct lpfc_hba *phba)
6197{
6198 free_irq(phba->pcidev->irq, phba);
6199 pci_disable_msi(phba->pcidev);
6200 return;
6201}
6202
6203/**
6204 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
6205 * @phba: pointer to lpfc hba data structure.
6206 *
6207 * This routine is invoked to enable device interrupt and associate driver's
6208 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
6209 * spec. Depends on the interrupt mode configured to the driver, the driver
6210 * will try to fallback from the configured interrupt mode to an interrupt
6211 * mode which is supported by the platform, kernel, and device in the order
6212 * of:
6213 * MSI-X -> MSI -> IRQ.
6214 *
6215 * Return codes
6216 * 0 - sucessful
6217 * other values - error
6218 **/
6219static uint32_t
6220lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
6221{
6222 uint32_t intr_mode = LPFC_INTR_ERROR;
6223 int retval;
6224
6225 if (cfg_mode == 2) {
6226 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
6227 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
6228 if (!retval) {
6229 /* Now, try to enable MSI-X interrupt mode */
6230 retval = lpfc_sli_enable_msix(phba);
6231 if (!retval) {
6232 /* Indicate initialization to MSI-X mode */
6233 phba->intr_type = MSIX;
6234 intr_mode = 2;
6235 }
6236 }
6237 }
6238
6239 /* Fallback to MSI if MSI-X initialization failed */
6240 if (cfg_mode >= 1 && phba->intr_type == NONE) {
6241 retval = lpfc_sli_enable_msi(phba);
6242 if (!retval) {
6243 /* Indicate initialization to MSI mode */
6244 phba->intr_type = MSI;
6245 intr_mode = 1;
6246 }
6247 }
6248
6249 /* Fallback to INTx if both MSI-X/MSI initalization failed */
6250 if (phba->intr_type == NONE) {
6251 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
6252 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
6253 if (!retval) {
6254 /* Indicate initialization to INTx mode */
6255 phba->intr_type = INTx;
6256 intr_mode = 0;
6257 }
6258 }
6259 return intr_mode;
6260}
6261
6262/**
6263 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
6264 * @phba: pointer to lpfc hba data structure.
6265 *
6266 * This routine is invoked to disable device interrupt and disassociate the
6267 * driver's interrupt handler(s) from interrupt vector(s) to device with
6268 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
6269 * release the interrupt vector(s) for the message signaled interrupt.
6270 **/
6271static void
6272lpfc_sli_disable_intr(struct lpfc_hba *phba)
6273{
6274 /* Disable the currently initialized interrupt mode */
6275 if (phba->intr_type == MSIX)
6276 lpfc_sli_disable_msix(phba);
6277 else if (phba->intr_type == MSI)
6278 lpfc_sli_disable_msi(phba);
6279 else if (phba->intr_type == INTx)
6280 free_irq(phba->pcidev->irq, phba);
6281
6282 /* Reset interrupt management states */
6283 phba->intr_type = NONE;
6284 phba->sli.slistat.sli_intr = 0;
6285
6286 return;
6287}
6288
6289/**
James Smartda0436e2009-05-22 14:51:39 -04006290 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
6291 * @phba: pointer to lpfc hba data structure.
6292 *
6293 * This routine is invoked to enable the MSI-X interrupt vectors to device
6294 * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
6295 * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
6296 * enables either all or nothing, depending on the current availability of
6297 * PCI vector resources. The device driver is responsible for calling the
6298 * individual request_irq() to register each MSI-X vector with a interrupt
6299 * handler, which is done in this function. Note that later when device is
6300 * unloading, the driver should always call free_irq() on all MSI-X vectors
6301 * it has done request_irq() on before calling pci_disable_msix(). Failure
6302 * to do so results in a BUG_ON() and a device will be left with MSI-X
6303 * enabled and leaks its vectors.
6304 *
6305 * Return codes
6306 * 0 - sucessful
6307 * other values - error
6308 **/
6309static int
6310lpfc_sli4_enable_msix(struct lpfc_hba *phba)
6311{
6312 int rc, index;
6313
6314 /* Set up MSI-X multi-message vectors */
6315 for (index = 0; index < phba->sli4_hba.cfg_eqn; index++)
6316 phba->sli4_hba.msix_entries[index].entry = index;
6317
6318 /* Configure MSI-X capability structure */
6319 rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries,
6320 phba->sli4_hba.cfg_eqn);
6321 if (rc) {
6322 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6323 "0484 PCI enable MSI-X failed (%d)\n", rc);
6324 goto msi_fail_out;
6325 }
6326 /* Log MSI-X vector assignment */
6327 for (index = 0; index < phba->sli4_hba.cfg_eqn; index++)
6328 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6329 "0489 MSI-X entry[%d]: vector=x%x "
6330 "message=%d\n", index,
6331 phba->sli4_hba.msix_entries[index].vector,
6332 phba->sli4_hba.msix_entries[index].entry);
6333 /*
6334 * Assign MSI-X vectors to interrupt handlers
6335 */
6336
6337 /* The first vector must associated to slow-path handler for MQ */
6338 rc = request_irq(phba->sli4_hba.msix_entries[0].vector,
6339 &lpfc_sli4_sp_intr_handler, IRQF_SHARED,
6340 LPFC_SP_DRIVER_HANDLER_NAME, phba);
6341 if (rc) {
6342 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6343 "0485 MSI-X slow-path request_irq failed "
6344 "(%d)\n", rc);
6345 goto msi_fail_out;
6346 }
6347
6348 /* The rest of the vector(s) are associated to fast-path handler(s) */
6349 for (index = 1; index < phba->sli4_hba.cfg_eqn; index++) {
6350 phba->sli4_hba.fcp_eq_hdl[index - 1].idx = index - 1;
6351 phba->sli4_hba.fcp_eq_hdl[index - 1].phba = phba;
6352 rc = request_irq(phba->sli4_hba.msix_entries[index].vector,
6353 &lpfc_sli4_fp_intr_handler, IRQF_SHARED,
6354 LPFC_FP_DRIVER_HANDLER_NAME,
6355 &phba->sli4_hba.fcp_eq_hdl[index - 1]);
6356 if (rc) {
6357 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6358 "0486 MSI-X fast-path (%d) "
6359 "request_irq failed (%d)\n", index, rc);
6360 goto cfg_fail_out;
6361 }
6362 }
6363
6364 return rc;
6365
6366cfg_fail_out:
6367 /* free the irq already requested */
6368 for (--index; index >= 1; index--)
6369 free_irq(phba->sli4_hba.msix_entries[index - 1].vector,
6370 &phba->sli4_hba.fcp_eq_hdl[index - 1]);
6371
6372 /* free the irq already requested */
6373 free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
6374
6375msi_fail_out:
6376 /* Unconfigure MSI-X capability structure */
6377 pci_disable_msix(phba->pcidev);
6378 return rc;
6379}
6380
6381/**
6382 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
6383 * @phba: pointer to lpfc hba data structure.
6384 *
6385 * This routine is invoked to release the MSI-X vectors and then disable the
6386 * MSI-X interrupt mode to device with SLI-4 interface spec.
6387 **/
6388static void
6389lpfc_sli4_disable_msix(struct lpfc_hba *phba)
6390{
6391 int index;
6392
6393 /* Free up MSI-X multi-message vectors */
6394 free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
6395
6396 for (index = 1; index < phba->sli4_hba.cfg_eqn; index++)
6397 free_irq(phba->sli4_hba.msix_entries[index].vector,
6398 &phba->sli4_hba.fcp_eq_hdl[index - 1]);
6399 /* Disable MSI-X */
6400 pci_disable_msix(phba->pcidev);
6401
6402 return;
6403}
6404
6405/**
6406 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
6407 * @phba: pointer to lpfc hba data structure.
6408 *
6409 * This routine is invoked to enable the MSI interrupt mode to device with
6410 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
6411 * to enable the MSI vector. The device driver is responsible for calling
6412 * the request_irq() to register MSI vector with a interrupt the handler,
6413 * which is done in this function.
6414 *
6415 * Return codes
6416 * 0 - sucessful
6417 * other values - error
6418 **/
6419static int
6420lpfc_sli4_enable_msi(struct lpfc_hba *phba)
6421{
6422 int rc, index;
6423
6424 rc = pci_enable_msi(phba->pcidev);
6425 if (!rc)
6426 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6427 "0487 PCI enable MSI mode success.\n");
6428 else {
6429 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6430 "0488 PCI enable MSI mode failed (%d)\n", rc);
6431 return rc;
6432 }
6433
6434 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
6435 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
6436 if (rc) {
6437 pci_disable_msi(phba->pcidev);
6438 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6439 "0490 MSI request_irq failed (%d)\n", rc);
6440 }
6441
6442 for (index = 0; index < phba->cfg_fcp_eq_count; index++) {
6443 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
6444 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
6445 }
6446
6447 return rc;
6448}
6449
6450/**
6451 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
6452 * @phba: pointer to lpfc hba data structure.
6453 *
6454 * This routine is invoked to disable the MSI interrupt mode to device with
6455 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
6456 * done request_irq() on before calling pci_disable_msi(). Failure to do so
6457 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
6458 * its vector.
6459 **/
6460static void
6461lpfc_sli4_disable_msi(struct lpfc_hba *phba)
6462{
6463 free_irq(phba->pcidev->irq, phba);
6464 pci_disable_msi(phba->pcidev);
6465 return;
6466}
6467
6468/**
6469 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
6470 * @phba: pointer to lpfc hba data structure.
6471 *
6472 * This routine is invoked to enable device interrupt and associate driver's
6473 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
6474 * interface spec. Depends on the interrupt mode configured to the driver,
6475 * the driver will try to fallback from the configured interrupt mode to an
6476 * interrupt mode which is supported by the platform, kernel, and device in
6477 * the order of:
6478 * MSI-X -> MSI -> IRQ.
6479 *
6480 * Return codes
6481 * 0 - sucessful
6482 * other values - error
6483 **/
6484static uint32_t
6485lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
6486{
6487 uint32_t intr_mode = LPFC_INTR_ERROR;
6488 int retval, index;
6489
6490 if (cfg_mode == 2) {
6491 /* Preparation before conf_msi mbox cmd */
6492 retval = 0;
6493 if (!retval) {
6494 /* Now, try to enable MSI-X interrupt mode */
6495 retval = lpfc_sli4_enable_msix(phba);
6496 if (!retval) {
6497 /* Indicate initialization to MSI-X mode */
6498 phba->intr_type = MSIX;
6499 intr_mode = 2;
6500 }
6501 }
6502 }
6503
6504 /* Fallback to MSI if MSI-X initialization failed */
6505 if (cfg_mode >= 1 && phba->intr_type == NONE) {
6506 retval = lpfc_sli4_enable_msi(phba);
6507 if (!retval) {
6508 /* Indicate initialization to MSI mode */
6509 phba->intr_type = MSI;
6510 intr_mode = 1;
6511 }
6512 }
6513
6514 /* Fallback to INTx if both MSI-X/MSI initalization failed */
6515 if (phba->intr_type == NONE) {
6516 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
6517 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
6518 if (!retval) {
6519 /* Indicate initialization to INTx mode */
6520 phba->intr_type = INTx;
6521 intr_mode = 0;
6522 for (index = 0; index < phba->cfg_fcp_eq_count;
6523 index++) {
6524 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
6525 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
6526 }
6527 }
6528 }
6529 return intr_mode;
6530}
6531
6532/**
6533 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
6534 * @phba: pointer to lpfc hba data structure.
6535 *
6536 * This routine is invoked to disable device interrupt and disassociate
6537 * the driver's interrupt handler(s) from interrupt vector(s) to device
6538 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
6539 * will release the interrupt vector(s) for the message signaled interrupt.
6540 **/
6541static void
6542lpfc_sli4_disable_intr(struct lpfc_hba *phba)
6543{
6544 /* Disable the currently initialized interrupt mode */
6545 if (phba->intr_type == MSIX)
6546 lpfc_sli4_disable_msix(phba);
6547 else if (phba->intr_type == MSI)
6548 lpfc_sli4_disable_msi(phba);
6549 else if (phba->intr_type == INTx)
6550 free_irq(phba->pcidev->irq, phba);
6551
6552 /* Reset interrupt management states */
6553 phba->intr_type = NONE;
6554 phba->sli.slistat.sli_intr = 0;
6555
6556 return;
6557}
6558
6559/**
James Smart3772a992009-05-22 14:50:54 -04006560 * lpfc_unset_hba - Unset SLI3 hba device initialization
6561 * @phba: pointer to lpfc hba data structure.
6562 *
6563 * This routine is invoked to unset the HBA device initialization steps to
6564 * a device with SLI-3 interface spec.
6565 **/
6566static void
6567lpfc_unset_hba(struct lpfc_hba *phba)
6568{
6569 struct lpfc_vport *vport = phba->pport;
6570 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6571
6572 spin_lock_irq(shost->host_lock);
6573 vport->load_flag |= FC_UNLOADING;
6574 spin_unlock_irq(shost->host_lock);
6575
6576 lpfc_stop_hba_timers(phba);
6577
6578 phba->pport->work_port_events = 0;
6579
6580 lpfc_sli_hba_down(phba);
6581
6582 lpfc_sli_brdrestart(phba);
6583
6584 lpfc_sli_disable_intr(phba);
6585
6586 return;
6587}
6588
6589/**
James Smartda0436e2009-05-22 14:51:39 -04006590 * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization.
6591 * @phba: pointer to lpfc hba data structure.
6592 *
6593 * This routine is invoked to unset the HBA device initialization steps to
6594 * a device with SLI-4 interface spec.
6595 **/
6596static void
6597lpfc_sli4_unset_hba(struct lpfc_hba *phba)
6598{
6599 struct lpfc_vport *vport = phba->pport;
6600 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6601
6602 spin_lock_irq(shost->host_lock);
6603 vport->load_flag |= FC_UNLOADING;
6604 spin_unlock_irq(shost->host_lock);
6605
6606 phba->pport->work_port_events = 0;
6607
6608 lpfc_sli4_hba_down(phba);
6609
6610 lpfc_sli4_disable_intr(phba);
6611
6612 return;
6613}
6614
6615/**
6616 * lpfc_sli4_hba_unset - Unset the fcoe hba
6617 * @phba: Pointer to HBA context object.
6618 *
6619 * This function is called in the SLI4 code path to reset the HBA's FCoE
6620 * function. The caller is not required to hold any lock. This routine
6621 * issues PCI function reset mailbox command to reset the FCoE function.
6622 * At the end of the function, it calls lpfc_hba_down_post function to
6623 * free any pending commands.
6624 **/
6625static void
6626lpfc_sli4_hba_unset(struct lpfc_hba *phba)
6627{
6628 int wait_cnt = 0;
6629 LPFC_MBOXQ_t *mboxq;
6630
6631 lpfc_stop_hba_timers(phba);
6632 phba->sli4_hba.intr_enable = 0;
6633
6634 /*
6635 * Gracefully wait out the potential current outstanding asynchronous
6636 * mailbox command.
6637 */
6638
6639 /* First, block any pending async mailbox command from posted */
6640 spin_lock_irq(&phba->hbalock);
6641 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
6642 spin_unlock_irq(&phba->hbalock);
6643 /* Now, trying to wait it out if we can */
6644 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
6645 msleep(10);
6646 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
6647 break;
6648 }
6649 /* Forcefully release the outstanding mailbox command if timed out */
6650 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
6651 spin_lock_irq(&phba->hbalock);
6652 mboxq = phba->sli.mbox_active;
6653 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
6654 __lpfc_mbox_cmpl_put(phba, mboxq);
6655 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
6656 phba->sli.mbox_active = NULL;
6657 spin_unlock_irq(&phba->hbalock);
6658 }
6659
6660 /* Tear down the queues in the HBA */
6661 lpfc_sli4_queue_unset(phba);
6662
6663 /* Disable PCI subsystem interrupt */
6664 lpfc_sli4_disable_intr(phba);
6665
6666 /* Stop kthread signal shall trigger work_done one more time */
6667 kthread_stop(phba->worker_thread);
6668
6669 /* Stop the SLI4 device port */
6670 phba->pport->work_port_events = 0;
6671}
6672
6673/**
James Smart3772a992009-05-22 14:50:54 -04006674 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
6675 * @pdev: pointer to PCI device
6676 * @pid: pointer to PCI device identifier
6677 *
6678 * This routine is to be called to attach a device with SLI-3 interface spec
6679 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
6680 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
6681 * information of the device and driver to see if the driver state that it can
6682 * support this kind of device. If the match is successful, the driver core
6683 * invokes this routine. If this routine determines it can claim the HBA, it
6684 * does all the initialization that it needs to do to handle the HBA properly.
6685 *
6686 * Return code
6687 * 0 - driver can claim the device
6688 * negative value - driver can not claim the device
6689 **/
6690static int __devinit
6691lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
6692{
6693 struct lpfc_hba *phba;
6694 struct lpfc_vport *vport = NULL;
6695 int error;
6696 uint32_t cfg_mode, intr_mode;
6697
6698 /* Allocate memory for HBA structure */
6699 phba = lpfc_hba_alloc(pdev);
6700 if (!phba)
6701 return -ENOMEM;
6702
6703 /* Perform generic PCI device enabling operation */
6704 error = lpfc_enable_pci_dev(phba);
6705 if (error) {
6706 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6707 "1401 Failed to enable pci device.\n");
6708 goto out_free_phba;
6709 }
6710
6711 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
6712 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
6713 if (error)
6714 goto out_disable_pci_dev;
6715
6716 /* Set up SLI-3 specific device PCI memory space */
6717 error = lpfc_sli_pci_mem_setup(phba);
6718 if (error) {
6719 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6720 "1402 Failed to set up pci memory space.\n");
6721 goto out_disable_pci_dev;
6722 }
6723
6724 /* Set up phase-1 common device driver resources */
6725 error = lpfc_setup_driver_resource_phase1(phba);
6726 if (error) {
6727 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6728 "1403 Failed to set up driver resource.\n");
6729 goto out_unset_pci_mem_s3;
6730 }
6731
6732 /* Set up SLI-3 specific device driver resources */
6733 error = lpfc_sli_driver_resource_setup(phba);
6734 if (error) {
6735 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6736 "1404 Failed to set up driver resource.\n");
6737 goto out_unset_pci_mem_s3;
6738 }
6739
6740 /* Initialize and populate the iocb list per host */
6741 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
6742 if (error) {
6743 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6744 "1405 Failed to initialize iocb list.\n");
6745 goto out_unset_driver_resource_s3;
6746 }
6747
6748 /* Set up common device driver resources */
6749 error = lpfc_setup_driver_resource_phase2(phba);
6750 if (error) {
6751 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6752 "1406 Failed to set up driver resource.\n");
6753 goto out_free_iocb_list;
6754 }
6755
6756 /* Create SCSI host to the physical port */
6757 error = lpfc_create_shost(phba);
6758 if (error) {
6759 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6760 "1407 Failed to create scsi host.\n");
6761 goto out_unset_driver_resource;
6762 }
6763
6764 /* Configure sysfs attributes */
6765 vport = phba->pport;
6766 error = lpfc_alloc_sysfs_attr(vport);
6767 if (error) {
6768 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6769 "1476 Failed to allocate sysfs attr\n");
6770 goto out_destroy_shost;
6771 }
6772
6773 /* Now, trying to enable interrupt and bring up the device */
6774 cfg_mode = phba->cfg_use_msi;
6775 while (true) {
6776 /* Put device to a known state before enabling interrupt */
6777 lpfc_stop_port(phba);
6778 /* Configure and enable interrupt */
6779 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
6780 if (intr_mode == LPFC_INTR_ERROR) {
6781 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6782 "0431 Failed to enable interrupt.\n");
6783 error = -ENODEV;
6784 goto out_free_sysfs_attr;
6785 }
6786 /* SLI-3 HBA setup */
6787 if (lpfc_sli_hba_setup(phba)) {
6788 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6789 "1477 Failed to set up hba\n");
6790 error = -ENODEV;
6791 goto out_remove_device;
6792 }
6793
6794 /* Wait 50ms for the interrupts of previous mailbox commands */
6795 msleep(50);
6796 /* Check active interrupts on message signaled interrupts */
6797 if (intr_mode == 0 ||
6798 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
6799 /* Log the current active interrupt mode */
6800 phba->intr_mode = intr_mode;
6801 lpfc_log_intr_mode(phba, intr_mode);
6802 break;
6803 } else {
6804 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6805 "0447 Configure interrupt mode (%d) "
6806 "failed active interrupt test.\n",
6807 intr_mode);
6808 /* Disable the current interrupt mode */
6809 lpfc_sli_disable_intr(phba);
6810 /* Try next level of interrupt mode */
6811 cfg_mode = --intr_mode;
6812 }
6813 }
6814
6815 /* Perform post initialization setup */
6816 lpfc_post_init_setup(phba);
6817
6818 /* Check if there are static vports to be created. */
6819 lpfc_create_static_vport(phba);
6820
6821 return 0;
6822
6823out_remove_device:
6824 lpfc_unset_hba(phba);
6825out_free_sysfs_attr:
6826 lpfc_free_sysfs_attr(vport);
6827out_destroy_shost:
6828 lpfc_destroy_shost(phba);
6829out_unset_driver_resource:
6830 lpfc_unset_driver_resource_phase2(phba);
6831out_free_iocb_list:
6832 lpfc_free_iocb_list(phba);
6833out_unset_driver_resource_s3:
6834 lpfc_sli_driver_resource_unset(phba);
6835out_unset_pci_mem_s3:
6836 lpfc_sli_pci_mem_unset(phba);
6837out_disable_pci_dev:
6838 lpfc_disable_pci_dev(phba);
6839out_free_phba:
6840 lpfc_hba_free(phba);
6841 return error;
6842}
6843
6844/**
6845 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -04006846 * @pdev: pointer to PCI device
6847 *
James Smart3772a992009-05-22 14:50:54 -04006848 * This routine is to be called to disattach a device with SLI-3 interface
6849 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
6850 * removed from PCI bus, it performs all the necessary cleanup for the HBA
6851 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -04006852 **/
dea31012005-04-17 16:05:31 -05006853static void __devexit
James Smart3772a992009-05-22 14:50:54 -04006854lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -05006855{
James Smart2e0fef82007-06-17 19:56:36 -05006856 struct Scsi_Host *shost = pci_get_drvdata(pdev);
6857 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -05006858 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -05006859 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -05006860 int i;
Tomohiro Kusumi8a4df122008-01-11 01:53:00 -05006861 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
6862
James Smart549e55c2007-08-02 11:09:51 -04006863 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04006864 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04006865 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006866
James Smart858c9f62007-06-17 19:56:39 -05006867 lpfc_free_sysfs_attr(vport);
6868
James Smarteada2722008-12-04 22:39:13 -05006869 /* Release all the vports against this physical port */
6870 vports = lpfc_create_vport_work_array(phba);
6871 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -04006872 for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
James Smarteada2722008-12-04 22:39:13 -05006873 fc_vport_terminate(vports[i]->fc_vport);
6874 lpfc_destroy_vport_work_array(phba, vports);
6875
6876 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -05006877 fc_remove_host(shost);
6878 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04006879 lpfc_cleanup(vport);
6880
James Smart2e0fef82007-06-17 19:56:36 -05006881 /*
6882 * Bring down the SLI Layer. This step disable all interrupts,
6883 * clears the rings, discards all mailbox commands, and resets
6884 * the HBA.
6885 */
James Smarta257bf92009-04-06 18:48:10 -04006886
6887 /* HBA interrupt will be diabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -05006888 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -04006889 /* Stop kthread signal shall trigger work_done one more time */
6890 kthread_stop(phba->worker_thread);
6891 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -05006892 lpfc_sli_brdrestart(phba);
6893
James Smart3772a992009-05-22 14:50:54 -04006894 lpfc_stop_hba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05006895 spin_lock_irq(&phba->hbalock);
6896 list_del_init(&vport->listentry);
6897 spin_unlock_irq(&phba->hbalock);
6898
James Smart858c9f62007-06-17 19:56:39 -05006899 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05006900
James Smart5b75da22008-12-04 22:39:35 -05006901 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -04006902 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -05006903
6904 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05006905 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05006906
6907 /*
6908 * Call scsi_free before mem_free since scsi bufs are released to their
6909 * corresponding pools here.
6910 */
6911 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -04006912 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -05006913
James Smart34b02dc2008-08-24 21:49:55 -04006914 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
6915 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -05006916
James Smart2e0fef82007-06-17 19:56:36 -05006917 /* Free resources associated with SLI2 interface */
6918 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -04006919 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -05006920
6921 /* unmap adapter SLIM and Control Registers */
6922 iounmap(phba->ctrl_regs_memmap_p);
6923 iounmap(phba->slim_memmap_p);
6924
James Smart3772a992009-05-22 14:50:54 -04006925 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -05006926
Tomohiro Kusumi8a4df122008-01-11 01:53:00 -05006927 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05006928 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05006929}
6930
Linas Vepstas8d63f372007-02-14 14:28:36 -06006931/**
James Smart3772a992009-05-22 14:50:54 -04006932 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05006933 * @pdev: pointer to PCI device
6934 * @msg: power management message
6935 *
James Smart3772a992009-05-22 14:50:54 -04006936 * This routine is to be called from the kernel's PCI subsystem to support
6937 * system Power Management (PM) to device with SLI-3 interface spec. When
6938 * PM invokes this method, it quiesces the device by stopping the driver's
6939 * worker thread for the device, turning off device's interrupt and DMA,
6940 * and bring the device offline. Note that as the driver implements the
6941 * minimum PM requirements to a power-aware driver's PM support for the
6942 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
6943 * to the suspend() method call will be treated as SUSPEND and the driver will
6944 * fully reinitialize its device during resume() method call, the driver will
6945 * set device to PCI_D3hot state in PCI config space instead of setting it
6946 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -05006947 *
6948 * Return code
James Smart3772a992009-05-22 14:50:54 -04006949 * 0 - driver suspended the device
6950 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05006951 **/
6952static int
James Smart3772a992009-05-22 14:50:54 -04006953lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -05006954{
6955 struct Scsi_Host *shost = pci_get_drvdata(pdev);
6956 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
6957
6958 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6959 "0473 PCI device Power Management suspend.\n");
6960
6961 /* Bring down the device */
6962 lpfc_offline_prep(phba);
6963 lpfc_offline(phba);
6964 kthread_stop(phba->worker_thread);
6965
6966 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -04006967 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -05006968
6969 /* Save device state to PCI config space */
6970 pci_save_state(pdev);
6971 pci_set_power_state(pdev, PCI_D3hot);
6972
6973 return 0;
6974}
6975
6976/**
James Smart3772a992009-05-22 14:50:54 -04006977 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05006978 * @pdev: pointer to PCI device
6979 *
James Smart3772a992009-05-22 14:50:54 -04006980 * This routine is to be called from the kernel's PCI subsystem to support
6981 * system Power Management (PM) to device with SLI-3 interface spec. When PM
6982 * invokes this method, it restores the device's PCI config space state and
6983 * fully reinitializes the device and brings it online. Note that as the
6984 * driver implements the minimum PM requirements to a power-aware driver's
6985 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
6986 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
6987 * driver will fully reinitialize its device during resume() method call,
6988 * the device will be set to PCI_D0 directly in PCI config space before
6989 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -05006990 *
6991 * Return code
James Smart3772a992009-05-22 14:50:54 -04006992 * 0 - driver suspended the device
6993 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05006994 **/
6995static int
James Smart3772a992009-05-22 14:50:54 -04006996lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -05006997{
6998 struct Scsi_Host *shost = pci_get_drvdata(pdev);
6999 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -05007000 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05007001 int error;
7002
7003 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7004 "0452 PCI device Power Management resume.\n");
7005
7006 /* Restore device state from PCI config space */
7007 pci_set_power_state(pdev, PCI_D0);
7008 pci_restore_state(pdev);
7009 if (pdev->is_busmaster)
7010 pci_set_master(pdev);
7011
7012 /* Startup the kernel thread for this host adapter. */
7013 phba->worker_thread = kthread_run(lpfc_do_work, phba,
7014 "lpfc_worker_%d", phba->brd_no);
7015 if (IS_ERR(phba->worker_thread)) {
7016 error = PTR_ERR(phba->worker_thread);
7017 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7018 "0434 PM resume failed to start worker "
7019 "thread: error=x%x.\n", error);
7020 return error;
7021 }
7022
James Smart5b75da22008-12-04 22:39:35 -05007023 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04007024 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05007025 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -05007026 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -05007027 "0430 PM resume Failed to enable interrupt\n");
7028 return -EIO;
7029 } else
7030 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05007031
7032 /* Restart HBA and bring it online */
7033 lpfc_sli_brdrestart(phba);
7034 lpfc_online(phba);
7035
James Smart5b75da22008-12-04 22:39:35 -05007036 /* Log the current active interrupt mode */
7037 lpfc_log_intr_mode(phba, phba->intr_mode);
7038
James Smart3a55b532008-12-04 22:38:54 -05007039 return 0;
7040}
7041
7042/**
James Smart3772a992009-05-22 14:50:54 -04007043 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -04007044 * @pdev: pointer to PCI device.
7045 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -06007046 *
James Smart3772a992009-05-22 14:50:54 -04007047 * This routine is called from the PCI subsystem for I/O error handling to
7048 * device with SLI-3 interface spec. This function is called by the PCI
7049 * subsystem after a PCI bus error affecting this device has been detected.
7050 * When this function is invoked, it will need to stop all the I/Os and
7051 * interrupt(s) to the device. Once that is done, it will return
7052 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
7053 * as desired.
James Smarte59058c2008-08-24 21:49:00 -04007054 *
7055 * Return codes
James Smart3772a992009-05-22 14:50:54 -04007056 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
7057 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -04007058 **/
James Smart3772a992009-05-22 14:50:54 -04007059static pci_ers_result_t
7060lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -06007061{
James Smart51ef4c22007-08-02 11:10:31 -04007062 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7063 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06007064 struct lpfc_sli *psli = &phba->sli;
7065 struct lpfc_sli_ring *pring;
7066
James Smarta8e497d2008-08-24 21:50:11 -04007067 if (state == pci_channel_io_perm_failure) {
7068 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7069 "0472 PCI channel I/O permanent failure\n");
7070 /* Block all SCSI devices' I/Os on the host */
7071 lpfc_scsi_dev_block(phba);
7072 /* Clean up all driver's outstanding SCSI I/Os */
7073 lpfc_sli_flush_fcp_rings(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06007074 return PCI_ERS_RESULT_DISCONNECT;
James Smarta8e497d2008-08-24 21:50:11 -04007075 }
Linas Vepstas5daa49e2007-03-08 16:19:11 -06007076
Linas Vepstas8d63f372007-02-14 14:28:36 -06007077 pci_disable_device(pdev);
7078 /*
7079 * There may be I/Os dropped by the firmware.
7080 * Error iocb (I/O) on txcmplq and let the SCSI layer
7081 * retry it after re-establishing link.
7082 */
7083 pring = &psli->ring[psli->fcp_ring];
7084 lpfc_sli_abort_iocb_ring(phba, pring);
7085
James Smart5b75da22008-12-04 22:39:35 -05007086 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -04007087 lpfc_sli_disable_intr(phba);
James Smart51ef4c22007-08-02 11:10:31 -04007088
Linas Vepstas8d63f372007-02-14 14:28:36 -06007089 /* Request a slot reset. */
7090 return PCI_ERS_RESULT_NEED_RESET;
7091}
7092
7093/**
James Smart3772a992009-05-22 14:50:54 -04007094 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -04007095 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -06007096 *
James Smart3772a992009-05-22 14:50:54 -04007097 * This routine is called from the PCI subsystem for error handling to
7098 * device with SLI-3 interface spec. This is called after PCI bus has been
7099 * reset to restart the PCI card from scratch, as if from a cold-boot.
7100 * During the PCI subsystem error recovery, after driver returns
7101 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
7102 * recovery and then call this routine before calling the .resume method
7103 * to recover the device. This function will initialize the HBA device,
7104 * enable the interrupt, but it will just put the HBA to offline state
7105 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -04007106 *
7107 * Return codes
James Smart3772a992009-05-22 14:50:54 -04007108 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
7109 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -06007110 */
James Smart3772a992009-05-22 14:50:54 -04007111static pci_ers_result_t
7112lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -06007113{
James Smart51ef4c22007-08-02 11:10:31 -04007114 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7115 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06007116 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -05007117 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06007118
7119 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11007120 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -06007121 printk(KERN_ERR "lpfc: Cannot re-enable "
7122 "PCI device after reset.\n");
7123 return PCI_ERS_RESULT_DISCONNECT;
7124 }
7125
James Smart97207482008-12-04 22:39:19 -05007126 pci_restore_state(pdev);
7127 if (pdev->is_busmaster)
7128 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -06007129
James Smart92d7f7b2007-06-17 19:56:38 -05007130 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -04007131 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05007132 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06007133
James Smart5b75da22008-12-04 22:39:35 -05007134 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04007135 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05007136 if (intr_mode == LPFC_INTR_ERROR) {
7137 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7138 "0427 Cannot re-enable interrupt after "
7139 "slot reset.\n");
7140 return PCI_ERS_RESULT_DISCONNECT;
7141 } else
7142 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06007143
7144 /* Take device offline; this will perform cleanup */
7145 lpfc_offline(phba);
7146 lpfc_sli_brdrestart(phba);
7147
James Smart5b75da22008-12-04 22:39:35 -05007148 /* Log the current active interrupt mode */
7149 lpfc_log_intr_mode(phba, phba->intr_mode);
7150
Linas Vepstas8d63f372007-02-14 14:28:36 -06007151 return PCI_ERS_RESULT_RECOVERED;
7152}
7153
7154/**
James Smart3772a992009-05-22 14:50:54 -04007155 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -04007156 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -06007157 *
James Smart3772a992009-05-22 14:50:54 -04007158 * This routine is called from the PCI subsystem for error handling to device
7159 * with SLI-3 interface spec. It is called when kernel error recovery tells
7160 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
7161 * error recovery. After this call, traffic can start to flow from this device
7162 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -06007163 */
James Smart3772a992009-05-22 14:50:54 -04007164static void
7165lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -06007166{
James Smart51ef4c22007-08-02 11:10:31 -04007167 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7168 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06007169
James Smart58da1ff2008-04-07 10:15:56 -04007170 lpfc_online(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06007171}
7172
James Smart3772a992009-05-22 14:50:54 -04007173/**
James Smartda0436e2009-05-22 14:51:39 -04007174 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
7175 * @phba: pointer to lpfc hba data structure.
7176 *
7177 * returns the number of ELS/CT IOCBs to reserve
7178 **/
7179int
7180lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
7181{
7182 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
7183
James Smartf1126682009-06-10 17:22:44 -04007184 if (phba->sli_rev == LPFC_SLI_REV4) {
7185 if (max_xri <= 100)
7186 return 4;
7187 else if (max_xri <= 256)
7188 return 8;
7189 else if (max_xri <= 512)
7190 return 16;
7191 else if (max_xri <= 1024)
7192 return 32;
7193 else
7194 return 48;
7195 } else
7196 return 0;
James Smartda0436e2009-05-22 14:51:39 -04007197}
7198
7199/**
7200 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
7201 * @pdev: pointer to PCI device
7202 * @pid: pointer to PCI device identifier
7203 *
7204 * This routine is called from the kernel's PCI subsystem to device with
7205 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
7206 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
7207 * information of the device and driver to see if the driver state that it
7208 * can support this kind of device. If the match is successful, the driver
7209 * core invokes this routine. If this routine determines it can claim the HBA,
7210 * it does all the initialization that it needs to do to handle the HBA
7211 * properly.
7212 *
7213 * Return code
7214 * 0 - driver can claim the device
7215 * negative value - driver can not claim the device
7216 **/
7217static int __devinit
7218lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
7219{
7220 struct lpfc_hba *phba;
7221 struct lpfc_vport *vport = NULL;
7222 int error;
7223 uint32_t cfg_mode, intr_mode;
7224 int mcnt;
7225
7226 /* Allocate memory for HBA structure */
7227 phba = lpfc_hba_alloc(pdev);
7228 if (!phba)
7229 return -ENOMEM;
7230
7231 /* Perform generic PCI device enabling operation */
7232 error = lpfc_enable_pci_dev(phba);
7233 if (error) {
7234 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7235 "1409 Failed to enable pci device.\n");
7236 goto out_free_phba;
7237 }
7238
7239 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
7240 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
7241 if (error)
7242 goto out_disable_pci_dev;
7243
7244 /* Set up SLI-4 specific device PCI memory space */
7245 error = lpfc_sli4_pci_mem_setup(phba);
7246 if (error) {
7247 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7248 "1410 Failed to set up pci memory space.\n");
7249 goto out_disable_pci_dev;
7250 }
7251
7252 /* Set up phase-1 common device driver resources */
7253 error = lpfc_setup_driver_resource_phase1(phba);
7254 if (error) {
7255 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7256 "1411 Failed to set up driver resource.\n");
7257 goto out_unset_pci_mem_s4;
7258 }
7259
7260 /* Set up SLI-4 Specific device driver resources */
7261 error = lpfc_sli4_driver_resource_setup(phba);
7262 if (error) {
7263 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7264 "1412 Failed to set up driver resource.\n");
7265 goto out_unset_pci_mem_s4;
7266 }
7267
7268 /* Initialize and populate the iocb list per host */
7269 error = lpfc_init_iocb_list(phba,
7270 phba->sli4_hba.max_cfg_param.max_xri);
7271 if (error) {
7272 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7273 "1413 Failed to initialize iocb list.\n");
7274 goto out_unset_driver_resource_s4;
7275 }
7276
7277 /* Set up common device driver resources */
7278 error = lpfc_setup_driver_resource_phase2(phba);
7279 if (error) {
7280 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7281 "1414 Failed to set up driver resource.\n");
7282 goto out_free_iocb_list;
7283 }
7284
7285 /* Create SCSI host to the physical port */
7286 error = lpfc_create_shost(phba);
7287 if (error) {
7288 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7289 "1415 Failed to create scsi host.\n");
7290 goto out_unset_driver_resource;
7291 }
7292
7293 /* Configure sysfs attributes */
7294 vport = phba->pport;
7295 error = lpfc_alloc_sysfs_attr(vport);
7296 if (error) {
7297 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7298 "1416 Failed to allocate sysfs attr\n");
7299 goto out_destroy_shost;
7300 }
7301
7302 /* Now, trying to enable interrupt and bring up the device */
7303 cfg_mode = phba->cfg_use_msi;
7304 while (true) {
7305 /* Put device to a known state before enabling interrupt */
7306 lpfc_stop_port(phba);
7307 /* Configure and enable interrupt */
7308 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
7309 if (intr_mode == LPFC_INTR_ERROR) {
7310 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7311 "0426 Failed to enable interrupt.\n");
7312 error = -ENODEV;
7313 goto out_free_sysfs_attr;
7314 }
7315 /* Set up SLI-4 HBA */
7316 if (lpfc_sli4_hba_setup(phba)) {
7317 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7318 "1421 Failed to set up hba\n");
7319 error = -ENODEV;
7320 goto out_disable_intr;
7321 }
7322
7323 /* Send NOP mbx cmds for non-INTx mode active interrupt test */
7324 if (intr_mode != 0)
7325 mcnt = lpfc_sli4_send_nop_mbox_cmds(phba,
7326 LPFC_ACT_INTR_CNT);
7327
7328 /* Check active interrupts received only for MSI/MSI-X */
7329 if (intr_mode == 0 ||
7330 phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) {
7331 /* Log the current active interrupt mode */
7332 phba->intr_mode = intr_mode;
7333 lpfc_log_intr_mode(phba, intr_mode);
7334 break;
7335 }
7336 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7337 "0451 Configure interrupt mode (%d) "
7338 "failed active interrupt test.\n",
7339 intr_mode);
7340 /* Unset the preivous SLI-4 HBA setup */
7341 lpfc_sli4_unset_hba(phba);
7342 /* Try next level of interrupt mode */
7343 cfg_mode = --intr_mode;
7344 }
7345
7346 /* Perform post initialization setup */
7347 lpfc_post_init_setup(phba);
7348
7349 return 0;
7350
7351out_disable_intr:
7352 lpfc_sli4_disable_intr(phba);
7353out_free_sysfs_attr:
7354 lpfc_free_sysfs_attr(vport);
7355out_destroy_shost:
7356 lpfc_destroy_shost(phba);
7357out_unset_driver_resource:
7358 lpfc_unset_driver_resource_phase2(phba);
7359out_free_iocb_list:
7360 lpfc_free_iocb_list(phba);
7361out_unset_driver_resource_s4:
7362 lpfc_sli4_driver_resource_unset(phba);
7363out_unset_pci_mem_s4:
7364 lpfc_sli4_pci_mem_unset(phba);
7365out_disable_pci_dev:
7366 lpfc_disable_pci_dev(phba);
7367out_free_phba:
7368 lpfc_hba_free(phba);
7369 return error;
7370}
7371
7372/**
7373 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
7374 * @pdev: pointer to PCI device
7375 *
7376 * This routine is called from the kernel's PCI subsystem to device with
7377 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
7378 * removed from PCI bus, it performs all the necessary cleanup for the HBA
7379 * device to be removed from the PCI subsystem properly.
7380 **/
7381static void __devexit
7382lpfc_pci_remove_one_s4(struct pci_dev *pdev)
7383{
7384 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7385 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
7386 struct lpfc_vport **vports;
7387 struct lpfc_hba *phba = vport->phba;
7388 int i;
7389
7390 /* Mark the device unloading flag */
7391 spin_lock_irq(&phba->hbalock);
7392 vport->load_flag |= FC_UNLOADING;
7393 spin_unlock_irq(&phba->hbalock);
7394
7395 /* Free the HBA sysfs attributes */
7396 lpfc_free_sysfs_attr(vport);
7397
7398 /* Release all the vports against this physical port */
7399 vports = lpfc_create_vport_work_array(phba);
7400 if (vports != NULL)
7401 for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
7402 fc_vport_terminate(vports[i]->fc_vport);
7403 lpfc_destroy_vport_work_array(phba, vports);
7404
7405 /* Remove FC host and then SCSI host with the physical port */
7406 fc_remove_host(shost);
7407 scsi_remove_host(shost);
7408
7409 /* Perform cleanup on the physical port */
7410 lpfc_cleanup(vport);
7411
7412 /*
7413 * Bring down the SLI Layer. This step disables all interrupts,
7414 * clears the rings, discards all mailbox commands, and resets
7415 * the HBA FCoE function.
7416 */
7417 lpfc_debugfs_terminate(vport);
7418 lpfc_sli4_hba_unset(phba);
7419
7420 spin_lock_irq(&phba->hbalock);
7421 list_del_init(&vport->listentry);
7422 spin_unlock_irq(&phba->hbalock);
7423
7424 /* Call scsi_free before lpfc_sli4_driver_resource_unset since scsi
7425 * buffers are released to their corresponding pools here.
7426 */
7427 lpfc_scsi_free(phba);
7428 lpfc_sli4_driver_resource_unset(phba);
7429
7430 /* Unmap adapter Control and Doorbell registers */
7431 lpfc_sli4_pci_mem_unset(phba);
7432
7433 /* Release PCI resources and disable device's PCI function */
7434 scsi_host_put(shost);
7435 lpfc_disable_pci_dev(phba);
7436
7437 /* Finally, free the driver's device data structure */
7438 lpfc_hba_free(phba);
7439
7440 return;
7441}
7442
7443/**
7444 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
7445 * @pdev: pointer to PCI device
7446 * @msg: power management message
7447 *
7448 * This routine is called from the kernel's PCI subsystem to support system
7449 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
7450 * this method, it quiesces the device by stopping the driver's worker
7451 * thread for the device, turning off device's interrupt and DMA, and bring
7452 * the device offline. Note that as the driver implements the minimum PM
7453 * requirements to a power-aware driver's PM support for suspend/resume -- all
7454 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
7455 * method call will be treated as SUSPEND and the driver will fully
7456 * reinitialize its device during resume() method call, the driver will set
7457 * device to PCI_D3hot state in PCI config space instead of setting it
7458 * according to the @msg provided by the PM.
7459 *
7460 * Return code
7461 * 0 - driver suspended the device
7462 * Error otherwise
7463 **/
7464static int
7465lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
7466{
7467 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7468 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
7469
7470 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7471 "0298 PCI device Power Management suspend.\n");
7472
7473 /* Bring down the device */
7474 lpfc_offline_prep(phba);
7475 lpfc_offline(phba);
7476 kthread_stop(phba->worker_thread);
7477
7478 /* Disable interrupt from device */
7479 lpfc_sli4_disable_intr(phba);
7480
7481 /* Save device state to PCI config space */
7482 pci_save_state(pdev);
7483 pci_set_power_state(pdev, PCI_D3hot);
7484
7485 return 0;
7486}
7487
7488/**
7489 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
7490 * @pdev: pointer to PCI device
7491 *
7492 * This routine is called from the kernel's PCI subsystem to support system
7493 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
7494 * this method, it restores the device's PCI config space state and fully
7495 * reinitializes the device and brings it online. Note that as the driver
7496 * implements the minimum PM requirements to a power-aware driver's PM for
7497 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
7498 * to the suspend() method call will be treated as SUSPEND and the driver
7499 * will fully reinitialize its device during resume() method call, the device
7500 * will be set to PCI_D0 directly in PCI config space before restoring the
7501 * state.
7502 *
7503 * Return code
7504 * 0 - driver suspended the device
7505 * Error otherwise
7506 **/
7507static int
7508lpfc_pci_resume_one_s4(struct pci_dev *pdev)
7509{
7510 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7511 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
7512 uint32_t intr_mode;
7513 int error;
7514
7515 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7516 "0292 PCI device Power Management resume.\n");
7517
7518 /* Restore device state from PCI config space */
7519 pci_set_power_state(pdev, PCI_D0);
7520 pci_restore_state(pdev);
7521 if (pdev->is_busmaster)
7522 pci_set_master(pdev);
7523
7524 /* Startup the kernel thread for this host adapter. */
7525 phba->worker_thread = kthread_run(lpfc_do_work, phba,
7526 "lpfc_worker_%d", phba->brd_no);
7527 if (IS_ERR(phba->worker_thread)) {
7528 error = PTR_ERR(phba->worker_thread);
7529 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7530 "0293 PM resume failed to start worker "
7531 "thread: error=x%x.\n", error);
7532 return error;
7533 }
7534
7535 /* Configure and enable interrupt */
7536 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
7537 if (intr_mode == LPFC_INTR_ERROR) {
7538 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7539 "0294 PM resume Failed to enable interrupt\n");
7540 return -EIO;
7541 } else
7542 phba->intr_mode = intr_mode;
7543
7544 /* Restart HBA and bring it online */
7545 lpfc_sli_brdrestart(phba);
7546 lpfc_online(phba);
7547
7548 /* Log the current active interrupt mode */
7549 lpfc_log_intr_mode(phba, phba->intr_mode);
7550
7551 return 0;
7552}
7553
7554/**
7555 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
7556 * @pdev: pointer to PCI device.
7557 * @state: the current PCI connection state.
7558 *
7559 * This routine is called from the PCI subsystem for error handling to device
7560 * with SLI-4 interface spec. This function is called by the PCI subsystem
7561 * after a PCI bus error affecting this device has been detected. When this
7562 * function is invoked, it will need to stop all the I/Os and interrupt(s)
7563 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
7564 * for the PCI subsystem to perform proper recovery as desired.
7565 *
7566 * Return codes
7567 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
7568 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
7569 **/
7570static pci_ers_result_t
7571lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
7572{
7573 return PCI_ERS_RESULT_NEED_RESET;
7574}
7575
7576/**
7577 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
7578 * @pdev: pointer to PCI device.
7579 *
7580 * This routine is called from the PCI subsystem for error handling to device
7581 * with SLI-4 interface spec. It is called after PCI bus has been reset to
7582 * restart the PCI card from scratch, as if from a cold-boot. During the
7583 * PCI subsystem error recovery, after the driver returns
7584 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
7585 * recovery and then call this routine before calling the .resume method to
7586 * recover the device. This function will initialize the HBA device, enable
7587 * the interrupt, but it will just put the HBA to offline state without
7588 * passing any I/O traffic.
7589 *
7590 * Return codes
7591 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
7592 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
7593 */
7594static pci_ers_result_t
7595lpfc_io_slot_reset_s4(struct pci_dev *pdev)
7596{
7597 return PCI_ERS_RESULT_RECOVERED;
7598}
7599
7600/**
7601 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
7602 * @pdev: pointer to PCI device
7603 *
7604 * This routine is called from the PCI subsystem for error handling to device
7605 * with SLI-4 interface spec. It is called when kernel error recovery tells
7606 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
7607 * error recovery. After this call, traffic can start to flow from this device
7608 * again.
7609 **/
7610static void
7611lpfc_io_resume_s4(struct pci_dev *pdev)
7612{
7613 return;
7614}
7615
7616/**
James Smart3772a992009-05-22 14:50:54 -04007617 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
7618 * @pdev: pointer to PCI device
7619 * @pid: pointer to PCI device identifier
7620 *
7621 * This routine is to be registered to the kernel's PCI subsystem. When an
7622 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
7623 * at PCI device-specific information of the device and driver to see if the
7624 * driver state that it can support this kind of device. If the match is
7625 * successful, the driver core invokes this routine. This routine dispatches
7626 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
7627 * do all the initialization that it needs to do to handle the HBA device
7628 * properly.
7629 *
7630 * Return code
7631 * 0 - driver can claim the device
7632 * negative value - driver can not claim the device
7633 **/
7634static int __devinit
7635lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
7636{
7637 int rc;
James Smart8fa38512009-07-19 10:01:03 -04007638 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -04007639
James Smart8fa38512009-07-19 10:01:03 -04007640 if (pci_read_config_dword(pdev, LPFC_SLIREV_CONF_WORD, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -04007641 return -ENODEV;
7642
James Smart8fa38512009-07-19 10:01:03 -04007643 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
7644 (bf_get(lpfc_sli_intf_rev, &intf) == LPFC_SLIREV_CONF_SLI4))
James Smartda0436e2009-05-22 14:51:39 -04007645 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -04007646 else
James Smart3772a992009-05-22 14:50:54 -04007647 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -04007648
James Smart3772a992009-05-22 14:50:54 -04007649 return rc;
7650}
7651
7652/**
7653 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
7654 * @pdev: pointer to PCI device
7655 *
7656 * This routine is to be registered to the kernel's PCI subsystem. When an
7657 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
7658 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
7659 * remove routine, which will perform all the necessary cleanup for the
7660 * device to be removed from the PCI subsystem properly.
7661 **/
7662static void __devexit
7663lpfc_pci_remove_one(struct pci_dev *pdev)
7664{
7665 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7666 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
7667
7668 switch (phba->pci_dev_grp) {
7669 case LPFC_PCI_DEV_LP:
7670 lpfc_pci_remove_one_s3(pdev);
7671 break;
James Smartda0436e2009-05-22 14:51:39 -04007672 case LPFC_PCI_DEV_OC:
7673 lpfc_pci_remove_one_s4(pdev);
7674 break;
James Smart3772a992009-05-22 14:50:54 -04007675 default:
7676 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7677 "1424 Invalid PCI device group: 0x%x\n",
7678 phba->pci_dev_grp);
7679 break;
7680 }
7681 return;
7682}
7683
7684/**
7685 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
7686 * @pdev: pointer to PCI device
7687 * @msg: power management message
7688 *
7689 * This routine is to be registered to the kernel's PCI subsystem to support
7690 * system Power Management (PM). When PM invokes this method, it dispatches
7691 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
7692 * suspend the device.
7693 *
7694 * Return code
7695 * 0 - driver suspended the device
7696 * Error otherwise
7697 **/
7698static int
7699lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
7700{
7701 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7702 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
7703 int rc = -ENODEV;
7704
7705 switch (phba->pci_dev_grp) {
7706 case LPFC_PCI_DEV_LP:
7707 rc = lpfc_pci_suspend_one_s3(pdev, msg);
7708 break;
James Smartda0436e2009-05-22 14:51:39 -04007709 case LPFC_PCI_DEV_OC:
7710 rc = lpfc_pci_suspend_one_s4(pdev, msg);
7711 break;
James Smart3772a992009-05-22 14:50:54 -04007712 default:
7713 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7714 "1425 Invalid PCI device group: 0x%x\n",
7715 phba->pci_dev_grp);
7716 break;
7717 }
7718 return rc;
7719}
7720
7721/**
7722 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
7723 * @pdev: pointer to PCI device
7724 *
7725 * This routine is to be registered to the kernel's PCI subsystem to support
7726 * system Power Management (PM). When PM invokes this method, it dispatches
7727 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
7728 * resume the device.
7729 *
7730 * Return code
7731 * 0 - driver suspended the device
7732 * Error otherwise
7733 **/
7734static int
7735lpfc_pci_resume_one(struct pci_dev *pdev)
7736{
7737 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7738 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
7739 int rc = -ENODEV;
7740
7741 switch (phba->pci_dev_grp) {
7742 case LPFC_PCI_DEV_LP:
7743 rc = lpfc_pci_resume_one_s3(pdev);
7744 break;
James Smartda0436e2009-05-22 14:51:39 -04007745 case LPFC_PCI_DEV_OC:
7746 rc = lpfc_pci_resume_one_s4(pdev);
7747 break;
James Smart3772a992009-05-22 14:50:54 -04007748 default:
7749 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7750 "1426 Invalid PCI device group: 0x%x\n",
7751 phba->pci_dev_grp);
7752 break;
7753 }
7754 return rc;
7755}
7756
7757/**
7758 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
7759 * @pdev: pointer to PCI device.
7760 * @state: the current PCI connection state.
7761 *
7762 * This routine is registered to the PCI subsystem for error handling. This
7763 * function is called by the PCI subsystem after a PCI bus error affecting
7764 * this device has been detected. When this routine is invoked, it dispatches
7765 * the action to the proper SLI-3 or SLI-4 device error detected handling
7766 * routine, which will perform the proper error detected operation.
7767 *
7768 * Return codes
7769 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
7770 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
7771 **/
7772static pci_ers_result_t
7773lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
7774{
7775 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7776 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
7777 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
7778
7779 switch (phba->pci_dev_grp) {
7780 case LPFC_PCI_DEV_LP:
7781 rc = lpfc_io_error_detected_s3(pdev, state);
7782 break;
James Smartda0436e2009-05-22 14:51:39 -04007783 case LPFC_PCI_DEV_OC:
7784 rc = lpfc_io_error_detected_s4(pdev, state);
7785 break;
James Smart3772a992009-05-22 14:50:54 -04007786 default:
7787 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7788 "1427 Invalid PCI device group: 0x%x\n",
7789 phba->pci_dev_grp);
7790 break;
7791 }
7792 return rc;
7793}
7794
7795/**
7796 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
7797 * @pdev: pointer to PCI device.
7798 *
7799 * This routine is registered to the PCI subsystem for error handling. This
7800 * function is called after PCI bus has been reset to restart the PCI card
7801 * from scratch, as if from a cold-boot. When this routine is invoked, it
7802 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
7803 * routine, which will perform the proper device reset.
7804 *
7805 * Return codes
7806 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
7807 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
7808 **/
7809static pci_ers_result_t
7810lpfc_io_slot_reset(struct pci_dev *pdev)
7811{
7812 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7813 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
7814 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
7815
7816 switch (phba->pci_dev_grp) {
7817 case LPFC_PCI_DEV_LP:
7818 rc = lpfc_io_slot_reset_s3(pdev);
7819 break;
James Smartda0436e2009-05-22 14:51:39 -04007820 case LPFC_PCI_DEV_OC:
7821 rc = lpfc_io_slot_reset_s4(pdev);
7822 break;
James Smart3772a992009-05-22 14:50:54 -04007823 default:
7824 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7825 "1428 Invalid PCI device group: 0x%x\n",
7826 phba->pci_dev_grp);
7827 break;
7828 }
7829 return rc;
7830}
7831
7832/**
7833 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
7834 * @pdev: pointer to PCI device
7835 *
7836 * This routine is registered to the PCI subsystem for error handling. It
7837 * is called when kernel error recovery tells the lpfc driver that it is
7838 * OK to resume normal PCI operation after PCI bus error recovery. When
7839 * this routine is invoked, it dispatches the action to the proper SLI-3
7840 * or SLI-4 device io_resume routine, which will resume the device operation.
7841 **/
7842static void
7843lpfc_io_resume(struct pci_dev *pdev)
7844{
7845 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7846 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
7847
7848 switch (phba->pci_dev_grp) {
7849 case LPFC_PCI_DEV_LP:
7850 lpfc_io_resume_s3(pdev);
7851 break;
James Smartda0436e2009-05-22 14:51:39 -04007852 case LPFC_PCI_DEV_OC:
7853 lpfc_io_resume_s4(pdev);
7854 break;
James Smart3772a992009-05-22 14:50:54 -04007855 default:
7856 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7857 "1429 Invalid PCI device group: 0x%x\n",
7858 phba->pci_dev_grp);
7859 break;
7860 }
7861 return;
7862}
7863
dea31012005-04-17 16:05:31 -05007864static struct pci_device_id lpfc_id_table[] = {
7865 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
7866 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04007867 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
7868 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05007869 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
7870 PCI_ANY_ID, PCI_ANY_ID, },
7871 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
7872 PCI_ANY_ID, PCI_ANY_ID, },
7873 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
7874 PCI_ANY_ID, PCI_ANY_ID, },
7875 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
7876 PCI_ANY_ID, PCI_ANY_ID, },
7877 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
7878 PCI_ANY_ID, PCI_ANY_ID, },
7879 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
7880 PCI_ANY_ID, PCI_ANY_ID, },
7881 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
7882 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05007883 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
7884 PCI_ANY_ID, PCI_ANY_ID, },
7885 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
7886 PCI_ANY_ID, PCI_ANY_ID, },
7887 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
7888 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05007889 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
7890 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05007891 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
7892 PCI_ANY_ID, PCI_ANY_ID, },
7893 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
7894 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05007895 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
7896 PCI_ANY_ID, PCI_ANY_ID, },
7897 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
7898 PCI_ANY_ID, PCI_ANY_ID, },
7899 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
7900 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -04007901 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
7902 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05007903 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
7904 PCI_ANY_ID, PCI_ANY_ID, },
7905 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
7906 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05007907 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
7908 PCI_ANY_ID, PCI_ANY_ID, },
7909 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
7910 PCI_ANY_ID, PCI_ANY_ID, },
7911 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
7912 PCI_ANY_ID, PCI_ANY_ID, },
7913 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
7914 PCI_ANY_ID, PCI_ANY_ID, },
7915 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
7916 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05007917 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
7918 PCI_ANY_ID, PCI_ANY_ID, },
7919 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
7920 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -04007921 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
7922 PCI_ANY_ID, PCI_ANY_ID, },
7923 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
7924 PCI_ANY_ID, PCI_ANY_ID, },
7925 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
7926 PCI_ANY_ID, PCI_ANY_ID, },
7927 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
7928 PCI_ANY_ID, PCI_ANY_ID, },
7929 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
7930 PCI_ANY_ID, PCI_ANY_ID, },
7931 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
7932 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -04007933 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
7934 PCI_ANY_ID, PCI_ANY_ID, },
7935 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
7936 PCI_ANY_ID, PCI_ANY_ID, },
7937 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
7938 PCI_ANY_ID, PCI_ANY_ID, },
James Smart3772a992009-05-22 14:50:54 -04007939 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
7940 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05007941 { 0 }
7942};
7943
7944MODULE_DEVICE_TABLE(pci, lpfc_id_table);
7945
Linas Vepstas8d63f372007-02-14 14:28:36 -06007946static struct pci_error_handlers lpfc_err_handler = {
7947 .error_detected = lpfc_io_error_detected,
7948 .slot_reset = lpfc_io_slot_reset,
7949 .resume = lpfc_io_resume,
7950};
7951
dea31012005-04-17 16:05:31 -05007952static struct pci_driver lpfc_driver = {
7953 .name = LPFC_DRIVER_NAME,
7954 .id_table = lpfc_id_table,
7955 .probe = lpfc_pci_probe_one,
7956 .remove = __devexit_p(lpfc_pci_remove_one),
James Smart3a55b532008-12-04 22:38:54 -05007957 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -04007958 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -05007959 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -05007960};
7961
James Smarte59058c2008-08-24 21:49:00 -04007962/**
James Smart3621a712009-04-06 18:47:14 -04007963 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -04007964 *
7965 * This routine is to be invoked when the lpfc module is loaded into the
7966 * kernel. The special kernel macro module_init() is used to indicate the
7967 * role of this routine to the kernel as lpfc module entry point.
7968 *
7969 * Return codes
7970 * 0 - successful
7971 * -ENOMEM - FC attach transport failed
7972 * all others - failed
7973 */
dea31012005-04-17 16:05:31 -05007974static int __init
7975lpfc_init(void)
7976{
7977 int error = 0;
7978
7979 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007980 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -05007981
James Smart7ee5d432007-10-27 13:37:17 -04007982 if (lpfc_enable_npiv) {
7983 lpfc_transport_functions.vport_create = lpfc_vport_create;
7984 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
7985 }
dea31012005-04-17 16:05:31 -05007986 lpfc_transport_template =
7987 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -04007988 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -05007989 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -04007990 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -04007991 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -04007992 fc_attach_transport(&lpfc_vport_transport_functions);
7993 if (lpfc_vport_transport_template == NULL) {
7994 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04007995 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -04007996 }
James Smart7ee5d432007-10-27 13:37:17 -04007997 }
dea31012005-04-17 16:05:31 -05007998 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -05007999 if (error) {
dea31012005-04-17 16:05:31 -05008000 fc_release_transport(lpfc_transport_template);
James Smartd7c255b2008-08-24 21:50:00 -04008001 if (lpfc_enable_npiv)
8002 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -05008003 }
dea31012005-04-17 16:05:31 -05008004
8005 return error;
8006}
8007
James Smarte59058c2008-08-24 21:49:00 -04008008/**
James Smart3621a712009-04-06 18:47:14 -04008009 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -04008010 *
8011 * This routine is invoked when the lpfc module is removed from the kernel.
8012 * The special kernel macro module_exit() is used to indicate the role of
8013 * this routine to the kernel as lpfc module exit point.
8014 */
dea31012005-04-17 16:05:31 -05008015static void __exit
8016lpfc_exit(void)
8017{
8018 pci_unregister_driver(&lpfc_driver);
8019 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04008020 if (lpfc_enable_npiv)
8021 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -05008022 if (_dump_buf_data) {
8023 printk(KERN_ERR "BLKGRD freeing %lu pages for _dump_buf_data "
8024 "at 0x%p\n",
8025 (1L << _dump_buf_data_order), _dump_buf_data);
8026 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
8027 }
8028
8029 if (_dump_buf_dif) {
8030 printk(KERN_ERR "BLKGRD freeing %lu pages for _dump_buf_dif "
8031 "at 0x%p\n",
8032 (1L << _dump_buf_dif_order), _dump_buf_dif);
8033 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
8034 }
dea31012005-04-17 16:05:31 -05008035}
8036
8037module_init(lpfc_init);
8038module_exit(lpfc_exit);
8039MODULE_LICENSE("GPL");
8040MODULE_DESCRIPTION(LPFC_MODULE_DESC);
8041MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
8042MODULE_VERSION("0:" LPFC_DRIVER_VERSION);